graph_displayer_canvas.cc
changeset 190 2cac5b936a2b
parent 187 b465e2c34f23
child 194 6b2b718420eb
     1.1 --- a/graph_displayer_canvas.cc	Tue Feb 20 15:46:19 2007 +0000
     1.2 +++ b/graph_displayer_canvas.cc	Tue Feb 20 17:45:44 2007 +0000
     1.3 @@ -323,110 +323,115 @@
     1.4  
     1.5  void GraphDisplayerCanvas::reDesignGraph()
     1.6  {
     1.7 -  double max_coord=50000;
     1.8 -  double min_dist=20;
     1.9 -  double init_vector_length=25;
    1.10 +  NodeIt firstnode((mytab.mapstorage).graph);
    1.11 +  //is it not an empty graph?
    1.12 +  if(firstnode!=INVALID)
    1.13 +    {
    1.14 +      double max_coord=50000;
    1.15 +      double min_dist=20;
    1.16 +      double init_vector_length=25;
    1.17  
    1.18 -  if(!was_redesigned)
    1.19 -    {
    1.20 -      NodeIt i((mytab.mapstorage).graph);
    1.21 +      if(!was_redesigned)
    1.22 +	{
    1.23 +	  NodeIt i((mytab.mapstorage).graph);
    1.24  
    1.25 -      dim2::Point<double> init(init_vector_length*rnd(),
    1.26 -			       init_vector_length*rnd());
    1.27 -      moveNode(init.x, init.y, nodesmap[i], i);
    1.28 -      was_redesigned=true;
    1.29 -    }
    1.30 +	  dim2::Point<double> init(init_vector_length*rnd(),
    1.31 +				   init_vector_length*rnd());
    1.32 +	  moveNode(init.x, init.y, nodesmap[i], i);
    1.33 +	  was_redesigned=true;
    1.34 +	}
    1.35  
    1.36 -  double attraction;
    1.37 -  double propulsation;
    1.38 -  int iterations;
    1.39 +      double attraction;
    1.40 +      double propulsation;
    1.41 +      int iterations;
    1.42  
    1.43 -  (mytab.mapstorage).get_design_data(attraction, propulsation, iterations);
    1.44 +      (mytab.mapstorage).get_design_data(attraction, propulsation, iterations);
    1.45  
    1.46 -  //iteration counter
    1.47 -  for(int l=0;l<iterations;l++)
    1.48 -    {
    1.49 -      Graph::NodeMap<double> x(mytab.mapstorage.graph);
    1.50 -      Graph::NodeMap<double> y(mytab.mapstorage.graph);
    1.51 -      XYMap<Graph::NodeMap<double> > actual_forces;
    1.52 -      actual_forces.setXMap(x);
    1.53 -      actual_forces.setYMap(y);
    1.54 +      //iteration counter
    1.55 +      for(int l=0;l<iterations;l++)
    1.56 +	{
    1.57 +	  Graph::NodeMap<double> x(mytab.mapstorage.graph);
    1.58 +	  Graph::NodeMap<double> y(mytab.mapstorage.graph);
    1.59 +	  XYMap<Graph::NodeMap<double> > actual_forces;
    1.60 +	  actual_forces.setXMap(x);
    1.61 +	  actual_forces.setYMap(y);
    1.62  
    1.63 -      //count actual force for each nodes
    1.64 -      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    1.65 -	{
    1.66 -	  //propulsation of nodes
    1.67 -	  for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j)
    1.68 +	  //count actual force for each nodes
    1.69 +	  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    1.70  	    {
    1.71 -	      if(i!=j)
    1.72 +	      //propulsation of nodes
    1.73 +	      for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j)
    1.74 +		{
    1.75 +		  if(i!=j)
    1.76 +		    {
    1.77 +		      lemon::dim2::Point<double> delta =
    1.78 +			((mytab.mapstorage).coords[i]-
    1.79 +			 (mytab.mapstorage).coords[j]);
    1.80 +
    1.81 +		      const double length_sqr=std::max(delta.normSquare(),min_dist);
    1.82 +
    1.83 +		      //normalize vector
    1.84 +		      delta/=sqrt(length_sqr);
    1.85 +
    1.86 +		      //calculating propulsation strength
    1.87 +		      //greater distance menas smaller propulsation strength
    1.88 +		      delta*=propulsation/length_sqr;
    1.89 +		    
    1.90 +		      actual_forces.set(i,(actual_forces[i]+delta));
    1.91 +		    }
    1.92 +		}
    1.93 +	      //attraction of nodes, to which actual node is bound
    1.94 +	      for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
    1.95  		{
    1.96  		  lemon::dim2::Point<double> delta =
    1.97  		    ((mytab.mapstorage).coords[i]-
    1.98 -		     (mytab.mapstorage).coords[j]);
    1.99 -
   1.100 -		  const double length_sqr=std::max(delta.normSquare(),min_dist);
   1.101 -
   1.102 -		  //normalize vector
   1.103 -		  delta/=sqrt(length_sqr);
   1.104 -
   1.105 -		  //calculating propulsation strength
   1.106 -		  //greater distance menas smaller propulsation strength
   1.107 -		  delta*=propulsation/length_sqr;
   1.108 -		    
   1.109 -		  actual_forces.set(i,(actual_forces[i]+delta));
   1.110 +		     (mytab.mapstorage).coords[mytab.mapstorage.
   1.111 +					       graph.target(ei)]);
   1.112 +		
   1.113 +		  //calculating attraction strength
   1.114 +		  //greater distance means greater strength
   1.115 +		  delta*=attraction;
   1.116 +		
   1.117 +		  actual_forces.set(i,actual_forces[i]-delta);
   1.118 +		}
   1.119 +	      for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.120 +		{
   1.121 +		  lemon::dim2::Point<double> delta =
   1.122 +		    ((mytab.mapstorage).coords[i]-
   1.123 +		     (mytab.mapstorage).coords[mytab.mapstorage.
   1.124 +					       graph.source(ei)]);
   1.125 +		
   1.126 +		  //calculating attraction strength
   1.127 +		  //greater distance means greater strength
   1.128 +		  delta*=attraction;
   1.129 +		
   1.130 +		  actual_forces.set(i,actual_forces[i]-delta);
   1.131  		}
   1.132  	    }
   1.133 -	  //attraction of nodes, to which actual node is bound
   1.134 -	  for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.135 +	  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.136  	    {
   1.137 -	      lemon::dim2::Point<double> delta =
   1.138 -		((mytab.mapstorage).coords[i]-
   1.139 -		 (mytab.mapstorage).coords[mytab.mapstorage.
   1.140 -					   graph.target(ei)]);
   1.141 -		
   1.142 -		//calculating attraction strength
   1.143 -		//greater distance means greater strength
   1.144 -		delta*=attraction;
   1.145 -		
   1.146 -		actual_forces.set(i,actual_forces[i]-delta);
   1.147 +	      if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord)
   1.148 +		{
   1.149 +		  actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x);
   1.150 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.151 +		}
   1.152 +	      else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord))
   1.153 +		{
   1.154 +		  actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x);
   1.155 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.156 +		}
   1.157 +	      if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord)
   1.158 +		{
   1.159 +		  actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y);
   1.160 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.161 +		}
   1.162 +	      else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord))
   1.163 +		{
   1.164 +		  actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y);
   1.165 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.166 +		}
   1.167 +	      moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
   1.168  	    }
   1.169 -	  for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.170 -	    {
   1.171 -	      lemon::dim2::Point<double> delta =
   1.172 -		((mytab.mapstorage).coords[i]-
   1.173 -		 (mytab.mapstorage).coords[mytab.mapstorage.
   1.174 -					   graph.source(ei)]);
   1.175 -		
   1.176 -		//calculating attraction strength
   1.177 -		//greater distance means greater strength
   1.178 -		delta*=attraction;
   1.179 -		
   1.180 -		actual_forces.set(i,actual_forces[i]-delta);
   1.181 -	    }
   1.182 -	}
   1.183 -      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.184 -	{
   1.185 -	  if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord)
   1.186 -	    {
   1.187 -	      actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x);
   1.188 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.189 -	    }
   1.190 -	  else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord))
   1.191 -	    {
   1.192 -	      actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x);
   1.193 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.194 -	    }
   1.195 -	  if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord)
   1.196 -	    {
   1.197 -	      actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y);
   1.198 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.199 -	    }
   1.200 -	  else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord))
   1.201 -	    {
   1.202 -	      actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y);
   1.203 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.204 -	    }
   1.205 -	  moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
   1.206  	}
   1.207      }
   1.208  }