Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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