Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

Level.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/SList.h>
36 #include <ogdf/basic/tuples.h>
38 
39 namespace ogdf {
40 
41 class HierarchyLevels;
42 class LayerBasedUPRLayout;
43 
44 
45 template <class T = double>
48 
49 public:
50  explicit WeightComparer(const NodeArray<T> *pWeight) : m_pWeight(pWeight) { }
51 
52  bool less(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
53  bool operator()(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
54 };
55 
56 
58 
61 class OGDF_EXPORT Level : public LevelBase {
62 
63  friend class HierarchyLevels;
64  friend class HierarchyLayoutModule;
65  friend class LayerBasedUPRLayout;
66 
69  int m_index;
70 
71 public:
73 
78  Level(HierarchyLevels *pLevels, int index, int num) :
79  m_nodes(num), m_pLevels(pLevels), m_index(index) { }
80 
81  // destruction
82  ~Level() { }
83 
85  const node &operator[](int i) const override { return m_nodes[i]; }
87  node &operator[](int i) override { return m_nodes[i]; }
88 
90  int size() const override { return m_nodes.size(); }
91 
93  int high() const override { return m_nodes.high(); }
94 
96  int index() const { return m_index; }
97 
99  const Array<node> &adjNodes(node v) const;
100 
102  const HierarchyLevels &levels() const { return *m_pLevels; }
103 
105  void swap(int i, int j);
106 
108  void sort(NodeArray<double> &weight);
109 
111  void sort(NodeArray<int> &weight, int minBucket, int maxBucket);
112 
114  void sortByWeightOnly(NodeArray<double> &weight);
115 
117  template<class C>
118  void sortOrder(C &orderComparer) {
119  m_nodes.quicksort(orderComparer);
120  recalcPos();
121  }
122 
123  void recalcPos();
124 
125  friend ostream &operator<<(ostream &os, const Level &L) {
126  os << L.m_nodes;
127  return os;
128  }
129 
130 private:
131  void getIsolatedNodes(SListPure<Tuple2<node,int> > &isolated) const;
132  void setIsolatedNodes(SListPure<Tuple2<node,int> > &isolated);
133 
135 };
136 
137 } // end namespace ogdf
Declaration of singly linked lists and iterators.
bool less(node v, node w) const
Definition: Level.h:52
node & operator[](int i) override
Returns the node at position i.
Definition: Level.h:87
Representation of proper hierarchies used by Sugiyama-layout.
HierarchyLevels * m_pLevels
The hierarchy to which this level belongs.
Definition: Level.h:68
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
bool operator()(node v, node w) const
Definition: Level.h:53
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:91
Singly linked lists.
Definition: SList.h:38
INDEX high() const
Returns the maximal array index.
Definition: Array.h:131
Declaration of interfaces used in Sugiyama framework.
int high() const override
Returns the maximal array index (= size()-1).
Definition: Level.h:93
Level(HierarchyLevels *pLevels, int index, int num)
Creates a level with index index in hierarchy pLevels.
Definition: Level.h:78
const HierarchyLevels & levels() const
Returns the hierarchy to which this level belongs.
Definition: Level.h:102
Representation of levels in hierarchies.
Definition: Level.h:61
Representation of levels in hierarchies.
~Level()
Definition: Level.h:82
int m_index
The index of this level.
Definition: Level.h:69
Array< node > m_nodes
The nodes on this level.
Definition: Level.h:67
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:57
const NodeArray< T > * m_pWeight
Definition: Level.h:47
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:134
Interface of hierarchy layout algorithms.
int index() const
Returns the array index of this level in the hierarchy.
Definition: Level.h:96
Class for the representation of nodes.
Definition: Graph_d.h:167
Declaration and implementation of class Tuple2, Tuple3 and Tuple4.
Includes declaration of graph class.
void sortOrder(C &orderComparer)
Sorts the nodes according to orderComparer.
Definition: Level.h:118
void quicksort()
Sorts array using Quicksort.
Definition: Array.h:434
The namespace for all OGDF objects.
friend ostream & operator<<(ostream &os, const Level &L)
Definition: Level.h:125
WeightComparer(const NodeArray< T > *pWeight)
Definition: Level.h:50
const node & operator[](int i) const override
Returns the node at position i.
Definition: Level.h:85
int size() const override
Returns the number of nodes on this level.
Definition: Level.h:90