Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

IOPoints.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/planarity/PlanRep.h>
36 
37 
38 namespace ogdf {
39 
40 
42 struct InOutPoint
43 {
44  int m_dx, m_dy;
46 
48  m_dx = m_dy = 0; m_adj = nullptr;
49  }
50  explicit InOutPoint(adjEntry adj) {
51  m_adj = adj; m_dx = m_dy = 0;
52  }
53 };
54 
55 
57 class IOPoints {
58 public:
59  IOPoints() { }
60  explicit IOPoints(const Graph &G) : m_depth(G,0), m_height(G,0), m_in(G), m_out(G),
61  m_mark(G,false), m_pointOf(G,nullptr) { }
62 
63  ~IOPoints () { }
64 
65 
66  // length of in- or outpoint list
67  int out(node v) const {
68  return m_out[v].size();
69  }
70  int in(node v) const {
71  return m_in[v].size();
72  }
73 
74  // getting a const-reference to in- or outpoint list
75  const List<InOutPoint> &inpoints(node v) const {
76  return m_in [v];
77  }
79  return m_in [v];
80  }
81 
82  const List<InOutPoint> &outpoints(node v) const {
83  return m_out [v];
84  }
86  return m_out [v];
87  }
88 
89  // getting the in-/outpoint belonging to an adjacency entry
90  const InOutPoint *pointOf(adjEntry adj) const {
91  return m_pointOf[adj];
92  }
93 
94  // marking adjacency entries
95  bool marked(adjEntry adj) const {
96  return m_mark[adj];
97  }
98 
99  bool marked(node v) {
100  return v->outdeg() == 1 && marked(v->firstAdj());
101  }
102 
103  // finding outpoints belonging to non-marked edges
105  return searchRealForward(m_out[v].begin());
106  }
107 
109  return searchRealBackward(m_out[v].rbegin());
110  }
111 
113  return searchRealForward(it.succ());
114  }
115 
117  return searchRealBackward(it.pred());
118  }
119 
120  // building in-/outpoint lists
122  node v = adj->theNode();
123  m_pointOf[adj] = &(*m_in[v].pushBack(InOutPoint(adj)));
124  }
126  node v = adj->theNode();
127  m_pointOf[adj] = &(*m_out[v].pushBack(InOutPoint(adj)));
128  }
129  void pushInpoint(adjEntry adj) {
130  node v = adj->theNode();
131  m_pointOf[adj] = &(*m_in[v].pushFront(InOutPoint(adj)));
132  }
133 
134  // setting relative coordinates
135  void setOutCoord (ListIterator<InOutPoint> it, int dx, int dy) {
136  (*it).m_dx = dx;
137  (*it).m_dy = dy;
138  }
139  void setInCoord (ListIterator<InOutPoint> it, int dx, int dy) {
140  (*it).m_dx = dx;
141  (*it).m_dy = dy;
142  }
143 
145  (*it).m_dx = dx;
146  }
147 
148  void restoreDeg1Nodes(PlanRep &PG, ArrayBuffer<PlanRep::Deg1RestoreInfo> &S);
149 
150  void changeEdge(node v, adjEntry adj_new) {
151  m_out[v].popBack();
152  appendInpoint(adj_new);
153  }
154 
155  // belongs v to a chain (= at most to non-marked incoming edges
156  bool isChain(node v) const {
157  int i = 0;
158  for(const InOutPoint &iop : m_in[v])
159  if (!marked(iop.m_adj)) ++i;
160  return i <= 2;
161  }
162 
163  // width of the left-/right side of an in-/outpoint list
164  int outLeft(node v) const {
165  return (m_out[v].empty()) ? 0 : (-m_out[v].front().m_dx);
166  }
167 
168  int outRight(node v) const {
169  return (m_out[v].empty()) ? 0 : (m_out[v].back().m_dx);
170  }
171 
172  int inLeft(node v) const {
173  return (m_in[v].empty()) ? 0 : (-m_in[v].front().m_dx);
174  }
175 
176  int inRight(node v) const {
177  return (m_in[v].empty()) ? 0 : (m_in[v].back().m_dx);
178  }
179 
180  int maxLeft(node v) const {
181  return max(inLeft(v), outLeft(v));
182  }
183 
184  int maxRight(node v) const {
185  return max(inRight(v), outRight(v));
186  }
187 
188  int maxPlusLeft(node v) const {
189  return (in(v) >= 3) ?
190  max(inLeft(v)+1, outLeft(v)) : maxLeft(v);
191  }
192 
193  int maxPlusRight(node v) const {
194  return (in(v) >= 3) ?
195  max(inRight(v)+1, outRight(v)) : maxRight(v);
196  }
197 
198  InOutPoint middleNeighbor(node z1) const;
199 
200  void numDeg1(node v, int &xl, int &xr,
201  bool doubleCount) const;
202 
203  adjEntry switchBeginIn(node v);
204  adjEntry switchEndIn (node v);
205 
206  void switchBeginOut(node v);
207  void switchEndOut (node v);
208 
209 
211 
212 
213 private:
217 
220 };
221 
222 }
int maxRight(node v) const
Definition: IOPoints.h:184
bool isChain(node v) const
Definition: IOPoints.h:156
AdjEntryArray< bool > m_mark
Definition: IOPoints.h:215
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:145
int inRight(node v) const
Definition: IOPoints.h:176
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
IOPoints(const Graph &G)
Definition: IOPoints.h:60
adjEntry m_adj
Definition: IOPoints.h:45
Representation of an in- or outpoint.
Definition: IOPoints.h:42
int outdeg() const
Returns the outdegree of the node.
Definition: Graph_d.h:208
const List< InOutPoint > & outpoints(node v) const
Definition: IOPoints.h:82
void appendInpoint(adjEntry adj)
Definition: IOPoints.h:121
Declaration of a base class for planar representations of graphs and cluster graphs.
const List< InOutPoint > & inpoints(node v) const
Definition: IOPoints.h:75
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Definition: Array.h:45
bool marked(node v)
Definition: IOPoints.h:99
int maxPlusRight(node v) const
Definition: IOPoints.h:193
InOutPoint(adjEntry adj)
Definition: IOPoints.h:50
ListConstIterator< InOutPoint > prevRealOut(ListConstIterator< InOutPoint > it) const
Definition: IOPoints.h:116
int outRight(node v) const
Definition: IOPoints.h:168
Representation of in- and outpoint lists.
Definition: IOPoints.h:57
NodeArray< int > m_height
Definition: IOPoints.h:210
int inLeft(node v) const
Definition: IOPoints.h:172
ListConstIterator< InOutPoint > nextRealOut(ListConstIterator< InOutPoint > it) const
Definition: IOPoints.h:112
ListIteratorBase< E, isConst, isReverse > pred() const
Returns predecessor iterator.
Definition: List.h:150
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
NodeArray< List< InOutPoint > > m_out
Definition: IOPoints.h:214
void appendOutpoint(adjEntry adj)
Definition: IOPoints.h:125
int in(node v) const
Definition: IOPoints.h:70
int outLeft(node v) const
Definition: IOPoints.h:164
void changeEdge(node v, adjEntry adj_new)
Definition: IOPoints.h:150
AdjEntryArray< InOutPoint * > m_pointOf
Definition: IOPoints.h:216
Class for the representation of nodes.
Definition: Graph_d.h:169
bool marked(adjEntry adj) const
Definition: IOPoints.h:95
int maxPlusLeft(node v) const
Definition: IOPoints.h:188
Encapsulates a pointer to a list element.
Definition: List.h:42
List< InOutPoint > & outpoints(node v)
Definition: IOPoints.h:85
void setOutDx(ListIterator< InOutPoint > it, int dx)
Definition: IOPoints.h:144
ListConstIterator< InOutPoint > lastRealOut(node v) const
Definition: IOPoints.h:108
void pushInpoint(adjEntry adj)
Definition: IOPoints.h:129
The namespace for all OGDF objects.
void setOutCoord(ListIterator< InOutPoint > it, int dx, int dy)
Definition: IOPoints.h:135
List< InOutPoint > & inpoints(node v)
Definition: IOPoints.h:78
int maxLeft(node v) const
Definition: IOPoints.h:180
void setInCoord(ListIterator< InOutPoint > it, int dx, int dy)
Definition: IOPoints.h:139
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:213
const InOutPoint * pointOf(adjEntry adj) const
Definition: IOPoints.h:90
int out(node v) const
Definition: IOPoints.h:67
ListConstIterator< InOutPoint > firstRealOut(node v) const
Definition: IOPoints.h:104
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:100
Class for adjacency list elements.
Definition: Graph_d.h:79
Planarized representations (of a connected component) of a graph.
Definition: PlanRep.h:59