COIN-OR::LEMON - Graph Library

Changeset 160:14a76109b561 in glemon-0.x for graph_displayer_canvas.cc


Ignore:
Timestamp:
10/12/06 13:39:29 (18 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@2982
Message:

Node antigravity and edge elasticity based graph layout redesigner.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graph_displayer_canvas.cc

    r157 r160  
    66  nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
    77  isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
    8   edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10), mytab(mainw)
     8  edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
     9  iterations(20), attraction(0.05), propulsation(40000), mytab(mainw)
    910{
    1011  //base event handler is move tool
     
    252253  radius_p=radius_size;
    253254}
     255
     256void GraphDisplayerCanvas::reDesignGraph()
     257{
     258  double min_dist=40;
     259
     260  //iteration counter
     261  for(int l=0;l<iterations;l++)
     262    {
     263      Graph::NodeMap<double> x(mytab.mapstorage.graph);
     264      Graph::NodeMap<double> y(mytab.mapstorage.graph);
     265      XYMap<Graph::NodeMap<double> > actual_forces;
     266      actual_forces.setXMap(x);
     267      actual_forces.setYMap(y);
     268
     269      lemon::dim2::Point<double> delta;
     270
     271      //count actual force for each nodes
     272      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
     273        {
     274          //propulsation of nodes
     275          for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j)
     276            {
     277              if(i!=j)
     278                {
     279                  delta=((mytab.mapstorage).coords[i]-(mytab.mapstorage).coords[j]);
     280
     281                  double length_sqr=delta.normSquare();
     282                  double length=sqrt(length_sqr);
     283                  if(length_sqr<min_dist)
     284                    {
     285                      length_sqr=min_dist;
     286                    }
     287
     288                  //normalize vector
     289                  delta/=length;
     290
     291                  //calculating propulsation strength
     292                  //greater distance menas smaller propulsation strength
     293                  delta*=propulsation/length_sqr;
     294                   
     295                  actual_forces.set(i,(actual_forces[i]+delta));
     296                }
     297            }
     298          //attraction of nodes, to which actual node is bound
     299          for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
     300            {
     301              delta=((mytab.mapstorage).coords[i]-(mytab.mapstorage).coords[mytab.mapstorage.graph.target(ei)]);
     302
     303              double length_sqr=delta.normSquare();
     304              double length=sqrt(length_sqr);
     305              if(length_sqr<min_dist)
     306                {
     307                  length_sqr=min_dist;
     308                }
     309
     310              //normalize vector
     311              delta/=length;
     312
     313              //calculating attraction strength
     314              //greater distance means greater strength
     315              delta*=attraction*length;
     316
     317              actual_forces.set(i,actual_forces[i]-delta);
     318            }
     319          for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
     320            {
     321              delta=((mytab.mapstorage).coords[i]-(mytab.mapstorage).coords[mytab.mapstorage.graph.source(ei)]);
     322
     323              double length_sqr=delta.normSquare();
     324              double length=sqrt(length_sqr);
     325              if(length_sqr<min_dist)
     326                {
     327                  length_sqr=min_dist;
     328                }
     329
     330              //normalize vector
     331              delta/=length;
     332
     333              //calculating attraction strength
     334              //greater distance means greater strength
     335              delta*=attraction*length;
     336
     337              actual_forces.set(i,actual_forces[i]-delta);
     338            }
     339        }
     340      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
     341        {
     342          moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
     343        }
     344    }
     345}
     346
     347void GraphDisplayerCanvas::get_design_data(double & attraction_p, double & propulsation_p, int & iterations_p)
     348{
     349  attraction_p=attraction;
     350  propulsation_p=propulsation;
     351  iterations_p=iterations;
     352}
     353
     354void GraphDisplayerCanvas::set_attraction(double attraction_p)
     355{
     356  attraction=attraction_p;
     357}
     358
     359void GraphDisplayerCanvas::set_propulsation(double propulsation_p)
     360{
     361  propulsation=propulsation_p;
     362}
     363
     364void GraphDisplayerCanvas::set_iteration(int iterations_p)
     365{
     366  iterations=iterations_p;
     367}
     368
Note: See TracChangeset for help on using the changeset viewer.