318 Graph::NodeMap<double> y(mytab.mapstorage.graph); |
318 Graph::NodeMap<double> y(mytab.mapstorage.graph); |
319 XYMap<Graph::NodeMap<double> > actual_forces; |
319 XYMap<Graph::NodeMap<double> > actual_forces; |
320 actual_forces.setXMap(x); |
320 actual_forces.setXMap(x); |
321 actual_forces.setYMap(y); |
321 actual_forces.setYMap(y); |
322 |
322 |
323 lemon::dim2::Point<double> delta; |
|
324 |
|
325 //count actual force for each nodes |
323 //count actual force for each nodes |
326 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
324 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
327 { |
325 { |
328 //propulsation of nodes |
326 //propulsation of nodes |
329 for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) |
327 for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) |
330 { |
328 { |
331 if(i!=j) |
329 if(i!=j) |
332 { |
330 { |
333 delta=((mytab.mapstorage).coords[i]-(mytab.mapstorage).coords[j]); |
331 lemon::dim2::Point<double> delta = |
334 |
332 ((mytab.mapstorage).coords[i]- |
335 double length_sqr=delta.normSquare(); |
333 (mytab.mapstorage).coords[j]); |
336 double length=sqrt(length_sqr); |
334 |
337 if(length_sqr<min_dist) |
335 const double length_sqr=std::max(delta.normSquare(),min_dist); |
338 { |
|
339 length_sqr=min_dist; |
|
340 } |
|
341 |
336 |
342 //normalize vector |
337 //normalize vector |
343 delta/=length; |
338 delta/=sqrt(length_sqr); |
344 |
339 |
345 //calculating propulsation strength |
340 //calculating propulsation strength |
346 //greater distance menas smaller propulsation strength |
341 //greater distance menas smaller propulsation strength |
347 delta*=propulsation/length_sqr; |
342 delta*=propulsation/length_sqr; |
348 |
343 |
350 } |
345 } |
351 } |
346 } |
352 //attraction of nodes, to which actual node is bound |
347 //attraction of nodes, to which actual node is bound |
353 for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
348 for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
354 { |
349 { |
355 delta=((mytab.mapstorage).coords[i]-(mytab.mapstorage).coords[mytab.mapstorage.graph.target(ei)]); |
350 lemon::dim2::Point<double> delta = |
356 |
351 ((mytab.mapstorage).coords[i]- |
357 double length_sqr=delta.normSquare(); |
352 (mytab.mapstorage).coords[mytab.mapstorage. |
358 double length=sqrt(length_sqr); |
353 graph.target(ei)]); |
359 if(length_sqr<min_dist) |
354 |
360 { |
355 //calculating attraction strength |
361 length_sqr=min_dist; |
356 //greater distance means greater strength |
362 } |
357 delta*=attraction; |
363 |
358 |
364 //normalize vector |
359 actual_forces.set(i,actual_forces[i]-delta); |
365 delta/=length; |
|
366 |
|
367 //calculating attraction strength |
|
368 //greater distance means greater strength |
|
369 delta*=attraction*length; |
|
370 |
|
371 actual_forces.set(i,actual_forces[i]-delta); |
|
372 } |
360 } |
373 for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
361 for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
374 { |
362 { |
375 delta=((mytab.mapstorage).coords[i]-(mytab.mapstorage).coords[mytab.mapstorage.graph.source(ei)]); |
363 lemon::dim2::Point<double> delta = |
376 |
364 ((mytab.mapstorage).coords[i]- |
377 double length_sqr=delta.normSquare(); |
365 (mytab.mapstorage).coords[mytab.mapstorage. |
378 double length=sqrt(length_sqr); |
366 graph.source(ei)]); |
379 if(length_sqr<min_dist) |
367 |
380 { |
368 //calculating attraction strength |
381 length_sqr=min_dist; |
369 //greater distance means greater strength |
382 } |
370 delta*=attraction; |
383 |
371 |
384 //normalize vector |
372 actual_forces.set(i,actual_forces[i]-delta); |
385 delta/=length; |
|
386 |
|
387 //calculating attraction strength |
|
388 //greater distance means greater strength |
|
389 delta*=attraction*length; |
|
390 |
|
391 actual_forces.set(i,actual_forces[i]-delta); |
|
392 } |
373 } |
393 } |
374 } |
394 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
375 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
395 { |
376 { |
396 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); |
377 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); |