/* Copyright (c) 1997-2006 Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany) http://www.math.tu-berlin.de/polymake, mailto:polymake@math.tu-berlin.de This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version: http://www.gnu.org/licenses/gpl.txt. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #ifndef _POLYMAKE_SPRING_EMBEDDER_H #define _POLYMAKE_SPRING_EMBEDDER_H "$Project: polymake $$Id: SpringEmbedder.h 7487 2006-12-06 15:16:09Z gawrilow $" #include #include #include #include #include #include namespace polymake { namespace graph { struct se_edge_attr { double wanted_length, inv_wanted_length; se_edge_attr() : wanted_length(1) { } explicit se_edge_attr(double d) : wanted_length(d) { } template friend Input& operator>> (GenericInput& is, se_edge_attr& me) { return is.top() >> me.wanted_length; } template friend Output& operator<< (GenericOutput& is, const se_edge_attr& me) { return is.top() << me.wanted_length; } bool operator== (const se_edge_attr& e) const { return wanted_length == e.wanted_length; } bool operator< (const se_edge_attr& e) const { return wanted_length < e.wanted_length; } bool operator> (const se_edge_attr& e) const { return wanted_length > e.wanted_length; } }; struct se_traits { static const int dim=3; typedef se_node_attr node_attr; typedef Graph graph_type; }; class SpringEmbedder : public SpringEmbedderBase { typedef SpringEmbedderBase _super; friend class SpringEmbedderBase; public: enum { opt_scale=_super::opt_next, opt_repulsion, opt_z_ordering, opt_z_factor, opt_skip_node_attr, opt_next }; protected: double scale, rep, z_factor; Vector z_ordering; double z_min, z_max; Set fixed_vertices; public: explicit SpringEmbedder(const argv_option *options) : _super(options) { init_params(options); } void init_params(const argv_option *options); void adjust_edge_lengths(bool different_edge_lengths); void set_repulsion(double r) { rep = r; } void set_z_factor(double f) { z_factor = f; } void set_z_ordering(Poly& p, const argv_option *options); void set_fixed_vertices(const Set& v) { fixed_vertices=v; } const double get_repulsion() { return rep; } const double get_z_factor() { return z_factor; } const bool has_z_ordering() { return !z_ordering.empty(); } template void start_points(Iterator src) { for (Entire< Nodes >::iterator n=entire(nodes(G)); !n.at_end(); ++n, ++src) n->x=*src * scale; if (has_z_ordering()) { z_min=-scale; z_max=scale; } gravity=fixed_vertices.empty(); barycenter.fill(0); scale=1; } void calculate_forces(std::vector& forces); }; } } #endif // _POLYMAKE_SPRING_EMBEDDER_H // Local Variables: // mode:C++ // c-basic-offset:3 // End: