Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

CombinatorialEmbedding.h
Go to the documentation of this file.
1 
34 #pragma once
35 
37 
38 namespace ogdf {
39 
40 using face = FaceElement*;
41 
42 // Definition of iterator and container types for adjacency entries in a face
43 // These declarations are just internal representations
44 namespace internal {
45 
48 
51 
52 public:
53  FaceAdjIterator() : m_adj(nullptr), m_adjFirst(nullptr) { }
54  explicit FaceAdjIterator(adjEntry adj) : m_adj(adj), m_adjFirst(adj) { }
55  FaceAdjIterator(adjEntry adjFirst, adjEntry adj) : m_adj(adj), m_adjFirst(adjFirst) { }
56 
57  bool operator==(const FaceAdjIterator &other) const {
58  return m_adj == other.m_adj;
59  }
60 
61  bool operator!=(const FaceAdjIterator &other) const {
62  return m_adj != other.m_adj;
63  }
64 
66  m_adjFirst = other.m_adjFirst;
67  m_adj = other.m_adj;
68  return *this;
69  }
70 
71  adjEntry operator*() const { return m_adj; }
72 
74  m_adj = m_adj->faceCycleSucc();
75  if (m_adj == m_adjFirst)
76  m_adj = nullptr;
77  return *this;
78  }
79 };
80 
81 
83 
88 
89  friend class ogdf::FaceElement;
92 
94 
95  FaceAdjContainer() : m_adjFirst(nullptr) { }
96  explicit FaceAdjContainer(adjEntry adjFirst) : m_adjFirst(adjFirst) { }
97 
98 public:
100 
101  iterator begin() const { return iterator(m_adjFirst); }
102  iterator end() const { return iterator(); }
103 };
104 
105 } // end namespace internal
106 
107 
112 {
116 
117  //adjEntry m_adjFirst; //!< The first adjacency element in the face.
118  int m_id;
119  int m_size;
120 
121 #ifdef OGDF_DEBUG
122  const ConstCombinatorialEmbedding *m_pEmbedding;
123 #endif
124 
125 #ifdef OGDF_DEBUG
126  FaceElement(const ConstCombinatorialEmbedding *pEmbedding,
128  adjEntry adjFirst,
129  int id) :
130  m_id(id), m_size(0), m_pEmbedding(pEmbedding), entries(adjFirst) { }
131 #else
132  FaceElement(adjEntry adjFirst, int id) :
134  m_id(id), m_size(0), entries(adjFirst) { }
135 #endif
136 
137 public:
140 
142  int index() const { return m_id; }
143 
145  adjEntry firstAdj() const { return entries.m_adjFirst; }
146 
148  int size() const { return m_size; }
149 
151  face succ() const { return static_cast<face>(m_next); }
152 
154  face pred() const { return static_cast<face>(m_prev); }
155 
158  adj = adj->faceCycleSucc();
159  return (adj != entries.m_adjFirst) ? adj : nullptr;
160  }
161 
162 #ifdef OGDF_DEBUG
163  const ConstCombinatorialEmbedding *embeddingOf() const { return m_pEmbedding; }
164 #endif
165 
167  static int compare(const FaceElement& x, const FaceElement& y) { return x.m_id - y.m_id; }
169 
171 }; // class FaceElement
172 
173 
174 class FaceArrayBase;
175 template<class T>class FaceArray;
176 
177 
200 {
201 protected:
202  const Graph *m_cpGraph;
203 
206 
209 
211 
212 #ifndef OGDF_MEMORY_POOL_NTS
213  mutable std::mutex m_mutexRegArrays;
214 #endif
215 
216 public:
219 
222 
227 
234  explicit ConstCombinatorialEmbedding(const Graph &G);
235 
236 
239 
242 
244  virtual ~ConstCombinatorialEmbedding();
245 
247  bool valid() const { return m_cpGraph != nullptr; }
248 
254  const Graph &getGraph() const {
255  OGDF_ASSERT(valid());
256  return *m_cpGraph;
257  }
258 
260  operator const Graph &() const { return getGraph(); }
261 
265  face firstFace() const { return faces.head(); }
266 
268  face lastFace() const { return faces.tail(); }
269 
271  int numberOfFaces() const { return faces.size(); }
272 
277  face rightFace(adjEntry adj) const { return m_rightFace[adj]; }
278 
283  face leftFace(adjEntry adj) const { return m_rightFace[adj->twin()]; }
284 
288  int maxFaceIndex() const { return m_faceIdCount-1; }
289 
291  int faceArrayTableSize() const { return m_faceArrayTableSize; }
292 
299  face chooseFace(std::function<bool(face)> includeFace = [](face) { return true; }, bool isFastTest = true) const;
300 
302  face maximalFace() const;
303 
307  face externalFace() const {
308  return m_externalFace;
309  }
310 
316  OGDF_ASSERT(f->embeddingOf() == this);
317  m_externalFace = f;
318  }
319 
320  bool isBridge(edge e) const {
321  return m_rightFace[e->adjSource()] == m_rightFace[e->adjTarget()];
322  }
323 
330  void init(const Graph &G);
331 
332  void init();
333 
335  void computeFaces();
336 
337 
341  bool consistencyCheck();
342 
343 
349  ListIterator<FaceArrayBase*> registerArray(FaceArrayBase *pFaceArray) const;
350 
356  void unregisterArray(ListIterator<FaceArrayBase*> it) const;
357 
359  void moveRegisterArray(ListIterator<FaceArrayBase*> it, FaceArrayBase *pFaceArray) const;
360 
370  adjEntry findCommonFace(const node v, const node w, bool left = true) const {
371  adjEntry adj;
372  return findCommonFace(v, w, adj, left);
373  }
374 
385  adjEntry findCommonFace(const node v, const node w, adjEntry &adjW, bool left = true) const;
386 
389 protected:
391  face createFaceElement(adjEntry adjFirst);
392 
394  void reinitArrays();
395 
396 }; // class ConstCombinatorialEmbedding
397 
398 
399 
413 {
414  friend class GraphCopy;
415 
417 
418  // the following methods are explicitly deleted
419  // It is not clear which meaning copying of a comb. embedding should
420  // have since we only store a pointer to the topology (Graph)
423 
424 public:
429  m_pGraph = nullptr;
430  }
431 
439  m_pGraph = &G;
440  }
441 
443 
447 
449  const Graph &getGraph() const
450  {
451  OGDF_ASSERT(valid());
452  return *m_cpGraph;
453  }
454 
456  {
457  OGDF_ASSERT(valid());
458  return *m_pGraph;
459  }
460 
461  operator const Graph &() const { return getGraph(); }
462 
463  operator Graph &() { return getGraph(); }
464 
465 
467 
471 
478  void init(Graph &G) {
480  m_pGraph = &G;
481  }
482 
486  void clear();
487 
488 
490 
494 
500  edge split(edge e);
501 
507  void unsplit(edge eIn, edge eOut);
508 
527  node splitNode(adjEntry adjStartLeft, adjEntry adjStartRight);
528 
534  node contract(edge e);
535 
547  edge splitFace(adjEntry adjSrc, adjEntry adjTgt);
548 
557  edge addEdgeToIsolatedNode(node v, adjEntry adjTgt);
558 
567  edge addEdgeToIsolatedNode(adjEntry adjSrc, node v);
568 
574  face joinFaces(edge e);
575 
577  void reverseEdge(edge e);
578 
580  void moveBridge(adjEntry adjBridge, adjEntry adjBefore);
581 
583  void removeDeg1(node v);
584 
586  void updateMerger(edge e, face fRight, face fLeft);
587 
588 
591 protected:
597  face joinFacesPure(edge e);
598 
599 private:
608  edge addEdgeToIsolatedNode(adjEntry adj, node v, bool adjSrc);
609 }; // class CombinatorialEmbedding
610 
611 } // end namespace ogdf
void init(Graph &G)
Initializes the embedding for graph G.
int m_size
The size of the face.
face lastFace() const
Returns the last face in the list of all faces.
void setExternalFace(face f)
Sets the external face to f.
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
CombinatorialEmbedding(Graph &G)
Creates a combinatorial embedding of graph G.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition: comparer.h:155
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:330
Declaration and implementation of AdjEntryArray class.
Combinatorial embeddings of planar graphs.
Doubly linked lists.
Definition: List.h:40
int m_faceIdCount
The index assigned to the next created face.
CombinatorialEmbedding()
Creates a combinatorial embedding associated with no graph.
face pred() const
Returns the predecessor in the list of all faces.
Forward iterator for adjacency entries in a face.
adjEntry firstAdj() const
Returns the first adjacency element in the face.
Dynamic arrays indexed with adjacency entries.
std::mutex m_mutexRegArrays
The critical section for protecting shared acces to register/unregister methods.
GraphObject * tail() const
Returns the last element in the list.
Definition: GraphList.h:272
int m_faceArrayTableSize
The current table size of face arrays.
adjEntry findCommonFace(const node v, const node w, bool left=true) const
Identifies a common face of two nodes and returns the respective adjacency entry. ...
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition: Graph_d.h:139
int size() const
Returns the number of elements in the container.
Definition: GraphList.h:396
internal::GraphObjectContainer< FaceElement > faces
The container containing all face objects.
face externalFace() const
Returns the external face.
int numberOfFaces() const
Returns the number of faces.
static int compare(const FaceElement &x, const FaceElement &y)
Standard Comparer.
Dynamic arrays indexed with faces of a combinatorial embedding.
AdjEntryArray< face > m_rightFace
The face to which an adjacency entry belongs.
GraphObject * head() const
Returns the first element in the list.
Definition: GraphList.h:269
Graph * m_pGraph
The associated graph.
const Graph * m_cpGraph
The associated graph.
int m_id
The index of the face.
ListPure< FaceArrayBase * > m_regFaceArrays
The external face.
int faceArrayTableSize() const
Returns the table size of face arrays associated with this embedding.
bool operator==(const FaceAdjIterator &other) const
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
Faces in a combinatorial embedding.
int size() const
Returns the size of the face, i.e., the number of edges in the face.
Class for the representation of edges.
Definition: Graph_d.h:291
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:102
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
The base class for objects used by (hyper)graphs.
Definition: GraphList.h:54
Class for the representation of nodes.
Definition: Graph_d.h:167
Encapsulates a pointer to a list element.
Definition: List.h:41
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
const Graph & getGraph() const
Returns the associated graph.
Container for the adjacency entries in a face.
bool operator!=(const FaceAdjIterator &other) const
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
adjEntry nextFaceEdge(adjEntry adj) const
Returns the successor of adj in the list of all adjacency elements in the face.
int index() const
Returns the index of the face.
The namespace for all OGDF objects.
FaceAdjIterator & operator=(FaceAdjIterator &other)
FaceAdjIterator(adjEntry adjFirst, adjEntry adj)
Lists of graph objects (like nodes, edges, etc.).
Definition: GraphList.h:252
Combinatorial embeddings of planar graphs with modification functionality.
int maxFaceIndex() const
Returns the largest used face index.
face firstFace() const
Returns the first face in the list of all faces.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:332
const Graph & getGraph() const
Returns the associated graph of the combinatorial embedding.
face succ() const
Returns the successor in the list of all faces.
Class for adjacency list elements.
Definition: Graph_d.h:78
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
bool valid() const
Returns whether the embedding is associated with a graph.
Abstract base class for face arrays.
Definition: FaceArray.h:47