Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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  }//init
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 
134  virtual ~NodeInfo() { }
135 
136  int coord(OrthoDir bs) const { return m_coord[static_cast<int>(bs)]; }//nodeboxside coordinates (real size)
137  int cageCoord(OrthoDir bs) const { return m_ccoord[static_cast<int>(bs)]; }//nodecageside coordinates (expanded size)
138 
139  //return distance between Node and Cage coord
141  {
142  int result;
143  int bsi = static_cast<int>(bs);
144  switch (bs)
145  {
146  case OrthoDir::South:
147  case OrthoDir::East:
148  result = m_ccoord[bsi] - m_coord[bsi];
149  break;
150  case OrthoDir::North:
151  case OrthoDir::West:
152  result = m_coord[bsi] - m_ccoord[bsi];
153  break;
154  default: cout<<"unknown direction in coordDistance"<<flush;
156  }//switch
157  OGDF_ASSERT(result >= 0);
158  return result;
159  }//coordDistance
160 
161  int node_xsize() const { return box_x_size; }//original box sizes, fake
162  int node_ysize() const { return box_y_size; }
163 
164  int nodeSize(OrthoDir od) const { return (static_cast<int>(od) % 2 == 0) ? box_y_size : box_x_size; }
165  int cageSize(OrthoDir od) const { return (static_cast<int>(od) % 2 == 0) ? cage_y_size : cage_x_size; }
166  int rc(OrthoDir od) const { return m_rc[static_cast<int>(od)]; } //routing channel size
167 
168  List<edge>& inList(OrthoDir bs) { return in_edges[static_cast<int>(bs)]; }
169  List<bool>& inPoint(OrthoDir bs) { return point_in[static_cast<int>(bs)]; }
170 
171  //these values are computed dependant on the nodes placement
172  int l_upper_unbend() { return lu; } //position of first and last unbend edge on every side
173  int l_lower_unbend() { return ll; }
174  int r_upper_unbend() { return ru; }
175  int r_lower_unbend() { return rl; }
176  int t_left_unbend() { return tl; }
177  int t_right_unbend() { return tr; }
178  int b_left_unbend() { return bl; }
179  int b_right_unbend() { return br; }
180 
181  //object separation distances
182  //if (no) generalization enters..., side/gener. dependant paper delta values
183  //distance at side mainside, left/right from existing generalization to side neighbour
184  int delta(OrthoDir mainside, OrthoDir neighbour) const { return m_delta[static_cast<int>(mainside)][static_cast<int>(neighbour)]; }
185 
186  //paper epsilon
187  int eps(OrthoDir mainside, OrthoDir neighbour) const { return m_eps[static_cast<int>(mainside)][static_cast<int>(neighbour)]; }
188 
189  //cardinality of the set of edges that will bend, bside side to the side bneighbour
190  int num_bend_edges(OrthoDir s1, OrthoDir sneighbour) { return m_nbe[static_cast<int>(s1)][static_cast<int>(sneighbour)]; }
191  //number of edges flipped from s1 to s2 to save one bend
192  int& flips(OrthoDir s1, OrthoDir s2) { return m_flips[static_cast<int>(s1)][static_cast<int>(s2)]; }
193 
194  int num_bend_free(OrthoDir s) const { return m_nbf[static_cast<int>(s)]; } //number of edges routed bendfree
195  void num_bend_free_increment(OrthoDir s) { ++m_nbf[static_cast<int>(s)]; }
196 
197  int num_edges(OrthoDir od) const {
198  return num_s_edges[static_cast<int>(od)]; //return number of edges at side od
199  }
200 
201  //position of gen. edges in edge lists for every side, starting with 1
202  int gen_pos(OrthoDir od) const { return m_gen_pos[static_cast<int>(od)]; }
203  bool has_gen(OrthoDir od) { return m_gen_pos[static_cast<int>(od)] > -1; }
204 
205  bool is_in_edge(OrthoDir od, int pos) {
206  ListConstIterator<bool> b_it = point_in[static_cast<int>(od)].get(pos);
207  return *b_it;
208  }
209 
210  void set_coord(OrthoDir bs, int co) { m_coord[static_cast<int>(bs)] = co; }
211  void setCageCoord(OrthoDir bs, int co) { m_ccoord[static_cast<int>(bs)] = co; }
212 
213  //delta values, due to placement problems, cut to box_size / 2
214  void set_delta(OrthoDir bside, OrthoDir bneighbour, int dval) {
215  int bsidei = static_cast<int>(bside);
216  int bneighbouri = static_cast<int>(bneighbour);
217  switch (bside)
218  {
219  case OrthoDir::North:
220  case OrthoDir::South:
221  if (dval > box_y_size) {
222  dval = int(floor(((double)box_y_size / 2))) - m_eps[bsidei][bneighbouri];
223  } break;
224  case OrthoDir::East:
225  case OrthoDir::West:
226  if (dval > box_x_size) {
227  dval = int(floor(((double)box_x_size / 2))) - m_eps[bsidei][bneighbouri];
228  } break;
229  default:
230  OGDF_ASSERT(false);
231  }//switch
232  m_delta[bsidei][bneighbouri] = dval;
233  }
234 
235  void set_eps(OrthoDir mainside, OrthoDir neighbour, int dval) { m_eps[static_cast<int>(mainside)][static_cast<int>(neighbour)] = dval; }
236 
237 #if 0
238  void set_num_bend_edges(box_side bs1, box_side bs2, int num) {nbe[bs1][bs2] = num;}
240 #endif
241 
243  void set_gen_pos(OrthoDir od, int pos) {
244  m_gen_pos[static_cast<int>(od)] = pos; //odir: N 0, E 1
245  }
246  void set_num_edges(OrthoDir od, int num) {
247  num_s_edges[static_cast<int>(od)] = num; //odir: N 0, E 1, check correct od parameter?
248  }
249 
250 
253  cage_x_size = m_ccoord[static_cast<int>(OrthoDir::South)]-m_ccoord[static_cast<int>(OrthoDir::North)];
254  cage_y_size = m_ccoord[static_cast<int>(OrthoDir::East)] - m_ccoord[static_cast<int>(OrthoDir::West)];
255  }
256 
257  //set the unbend edges after (in) placement step
258  void set_l_upper(int d) { lu = d; }
259  void set_l_lower(int d) { ll = d; }
260  void set_r_upper(int d) { ru = d; }
261  void set_r_lower(int d) { rl = d; }
262  void set_t_left(int d) { tl = d; }
263  void set_t_right(int d) { tr = d; }
264  void set_b_left(int d) { bl = d; }
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; m_nbe[s_from_i][s_to_i] += num;
272  }
273  void inc_E(OrthoDir s_from, OrthoDir s_to, int num = 1) {
274  m_nbe[static_cast<int>(s_from)][static_cast<int>(s_to)] += num;
275  }
276 
277  //read the information for node v from attributed graph/planrep
278  //(needs positions ...)
279  void get_data(
280  OrthoRep& O,
281  GridLayout& L,
282  node v,
284  NodeArray<int>& nw,
285  NodeArray<int>& nh); //check input parameter
286  int num_routable(OrthoDir s_from, OrthoDir s_to) const { return m_routable[static_cast<int>(s_from)][static_cast<int>(s_to)]; } //card. of paper E^_s1,s2
287  int vDegree() { return m_vdegree; }
288  adjEntry& firstAdj() { return m_firstAdj; }
289 
290  friend ostream& operator<<(ostream& O, const NodeInfo& inf);
291 
292 private:
293  std::array<int,4> m_rc;
294  std::array<int,4> m_coord; //coordinates of box segments, x for ls_left/right, y for s_top/bottom
295  std::array<int,4> m_ccoord; //coordinates of expanded cage segments, -"-
296  int cage_x_size, cage_y_size, //cage size
297  box_x_size, box_y_size; //box size
298  int lu,ll,ru,rl,tl,tr,bl,br; //first/last unbend edge on all sides
299  //most of the following are only [4][2] but use 44 for users conv
300  int m_delta[4][4]; //sepa. distance (paper delta)
301  int m_eps[4][4]; //corner separation distance (paper epsilon)
302  std::array<int,4> m_gen_pos; //pos num of generaliz. edge in adj lists
303  std::array<int,4> num_s_edges; //number of edges at sides 0..3=N..W
304  int m_routable[4][4]; //number of reroutable edges, paper E^_s1,s2, got to be initialized after box placement
305  int m_flips[4][4]; //real number of flipped edges
306  int m_nbe[4][4]; //paper E_s1,s2
307  std::array<int,4> m_nbf; //number of bendfree edges per side
308  adjEntry m_firstAdj; //adjEntry of first encountered outgoing edge, note: this is a copy
309 
310  std::array<List<edge>,4> in_edges; //inedges on each side will be replaced by dynamic ops
311  //preliminary bugfix of in/out dilemma
312  std::array<List<bool>,4> point_in; //save in/out info
313  adjEntry m_adj; //entry of inner cage face
314  //degree of expanded vertex
316 };
317 
318 ostream& operator<<(ostream& O, const NodeInfo& inf);
319 
320 }
321 } //end namespace
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:60
std::array< List< edge >, 4 > in_edges
Definition: NodeInfo.h:310
int num_bend_free(OrthoDir s) const
Definition: NodeInfo.h:194
Orthogonal representation of an embedded graph.
Definition: OrthoRep.h:237
ostream & operator<<(ostream &O, const NodeInfo &inf)
Declaration of a base class for planar representations of graphs and cluster graphs.
std::array< int, 4 > m_rc
Definition: NodeInfo.h:293
List< edge > & inList(OrthoDir bs)
Definition: NodeInfo.h:168
int delta(OrthoDir mainside, OrthoDir neighbour) const
Definition: NodeInfo.h:184
int gen_pos(OrthoDir od) const
Definition: NodeInfo.h:202
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:235
void set_gen_pos(OrthoDir od, int pos)
set position of generalization on each side
Definition: NodeInfo.h:243
int nodeSize(OrthoDir od) const
Definition: NodeInfo.h:164
std::array< int, 4 > num_s_edges
Definition: NodeInfo.h:303
void set_num_edges(OrthoDir od, int num)
Definition: NodeInfo.h:246
int eps(OrthoDir mainside, OrthoDir neighbour) const
Definition: NodeInfo.h:187
int cageCoord(OrthoDir bs) const
Definition: NodeInfo.h:137
std::array< int, 4 > m_ccoord
Definition: NodeInfo.h:295
std::array< int, 4 > m_gen_pos
Definition: NodeInfo.h:302
Declaration of class GridLayout.
std::array< int, 4 > m_nbf
Definition: NodeInfo.h:307
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing...
Definition: exceptions.h:308
std::array< int, 4 > m_coord
Definition: NodeInfo.h:294
int coord(OrthoDir bs) const
Definition: NodeInfo.h:136
NodeInfo(NodeInfo &&other)
Definition: NodeInfo.h:96
std::array< List< bool >, 4 > point_in
Definition: NodeInfo.h:312
void num_bend_free_increment(OrthoDir s)
Definition: NodeInfo.h:195
List< bool > & inPoint(OrthoDir bs)
Definition: NodeInfo.h:169
Class for the representation of nodes.
Definition: Graph_d.h:167
Encapsulates a pointer to a list element.
Definition: List.h:41
int & flips(OrthoDir s1, OrthoDir s2)
Definition: NodeInfo.h:192
OrthoDir
Definition: OrthoRep.h:52
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:252
int cageSize(OrthoDir od) const
Definition: NodeInfo.h:165
void set_coord(OrthoDir bs, int co)
Definition: NodeInfo.h:210
int coordDistance(OrthoDir bs)
Definition: NodeInfo.h:140
int num_bend_edges(OrthoDir s1, OrthoDir sneighbour)
Definition: NodeInfo.h:190
Declaration of class MinimumEdgeDistances which maintains minimum distances between attached edges at...
int num_edges(OrthoDir od) const
Definition: NodeInfo.h:197
void setCageCoord(OrthoDir bs, int co)
Definition: NodeInfo.h:211
int rc(OrthoDir od) const
Definition: NodeInfo.h:166
bool has_gen(OrthoDir od)
Definition: NodeInfo.h:203
void set_delta(OrthoDir bside, OrthoDir bneighbour, int dval)
Definition: NodeInfo.h:214
The namespace for all OGDF objects.
void inc_E_hook(OrthoDir s_from, OrthoDir s_to, int num=1)
Definition: NodeInfo.h:268
bool is_in_edge(OrthoDir od, int pos)
Definition: NodeInfo.h:205
int num_routable(OrthoDir s_from, OrthoDir s_to) const
Definition: NodeInfo.h:286
Class for adjacency list elements.
Definition: Graph_d.h:78
void inc_E(OrthoDir s_from, OrthoDir s_to, int num=1)
Definition: NodeInfo.h:273
#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