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