Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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