Changeset 190:2cac5b936a2b in glemon-0.x for graph_displayer_canvas.cc
- Timestamp:
- 02/20/07 18:45:44 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3194
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graph_displayer_canvas.cc
r187 r190 324 324 void GraphDisplayerCanvas::reDesignGraph() 325 325 { 326 double max_coord=50000; 327 double min_dist=20; 328 double init_vector_length=25; 329 330 if(!was_redesigned) 331 { 332 NodeIt i((mytab.mapstorage).graph); 333 334 dim2::Point<double> init(init_vector_length*rnd(), 335 init_vector_length*rnd()); 336 moveNode(init.x, init.y, nodesmap[i], i); 337 was_redesigned=true; 338 } 339 340 double attraction; 341 double propulsation; 342 int iterations; 343 344 (mytab.mapstorage).get_design_data(attraction, propulsation, iterations); 345 346 //iteration counter 347 for(int l=0;l<iterations;l++) 348 { 349 Graph::NodeMap<double> x(mytab.mapstorage.graph); 350 Graph::NodeMap<double> y(mytab.mapstorage.graph); 351 XYMap<Graph::NodeMap<double> > actual_forces; 352 actual_forces.setXMap(x); 353 actual_forces.setYMap(y); 354 355 //count actual force for each nodes 356 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) 357 { 358 //propulsation of nodes 359 for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) 360 { 361 if(i!=j) 326 NodeIt firstnode((mytab.mapstorage).graph); 327 //is it not an empty graph? 328 if(firstnode!=INVALID) 329 { 330 double max_coord=50000; 331 double min_dist=20; 332 double init_vector_length=25; 333 334 if(!was_redesigned) 335 { 336 NodeIt i((mytab.mapstorage).graph); 337 338 dim2::Point<double> init(init_vector_length*rnd(), 339 init_vector_length*rnd()); 340 moveNode(init.x, init.y, nodesmap[i], i); 341 was_redesigned=true; 342 } 343 344 double attraction; 345 double propulsation; 346 int iterations; 347 348 (mytab.mapstorage).get_design_data(attraction, propulsation, iterations); 349 350 //iteration counter 351 for(int l=0;l<iterations;l++) 352 { 353 Graph::NodeMap<double> x(mytab.mapstorage.graph); 354 Graph::NodeMap<double> y(mytab.mapstorage.graph); 355 XYMap<Graph::NodeMap<double> > actual_forces; 356 actual_forces.setXMap(x); 357 actual_forces.setYMap(y); 358 359 //count actual force for each nodes 360 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) 361 { 362 //propulsation of nodes 363 for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) 364 { 365 if(i!=j) 366 { 367 lemon::dim2::Point<double> delta = 368 ((mytab.mapstorage).coords[i]- 369 (mytab.mapstorage).coords[j]); 370 371 const double length_sqr=std::max(delta.normSquare(),min_dist); 372 373 //normalize vector 374 delta/=sqrt(length_sqr); 375 376 //calculating propulsation strength 377 //greater distance menas smaller propulsation strength 378 delta*=propulsation/length_sqr; 379 380 actual_forces.set(i,(actual_forces[i]+delta)); 381 } 382 } 383 //attraction of nodes, to which actual node is bound 384 for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) 362 385 { 363 386 lemon::dim2::Point<double> delta = 364 387 ((mytab.mapstorage).coords[i]- 365 (mytab.mapstorage).coords[j]); 366 367 const double length_sqr=std::max(delta.normSquare(),min_dist); 368 369 //normalize vector 370 delta/=sqrt(length_sqr); 371 372 //calculating propulsation strength 373 //greater distance menas smaller propulsation strength 374 delta*=propulsation/length_sqr; 375 376 actual_forces.set(i,(actual_forces[i]+delta)); 377 } 378 } 379 //attraction of nodes, to which actual node is bound 380 for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) 381 { 382 lemon::dim2::Point<double> delta = 383 ((mytab.mapstorage).coords[i]- 384 (mytab.mapstorage).coords[mytab.mapstorage. 385 graph.target(ei)]); 388 (mytab.mapstorage).coords[mytab.mapstorage. 389 graph.target(ei)]); 386 390 387 //calculating attraction strength388 //greater distance means greater strength389 delta*=attraction;391 //calculating attraction strength 392 //greater distance means greater strength 393 delta*=attraction; 390 394 391 actual_forces.set(i,actual_forces[i]-delta);392 393 for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)394 395 396 ((mytab.mapstorage).coords[i]-397 (mytab.mapstorage).coords[mytab.mapstorage.398 graph.source(ei)]);395 actual_forces.set(i,actual_forces[i]-delta); 396 } 397 for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) 398 { 399 lemon::dim2::Point<double> delta = 400 ((mytab.mapstorage).coords[i]- 401 (mytab.mapstorage).coords[mytab.mapstorage. 402 graph.source(ei)]); 399 403 400 //calculating attraction strength401 //greater distance means greater strength402 delta*=attraction;404 //calculating attraction strength 405 //greater distance means greater strength 406 delta*=attraction; 403 407 404 actual_forces.set(i,actual_forces[i]-delta); 405 } 406 } 407 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) 408 { 409 if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord) 410 { 411 actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x); 412 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; 413 } 414 else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord)) 415 { 416 actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x); 417 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; 418 } 419 if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord) 420 { 421 actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y); 422 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; 423 } 424 else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord)) 425 { 426 actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y); 427 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; 428 } 429 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); 430 } 431 } 432 } 433 408 actual_forces.set(i,actual_forces[i]-delta); 409 } 410 } 411 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) 412 { 413 if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord) 414 { 415 actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x); 416 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; 417 } 418 else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord)) 419 { 420 actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x); 421 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; 422 } 423 if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord) 424 { 425 actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y); 426 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; 427 } 428 else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord)) 429 { 430 actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y); 431 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; 432 } 433 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); 434 } 435 } 436 } 437 } 438
Note: See TracChangeset
for help on using the changeset viewer.