6 * $Date: 2012-07-03 09:54:22 +0200 (Tue, 03 Jul 2012) $
7 ***************************************************************/
10 * \brief Declaration of upward planarization layout algorithm.
12 * \author Hoi-Ming Wong
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
47 #ifndef OGDF_LAYER_BASED_UPR_LAYOUT_H
48 #define OGDF_LAYER_BASED_UPR_LAYOUT_H
52 #include <ogdf/basic/ModuleOption.h>
53 #include <ogdf/upward/UpwardPlanRep.h>
54 #include <ogdf/module/RankingModule.h>
55 #include <ogdf/module/UPRLayoutModule.h>
56 #include <ogdf/module/HierarchyLayoutModule.h>
57 #include <ogdf/layered/OptimalHierarchyLayout.h>
58 #include <ogdf/layered/FastHierarchyLayout.h>
59 #include <ogdf/layered/OptimalRanking.h>
67 OrderComparer(const UpwardPlanRep
&_UPR
, Hierarchy
&_H
);
69 // 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;
70 bool less(node vH1
, node vH2
) const ;
73 const UpwardPlanRep
&UPR
;
75 NodeArray
<int> dfsNum
;
76 //EdgeArray<int> outEdgeOrder;
77 mutable NodeArray
<bool> crossed
;
79 //traverse with dfs using edge order from left to right and compute the dfs number.
81 NodeArray
<bool> &visited
,
82 NodeArray
<int> &dfsNum
,
85 //return true if vUPR1 is on the lefthand side of vUPR2 according to UPR.
87 List
<edge
> chain1
, //if vUPR1 is associated with a long edge dummy vH1, then chain1 contain vH1
89 List
<edge
> chain2
// if vUPR2 is associated with a long edge dummy vH2, then chain2 contain vH2
92 //return true if vUPR1 is on the lefthand side of vUPR2 according to UPR.
93 // pred.: source or target of both edge muss identical
94 bool left(edge e1UPR
, edge e2UPR
) const;
96 //return true if vUPR1 is on the lefthand side of vUPR2 according to UPR.
97 // use only by method less for the case when both node vH1 and vH2 are long-edge dummies.
98 // level: the current level of the long-edge dummies
99 bool left(List
<edge
> &chain1
, List
<edge
> &chain2
, int level
) const;
101 //return true if there is a node above vUPR with rank level or lower
102 bool checkUp(node vUPR
, int level
) const;
106 class OGDF_EXPORT LayerBasedUPRLayout
: public UPRLayoutModule
110 // constructor: sets options to default values
111 LayerBasedUPRLayout()
114 FastHierarchyLayout
*fhl
= new FastHierarchyLayout();
115 fhl
->nodeDistance(40.0);
116 fhl
->layerDistance(40.0);
117 fhl
->fixedLayerDistance(true);
119 OptimalRanking
*opRank
= new OptimalRanking();
120 opRank
->separateMultiEdges(false);
121 m_ranking
.set(opRank
);
127 ~LayerBasedUPRLayout() { }
129 // returns the number of crossings in the layout after the algorithm
131 int numberOfCrossings() const { return m_crossings
; }
133 // module option for the computation of the final layout
134 void setLayout(HierarchyLayoutModule
*pLayout
) {
135 m_layout
.set(pLayout
);
139 void setRanking(RankingModule
*pRanking
) {
140 m_ranking
.set(pRanking
);
143 //! Use only the 3. phase of Sugiyama' framework for layout.
144 void UPRLayoutSimple(const UpwardPlanRep
&UPR
, GraphAttributes
&AG
);
146 //! Return the number of layers/levels. Not implemented if use methode callSimple(..).
147 int numberOfLayers() { return m_numLevels
; }
149 //! Return the max. number of elements on a layer. Not implemented if use methode callSimple(..).
150 int maxLayerSize() { return m_maxLevelSize
; }
155 * @param UPR is the upward planarized representation of the input graph.
156 * @param AG has to be assigned the hierarchy layout.
158 virtual void doCall(const UpwardPlanRep
&UPR
, GraphAttributes
&AG
);
162 ModuleOption
<RankingModule
> m_ranking
;
164 ModuleOption
<HierarchyLayoutModule
> m_layout
;
167 struct RankComparer
{
169 bool less(node v1
, node v2
) const {
170 return (H
->rank(v1
) < H
->rank(v2
));
177 // compute a ranking of the nodes of UPR.
178 // Precond. a ranking module muss be set
179 void computeRanking(const UpwardPlanRep
&UPR
, NodeArray
<int> &rank
);
182 //! rearanging the position of the sources in order to reduce some crossings.
183 void postProcessing_sourceReorder(Hierarchy
&H
, List
<node
> &sources
);
186 //! reduce the long edge dummies (LED)
187 void postProcessing_reduceLED(Hierarchy
&H
, List
<node
> &sources
) {
188 forall_listiterators(node
, it
, sources
)
189 postProcessing_reduceLED(H
, *it
);
192 void postProcessing_reduceLED(Hierarchy
&H
, node vH
);
194 void post_processing_reduce(Hierarchy
&H
, int &i
, node s
, int minIdx
, int maxIdx
, NodeArray
<bool> &markedNodes
);
196 //! mark all the nodes dominated by sH. (Help method for postProcessing_reduceLED() )
197 void postProcessing_markUp(Hierarchy
&H
, node sH
, NodeArray
<bool> &markedNodes
);
200 //! delete level i of H.
201 void post_processing_deleteLvl(Hierarchy
&H
, int i
);
203 //! delete the interval [beginIdx,endIdx] on the level j.
204 void post_processing_deleteInterval(Hierarchy
&H
, int beginIdx
, int endIdx
, int &j
);
206 //! insert the interval [beginIdx,endIdx] of level i-1 to level i at position pos.
207 void post_processing_CopyInterval(Hierarchy
&H
, int i
, int beginIdx
, int endIdx
, int pos
);
214 //------------------------ UPRLayoutSimple methods --------------------------------------------
215 void callSimple(GraphAttributes
&AG
, adjEntry adj
//left most edge of the source
218 // needed for UPRLayoutSimple
221 const NodeArray
<int> &rank
,
222 Array
<SListPure
<node
> > &nodes
);
224 // needed for UPRLayoutSimple
225 void longestPathRanking(const Graph
&G
, NodeArray
<int> &rank
);