3 |
3 |
4 GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) : |
4 GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) : |
5 nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph), |
5 nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph), |
6 nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0), |
6 nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0), |
7 isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""), |
7 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) |
9 { |
10 { |
10 //base event handler is move tool |
11 //base event handler is move tool |
11 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); |
12 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); |
12 actual_tool=MOVE; |
13 actual_tool=MOVE; |
13 |
14 |
249 autoscale_p=autoscale; |
250 autoscale_p=autoscale; |
250 zoomtrack_p=zoomtrack; |
251 zoomtrack_p=zoomtrack; |
251 width_p=edge_width; |
252 width_p=edge_width; |
252 radius_p=radius_size; |
253 radius_p=radius_size; |
253 } |
254 } |
|
255 |
|
256 void 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 |
|
347 void 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 |
|
354 void GraphDisplayerCanvas::set_attraction(double attraction_p) |
|
355 { |
|
356 attraction=attraction_p; |
|
357 } |
|
358 |
|
359 void GraphDisplayerCanvas::set_propulsation(double propulsation_p) |
|
360 { |
|
361 propulsation=propulsation_p; |
|
362 } |
|
363 |
|
364 void GraphDisplayerCanvas::set_iteration(int iterations_p) |
|
365 { |
|
366 iterations=iterations_p; |
|
367 } |
|
368 |