Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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 }
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 };
172 
173 class FaceArrayBase;
174 template<class T>class FaceArray;
175 
176 
199 {
200 protected:
201  const Graph *m_cpGraph;
202 
205 
208 
210 
211 #ifndef OGDF_MEMORY_POOL_NTS
212  mutable std::mutex m_mutexRegArrays;
213 #endif
214 
215 public:
218 
221 
226 
233  explicit ConstCombinatorialEmbedding(const Graph &G);
234 
235 
238 
241 
243  virtual ~ConstCombinatorialEmbedding();
244 
246  bool valid() const { return m_cpGraph != nullptr; }
247 
253  const Graph &getGraph() const {
254  OGDF_ASSERT(valid());
255  return *m_cpGraph;
256  }
257 
259  operator const Graph &() const { return getGraph(); }
260 
264  face firstFace() const { return faces.head(); }
265 
267  face lastFace() const { return faces.tail(); }
268 
270  int numberOfFaces() const { return faces.size(); }
271 
276  face rightFace(adjEntry adj) const { return m_rightFace[adj]; }
277 
282  face leftFace(adjEntry adj) const { return m_rightFace[adj->twin()]; }
283 
287  int maxFaceIndex() const { return m_faceIdCount-1; }
288 
290  int faceArrayTableSize() const { return m_faceArrayTableSize; }
291 
298  face chooseFace(std::function<bool(face)> includeFace = [](face) { return true; }, bool isFastTest = true) const;
299 
301  face maximalFace() const;
302 
306  face externalFace() const {
307  return m_externalFace;
308  }
309 
315  OGDF_ASSERT(f->embeddingOf() == this);
316  m_externalFace = f;
317  }
318 
319  bool isBridge(edge e) const {
320  return m_rightFace[e->adjSource()] == m_rightFace[e->adjTarget()];
321  }
322 
329  void init(const Graph &G);
330 
331  void init();
332 
334  void computeFaces();
335 
336 #ifdef OGDF_DEBUG
337  void consistencyCheck() const;
340 #endif
341 
342 
348  ListIterator<FaceArrayBase*> registerArray(FaceArrayBase *pFaceArray) const;
349 
355  void unregisterArray(ListIterator<FaceArrayBase*> it) const;
356 
358  void moveRegisterArray(ListIterator<FaceArrayBase*> it, FaceArrayBase *pFaceArray) const;
359 
369  adjEntry findCommonFace(const node v, const node w, bool left = true) const {
370  adjEntry adj;
371  return findCommonFace(v, w, adj, left);
372  }
373 
384  adjEntry findCommonFace(const node v, const node w, adjEntry &adjW, bool left = true) const;
385 
388 protected:
390  face createFaceElement(adjEntry adjFirst);
391 
393  void reinitArrays();
394 };
395 
410 {
411  friend class GraphCopy;
412 
414 
415  // the following methods are explicitly deleted
416  // It is not clear which meaning copying of a comb. embedding should
417  // have since we only store a pointer to the topology (Graph)
420 
421 public:
426  m_pGraph = nullptr;
427  }
428 
436  m_pGraph = &G;
437  }
438 
440 
444 
446  const Graph &getGraph() const
447  {
448  OGDF_ASSERT(valid());
449  return *m_cpGraph;
450  }
451 
453  {
454  OGDF_ASSERT(valid());
455  return *m_pGraph;
456  }
457 
458  operator const Graph &() const { return getGraph(); }
459 
460  operator Graph &() { return getGraph(); }
461 
462 
464 
468 
475  void init(Graph &G) {
477  m_pGraph = &G;
478  }
479 
483  void clear();
484 
485 
487 
491 
497  edge split(edge e);
498 
504  void unsplit(edge eIn, edge eOut);
505 
524  node splitNode(adjEntry adjStartLeft, adjEntry adjStartRight);
525 
531  node contract(edge e);
532 
544  edge splitFace(adjEntry adjSrc, adjEntry adjTgt);
545 
554  edge addEdgeToIsolatedNode(node v, adjEntry adjTgt);
555 
564  edge addEdgeToIsolatedNode(adjEntry adjSrc, node v);
565 
571  face joinFaces(edge e);
572 
574  void reverseEdge(edge e);
575 
577  void moveBridge(adjEntry adjBridge, adjEntry adjBefore);
578 
580  void removeDeg1(node v);
581 
583  void updateMerger(edge e, face fRight, face fLeft);
584 
585 
588 protected:
594  face joinFacesPure(edge e);
595 
596 private:
605  edge addEdgeToIsolatedNode(adjEntry adj, node v, bool adjSrc);
606 };
607 
608 }
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:492
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:157
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:333
Declaration and implementation of AdjEntryArray class.
Combinatorial embeddings of planar graphs.
Doubly linked lists.
Definition: List.h:41
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.
void init()
Definition: graphics.h:472
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:262
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:142
int size() const
Returns the number of elements in the container.
Definition: GraphList.h:386
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:259
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:292
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:105
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
The base class for objects used by (hyper)graphs.
Definition: GraphList.h:54
Class for the representation of nodes.
Definition: Graph_d.h:169
Encapsulates a pointer to a list element.
Definition: List.h:42
#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:242
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:335
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:79
#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