Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
NodeInfo.h
Go to the documentation of this file.
1
37#pragma once
38
39#include <ogdf/basic/Graph.h>
40#include <ogdf/basic/List.h>
41#include <ogdf/basic/basic.h>
45
46#include <array>
47#include <cmath>
48#include <iostream>
49
50namespace ogdf {
51class GridLayout;
52
53namespace edge_router {
54
56public:
57 //standard constr.
58 NodeInfo() { init(); }
59
60 void init() {
61 for (int i = 0; i < 4; i++) {
62 for (int j = 0; j < 4; j++) {
63 m_nbe[i][j] = 0;
64 m_delta[i][j] = 0;
65 m_eps[i][j] = 0;
66 m_routable[i][j] = 0;
67 m_flips[i][j] = 0;
68 }
69 num_s_edges[i] = 0;
70 m_gen_pos[i] = -1;
71 m_nbf[i] = 0;
72 m_rc[i] = 0;
73 m_coord[i] = 0;
74 m_ccoord[i] = 0;
75 }
76 lu = ll = ru = rl = tl = tr = bl = br = 0;
77 cage_x_size = cage_y_size = box_x_size = box_y_size = 0;
78 m_vdegree = 0;
79 m_firstAdj = m_adj = nullptr;
80 }
81
82 //Constructor, adj holds entry for inner face edge
85 : m_adj(adj) {
86 init();
87 get_data(H, L, v, rc, nw, nh);
88 }
89
91 int coord(OrthoDir bs) const { return m_coord[static_cast<int>(bs)]; }
92
94 int cageCoord(OrthoDir bs) const { return m_ccoord[static_cast<int>(bs)]; }
95
96 //return distance between Node and Cage coord
98 int result;
99 int bsi = static_cast<int>(bs);
100 switch (bs) {
101 case OrthoDir::South:
102 case OrthoDir::East:
103 result = m_ccoord[bsi] - m_coord[bsi];
104 break;
105 case OrthoDir::North:
106 case OrthoDir::West:
107 result = m_coord[bsi] - m_ccoord[bsi];
108 break;
109 default:
110 std::cout << "unknown direction in coordDistance" << std::flush;
112 }
113 OGDF_ASSERT(result >= 0);
114 return result;
115 }
116
117 // original box sizes, fake
118 int node_xsize() const { return box_x_size; }
119
120 int node_ysize() const { return box_y_size; }
121
122 int nodeSize(OrthoDir od) const {
123 return (static_cast<int>(od) % 2 == 0) ? box_y_size : box_x_size;
124 }
125
126 int cageSize(OrthoDir od) const {
127 return (static_cast<int>(od) % 2 == 0) ? cage_y_size : cage_x_size;
128 }
129
131 int rc(OrthoDir od) const { return m_rc[static_cast<int>(od)]; }
132
133 List<edge>& inList(OrthoDir bs) { return in_edges[static_cast<int>(bs)]; }
134
135 List<bool>& inPoint(OrthoDir bs) { return point_in[static_cast<int>(bs)]; }
136
137 //these values are computed dependant on the nodes placement
138 // position of first and last unbend edge on every side
139 int l_upper_unbend() { return lu; }
140
141 int l_lower_unbend() { return ll; }
142
143 int r_upper_unbend() { return ru; }
144
145 int r_lower_unbend() { return rl; }
146
147 int t_left_unbend() { return tl; }
148
149 int t_right_unbend() { return tr; }
150
151 int b_left_unbend() { return bl; }
152
153 int b_right_unbend() { return br; }
154
155 //object separation distances
156 //if (no) generalization enters..., side/gener. dependant paper delta values
157 //distance at side mainside, left/right from existing generalization to side neighbour
158 int delta(OrthoDir mainside, OrthoDir neighbour) const {
159 return m_delta[static_cast<int>(mainside)][static_cast<int>(neighbour)];
160 }
161
162 //paper epsilon
163 int eps(OrthoDir mainside, OrthoDir neighbour) const {
164 return m_eps[static_cast<int>(mainside)][static_cast<int>(neighbour)];
165 }
166
167 //cardinality of the set of edges that will bend, bside side to the side bneighbour
168 int num_bend_edges(OrthoDir s1, OrthoDir sneighbour) {
169 return m_nbe[static_cast<int>(s1)][static_cast<int>(sneighbour)];
170 }
171
172 //number of edges flipped from s1 to s2 to save one bend
173 int& flips(OrthoDir s1, OrthoDir s2) {
174 return m_flips[static_cast<int>(s1)][static_cast<int>(s2)];
175 }
176
177 // number of edges routed bendfree
178 int num_bend_free(OrthoDir s) const { return m_nbf[static_cast<int>(s)]; }
179
180 void num_bend_free_increment(OrthoDir s) { ++m_nbf[static_cast<int>(s)]; }
181
182 int num_edges(OrthoDir od) const {
183 return num_s_edges[static_cast<int>(od)]; //return number of edges at side od
184 }
185
186 //position of gen. edges in edge lists for every side, starting with 1
187 int gen_pos(OrthoDir od) const { return m_gen_pos[static_cast<int>(od)]; }
188
189 bool has_gen(OrthoDir od) { return m_gen_pos[static_cast<int>(od)] > -1; }
190
191 bool is_in_edge(OrthoDir od, int pos) {
192 ListConstIterator<bool> b_it = point_in[static_cast<int>(od)].get(pos);
193 OGDF_ASSERT(b_it.valid());
194 return *b_it;
195 }
196
197 void set_coord(OrthoDir bs, int co) { m_coord[static_cast<int>(bs)] = co; }
198
199 void setCageCoord(OrthoDir bs, int co) { m_ccoord[static_cast<int>(bs)] = co; }
200
201 //delta values, due to placement problems, cut to box_size / 2
202 void set_delta(OrthoDir bside, OrthoDir bneighbour, int dval) {
203 int bsidei = static_cast<int>(bside);
204 int bneighbouri = static_cast<int>(bneighbour);
205 switch (bside) {
206 case OrthoDir::North:
207 case OrthoDir::South:
208 if (dval > box_y_size) {
209 dval = int(floor(((double)box_y_size / 2))) - m_eps[bsidei][bneighbouri];
210 }
211 break;
212 case OrthoDir::East:
213 case OrthoDir::West:
214 if (dval > box_x_size) {
215 dval = int(floor(((double)box_x_size / 2))) - m_eps[bsidei][bneighbouri];
216 }
217 break;
218 default:
219 OGDF_ASSERT(false);
220 }
221 m_delta[bsidei][bneighbouri] = dval;
222 }
223
224 void set_eps(OrthoDir mainside, OrthoDir neighbour, int dval) {
225 m_eps[static_cast<int>(mainside)][static_cast<int>(neighbour)] = dval;
226 }
227
228#if 0
230 void set_num_bend_edges(box_side bs1, box_side bs2, int num) {nbe[bs1][bs2] = num;}
231#endif
232
234 void set_gen_pos(OrthoDir od, int pos) {
235 m_gen_pos[static_cast<int>(od)] = pos; //odir: N 0, E 1
236 }
237
238 void set_num_edges(OrthoDir od, int num) {
239 num_s_edges[static_cast<int>(od)] = num; //odir: N 0, E 1, check correct od parameter?
240 }
241
244 cage_x_size = m_ccoord[static_cast<int>(OrthoDir::South)]
245 - m_ccoord[static_cast<int>(OrthoDir::North)];
246 cage_y_size = m_ccoord[static_cast<int>(OrthoDir::East)]
247 - m_ccoord[static_cast<int>(OrthoDir::West)];
248 }
249
250 //set the unbend edges after (in) placement step
251 void set_l_upper(int d) { lu = d; }
252
253 void set_l_lower(int d) { ll = d; }
254
255 void set_r_upper(int d) { ru = d; }
256
257 void set_r_lower(int d) { rl = d; }
258
259 void set_t_left(int d) { tl = d; }
260
261 void set_t_right(int d) { tr = d; }
262
263 void set_b_left(int d) { bl = d; }
264
265 void set_b_right(int d) { br = d; }
266
267 //paper set E_s1_s2
268 void inc_E_hook(OrthoDir s_from, OrthoDir s_to, int num = 1) {
269 int s_from_i = static_cast<int>(s_from);
270 int s_to_i = static_cast<int>(s_to);
271 m_routable[s_from_i][s_to_i] += num;
272 m_nbe[s_from_i][s_to_i] += num;
273 }
274
275 void inc_E(OrthoDir s_from, OrthoDir s_to, int num = 1) {
276 m_nbe[static_cast<int>(s_from)][static_cast<int>(s_to)] += num;
277 }
278
279 //read the information for node v from attributed graph/planrep
280 //(needs positions ...)
282 NodeArray<int>& nh); //check input parameter
283
284 // card. of paper E^_s1,s2
285 int num_routable(OrthoDir s_from, OrthoDir s_to) const {
286 return m_routable[static_cast<int>(s_from)][static_cast<int>(s_to)];
287 }
288
289 int vDegree() { return m_vdegree; }
290
291 adjEntry& firstAdj() { return m_firstAdj; }
292
293 friend std::ostream& operator<<(std::ostream& O, const NodeInfo& inf);
294
295private:
296 std::array<int, 4> m_rc;
297 std::array<int, 4> m_coord; //coordinates of box segments, x for ls_left/right, y for s_top/bottom
298 std::array<int, 4> m_ccoord; //coordinates of expanded cage segments, -"-
299 int cage_x_size, cage_y_size, //cage size
300 box_x_size, box_y_size; //box size
301 int lu, ll, ru, rl, tl, tr, bl, br; //first/last unbend edge on all sides
302 //most of the following are only [4][2] but use 44 for users conv
303 int m_delta[4][4]; //sepa. distance (paper delta)
304 int m_eps[4][4]; //corner separation distance (paper epsilon)
305 std::array<int, 4> m_gen_pos; //pos num of generaliz. edge in adj lists
306 std::array<int, 4> num_s_edges; //number of edges at sides 0..3=N..W
307 int m_routable[4][4]; //number of reroutable edges, paper E^_s1,s2, got to be initialized after box placement
308 int m_flips[4][4]; //real number of flipped edges
309 int m_nbe[4][4]; //paper E_s1,s2
310 std::array<int, 4> m_nbf; //number of bendfree edges per side
311 adjEntry m_firstAdj; //adjEntry of first encountered outgoing edge, note: this is a copy
312
313 std::array<List<edge>, 4> in_edges; //inedges on each side will be replaced by dynamic ops
314 //preliminary bugfix of in/out dilemma
315 std::array<List<bool>, 4> point_in; //save in/out info
316 adjEntry m_adj; //entry of inner cage face
317 //degree of expanded vertex
319};
320
321std::ostream& operator<<(std::ostream& O, const NodeInfo& inf);
322
323}
324}
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Declaration of orthogonal representation of planar graphs.
Declaration of class RoutingChannel which maintains required size of routing channels and separation,...
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition exceptions.h:247
Representation of a graph's grid layout.
Definition GridLayout.h:47
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Encapsulates a pointer to a list element.
Definition List.h:113
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:153
Class for the representation of nodes.
Definition Graph_d.h:241
Orthogonal representation of an embedded graph.
Definition OrthoRep.h:225
Maintains input sizes for constructive compaction (size of routing channels, separation,...
int num_routable(OrthoDir s_from, OrthoDir s_to) const
Definition NodeInfo.h:285
int coord(OrthoDir bs) const
Returns nodeboxside coordinates (real size)
Definition NodeInfo.h:91
List< edge > & inList(OrthoDir bs)
Definition NodeInfo.h:133
NodeInfo(OrthoRep &H, GridLayout &L, node v, adjEntry adj, RoutingChannel< int > &rc, NodeArray< int > &nw, NodeArray< int > &nh)
Definition NodeInfo.h:83
void num_bend_free_increment(OrthoDir s)
Definition NodeInfo.h:180
void setCageCoord(OrthoDir bs, int co)
Definition NodeInfo.h:199
bool has_gen(OrthoDir od)
Definition NodeInfo.h:189
int gen_pos(OrthoDir od) const
Definition NodeInfo.h:187
void compute_cage_size()
compute the size of the cage face and the node box
Definition NodeInfo.h:243
int & flips(OrthoDir s1, OrthoDir s2)
Definition NodeInfo.h:173
bool is_in_edge(OrthoDir od, int pos)
Definition NodeInfo.h:191
void inc_E_hook(OrthoDir s_from, OrthoDir s_to, int num=1)
Definition NodeInfo.h:268
List< bool > & inPoint(OrthoDir bs)
Definition NodeInfo.h:135
std::array< List< bool >, 4 > point_in
Definition NodeInfo.h:315
void set_coord(OrthoDir bs, int co)
Definition NodeInfo.h:197
int num_bend_free(OrthoDir s) const
Definition NodeInfo.h:178
std::array< List< edge >, 4 > in_edges
Definition NodeInfo.h:313
void set_gen_pos(OrthoDir od, int pos)
set position of generalization on each side
Definition NodeInfo.h:234
int eps(OrthoDir mainside, OrthoDir neighbour) const
Definition NodeInfo.h:163
void set_delta(OrthoDir bside, OrthoDir bneighbour, int dval)
Definition NodeInfo.h:202
int coordDistance(OrthoDir bs)
Definition NodeInfo.h:97
void inc_E(OrthoDir s_from, OrthoDir s_to, int num=1)
Definition NodeInfo.h:275
std::array< int, 4 > m_nbf
Definition NodeInfo.h:310
int cageSize(OrthoDir od) const
Definition NodeInfo.h:126
void set_eps(OrthoDir mainside, OrthoDir neighbour, int dval)
Definition NodeInfo.h:224
void set_num_edges(OrthoDir od, int num)
Definition NodeInfo.h:238
int delta(OrthoDir mainside, OrthoDir neighbour) const
Definition NodeInfo.h:158
int cageCoord(OrthoDir bs) const
Returns nodecageside coordinates (expanded size)
Definition NodeInfo.h:94
std::array< int, 4 > num_s_edges
Definition NodeInfo.h:306
std::array< int, 4 > m_rc
Definition NodeInfo.h:296
friend std::ostream & operator<<(std::ostream &O, const NodeInfo &inf)
int num_bend_edges(OrthoDir s1, OrthoDir sneighbour)
Definition NodeInfo.h:168
std::array< int, 4 > m_ccoord
Definition NodeInfo.h:298
void get_data(OrthoRep &O, GridLayout &L, node v, RoutingChannel< int > &rc, NodeArray< int > &nw, NodeArray< int > &nh)
int num_edges(OrthoDir od) const
Definition NodeInfo.h:182
int rc(OrthoDir od) const
Returns routing channel size.
Definition NodeInfo.h:131
std::array< int, 4 > m_gen_pos
Definition NodeInfo.h:305
int nodeSize(OrthoDir od) const
Definition NodeInfo.h:122
std::array< int, 4 > m_coord
Definition NodeInfo.h:297
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
Definition of exception classes.
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition exceptions.h:67
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
std::ostream & operator<<(std::ostream &O, const NodeInfo &inf)
The namespace for all OGDF objects.
OrthoDir
Definition OrthoRep.h:56