hegyi@1
|
1 |
/* -*- C++ -*-
|
hegyi@1
|
2 |
*
|
hegyi@1
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
hegyi@1
|
4 |
*
|
hegyi@1
|
5 |
* Copyright (C) 2003-2006
|
hegyi@1
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
hegyi@1
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
hegyi@1
|
8 |
*
|
hegyi@1
|
9 |
* Permission to use, modify and distribute this software is granted
|
hegyi@1
|
10 |
* provided that this copyright notice appears in all copies. For
|
hegyi@1
|
11 |
* precise terms see the accompanying LICENSE file.
|
hegyi@1
|
12 |
*
|
hegyi@1
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
hegyi@1
|
14 |
* express or implied, and with no claim as to its suitability for any
|
hegyi@1
|
15 |
* purpose.
|
hegyi@1
|
16 |
*
|
hegyi@1
|
17 |
*/
|
hegyi@1
|
18 |
|
hegyi@1
|
19 |
#include <mapstorage.h>
|
hegyi@1
|
20 |
#include <nbtab.h>
|
hegyi@1
|
21 |
#include <graph_displayer_canvas.h>
|
hegyi@1
|
22 |
#include <lemon/random.h>
|
hegyi@1
|
23 |
#include <cmath>
|
hegyi@1
|
24 |
|
hegyi@1
|
25 |
DigraphDisplayerCanvas::DigraphDisplayerCanvas(NoteBookTab & mainw) :
|
hegyi@1
|
26 |
nodesmap(mainw.mapstorage->digraph), arcsmap(mainw.mapstorage->digraph), arctextmap(mainw.mapstorage->digraph),
|
hegyi@1
|
27 |
nodetextmap(mainw.mapstorage->digraph), displayed_graph(*(root()), 0, 0),
|
hegyi@1
|
28 |
isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
|
hegyi@1
|
29 |
arcmap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), arc_width(10),
|
hegyi@1
|
30 |
was_redesigned(false), is_drawn(false), mytab(mainw),
|
hegyi@1
|
31 |
background_set(false)
|
hegyi@1
|
32 |
{
|
hegyi@1
|
33 |
//add mouse scroll event handler - it won't be changed, it handles zoom
|
hegyi@1
|
34 |
signal_event().connect(sigc::mem_fun(*this, &DigraphDisplayerCanvas::scrollEventHandler), false);
|
hegyi@1
|
35 |
|
hegyi@1
|
36 |
//base event handler is move tool
|
hegyi@1
|
37 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &DigraphDisplayerCanvas::moveEventHandler), false);
|
hegyi@1
|
38 |
actual_tool=MOVE;
|
hegyi@1
|
39 |
|
hegyi@1
|
40 |
|
hegyi@1
|
41 |
active_node=INVALID;
|
hegyi@1
|
42 |
active_arc=INVALID;
|
hegyi@1
|
43 |
forming_arc=INVALID;
|
hegyi@1
|
44 |
|
hegyi@1
|
45 |
setBackground();
|
hegyi@1
|
46 |
}
|
hegyi@1
|
47 |
|
hegyi@1
|
48 |
void DigraphDisplayerCanvas::setBackground()
|
hegyi@1
|
49 |
{
|
hegyi@1
|
50 |
if (background_set)
|
hegyi@1
|
51 |
{
|
hegyi@1
|
52 |
delete background;
|
hegyi@1
|
53 |
}
|
hegyi@1
|
54 |
if (mytab.mapstorage->isBackgroundSet())
|
hegyi@1
|
55 |
{
|
hegyi@1
|
56 |
background_set = true;
|
hegyi@1
|
57 |
refBackground = Gdk::Pixbuf::create_from_file(
|
hegyi@1
|
58 |
mytab.mapstorage->getBackgroundFilename());
|
hegyi@1
|
59 |
background = new Gnome::Canvas::Pixbuf(
|
hegyi@1
|
60 |
*(root()),
|
hegyi@1
|
61 |
0.0 - refBackground->get_width() / 2.0,
|
hegyi@1
|
62 |
0.0 - refBackground->get_height() / 2.0,
|
hegyi@1
|
63 |
refBackground);
|
hegyi@1
|
64 |
background->lower_to_bottom();
|
hegyi@1
|
65 |
}
|
hegyi@1
|
66 |
else
|
hegyi@1
|
67 |
{
|
hegyi@1
|
68 |
background_set = false;
|
hegyi@1
|
69 |
}
|
hegyi@1
|
70 |
}
|
hegyi@1
|
71 |
|
hegyi@1
|
72 |
DigraphDisplayerCanvas::~DigraphDisplayerCanvas()
|
hegyi@1
|
73 |
{
|
hegyi@1
|
74 |
for (NodeIt n((mytab.mapstorage)->digraph); n != INVALID; ++n)
|
hegyi@1
|
75 |
{
|
hegyi@1
|
76 |
delete nodesmap[n];
|
hegyi@1
|
77 |
delete nodetextmap[n];
|
hegyi@1
|
78 |
}
|
hegyi@1
|
79 |
|
hegyi@1
|
80 |
for (ArcIt e((mytab.mapstorage)->digraph); e != INVALID; ++e)
|
hegyi@1
|
81 |
{
|
hegyi@1
|
82 |
delete arcsmap[e];
|
hegyi@1
|
83 |
delete arctextmap[e];
|
hegyi@1
|
84 |
}
|
hegyi@1
|
85 |
}
|
hegyi@1
|
86 |
|
hegyi@1
|
87 |
void DigraphDisplayerCanvas::propertyChange(bool itisarc, int prop)
|
hegyi@1
|
88 |
{
|
hegyi@1
|
89 |
if(itisarc)
|
hegyi@1
|
90 |
{
|
hegyi@1
|
91 |
propertyUpdate(Arc(INVALID), prop);
|
hegyi@1
|
92 |
}
|
hegyi@1
|
93 |
else
|
hegyi@1
|
94 |
{
|
hegyi@1
|
95 |
propertyUpdate(Node(INVALID), prop);
|
hegyi@1
|
96 |
}
|
hegyi@1
|
97 |
}
|
hegyi@1
|
98 |
|
hegyi@1
|
99 |
void DigraphDisplayerCanvas::propertyUpdate(Arc arc)
|
hegyi@1
|
100 |
{
|
hegyi@1
|
101 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@1
|
102 |
{
|
hegyi@1
|
103 |
propertyUpdate(arc, i);
|
hegyi@1
|
104 |
}
|
hegyi@1
|
105 |
}
|
hegyi@1
|
106 |
|
hegyi@1
|
107 |
void DigraphDisplayerCanvas::propertyUpdate(Node node)
|
hegyi@1
|
108 |
{
|
hegyi@1
|
109 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@1
|
110 |
{
|
hegyi@1
|
111 |
propertyUpdate(node, i);
|
hegyi@1
|
112 |
}
|
hegyi@1
|
113 |
}
|
hegyi@1
|
114 |
|
hegyi@1
|
115 |
void DigraphDisplayerCanvas::propertyUpdate(Node node, int prop)
|
hegyi@1
|
116 |
{
|
hegyi@1
|
117 |
std::string mapname=mytab.getActiveNodeMap(prop);
|
hegyi@1
|
118 |
|
hegyi@1
|
119 |
if(is_drawn)
|
hegyi@1
|
120 |
{
|
hegyi@1
|
121 |
if(mapname!="")
|
hegyi@1
|
122 |
{
|
hegyi@1
|
123 |
std::vector<std::string> nodemaps = mytab.mapstorage->getNodeMapList();
|
hegyi@1
|
124 |
bool found = false;
|
hegyi@1
|
125 |
for (std::vector<std::string>::const_iterator it = nodemaps.begin();
|
hegyi@1
|
126 |
it != nodemaps.end(); ++it)
|
hegyi@1
|
127 |
{
|
hegyi@1
|
128 |
if (*it == mapname)
|
hegyi@1
|
129 |
{
|
hegyi@1
|
130 |
found = true;
|
hegyi@1
|
131 |
break;
|
hegyi@1
|
132 |
}
|
hegyi@1
|
133 |
}
|
hegyi@1
|
134 |
if (found)
|
hegyi@1
|
135 |
{
|
hegyi@1
|
136 |
switch(prop)
|
hegyi@1
|
137 |
{
|
hegyi@1
|
138 |
case N_RADIUS:
|
hegyi@1
|
139 |
changeNodeRadius(mapname, node);
|
hegyi@1
|
140 |
break;
|
hegyi@1
|
141 |
case N_COLOR:
|
hegyi@1
|
142 |
changeNodeColor(mapname, node);
|
hegyi@1
|
143 |
break;
|
hegyi@1
|
144 |
case N_TEXT:
|
hegyi@1
|
145 |
changeNodeText(mapname, node);
|
hegyi@1
|
146 |
break;
|
hegyi@1
|
147 |
default:
|
hegyi@1
|
148 |
std::cerr<<"Error\n";
|
hegyi@1
|
149 |
}
|
hegyi@1
|
150 |
}
|
hegyi@1
|
151 |
}
|
hegyi@1
|
152 |
else //mapname==""
|
hegyi@1
|
153 |
{
|
hegyi@1
|
154 |
Node node=INVALID;
|
hegyi@1
|
155 |
switch(prop)
|
hegyi@1
|
156 |
{
|
hegyi@1
|
157 |
case N_RADIUS:
|
hegyi@1
|
158 |
resetNodeRadius(node);
|
hegyi@1
|
159 |
break;
|
hegyi@1
|
160 |
case N_COLOR:
|
hegyi@1
|
161 |
resetNodeColor(node);
|
hegyi@1
|
162 |
break;
|
hegyi@1
|
163 |
case N_TEXT:
|
hegyi@1
|
164 |
resetNodeText(node);
|
hegyi@1
|
165 |
break;
|
hegyi@1
|
166 |
default:
|
hegyi@1
|
167 |
std::cerr<<"Error\n";
|
hegyi@1
|
168 |
}
|
hegyi@1
|
169 |
}
|
hegyi@1
|
170 |
}
|
hegyi@1
|
171 |
}
|
hegyi@1
|
172 |
|
hegyi@1
|
173 |
void DigraphDisplayerCanvas::propertyUpdate(Arc arc, int prop)
|
hegyi@1
|
174 |
{
|
hegyi@1
|
175 |
std::string mapname=mytab.getActiveArcMap(prop);
|
hegyi@1
|
176 |
|
hegyi@1
|
177 |
if(is_drawn)
|
hegyi@1
|
178 |
{
|
hegyi@1
|
179 |
if(mapname!="")
|
hegyi@1
|
180 |
{
|
hegyi@1
|
181 |
std::vector<std::string> arcmaps = mytab.mapstorage->getArcMapList();
|
hegyi@1
|
182 |
bool found = false;
|
hegyi@1
|
183 |
for (std::vector<std::string>::const_iterator it = arcmaps.begin();
|
hegyi@1
|
184 |
it != arcmaps.end(); ++it)
|
hegyi@1
|
185 |
{
|
hegyi@1
|
186 |
if (*it == mapname)
|
hegyi@1
|
187 |
{
|
hegyi@1
|
188 |
found = true;
|
hegyi@1
|
189 |
break;
|
hegyi@1
|
190 |
}
|
hegyi@1
|
191 |
}
|
hegyi@1
|
192 |
if (found)
|
hegyi@1
|
193 |
{
|
hegyi@1
|
194 |
switch(prop)
|
hegyi@1
|
195 |
{
|
hegyi@1
|
196 |
case E_WIDTH:
|
hegyi@1
|
197 |
changeArcWidth(mapname, arc);
|
hegyi@1
|
198 |
break;
|
hegyi@1
|
199 |
case E_COLOR:
|
hegyi@1
|
200 |
changeArcColor(mapname, arc);
|
hegyi@1
|
201 |
break;
|
hegyi@1
|
202 |
case E_TEXT:
|
hegyi@1
|
203 |
changeArcText(mapname, arc);
|
hegyi@1
|
204 |
break;
|
hegyi@1
|
205 |
default:
|
hegyi@1
|
206 |
std::cerr<<"Error\n";
|
hegyi@1
|
207 |
}
|
hegyi@1
|
208 |
}
|
hegyi@1
|
209 |
}
|
hegyi@1
|
210 |
else //mapname==""
|
hegyi@1
|
211 |
{
|
hegyi@1
|
212 |
switch(prop)
|
hegyi@1
|
213 |
{
|
hegyi@1
|
214 |
case E_WIDTH:
|
hegyi@1
|
215 |
resetArcWidth(arc);
|
hegyi@1
|
216 |
break;
|
hegyi@1
|
217 |
case E_COLOR:
|
hegyi@1
|
218 |
resetArcColor(arc);
|
hegyi@1
|
219 |
break;
|
hegyi@1
|
220 |
case E_TEXT:
|
hegyi@1
|
221 |
resetArcText(arc);
|
hegyi@1
|
222 |
break;
|
hegyi@1
|
223 |
default:
|
hegyi@1
|
224 |
std::cerr<<"Error\n";
|
hegyi@1
|
225 |
}
|
hegyi@1
|
226 |
}
|
hegyi@1
|
227 |
}
|
hegyi@1
|
228 |
}
|
hegyi@1
|
229 |
|
hegyi@1
|
230 |
void DigraphDisplayerCanvas::drawDigraph()
|
hegyi@1
|
231 |
{
|
hegyi@1
|
232 |
//first arcs are drawn, to hide joining with nodes later
|
hegyi@1
|
233 |
|
hegyi@1
|
234 |
for (ArcIt i((mytab.mapstorage)->digraph); i!=INVALID; ++i)
|
hegyi@1
|
235 |
{
|
hegyi@1
|
236 |
if (mytab.mapstorage->digraph.source(i) == mytab.mapstorage->digraph.target(i))
|
hegyi@1
|
237 |
{
|
hegyi@1
|
238 |
arcsmap[i]=new LoopArc(displayed_graph, i, *this);
|
hegyi@1
|
239 |
}
|
hegyi@1
|
240 |
else
|
hegyi@1
|
241 |
{
|
hegyi@1
|
242 |
arcsmap[i]=new BrokenArc(displayed_graph, i, *this);
|
hegyi@1
|
243 |
}
|
hegyi@1
|
244 |
//initializing arc-text as well, to empty string
|
hegyi@1
|
245 |
|
hegyi@1
|
246 |
XY text_pos=mytab.mapstorage->getArrowCoords(i);
|
hegyi@1
|
247 |
text_pos+=(XY(10,10));
|
hegyi@1
|
248 |
|
hegyi@1
|
249 |
arctextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
|
hegyi@1
|
250 |
arctextmap[i]->property_fill_color().set_value("darkgreen");
|
hegyi@1
|
251 |
arctextmap[i]->signal_event().connect(sigc::mem_fun(*this, &DigraphDisplayerCanvas::mapEditEventHandler), false);
|
hegyi@1
|
252 |
arctextmap[i]->raise_to_top();
|
hegyi@1
|
253 |
}
|
hegyi@1
|
254 |
|
hegyi@1
|
255 |
//afterwards nodes come to be drawn
|
hegyi@1
|
256 |
|
hegyi@1
|
257 |
for (NodeIt i((mytab.mapstorage)->digraph); i!=INVALID; ++i)
|
hegyi@1
|
258 |
{
|
hegyi@1
|
259 |
//drawing bule nodes, with black line around them
|
hegyi@1
|
260 |
|
hegyi@1
|
261 |
nodesmap[i]=new Gnome::Canvas::Ellipse(
|
hegyi@1
|
262 |
displayed_graph,
|
hegyi@1
|
263 |
mytab.mapstorage->getNodeCoords(i).x-20,
|
hegyi@1
|
264 |
mytab.mapstorage->getNodeCoords(i).y-20,
|
hegyi@1
|
265 |
mytab.mapstorage->getNodeCoords(i).x+20,
|
hegyi@1
|
266 |
mytab.mapstorage->getNodeCoords(i).y+20);
|
hegyi@1
|
267 |
*(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1
|
268 |
*(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
|
hegyi@1
|
269 |
nodesmap[i]->raise_to_top();
|
hegyi@1
|
270 |
|
hegyi@1
|
271 |
//initializing arc-text as well, to empty string
|
hegyi@1
|
272 |
|
hegyi@1
|
273 |
XY text_pos(
|
hegyi@1
|
274 |
(mytab.mapstorage->getNodeCoords(i).x+node_property_defaults[N_RADIUS]+5),
|
hegyi@1
|
275 |
(mytab.mapstorage->getNodeCoords(i).y+node_property_defaults[N_RADIUS]+5));
|
hegyi@1
|
276 |
|
hegyi@1
|
277 |
nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
|
hegyi@1
|
278 |
text_pos.x, text_pos.y, "");
|
hegyi@1
|
279 |
nodetextmap[i]->property_fill_color().set_value("darkblue");
|
hegyi@1
|
280 |
nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &DigraphDisplayerCanvas::mapEditEventHandler), false);
|
hegyi@1
|
281 |
nodetextmap[i]->raise_to_top();
|
hegyi@1
|
282 |
}
|
hegyi@1
|
283 |
|
hegyi@1
|
284 |
is_drawn=true;
|
hegyi@1
|
285 |
|
hegyi@1
|
286 |
//upon drawing digraph
|
hegyi@1
|
287 |
//properties have to
|
hegyi@1
|
288 |
//be set in as well
|
hegyi@1
|
289 |
for(int i=0;i<NODE_PROPERTY_NUM;i++)
|
hegyi@1
|
290 |
{
|
hegyi@1
|
291 |
propertyUpdate(Node(INVALID), i);
|
hegyi@1
|
292 |
}
|
hegyi@1
|
293 |
|
hegyi@1
|
294 |
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
|
hegyi@1
|
295 |
{
|
hegyi@1
|
296 |
propertyUpdate(Arc(INVALID), i);
|
hegyi@1
|
297 |
}
|
hegyi@1
|
298 |
|
hegyi@1
|
299 |
updateScrollRegion();
|
hegyi@1
|
300 |
}
|
hegyi@1
|
301 |
|
hegyi@1
|
302 |
void DigraphDisplayerCanvas::clear()
|
hegyi@1
|
303 |
{
|
hegyi@1
|
304 |
active_node=INVALID;
|
hegyi@1
|
305 |
active_arc=INVALID;
|
hegyi@1
|
306 |
forming_arc=INVALID;
|
hegyi@1
|
307 |
|
hegyi@1
|
308 |
for (NodeIt n((mytab.mapstorage)->digraph); n != INVALID; ++n)
|
hegyi@1
|
309 |
{
|
hegyi@1
|
310 |
delete nodesmap[n];
|
hegyi@1
|
311 |
delete nodetextmap[n];
|
hegyi@1
|
312 |
}
|
hegyi@1
|
313 |
|
hegyi@1
|
314 |
for (ArcIt e((mytab.mapstorage)->digraph); e != INVALID; ++e)
|
hegyi@1
|
315 |
{
|
hegyi@1
|
316 |
delete arcsmap[e];
|
hegyi@1
|
317 |
delete arctextmap[e];
|
hegyi@1
|
318 |
}
|
hegyi@1
|
319 |
|
hegyi@1
|
320 |
is_drawn=false;
|
hegyi@1
|
321 |
}
|
hegyi@1
|
322 |
|
hegyi@1
|
323 |
void DigraphDisplayerCanvas::setView(bool autoscale_p, bool zoomtrack_p, double width_p, double radius_p)
|
hegyi@1
|
324 |
{
|
hegyi@1
|
325 |
autoscale=autoscale_p;
|
hegyi@1
|
326 |
arc_width=width_p;
|
hegyi@1
|
327 |
radius_size=radius_p;
|
hegyi@1
|
328 |
|
hegyi@1
|
329 |
if((!zoomtrack) && zoomtrack_p)
|
hegyi@1
|
330 |
{
|
hegyi@1
|
331 |
fixed_zoom_factor=get_pixels_per_unit();
|
hegyi@1
|
332 |
}
|
hegyi@1
|
333 |
|
hegyi@1
|
334 |
zoomtrack=zoomtrack_p;
|
hegyi@1
|
335 |
|
hegyi@1
|
336 |
propertyChange(false, N_RADIUS);
|
hegyi@1
|
337 |
propertyChange(true, E_WIDTH);
|
hegyi@1
|
338 |
}
|
hegyi@1
|
339 |
|
hegyi@1
|
340 |
void DigraphDisplayerCanvas::getView(bool & autoscale_p, bool & zoomtrack_p, double& width_p, double& radius_p)
|
hegyi@1
|
341 |
{
|
hegyi@1
|
342 |
autoscale_p=autoscale;
|
hegyi@1
|
343 |
zoomtrack_p=zoomtrack;
|
hegyi@1
|
344 |
width_p=arc_width;
|
hegyi@1
|
345 |
radius_p=radius_size;
|
hegyi@1
|
346 |
}
|
hegyi@1
|
347 |
|
hegyi@1
|
348 |
void DigraphDisplayerCanvas::reDesignDigraph()
|
hegyi@1
|
349 |
{
|
hegyi@1
|
350 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
351 |
NodeIt firstnode(ms.digraph);
|
hegyi@1
|
352 |
//is it not an empty digraph?
|
hegyi@1
|
353 |
if(firstnode!=INVALID)
|
hegyi@1
|
354 |
{
|
hegyi@1
|
355 |
double max_coord=50000;
|
hegyi@1
|
356 |
double min_dist=20;
|
hegyi@1
|
357 |
double init_vector_length=25;
|
hegyi@1
|
358 |
|
hegyi@1
|
359 |
if(!was_redesigned)
|
hegyi@1
|
360 |
{
|
hegyi@1
|
361 |
NodeIt i(ms.digraph);
|
hegyi@1
|
362 |
|
hegyi@1
|
363 |
dim2::Point<double> init(init_vector_length*rnd(),
|
hegyi@1
|
364 |
init_vector_length*rnd());
|
hegyi@1
|
365 |
moveNode(init.x, init.y, nodesmap[i], i);
|
hegyi@1
|
366 |
was_redesigned=true;
|
hegyi@1
|
367 |
}
|
hegyi@1
|
368 |
|
hegyi@1
|
369 |
double attraction;
|
hegyi@1
|
370 |
double propulsation;
|
hegyi@1
|
371 |
int iterations;
|
hegyi@1
|
372 |
|
hegyi@1
|
373 |
ms.get_design_data(attraction, propulsation, iterations);
|
hegyi@1
|
374 |
|
hegyi@1
|
375 |
//iteration counter
|
hegyi@1
|
376 |
for(int l=0;l<iterations;l++)
|
hegyi@1
|
377 |
{
|
hegyi@1
|
378 |
Digraph::NodeMap<double> x(ms.digraph);
|
hegyi@1
|
379 |
Digraph::NodeMap<double> y(ms.digraph);
|
hegyi@1
|
380 |
XYMap<Digraph::NodeMap<double> > actual_forces;
|
hegyi@1
|
381 |
actual_forces.setXMap(x);
|
hegyi@1
|
382 |
actual_forces.setYMap(y);
|
hegyi@1
|
383 |
|
hegyi@1
|
384 |
//count actual force for each nodes
|
hegyi@1
|
385 |
for (NodeIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
386 |
{
|
hegyi@1
|
387 |
//propulsation of nodes
|
hegyi@1
|
388 |
for (NodeIt j(ms.digraph); j!=INVALID; ++j)
|
hegyi@1
|
389 |
{
|
hegyi@1
|
390 |
if(i!=j)
|
hegyi@1
|
391 |
{
|
hegyi@1
|
392 |
lemon::dim2::Point<double> delta =
|
hegyi@1
|
393 |
(ms.getNodeCoords(i)-
|
hegyi@1
|
394 |
ms.getNodeCoords(j));
|
hegyi@1
|
395 |
|
hegyi@1
|
396 |
const double length_sqr=std::max(delta.normSquare(),min_dist);
|
hegyi@1
|
397 |
|
hegyi@1
|
398 |
//normalize vector
|
hegyi@1
|
399 |
delta/=sqrt(length_sqr);
|
hegyi@1
|
400 |
|
hegyi@1
|
401 |
//calculating propulsation strength
|
hegyi@1
|
402 |
//greater distance menas smaller propulsation strength
|
hegyi@1
|
403 |
delta*=propulsation/length_sqr;
|
hegyi@1
|
404 |
|
hegyi@1
|
405 |
actual_forces.set(i,(actual_forces[i]+delta));
|
hegyi@1
|
406 |
}
|
hegyi@1
|
407 |
}
|
hegyi@1
|
408 |
//attraction of nodes, to which actual node is bound
|
hegyi@1
|
409 |
for(OutArcIt ei(ms.digraph,i);ei!=INVALID;++ei)
|
hegyi@1
|
410 |
{
|
hegyi@1
|
411 |
lemon::dim2::Point<double> delta =
|
hegyi@1
|
412 |
(ms.getNodeCoords(i)-
|
hegyi@1
|
413 |
ms.getNodeCoords(ms.digraph.target(ei)));
|
hegyi@1
|
414 |
|
hegyi@1
|
415 |
//calculating attraction strength
|
hegyi@1
|
416 |
//greater distance means greater strength
|
hegyi@1
|
417 |
delta*=attraction;
|
hegyi@1
|
418 |
|
hegyi@1
|
419 |
actual_forces.set(i,actual_forces[i]-delta);
|
hegyi@1
|
420 |
}
|
hegyi@1
|
421 |
for(InArcIt ei(ms.digraph,i);ei!=INVALID;++ei)
|
hegyi@1
|
422 |
{
|
hegyi@1
|
423 |
lemon::dim2::Point<double> delta =
|
hegyi@1
|
424 |
(ms.getNodeCoords(i)-
|
hegyi@1
|
425 |
ms.getNodeCoords(ms.digraph.source(ei)));
|
hegyi@1
|
426 |
|
hegyi@1
|
427 |
//calculating attraction strength
|
hegyi@1
|
428 |
//greater distance means greater strength
|
hegyi@1
|
429 |
delta*=attraction;
|
hegyi@1
|
430 |
|
hegyi@1
|
431 |
actual_forces.set(i,actual_forces[i]-delta);
|
hegyi@1
|
432 |
}
|
hegyi@1
|
433 |
}
|
hegyi@1
|
434 |
for (NodeIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
435 |
{
|
hegyi@1
|
436 |
if((ms.getNodeCoords(i).x)+actual_forces[i].x>max_coord)
|
hegyi@1
|
437 |
{
|
hegyi@1
|
438 |
actual_forces[i].x=max_coord-(ms.getNodeCoords(i).x);
|
hegyi@1
|
439 |
std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl;
|
hegyi@1
|
440 |
}
|
hegyi@1
|
441 |
else if((ms.getNodeCoords(i).x)+actual_forces[i].x<(0-max_coord))
|
hegyi@1
|
442 |
{
|
hegyi@1
|
443 |
actual_forces[i].x=0-max_coord-(ms.getNodeCoords(i).x);
|
hegyi@1
|
444 |
std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl;
|
hegyi@1
|
445 |
}
|
hegyi@1
|
446 |
if((ms.getNodeCoords(i).y)+actual_forces[i].y>max_coord)
|
hegyi@1
|
447 |
{
|
hegyi@1
|
448 |
actual_forces[i].y=max_coord-(ms.getNodeCoords(i).y);
|
hegyi@1
|
449 |
std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl;
|
hegyi@1
|
450 |
}
|
hegyi@1
|
451 |
else if((ms.getNodeCoords(i).y)+actual_forces[i].y<(0-max_coord))
|
hegyi@1
|
452 |
{
|
hegyi@1
|
453 |
actual_forces[i].y=0-max_coord-(ms.getNodeCoords(i).y);
|
hegyi@1
|
454 |
std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl;
|
hegyi@1
|
455 |
}
|
hegyi@1
|
456 |
moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
|
hegyi@1
|
457 |
}
|
hegyi@1
|
458 |
}
|
hegyi@1
|
459 |
}
|
hegyi@1
|
460 |
}
|
hegyi@1
|
461 |
|