Open
Graph Drawing
Framework

 v.2012.05
 

LayerBasedUPRLayout.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  
00041 #ifdef _MSC_VER
00042 #pragma once
00043 #endif
00044 
00045 #ifndef OGDF_LAYER_BASED_UPR_LAYOUT_H
00046 #define OGDF_LAYER_BASED_UPR_LAYOUT_H
00047 
00048 
00049 
00050 #include <ogdf/basic/ModuleOption.h>
00051 #include <ogdf/upward/UpwardPlanRep.h>
00052 #include <ogdf/module/RankingModule.h>
00053 #include <ogdf/module/UPRLayoutModule.h>
00054 #include <ogdf/module/HierarchyLayoutModule.h>
00055 #include <ogdf/layered/OptimalHierarchyLayout.h>
00056 #include <ogdf/layered/FastHierarchyLayout.h>
00057 #include <ogdf/layered/OptimalRanking.h>
00058 
00059 
00060 namespace ogdf {
00061 
00062 class OrderComparer 
00063 {
00064 public:
00065     OrderComparer(const UpwardPlanRep &_UPR, Hierarchy &_H);    
00066     
00067     // if vH1 and vH2 are placed on the same layer and node vH1 has to drawn on the lefthand side of vH2 (according to UPR) then return true;
00068     bool less(node vH1, node vH2) const ;
00069 
00070 private:
00071     const UpwardPlanRep &UPR;
00072     Hierarchy &H;
00073     NodeArray<int> dfsNum;
00074     //EdgeArray<int> outEdgeOrder;
00075     mutable NodeArray<bool> crossed;
00076 
00077     //traverse with dfs using edge order from left to right and compute the dfs number.
00078     void dfs_LR( edge e, 
00079                  NodeArray<bool> &visited,              
00080                  NodeArray<int> &dfsNum,
00081                  int &num); 
00082 
00083     //return true if vUPR1 is on the lefthand side of vUPR2 according to UPR.
00084     bool left(node vUPR1,
00085             List<edge> chain1, //if vUPR1 is associated with a long edge dummy vH1, then chain1 contain vH1
00086             node vUPR2 , 
00087             List<edge> chain2 // if vUPR2 is associated with a long edge dummy vH2, then chain2 contain vH2
00088             ) const;
00089     
00090     //return true if vUPR1 is on the lefthand side of vUPR2 according to UPR.
00091     // pred.: source or target of both edge muss identical
00092     bool left(edge e1UPR, edge e2UPR) const;
00093 
00094     //return true if vUPR1 is on the lefthand side of vUPR2 according to UPR.
00095     // use only by method less for the case when both node vH1 and vH2 are long-edge dummies.
00096     // level: the current level of the long-edge dummies
00097     bool left(List<edge> &chain1, List<edge> &chain2, int level) const;
00098 
00099     //return true if there is a node above vUPR with rank level or lower
00100     bool checkUp(node vUPR, int level) const;
00101 };
00102 
00103 
00104 class OGDF_EXPORT LayerBasedUPRLayout : public UPRLayoutModule
00105 {
00106 public:
00107 
00108     // constructor: sets options to default values
00109     LayerBasedUPRLayout() 
00110     {
00111         // set default value
00112         FastHierarchyLayout *fhl = new FastHierarchyLayout();
00113         fhl->nodeDistance(40.0);
00114         fhl->layerDistance(40.0);
00115         fhl->fixedLayerDistance(true);
00116         m_layout.set(fhl);
00117         OptimalRanking *opRank = new OptimalRanking();
00118         opRank->separateMultiEdges(false);
00119         m_ranking.set(opRank);
00120         m_numLevels = 0;
00121         m_maxLevelSize = 0;
00122     }
00123 
00124     // destructor
00125     ~LayerBasedUPRLayout() { }
00126 
00127     // returns the number of crossings in the layout after the algorithm
00128     // has been applied
00129     int numberOfCrossings() const { return m_crossings; }
00130 
00131     // module option for the computation of the final layout
00132     void setLayout(HierarchyLayoutModule *pLayout) {
00133         m_layout.set(pLayout); 
00134     }
00135     
00136     
00137     void setRanking(RankingModule *pRanking) {
00138         m_ranking.set(pRanking);
00139     }   
00140 
00142     void UPRLayoutSimple(const UpwardPlanRep &UPR, GraphAttributes &AG);
00143 
00145     int numberOfLayers() { return m_numLevels; }
00146     
00148     int maxLayerSize() { return m_maxLevelSize; }
00149 
00150 protected :
00151         
00152     /*
00153      * @param UPR is the upward planarized representation of the input graph.
00154      * @param AG has to be assigned the hierarchy layout.
00155      */
00156     virtual void doCall(const UpwardPlanRep &UPR, GraphAttributes &AG); 
00157 
00158     int m_crossings;
00159     
00160     ModuleOption<RankingModule> m_ranking;
00161 
00162     ModuleOption<HierarchyLayoutModule> m_layout;
00163 
00164     
00165     struct RankComparer {       
00166         Hierarchy *H;
00167         bool less(node v1, node v2) const {
00168             return (H->rank(v1) < H->rank(v2));
00169         }   
00170     }; 
00171 
00172 
00173 private:    
00174 
00175     // compute a ranking of the nodes of UPR. 
00176     // Precond. a ranking module muss be set
00177     void computeRanking(const UpwardPlanRep &UPR, NodeArray<int> &rank);
00178     
00179     
00181     void postProcessing_sourceReorder(Hierarchy &H, List<node> &sources);   
00182     
00183 
00185     void postProcessing_reduceLED(Hierarchy &H, List<node> &sources) {
00186         forall_listiterators(node, it, sources) 
00187             postProcessing_reduceLED(H, *it);
00188     }
00189     
00190     void postProcessing_reduceLED(Hierarchy &H, node vH);
00191 
00192     void post_processing_reduce(Hierarchy &H, int &i, node s, int minIdx, int maxIdx, NodeArray<bool> &markedNodes);
00193 
00195     void postProcessing_markUp(Hierarchy &H, node sH, NodeArray<bool> &markedNodes);    
00196 
00197     
00199     void post_processing_deleteLvl(Hierarchy &H, int i);
00200 
00202     void post_processing_deleteInterval(Hierarchy &H, int beginIdx, int endIdx, int &j);
00203     
00205     void post_processing_CopyInterval(Hierarchy &H, int i, int beginIdx, int endIdx, int pos);      
00206 
00207     int m_numLevels;    
00208     int m_maxLevelSize;
00209 
00210     
00211     
00212     //------------------------ UPRLayoutSimple methods --------------------------------------------
00213     void callSimple(GraphAttributes &AG, adjEntry adj //left most edge of the source
00214                     );
00215 
00216     // needed for UPRLayoutSimple
00217     void dfsSortLevels(
00218         adjEntry adj1,
00219         const NodeArray<int> &rank,
00220         Array<SListPure<node> > &nodes);
00221     
00222     // needed for UPRLayoutSimple
00223     void longestPathRanking(const Graph &G, NodeArray<int> &rank);
00224 
00225     
00226 };
00227 
00228 }
00229 
00230 #endif