diff -r 8b69c54d5bf0 -r 2cac5b936a2b graph_displayer_canvas.cc --- a/graph_displayer_canvas.cc Tue Feb 20 15:46:19 2007 +0000 +++ b/graph_displayer_canvas.cc Tue Feb 20 17:45:44 2007 +0000 @@ -323,110 +323,115 @@ void GraphDisplayerCanvas::reDesignGraph() { - double max_coord=50000; - double min_dist=20; - double init_vector_length=25; + NodeIt firstnode((mytab.mapstorage).graph); + //is it not an empty graph? + if(firstnode!=INVALID) + { + double max_coord=50000; + double min_dist=20; + double init_vector_length=25; - if(!was_redesigned) - { - NodeIt i((mytab.mapstorage).graph); + if(!was_redesigned) + { + NodeIt i((mytab.mapstorage).graph); - dim2::Point init(init_vector_length*rnd(), - init_vector_length*rnd()); - moveNode(init.x, init.y, nodesmap[i], i); - was_redesigned=true; - } + dim2::Point init(init_vector_length*rnd(), + init_vector_length*rnd()); + moveNode(init.x, init.y, nodesmap[i], i); + was_redesigned=true; + } - double attraction; - double propulsation; - int iterations; + double attraction; + double propulsation; + int iterations; - (mytab.mapstorage).get_design_data(attraction, propulsation, iterations); + (mytab.mapstorage).get_design_data(attraction, propulsation, iterations); - //iteration counter - for(int l=0;l x(mytab.mapstorage.graph); - Graph::NodeMap y(mytab.mapstorage.graph); - XYMap > actual_forces; - actual_forces.setXMap(x); - actual_forces.setYMap(y); + //iteration counter + for(int l=0;l x(mytab.mapstorage.graph); + Graph::NodeMap y(mytab.mapstorage.graph); + XYMap > actual_forces; + actual_forces.setXMap(x); + actual_forces.setYMap(y); - //count actual force for each nodes - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - //propulsation of nodes - for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) + //count actual force for each nodes + for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { - if(i!=j) + //propulsation of nodes + for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) + { + if(i!=j) + { + lemon::dim2::Point delta = + ((mytab.mapstorage).coords[i]- + (mytab.mapstorage).coords[j]); + + const double length_sqr=std::max(delta.normSquare(),min_dist); + + //normalize vector + delta/=sqrt(length_sqr); + + //calculating propulsation strength + //greater distance menas smaller propulsation strength + delta*=propulsation/length_sqr; + + actual_forces.set(i,(actual_forces[i]+delta)); + } + } + //attraction of nodes, to which actual node is bound + for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) { lemon::dim2::Point delta = ((mytab.mapstorage).coords[i]- - (mytab.mapstorage).coords[j]); - - const double length_sqr=std::max(delta.normSquare(),min_dist); - - //normalize vector - delta/=sqrt(length_sqr); - - //calculating propulsation strength - //greater distance menas smaller propulsation strength - delta*=propulsation/length_sqr; - - actual_forces.set(i,(actual_forces[i]+delta)); + (mytab.mapstorage).coords[mytab.mapstorage. + graph.target(ei)]); + + //calculating attraction strength + //greater distance means greater strength + delta*=attraction; + + actual_forces.set(i,actual_forces[i]-delta); + } + for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) + { + lemon::dim2::Point delta = + ((mytab.mapstorage).coords[i]- + (mytab.mapstorage).coords[mytab.mapstorage. + graph.source(ei)]); + + //calculating attraction strength + //greater distance means greater strength + delta*=attraction; + + actual_forces.set(i,actual_forces[i]-delta); } } - //attraction of nodes, to which actual node is bound - for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) + for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { - lemon::dim2::Point delta = - ((mytab.mapstorage).coords[i]- - (mytab.mapstorage).coords[mytab.mapstorage. - graph.target(ei)]); - - //calculating attraction strength - //greater distance means greater strength - delta*=attraction; - - actual_forces.set(i,actual_forces[i]-delta); + if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord) + { + actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x); + std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; + } + else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord)) + { + actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x); + std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; + } + if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord) + { + actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y); + std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; + } + else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord)) + { + actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y); + std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; + } + moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); } - for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) - { - lemon::dim2::Point delta = - ((mytab.mapstorage).coords[i]- - (mytab.mapstorage).coords[mytab.mapstorage. - graph.source(ei)]); - - //calculating attraction strength - //greater distance means greater strength - delta*=attraction; - - actual_forces.set(i,actual_forces[i]-delta); - } - } - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord) - { - actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x); - std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; - } - else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord)) - { - actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x); - std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; - } - if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord) - { - actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y); - std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; - } - else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord)) - { - actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y); - std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; - } - moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); } } }