Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

OrthoRep.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/GraphCopy.h>
35 #include <ogdf/basic/FaceArray.h>
36 #include <ogdf/basic/tuples.h>
37 #include <ogdf/basic/Stack.h>
38 
39 
40 namespace ogdf {
41 
42 class OGDF_EXPORT PlanRep;
43 class OGDF_EXPORT PlanRepUML;
44 
45 
46 // type for bends (convex or reflex)
47 enum class OrthoBendType : char { convexBend = '0', reflexBend = '1' };
48 
49 // type of (orthogonal) directions
50 // horizontal: East or West
51 // vertical: North or South
52 enum class OrthoDir {
53  North = 0,
54  East = 1,
55  South = 2,
56  West = 3,
57  Undefined = 4
58 };
59 
60 // Option bits for orthogonal layouts, UML alignment, compaction scaling, progressive shape computation
61 enum class UMLOpt {OpAlign = 0x0001, OpScale = 0x0002, OpProg = 0x0004};
62 
63 inline int operator | (int lhs, UMLOpt rhs) { return lhs | static_cast<int>(rhs); }
64 inline int operator ~ (UMLOpt rhs) { return ~static_cast<int>(rhs); }
65 inline int operator & (int lhs, UMLOpt rhs) { return lhs & static_cast<int>(rhs); }
66 inline int operator += (int &lhs, UMLOpt rhs) { lhs += static_cast<int>(rhs); return lhs; }
67 
70 {
71 public:
72  // constructs empty bend string
74  m_pBend = nullptr;
75  m_len = 0;
76  }
77 
78  // constructs bend string as given by str
79  // Precond.: str is a 0 terminated C++ string consisting of '0's and '1's
80  explicit BendString(const char *str) {
81  init(str);
82  }
83 
84  // constructs bend string consisting of n c's
85  // Precond.: c is '0' or '1'
86  BendString(char c, size_t n) {
87  init(c,n);
88  }
89 
90  // copy constructor
91  BendString(const BendString &bs) {
92  init(bs);
93  }
94 
95  // copy constructor (move semantics)
96  BendString(BendString &&bs) : m_pBend(bs.m_pBend), m_len(bs.m_len) {
97  bs.m_pBend = nullptr;
98  bs.m_len = 0;
99  }
100 
101 
102  // destructor
104  delete[] m_pBend;
105  }
106 
107 
108  // returns i'th character in bend string
109  char operator[](size_t i) const {
110  // range check
111  OGDF_ASSERT(i < m_len);
112  return m_pBend[i];
113  }
114 
115  char &operator[](size_t i) {
116  // range check
117  OGDF_ASSERT(i < m_len);
118  return m_pBend[i];
119  }
120 
121  // returns number of characters in bend string
122  size_t size() const {
123  return m_len;
124  }
125 
126  // returns a pointer to the 0 terminated string
127  // or a 0-pointer if empty
128  const char *toString() const {
129  return m_pBend;
130  }
131 
132  // sets bend string to the string given by str
133  // Precond.: str is a 0 terminated C++ string consisting of '0's and '1's
134  void set(const char *str) {
135  delete[] m_pBend;
136  init(str);
137  }
138 
139  // sets bend string to the string consisting of n c's
140  // Precond.: c is '0' or '1'
141  void set(char c, size_t n) {
142  delete[] m_pBend;
143  init(c,n);
144  }
145  void set(OrthoBendType obt, size_t n) {
146  delete[] m_pBend;
147  init(static_cast<int>(obt),n);
148  }
149 
150 
151  // sets bend string to the empty bend string
152  void set() {
153  delete[] m_pBend;
154  m_pBend = nullptr;
155  m_len = 0;
156  }
157 
158 
159  // assignment operator
161  delete[] m_pBend;
162  init(bs);
163  return *this;
164  }
165 
166  // assignment operator (move semantics)
168  if (&bs != this) {
169  delete[] m_pBend;
170  m_pBend = bs.m_pBend;
171  m_len = bs.m_len;
172  bs.m_pBend = nullptr;
173  bs.m_len = 0;
174  }
175  return *this;
176  }
177 
178  BendString &operator+=(const char *str) {
179  return this->operator+=(BendString(str));
180  }
181 
183  char* temp = new char[m_len+bs.m_len+1];
184 
185  m_len = m_len + bs.m_len;
186 
187  if (m_len == 0)
188  {
189  *temp = 0;//temp = 0;
190  }
191  else
192  {
193  char *p = temp;
194  if (m_pBend != nullptr)
195  {
196  const char *str = m_pBend;
197  while ((*p++ = *str++) != 0) ;
198  }
199  else {*p = '0'; p++;}
200  if (bs.m_len > 0)
201  {
202  p--;
203  const char *str1 = bs.m_pBend;
204  while ((*p++ = *str1++) != 0) ;
205  }
206  }
207 
208  delete[] m_pBend;
209  m_pBend = temp;
210 
211  return *this;
212  }
213 
214  // output operator
215  // example output: "001101001" or ""
216  friend ostream &operator<<(ostream &os, const BendString &bs) {
217  if (bs.size() == 0)
218  os << "\"\"";
219  else
220  os << "\"" << bs.m_pBend << "\"";
221  return os;
222  }
223 
224 private:
225  void init(const char *str);
226  void init(char c, size_t n);
227  void init(const BendString &bs);
228 
229 
230  // poiner to 0 terminated character string
231  char *m_pBend;
232  // length of string (number of characters without ending 0)
233  size_t m_len;
234 };
235 
238 {
239 public:
241  struct SideInfoUML {
242  // adjacency entry of generalization attached at the side
243  // (or 0 if none)
245  // number of attached edges which have corresponding edges in the
246  // original graph to the left (index 0) or right of the
247  // attached generalization. If no generalization is attached,
248  // m_nAttached[0] is the total number of attached edges.
249  int m_nAttached[2];
250 
251  // constructor
253  m_adjGen = nullptr;
254  m_nAttached[0] = m_nAttached[1] = 0;
255  }
256 
257  // returns the total number of edges attached at this side
258  int totalAttached() const {
259  int nGen = (m_adjGen == nullptr) ? 0 : 1;
260  return nGen + m_nAttached[0] + m_nAttached[1];
261  }
262 
263 
264  // output operator for debugging
265  friend ostream &operator<<(ostream &os, const SideInfoUML &si)
266  {
267  os << "{ " << si.m_nAttached[0] <<
268  ", " << si.m_adjGen <<
269  ", " << si.m_nAttached[1] << " }";
270  return os;
271  }
272  };
273 
274  //only for debugging purposes
275  adjEntry externalAdjEntry() const {return m_adjExternal;}
276  adjEntry alignAdjEntry() const {return m_adjAlign;}
277 
279  struct VertexInfoUML {
280  // side information (North, East, South, West corresponds to
281  // left, top, right, bottom)
282  SideInfoUML m_side[4];
283  // m_corner[dir] is adjacency entry in direction dir starting at
284  // a corner
285  adjEntry m_corner[4];
286 
287  // constructor
289 #ifdef OGDF_DEBUG
290  m_corner[0] = m_corner[1] = m_corner[2] = m_corner[3] = nullptr;
291 #endif
292  }
294  };
295 
296 
297  // construction
298 
299  // dummy
300  OrthoRep() { m_pE = nullptr; }
301  // associates orthogonal representation with embedding E
302  explicit OrthoRep(CombinatorialEmbedding &E);
303 
304  // destruction
306  freeCageInfoUML();
307  }
308 
309  // reinitialization: associates orthogonal representation with embedding E
310  void init(CombinatorialEmbedding &E);
311 
312 
313  //
314  // access functions
315  //
316 
317  // returns associated embedding
318  operator const CombinatorialEmbedding &() const {
319  return *m_pE;
320  }
321 
322  // returns associated graph
323  operator const Graph &() const {
324  return *m_pE;
325  }
326 
327  // returns angle between adj and its successor
328  // (return value is angle divided by 90 degree)
329  int angle(adjEntry adj) const {
330  return m_angle[adj];
331  }
332 
333  int &angle(adjEntry adj) {
334  return m_angle[adj];
335  }
336 
337 
338  // returns bend string of adjacency entry adj
339  const BendString &bend(adjEntry adj) const {
340  return m_bends[adj];
341  }
342 
344  return m_bends[adj];
345  }
346 
347  // returns direction of adjacency entry
349  return m_dir[adj];
350  }
351 
352 
353  // returns cage info
354  const VertexInfoUML *cageInfo(node v) const {
355  return m_umlCageInfo[v];
356  }
357 
358  // returns cage info
360  return m_umlCageInfo[v];
361  }
362 
363 
364 
365  //
366  // update functions
367  //
368 
369  // normalizes the orthogonal representation, i.e., sets an artficial
370  // vertex on each bend
371  void normalize();
372 
373  // checks if the orth. repr. is normalized, i.e., each bend string is empty
374  bool isNormalized() const;
375 
376  // removes rectangular ears (pattern "100") by splitting edges and faces.
377  // Afterwards, each internal face is a rectangle and the external face
378  // contains no rectangular ear (but is not necessarily the complement of
379  // a rectangle).
380  // Precond.: The orth. repr. is normalized and contains no 0-degree angles
381  void dissect();
382  // same as dissect, attempting to save artificial nodes and allow preprocessing
383  void dissect2(PlanRep* PG = nullptr);
384  // variant for use with simple PlanRep
385  void gridDissect(PlanRep* PG);
386  // undoes a previous dissect() by removing dissection edges and unsplitting
387  // vertices
388  void undissect(bool align = false);
389 
390 
391  // assigns consistent directions to adjacency entries
392  void orientate();
393 
394  // assigns consistent directions to adj. entries such that most
395  // generalizations are directed in preferedDir
396  void orientate(const PlanRep &PG, OrthoDir preferedDir);
397 
398  // assigns consistent directions to adjacency entries,
399  // assigning dir to adj (fixing all others)
400  void orientate(adjEntry adj, OrthoDir dir);
401 
402  // returns true iff orientate() has been called before.
403  // If not, direction() may not be called since adj. entry array is not
404  // initialized!
405  bool isOrientated() const {
406  return m_dir.valid();
407  }
408 
409 
410  // rotates all directions of adjacency entries by r
411  void rotate(int r);
412 
413 
414  // computes further information about cages
415  void computeCageInfoUML(const PlanRep &PG/*, double sep*/);
416 
417 
418  // checks if the orth. repr. is a legal shape description, i.e., if there
419  // is an orthogonal embedding realizing this shape (if 0-degree angles are
420  // present, the condition is necessary but not sufficient).
421  // If false is returned, error contains a description of the reason.
422  bool check(string &error) const;
423 
424 
425  //
426  // static members
427  //
428 
429  // exchanges '1'->'0' and vice versa
430  static char flip(char c) {
431  return (c == '0') ? '1' : '0';
432  }
433 
436  return static_cast<OrthoDir>((static_cast<int>(d) + 2) & 3);
437  }
438 
441  return static_cast<OrthoDir>((static_cast<int>(d) + 1) & 3);
442  }
443 
446  return static_cast<OrthoDir>((static_cast<int>(d) + 3) & 3);
447  }
448 
449  friend ostream &operator<<(ostream &os, const OrthoRep &op) {
450  const Graph& E = op;
451  for(edge e : E.edges)
452  {
453  os << e <<": src angle "<<op.angle(e->adjSource())<<" bend "<<op.bend(e->adjSource())
454  <<"\n"<<" tgt angle "<<op.angle(e->adjTarget())<<" bend "<<op.bend(e->adjTarget())
455 
456  <<"\n";
457  }
458  return os;
459  }
460 
461 
462 
463 private:
464  void orientateFace(adjEntry adj, OrthoDir dir);
465  void freeCageInfoUML();
466 
467  // associated combinatorial embedding
469 
470  // * 90 deg = angle between e and its successor
472  // bends on edge e
474  // direction of adjacency entries
476 
477  // information about cages of original vertices; used for orthogonal
478  // representations of PlanRep's
480 
481  // The following members are used for undoing dissection
482  EdgeArray<bool> m_dissectionEdge; // = true iff dissection edge
483  //check if special gener. sons alignment edge
484  EdgeArray<bool> m_alignmentEdge; // = true iff alignment edge
485  // contains all nodes created by splitting non-dissection edges while
486  // dissect()
488  // stores adjacency entry on external face for restoring in undissect()
490  // stores adjacency entry on preliminary external face in alignment case
492  //starts dissection phase for special pattern 1 replacement before standard dissection
494  //special pattern after pattern 1
496 };
497 
498 
499 } // end namespace ogdf
BendString(const char *str)
Definition: OrthoRep.h:80
int operator&(int i, TopologyModule::Options b)
char & operator[](size_t i)
Definition: OrthoRep.h:115
adjEntry m_adjExternal
Definition: OrthoRep.h:489
int operator+=(int &lhs, UMLOpt rhs)
Definition: OrthoRep.h:66
BendString(char c, size_t n)
Definition: OrthoRep.h:86
bool m_preprocess
Definition: OrthoRep.h:493
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
BendString & bend(adjEntry adj)
Definition: OrthoRep.h:343
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:330
BendString(const BendString &bs)
Definition: OrthoRep.h:91
Information about a side of a vertex in UML diagrams.
Definition: OrthoRep.h:241
adjEntry alignAdjEntry() const
Definition: OrthoRep.h:276
int angle(adjEntry adj) const
Definition: OrthoRep.h:329
BendString(BendString &&bs)
Definition: OrthoRep.h:96
const char * toString() const
Definition: OrthoRep.h:128
Orthogonal representation of an embedded graph.
Definition: OrthoRep.h:237
adjEntry m_adjAlign
Definition: OrthoRep.h:491
Further information about the cages of vertices in UML diagrams.
Definition: OrthoRep.h:279
friend ostream & operator<<(ostream &os, const BendString &bs)
Definition: OrthoRep.h:216
declaration and implementation of FaceArray class
AdjEntryArray< int > m_angle
Definition: OrthoRep.h:471
friend ostream & operator<<(ostream &os, const SideInfoUML &si)
Definition: OrthoRep.h:265
OrthoBendType
Definition: OrthoRep.h:47
bool isOrientated() const
Definition: OrthoRep.h:405
char * m_pBend
Definition: OrthoRep.h:231
BendString & operator=(BendString &&bs)
Definition: OrthoRep.h:167
BendString & operator+=(const char *str)
Definition: OrthoRep.h:178
BendString & operator=(const BendString &bs)
Definition: OrthoRep.h:160
static char flip(char c)
Definition: OrthoRep.h:430
AdjEntryArray< OrthoDir > m_dir
Definition: OrthoRep.h:475
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:548
UMLOpt
Definition: OrthoRep.h:61
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
VertexInfoUML * cageInfo(node v)
Definition: OrthoRep.h:359
EdgeArray< bool > m_dissectionEdge
Definition: OrthoRep.h:482
NodeArray< VertexInfoUML * > m_umlCageInfo
Definition: OrthoRep.h:479
const BendString & bend(adjEntry adj) const
Definition: OrthoRep.h:339
BendString & operator+=(const BendString &bs)
Definition: OrthoRep.h:182
List-based stacks.
Definition: SList.h:39
int & angle(adjEntry adj)
Definition: OrthoRep.h:333
const VertexInfoUML * cageInfo(node v) const
Definition: OrthoRep.h:354
Declaration of graph copy classes.
static OrthoDir oppDir(OrthoDir d)
Returns the opposite OrthoDir.
Definition: OrthoRep.h:435
Class for the representation of edges.
Definition: Graph_d.h:291
Class for the representation of nodes.
Definition: Graph_d.h:167
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
OrthoDir
Definition: OrthoRep.h:52
adjEntry externalAdjEntry() const
Definition: OrthoRep.h:275
bool m_pattern2
Definition: OrthoRep.h:495
Declaration and implementation of class Tuple2, Tuple3 and Tuple4.
AdjEntryArray< BendString > m_bends
Definition: OrthoRep.h:473
int operator|(TopologyModule::Options a, TopologyModule::Options b)
static OrthoDir prevDir(OrthoDir d)
Returns the previous OrthoDir (in a clockwise manner)
Definition: OrthoRep.h:445
size_t size() const
Definition: OrthoRep.h:122
static OrthoDir nextDir(OrthoDir d)
Returns the next OrthoDir (in a clockwise manner)
Definition: OrthoRep.h:440
Represents the bends on an edge e consisting of vertical and horizontal segments. ...
Definition: OrthoRep.h:69
friend ostream & operator<<(ostream &os, const OrthoRep &op)
Definition: OrthoRep.h:449
OrthoDir direction(adjEntry adj) const
Definition: OrthoRep.h:348
EdgeArray< bool > m_alignmentEdge
Definition: OrthoRep.h:484
int operator~(UMLOpt rhs)
Definition: OrthoRep.h:64
CombinatorialEmbedding * m_pE
Definition: OrthoRep.h:468
The namespace for all OGDF objects.
char operator[](size_t i) const
Definition: OrthoRep.h:109
Combinatorial embeddings of planar graphs with modification functionality.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:332
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
Declaration and implementation of list-based stacks (StackPure<E> and Stack<E>).
Planarized representations (of a connected component) of a graph.
Definition: PlanRep.h:60
StackPure< node > m_splitNodes
Definition: OrthoRep.h:487