Open
Graph Drawing
Framework

 v.2012.05
 

Level.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046 
00047 #ifndef OGDF_LEVEL_H
00048 #define OGDF_LEVEL_H
00049 
00050 
00051 
00052 #include <ogdf/basic/Graph.h>
00053 #include <ogdf/basic/SList.h>
00054 #include <ogdf/basic/tuples.h>
00055 
00056 
00057 namespace ogdf {
00058 
00059 class OGDF_EXPORT Hierarchy;
00060 
00061 class LayerBasedUPRLayout;
00062 
00063 
00064 template <class T = double>
00065 class WeightComparer {
00066     const NodeArray<T> *m_pWeight;
00067 
00068 public:
00069     WeightComparer(const NodeArray<T> *pWeight) : m_pWeight(pWeight) { }
00070 
00071     bool less(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
00072     bool operator()(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
00073 };
00074 
00075 
00077 
00080 class OGDF_EXPORT Level {
00081 
00082     friend class Hierarchy;
00083     friend class LayerBasedUPRLayout;
00084     friend class HierarchyLayoutModule;
00085 
00086     Array<node> m_nodes;     
00087     Hierarchy *m_pHierarchy; 
00088     int m_index;             
00089 
00090 public:
00092 
00098     Level(Hierarchy *pHierarchy, int index, int num) :
00099         m_nodes(num), m_pHierarchy(pHierarchy), m_index(index) { }
00100 
00101     // destruction
00102     ~Level() { }
00103 
00105     const node &operator[](int i) const { return m_nodes[i]; }
00107     node &operator[](int i) { return m_nodes[i]; }
00108 
00110     int size() const { return m_nodes.size(); }
00112     int high() const { return m_nodes.high(); }
00113 
00115     int index() const { return m_index; }
00116 
00118     const Array<node> &adjNodes(node v);
00119 
00121     const Hierarchy &hierarchy() const { return *m_pHierarchy; }
00122 
00124     void swap(int i, int j);
00125 
00127     void sort(NodeArray<double> &weight);
00128 
00130     void sort(NodeArray<int> &weight, int minBucket, int maxBucket);
00131     
00133     void sortByWeightOnly(NodeArray<double> &weight);
00134 
00136     template<class C> 
00137     void sortOrder(C &orderComparer) {
00138         m_nodes.quicksort(orderComparer);
00139         recalcPos();
00140     }
00141 
00142     void recalcPos();
00143 
00144     friend ostream &operator<<(ostream &os, const Level &L) {
00145         os << L.m_nodes;
00146         return os;
00147     }
00148 
00149 private:
00150     void getIsolatedNodes(SListPure<Tuple2<node,int> > &isolated);
00151     void setIsolatedNodes(SListPure<Tuple2<node,int> > &isolated);
00152 
00153     OGDF_MALLOC_NEW_DELETE
00154 };
00155 
00156 } // end namespace ogdf
00157 
00158 
00159 #endif