Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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>
42 #include <ogdf/basic/exceptions.h>
45 
46 #include <array>
47 #include <cmath>
48 #include <iostream>
49 
50 namespace ogdf {
51 class GridLayout;
52 
53 namespace edge_router {
54 
56 public:
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
229  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 ...)
281  void get_data(OrthoRep& O, GridLayout& L, node v, RoutingChannel<int>& rc, NodeArray<int>& nw,
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 
295 private:
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 
321 std::ostream& operator<<(std::ostream& O, const NodeInfo& inf);
322 
323 }
324 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::edge_router::NodeInfo::node_xsize
int node_xsize() const
Definition: NodeInfo.h:118
Graph.h
Includes declaration of graph class.
ogdf::edge_router::NodeInfo::set_num_edges
void set_num_edges(OrthoDir od, int num)
Definition: NodeInfo.h:238
ogdf::edge_router::NodeInfo::t_left_unbend
int t_left_unbend()
Definition: NodeInfo.h:147
exceptions.h
Definition of exception classes.
ogdf::edge_router::NodeInfo::flips
int & flips(OrthoDir s1, OrthoDir s2)
Definition: NodeInfo.h:173
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::edge_router::NodeInfo
Definition: NodeInfo.h:55
ogdf::edge_router::NodeInfo::m_firstAdj
adjEntry m_firstAdj
Definition: NodeInfo.h:311
ogdf::edge_router::NodeInfo::m_rc
std::array< int, 4 > m_rc
Definition: NodeInfo.h:296
ogdf::edge_router::NodeInfo::vDegree
int vDegree()
Definition: NodeInfo.h:289
ogdf::edge_router::NodeInfo::l_upper_unbend
int l_upper_unbend()
Definition: NodeInfo.h:139
ogdf::edge_router::NodeInfo::set_l_upper
void set_l_upper(int d)
Definition: NodeInfo.h:251
ogdf::edge_router::NodeInfo::set_coord
void set_coord(OrthoDir bs, int co)
Definition: NodeInfo.h:197
ogdf::OrthoDir
OrthoDir
Definition: OrthoRep.h:56
ogdf::edge_router::NodeInfo::m_coord
std::array< int, 4 > m_coord
Definition: NodeInfo.h:297
ogdf::edge_router::NodeInfo::b_right_unbend
int b_right_unbend()
Definition: NodeInfo.h:153
ogdf::OrthoDir::West
@ West
ogdf::edge_router::NodeInfo::setCageCoord
void setCageCoord(OrthoDir bs, int co)
Definition: NodeInfo.h:199
ogdf::edge_router::NodeInfo::m_gen_pos
std::array< int, 4 > m_gen_pos
Definition: NodeInfo.h:305
ogdf::edge_router::NodeInfo::coord
int coord(OrthoDir bs) const
Returns nodeboxside coordinates (real size)
Definition: NodeInfo.h:91
ogdf::edge_router::NodeInfo::rc
int rc(OrthoDir od) const
Returns routing channel size.
Definition: NodeInfo.h:131
ogdf::edge_router::NodeInfo::coordDistance
int coordDistance(OrthoDir bs)
Definition: NodeInfo.h:97
ogdf::edge_router::NodeInfo::set_r_lower
void set_r_lower(int d)
Definition: NodeInfo.h:257
ogdf::edge_router::NodeInfo::inPoint
List< bool > & inPoint(OrthoDir bs)
Definition: NodeInfo.h:135
ogdf::edge_router::NodeInfo::cageSize
int cageSize(OrthoDir od) const
Definition: NodeInfo.h:126
ogdf::edge_router::NodeInfo::in_edges
std::array< List< edge >, 4 > in_edges
Definition: NodeInfo.h:313
ogdf::edge_router::NodeInfo::point_in
std::array< List< bool >, 4 > point_in
Definition: NodeInfo.h:315
ogdf::OrthoDir::South
@ South
ogdf::edge_router::NodeInfo::inc_E_hook
void inc_E_hook(OrthoDir s_from, OrthoDir s_to, int num=1)
Definition: NodeInfo.h:268
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:153
ogdf::edge_router::NodeInfo::num_bend_edges
int num_bend_edges(OrthoDir s1, OrthoDir sneighbour)
Definition: NodeInfo.h:168
ogdf::edge_router::NodeInfo::compute_cage_size
void compute_cage_size()
compute the size of the cage face and the node box
Definition: NodeInfo.h:243
ogdf::edge_router::NodeInfo::has_gen
bool has_gen(OrthoDir od)
Definition: NodeInfo.h:189
ogdf::edge_router::NodeInfo::b_left_unbend
int b_left_unbend()
Definition: NodeInfo.h:151
ogdf::edge_router::NodeInfo::set_delta
void set_delta(OrthoDir bside, OrthoDir bneighbour, int dval)
Definition: NodeInfo.h:202
ogdf::edge_router::NodeInfo::m_vdegree
int m_vdegree
Definition: NodeInfo.h:318
ogdf::edge_router::NodeInfo::set_b_right
void set_b_right(int d)
Definition: NodeInfo.h:265
ogdf::edge_router::NodeInfo::is_in_edge
bool is_in_edge(OrthoDir od, int pos)
Definition: NodeInfo.h:191
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::AlgorithmFailureException
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition: exceptions.h:247
ogdf::edge_router::NodeInfo::tr
int tr
Definition: NodeInfo.h:301
ogdf::edge_router::NodeInfo::num_edges
int num_edges(OrthoDir od) const
Definition: NodeInfo.h:182
ogdf::edge_router::NodeInfo::cage_y_size
int cage_y_size
Definition: NodeInfo.h:299
ogdf::edge_router::NodeInfo::num_routable
int num_routable(OrthoDir s_from, OrthoDir s_to) const
Definition: NodeInfo.h:285
ogdf::edge_router::NodeInfo::NodeInfo
NodeInfo(OrthoRep &H, GridLayout &L, node v, adjEntry adj, RoutingChannel< int > &rc, NodeArray< int > &nw, NodeArray< int > &nh)
Definition: NodeInfo.h:83
ogdf::edge_router::NodeInfo::m_adj
adjEntry m_adj
Definition: NodeInfo.h:316
ogdf::edge_router::NodeInfo::l_lower_unbend
int l_lower_unbend()
Definition: NodeInfo.h:141
OrthoRep.h
Declaration of orthogonal representation of planar graphs.
OGDF_THROW
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition: exceptions.h:74
ogdf::OrthoRep
Orthogonal representation of an embedded graph.
Definition: OrthoRep.h:225
ogdf::edge_router::NodeInfo::inc_E
void inc_E(OrthoDir s_from, OrthoDir s_to, int num=1)
Definition: NodeInfo.h:275
ogdf::edge_router::NodeInfo::firstAdj
adjEntry & firstAdj()
Definition: NodeInfo.h:291
ogdf::edge_router::NodeInfo::num_s_edges
std::array< int, 4 > num_s_edges
Definition: NodeInfo.h:306
ogdf::edge_router::NodeInfo::set_r_upper
void set_r_upper(int d)
Definition: NodeInfo.h:255
ogdf::edge_router::NodeInfo::set_l_lower
void set_l_lower(int d)
Definition: NodeInfo.h:253
ogdf::edge_router::NodeInfo::t_right_unbend
int t_right_unbend()
Definition: NodeInfo.h:149
ogdf::edge_router::NodeInfo::init
void init()
Definition: NodeInfo.h:60
ogdf::List< edge >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::edge_router::NodeInfo::r_lower_unbend
int r_lower_unbend()
Definition: NodeInfo.h:145
ogdf::edge_router::NodeInfo::set_t_right
void set_t_right(int d)
Definition: NodeInfo.h:261
ogdf::graphics::init
void init()
Definition: graphics.h:450
ogdf::edge_router::NodeInfo::node_ysize
int node_ysize() const
Definition: NodeInfo.h:120
ogdf::edge_router::NodeInfo::r_upper_unbend
int r_upper_unbend()
Definition: NodeInfo.h:143
ogdf::edge_router::NodeInfo::inList
List< edge > & inList(OrthoDir bs)
Definition: NodeInfo.h:133
ogdf::edge_router::NodeInfo::NodeInfo
NodeInfo()
Definition: NodeInfo.h:58
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::edge_router::NodeInfo::num_bend_free
int num_bend_free(OrthoDir s) const
Definition: NodeInfo.h:178
ogdf::edge_router::NodeInfo::set_t_left
void set_t_left(int d)
Definition: NodeInfo.h:259
ogdf::OrthoDir::East
@ East
ogdf::edge_router::NodeInfo::gen_pos
int gen_pos(OrthoDir od) const
Definition: NodeInfo.h:187
ogdf::edge_router::NodeInfo::delta
int delta(OrthoDir mainside, OrthoDir neighbour) const
Definition: NodeInfo.h:158
ogdf::edge_router::NodeInfo::m_ccoord
std::array< int, 4 > m_ccoord
Definition: NodeInfo.h:298
List.h
Declaration of doubly linked lists and iterators.
ogdf::edge_router::NodeInfo::m_nbf
std::array< int, 4 > m_nbf
Definition: NodeInfo.h:310
ogdf::GridLayout
Representation of a graph's grid layout.
Definition: GridLayout.h:47
ogdf::edge_router::NodeInfo::cageCoord
int cageCoord(OrthoDir bs) const
Returns nodecageside coordinates (expanded size)
Definition: NodeInfo.h:94
ogdf::OrthoDir::North
@ North
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:51
ogdf::edge_router::NodeInfo::set_eps
void set_eps(OrthoDir mainside, OrthoDir neighbour, int dval)
Definition: NodeInfo.h:224
RoutingChannel.h
Declaration of class RoutingChannel which maintains required size of routing channels and separation,...
ogdf::edge_router::NodeInfo::set_gen_pos
void set_gen_pos(OrthoDir od, int pos)
set position of generalization on each side
Definition: NodeInfo.h:234
ogdf::edge_router::operator<<
std::ostream & operator<<(std::ostream &O, const NodeInfo &inf)
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::edge_router::NodeInfo::box_y_size
int box_y_size
Definition: NodeInfo.h:300
ogdf::edge_router::NodeInfo::num_bend_free_increment
void num_bend_free_increment(OrthoDir s)
Definition: NodeInfo.h:180
ogdf::edge_router::NodeInfo::set_b_left
void set_b_left(int d)
Definition: NodeInfo.h:263
ogdf::edge_router::NodeInfo::eps
int eps(OrthoDir mainside, OrthoDir neighbour) const
Definition: NodeInfo.h:163
ogdf::edge_router::NodeInfo::nodeSize
int nodeSize(OrthoDir od) const
Definition: NodeInfo.h:122
ogdf::RoutingChannel< int >