Don't import ogdf namespace
[TortoiseGit.git] / ext / OGDF / ogdf / planarity / PlanarizationLayout.h
blob6f3965cf5bfe3f7f2c0270b6538327206132c316
1 /*
2 * $Revision: 2583 $
4 * last checkin:
5 * $Author: gutwenger $
6 * $Date: 2012-07-12 01:02:21 +0200 (Do, 12. Jul 2012) $
7 ***************************************************************/
9 /** \file
10 * \brief Declaration of class PlanarizationLayout.
12 * \author Carsten Gutwenger
14 * \par License:
15 * This file is part of the Open Graph Drawing Framework (OGDF).
17 * \par
18 * Copyright (C)<br>
19 * See README.txt in the root directory of the OGDF installation for details.
21 * \par
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
26 * for details.
28 * \par
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.
34 * \par
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 ***************************************************************/
44 #ifdef _MSC_VER
45 #pragma once
46 #endif
48 #ifndef OGDF_UML_PLANARIZATION_LAYOUT_H
49 #define OGDF_UML_PLANARIZATION_LAYOUT_H
53 #include <ogdf/module/UMLLayoutModule.h>
54 #include <ogdf/module/PlanarSubgraphModule.h>
55 #include <ogdf/module/EdgeInsertionModule.h>
56 #include <ogdf/module/LayoutPlanRepModule.h>
57 #include <ogdf/module/CCLayoutPackModule.h>
58 #include <ogdf/basic/ModuleOption.h>
59 #include <ogdf/module/EmbedderModule.h>
60 #include <ogdf/basic/HashArray.h>
64 namespace ogdf {
67 /**
68 * \brief The planarization layout algorithm.
70 * The class PlanarizationLayout represents a customizable implementation
71 * of the planarization approach for drawing graphs. The class provides
72 * three different algorithm calls:
73 * - Calling the algorithm for a usual graph (call with GraphAttributes).
74 * - Calling the algorithm for a mixed-upward graph (e.g., a UML class
75 * diagram; call with UMLGraph); a simplified version is provided by
76 * simpleCall.
77 * - Calling the algorithm for simultaneous drawing.
79 * If the planarization layout algorithm shall be used for simultaneous drawing,
80 * you need to define the different subgraphs by setting the <i>subgraphs</i>
81 * option.
83 * The implementation used in PlanarizationLayout is based on the following
84 * publication:
86 * C. Gutwenger, P. Mutzel: <i>An Experimental Study of Crossing
87 * Minimization Heuristics</i>. 11th International Symposium on %Graph
88 * Drawing 2003, Perugia (GD '03), LNCS 2912, pp. 13-24, 2004.
90 * <H3>Optional parameters</H3>
92 * <table>
93 * <tr>
94 * <th><i>Option</i><th><i>Type</i><th><i>Default</i><th><i>Description</i>
95 * </tr><tr>
96 * <td><i>pageRatio</i><td>double<td>1.0
97 * <td>Specifies the desired ration of width / height of the computed
98 * layout. It is currently only used when packing connected components.
99 * </tr><tr>
100 * <td><i>preprocessCliques</i><td>bool<td>false
101 * <td>If set to true, a preprocessing for cliques (complete subgraphs)
102 * is performed and cliques will be laid out in a special form (straight-line,
103 * not orthogonal). The preprocessing may reduce running time and improve
104 * layout quality if the input graphs contains dense subgraphs.
105 * </tr><tr>
106 * <td><i>minCliqueSize</i><td>int<td>10<td>If preprocessing of cliques is
107 * enabled, this option determines the minimal size of cliques to search for.
108 * </tr>
109 * </table>
111 * <H3>%Module options</H3>
112 * The various phases of the algorithm can be exchanged by setting
113 * module options allowing flexible customization. The algorithm provides
114 * the following module options:
116 * <table>
117 * <tr>
118 * <th><i>Option</i><th><i>Type</i><th><i>Default</i><th><i>Description</i>
119 * </tr><tr>
120 * <td><i>subgraph</i><td>PlanarSubgraphModule<td>FastPlanarSubgraph
121 * <td>The module for the computation of the planar subgraph.
122 * </tr><tr>
123 * <td><i>inserter</i><td>EdgeInsertionModule<td>FixedEmbeddingInserter
124 * <td>The module used for edge insertion which is applied in the second
125 * step of the planarization method. The edges not contained in the planar
126 * subgraph are re-inserted one-by-one, each with as few crossings as possible.
127 * </tr><tr>
128 * <td><i>embedder</i><td>EmbedderModule<td>SimpleEmbedder
129 * <td>The graph embedding algorithm applied after the crossing minimization
130 * step.
131 * </tr><tr>
132 * <td><i>planarLayouter</i><td>LayoutPlanRepModule<td>OrthoLayout
133 * <td>The planar layout algorithm used to compute a planar layout
134 * of the planarized representation resulting from the crossing minimization step.
135 * </tr><tr>
136 * <td><i>packer</i><td>CCLayoutPackModule<td>TileToRowsCCPacker
137 * <td>The packer module used for arranging connected components.
138 * </tr>
139 * </table>
141 class OGDF_EXPORT PlanarizationLayout : public UMLLayoutModule
143 public:
144 //! Creates an instance of planarization layout and sets options to default values.
145 PlanarizationLayout();
147 // destructor
148 virtual ~PlanarizationLayout() { }
151 * @name Algorithm call
152 * @{
156 * \brief Calls planarization layout for GraphAttributes \a GA and computes a layout.
157 * \pre The graph has no self-loops.
158 * @param GA is the input graph and will also be assigned the layout information.
160 void call(GraphAttributes &GA) {
161 doSimpleCall(&GA);
165 * \brief Calls planarization layout for UML-graph \a umlGraph and computes a mixed-upward layout.
166 * \pre The graph has no self-loops.
167 * @param umlGraph is the input graph and will also be assigned the layout information.
169 virtual void call(UMLGraph &umlGraph);
171 //! Simple call function that does not care about cliques etc.
172 void simpleCall(UMLGraph &umlGraph) {
173 //this simple call method does not care about any special treatments
174 //of subgraphs, layout informations etc., therefore we save the
175 //option status and set them back later on
176 //cliques are only handled for UMLGraphs, so it is save to
177 //only set this value here and not in the GraphAtrtibutes interface method.
178 bool l_saveCliqueHandling = m_processCliques;
179 m_processCliques = false;
181 //---------------------------------------------------
182 // preprocessing: insert a merger for generalizations
184 preProcess(umlGraph);
185 umlGraph.insertGenMergers();
187 doSimpleCall(&umlGraph);
189 umlGraph.undoGenMergers();
191 umlGraph.removeUnnecessaryBendsHV();
193 postProcess(umlGraph);
195 m_processCliques = l_saveCliqueHandling;
198 void simpleCall(GraphAttributes & GA)
200 doSimpleCall(&GA);
201 GA.removeUnnecessaryBendsHV();
204 //! Call for simultaneous drawing with graph \a umlGraph.
205 virtual void callSimDraw(UMLGraph &umlGraph);
208 * \brief Calls planarization layout with fixed embedding given by \a umlGraph.
209 * \pre The graph has no self-loops.
210 * @param umlGraph is the input graph and will also be assigned the layout information.
211 * The fixed embedding is obtained from the layout information (node
212 * coordinates, bend points) in \a umlGraph.
214 virtual void callFixEmbed(UMLGraph &umlGraph);
216 //call with information about objects that should be
217 //fixed as much as possible in the old/new drawing
218 //for incremental drawing: takes a fixed part of the input
219 //graph (indicated by fixedNodes(Edges)==true), embeds it using
220 //the input layout, then inserts the remaining part into this embedding
221 virtual void callIncremental(UMLGraph &umlgraph,
222 NodeArray<bool> &fixedNodes, const EdgeArray<bool> &fixedEdges);
225 /** @}
226 * @name Optional parameters
227 * @{
231 * \brief Returns the current setting of option pageRatio.
233 * This option specifies the desired ration width / height of the computed
234 * layout. It is currently only used for packing connected components.
236 double pageRatio() const {
237 return m_pageRatio;
240 //! Sets the option pageRatio to \a ratio.
241 void pageRatio(double ratio) {
242 m_pageRatio = ratio;
246 * \brief Returns the current setting of option preprocessCliques
248 * If this option is enabled (set to true), a preprocessing for cliques
249 * (complete subgraphs) is performed and cliques will be laid out
250 * in a special form (straight-line, not orthogonal). The preprocessing
251 * may reduce running time and improve layout quality if the input
252 * graphs contains dense subgraphs.
254 bool preprocessCliques() const {
255 return m_processCliques;
258 //! Sets the option preProcessCliques to \a b.
259 void preprocessCliques(bool b) {
260 m_processCliques = b;
264 * \brief Returns the current setting of option minCliqueSize.
266 * If preprocessing of cliques is enabled, this option determines the
267 * minimal size of cliques to search for.
269 int minCliqueSize() const {
270 return m_cliqueSize;
273 //! Set the option minCliqueSize to \a i.
274 void minCliqueSize(int i) {
275 m_cliqueSize = max(i, 3);
278 //set the option field for the planar layouter
279 void setLayouterOptions(int ops)
280 {m_planarLayouter.get().setOptions(ops);}
282 //draw hierarchy nodes corresponding to their level
283 void alignSons(bool b)
285 int opts = m_planarLayouter.get().getOptions();
287 if (b) m_planarLayouter.get().setOptions(opts | umlOpAlign);
288 else m_planarLayouter.get().setOptions(opts & ~umlOpAlign);
292 /** @}
293 * @name Module options
294 * @{
298 * \brief Sets the module option for the computation of the planar subgraph.
300 * The computation of a planar subgraph is the first step in the crossing
301 * minimization procedure of the planarization approach.
303 void setSubgraph(PlanarSubgraphModule *pSubgraph) {
304 m_subgraph.set(pSubgraph);
308 * \brief Sets the module option for edge insertion.
310 * The edge insertion module is applied in the second step of the planarization
311 * method. The edges not contained in the planar subgraph are re-inserted
312 * one-by-one, each with as few crossings as possible. The edge insertion
313 * module implements the whole second step, i.e., it inserts all edges.
315 void setInserter(EdgeInsertionModule *pInserter) {
316 m_inserter.set(pInserter);
320 * \brief Sets the module option for the graph embedding algorithm.
322 * The result of the crossing minimization step is a planar graph,
323 * in which crossings are replaced by dummy nodes. The embedding
324 * module then computes a planar embedding of this planar graph.
326 void setEmbedder(EmbedderModule *pEmbedder) {
327 m_embedder.set(pEmbedder);
331 * \brief Sets the module option for the planar layout algorithm.
333 * The planar layout algorithm is used to compute a planar layout
334 * of the planarized representation resulting from the crossing
335 * minimization step. Planarized representation means that edge crossings
336 * are replaced by dummy nodes of degree four, so the actual layout
337 * algorithm obtains a planar graph as input. By default, the planar
338 * layout algorithm produces an orthogonal drawing.
340 void setPlanarLayouter(LayoutPlanRepModule *pPlanarLayouter) {
341 m_planarLayouter.set(pPlanarLayouter);
345 * \brief Sets the module option for the arrangement of connected components.
347 * The planarization layout algorithm draws each connected component of
348 * the input graph seperately, and then arranges the resulting drawings
349 * using a packing algorithm.
351 void setPacker(CCLayoutPackModule *pPacker) {
352 m_packer.set(pPacker);
355 /** @}
356 * @name Further information
357 * @{
360 //! Returns the number of crossings in computed layout.
361 int numberOfCrossings() const {
362 return m_nCrossings;
365 //! Throws a PreconditionViolatedException if \a umlGraph violates a precondition of planarization layout.
366 void assureDrawability(UMLGraph& umlGraph);
368 //! @}
370 protected:
371 void doSimpleCall(GraphAttributes *pGA);
373 //sorts the additional nodes for piecewise insertion
374 void sortIncrementalNodes(List<node> &addNodes, const NodeArray<bool> &fixedNodes);
375 void getFixationDistance(node startNode, HashArray<int, int> &distance,
376 const NodeArray<bool> &fixedNodes);
377 //reembeds already planarized PG in case of errors
378 void reembed(PlanRepUML &PG, int ccNumber, bool l_align = false,
379 bool l_gensExist = false);
381 virtual void preProcess(UMLGraph &UG);
382 virtual void postProcess(UMLGraph& UG); //redo changes at original
384 //collect and store nodes around center in correct order
385 void fillAdjNodes(List<node>& adjNodes, PlanRepUML& PG, node centerNode,
386 NodeArray<bool>& isClique, Layout& drawing);
388 void arrangeCCs(PlanRep &PG, GraphAttributes &GA, Array<DPoint> &boundingBox);
390 private:
391 //! The module for computing a planar subgraph.
392 ModuleOption<PlanarSubgraphModule> m_subgraph;
394 //! The module for edge re-insertion.
395 ModuleOption<EdgeInsertionModule> m_inserter;
397 //! The module for planar embedding.
398 ModuleOption<EmbedderModule> m_embedder;
400 //! The module for computing a planar layout.
401 ModuleOption<LayoutPlanRepModule> m_planarLayouter;
403 //! The module for arranging connected components.
404 ModuleOption<CCLayoutPackModule> m_packer;
406 double m_pageRatio; //!< The desired page ratio.
407 int m_nCrossings; //!< The number of crossings in the computed layout.
408 bool m_arrangeLabels; //!< Option for re-arranging labels.
409 bool m_processCliques; //!< Option for preprocessing cliques (not UML layout).
410 int m_cliqueSize; //!< The minimum size of cliques to search for.
412 // temporary changes to avoid errors
413 List<edge> m_fakedGens; // made to associations
414 bool m_fakeTree;
416 face findBestExternalFace(
417 const PlanRep &PG,
418 const CombinatorialEmbedding &E);
422 //--------------------------------------------------------
423 //incremental part
425 //! Node comparer for sorting by decreasing int values.
426 class AddNodeComparer
428 HashArray<int, int> *m_indToDeg;
430 public:
431 AddNodeComparer(HashArray<int, int> &ha) : m_indToDeg(&ha) { }
433 int compare(const node &v1, const node &v2) const {
434 if ((*m_indToDeg)[v1->index()] < (*m_indToDeg)[v2->index()])
435 return 1;
436 else if ((*m_indToDeg)[v1->index()] > (*m_indToDeg)[v2->index()])
437 return -1;
438 else
439 return 0;
442 OGDF_AUGMENT_COMPARER(node)
446 } // end namespace ogdf
449 #endif