1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
|
/*
* $Revision: 3159 $
*
* last checkin:
* $Author: gutwenger $
* $Date: 2012-12-13 09:01:58 +0100 (Thu, 13 Dec 2012) $
***************************************************************/
/** \file
* \brief Declaration of class PlanarizationLayoutUML.
*
* \author Carsten Gutwenger
*
* \par License:
* This file is part of the Open Graph Drawing Framework (OGDF).
*
* \par
* Copyright (C)<br>
* See README.txt in the root directory of the OGDF installation for details.
*
* \par
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* Version 2 or 3 as published by the Free Software Foundation;
* see the file LICENSE.txt included in the packaging of this file
* for details.
*
* \par
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* \par
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* \see http://www.gnu.org/copyleft/gpl.html
***************************************************************/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef OGDF_PLANARIZATION_LAYOUT_UML_H
#define OGDF_PLANARIZATION_LAYOUT_UML_H
#include <ogdf/module/UMLLayoutModule.h>
#include <ogdf/module/UMLCrossingMinimizationModule.h>
#include <ogdf/module/LayoutPlanRepUMLModule.h>
#include <ogdf/module/CCLayoutPackModule.h>
#include <ogdf/basic/ModuleOption.h>
#include <ogdf/module/EmbedderModule.h>
#include <ogdf/basic/HashArray.h>
namespace ogdf {
/**
* \brief The planarization layout algorithm.
*
* The class PlanarizationLayout represents a customizable implementation
* of the planarization approach for drawing graphs. The class provides
* three different algorithm calls:
* - Calling the algorithm for a usual graph (call with GraphAttributes).
* - Calling the algorithm for a mixed-upward graph (e.g., a UML class
* diagram; call with UMLGraph); a simplified version is provided by
* simpleCall.
* - Calling the algorithm for simultaneous drawing.
*
* If the planarization layout algorithm shall be used for simultaneous drawing,
* you need to define the different subgraphs by setting the <i>subgraphs</i>
* option.
*
* The implementation used in PlanarizationLayout is based on the following
* publication:
*
* C. Gutwenger, P. Mutzel: <i>An Experimental Study of Crossing
* Minimization Heuristics</i>. 11th International Symposium on %Graph
* Drawing 2003, Perugia (GD '03), LNCS 2912, pp. 13-24, 2004.
*
* <H3>Optional parameters</H3>
*
* <table>
* <tr>
* <th><i>Option</i><th><i>Type</i><th><i>Default</i><th><i>Description</i>
* </tr><tr>
* <td><i>pageRatio</i><td>double<td>1.0
* <td>Specifies the desired ration of width / height of the computed
* layout. It is currently only used when packing connected components.
* </tr><tr>
* <td><i>preprocessCliques</i><td>bool<td>false
* <td>If set to true, a preprocessing for cliques (complete subgraphs)
* is performed and cliques will be laid out in a special form (straight-line,
* not orthogonal). The preprocessing may reduce running time and improve
* layout quality if the input graphs contains dense subgraphs.
* </tr><tr>
* <td><i>minCliqueSize</i><td>int<td>10<td>If preprocessing of cliques is
* enabled, this option determines the minimal size of cliques to search for.
* </tr>
* </table>
*
* <H3>%Module options</H3>
* The various phases of the algorithm can be exchanged by setting
* module options allowing flexible customization. The algorithm provides
* the following module options:
*
* <table>
* <tr>
* <th><i>Option</i><th><i>Type</i><th><i>Default</i><th><i>Description</i>
* </tr><tr>
* <td><i>crossMin</i><td>UMLCrossingMinimizationModule<td>SubgraphPlanarizerUML
* <td>The module used for the crossing minimization step.
* </tr><tr>
* <td><i>embedder</i><td>EmbedderModule<td>SimpleEmbedder
* <td>The graph embedding algorithm applied after the crossing minimization
* step.
* </tr><tr>
* <td><i>planarLayouter</i><td>LayoutPlanRepUMLModule<td>OrthoLayoutUML
* <td>The planar layout algorithm used to compute a planar layout
* of the planarized representation resulting from the crossing minimization step.
* </tr><tr>
* <td><i>packer</i><td>CCLayoutPackModule<td>TileToRowsCCPacker
* <td>The packer module used for arranging connected components.
* </tr>
* </table>
*/
class OGDF_EXPORT PlanarizationLayoutUML : public UMLLayoutModule
{
public:
//! Creates an instance of planarization layout and sets options to default values.
PlanarizationLayoutUML();
// destructor
virtual ~PlanarizationLayoutUML() { }
/**
* @name Algorithm call
* @{
*/
/**
* \brief Calls planarization layout for GraphAttributes \a GA and computes a layout.
* \pre The graph has no self-loops.
* @param GA is the input graph and will also be assigned the layout information.
*/
void call(GraphAttributes &GA) {
doSimpleCall(GA);
}
/**
* \brief Calls planarization layout for UML-graph \a umlGraph and computes a mixed-upward layout.
* \pre The graph has no self-loops.
* @param umlGraph is the input graph and will also be assigned the layout information.
*/
virtual void call(UMLGraph ¨Graph);
//! Simple call function that does not care about cliques etc.
void simpleCall(UMLGraph ¨Graph) {
//this simple call method does not care about any special treatments
//of subgraphs, layout informations etc., therefore we save the
//option status and set them back later on
//cliques are only handled for UMLGraphs, so it is save to
//only set this value here and not in the GraphAtrtibutes interface method.
//bool l_saveCliqueHandling = m_processCliques;
//m_processCliques = false;
//---------------------------------------------------
// preprocessing: insert a merger for generalizations
preProcess(umlGraph);
umlGraph.insertGenMergers();
doSimpleCall(umlGraph);
umlGraph.undoGenMergers();
umlGraph.removeUnnecessaryBendsHV();
postProcess(umlGraph);
//m_processCliques = l_saveCliqueHandling;
}
//! Simple call function.
void simpleCall(GraphAttributes &GA)
{
doSimpleCall(GA);
GA.removeUnnecessaryBendsHV();
}
//! Call for simultaneous drawing with graph \a umlGraph.
//virtual void callSimDraw(UMLGraph ¨Graph);
#if 0
**
* \brief Calls planarization layout with fixed embedding given by \a umlGraph.
* \pre The graph has no self-loops.
* @param umlGraph is the input graph and will also be assigned the layout information.
* The fixed embedding is obtained from the layout information (node
* coordinates, bend points) in \a umlGraph.
*/
virtual void callFixEmbed(UMLGraph ¨Graph);
#endif
//! Incremental call function.
/**
* Call with information about objects that should be fixed as much as possible
* in the old/new drawing for incremental drawing: takes a fixed part of the input
* graph (indicated by fixedNodes(Edges)==true), embeds it using the input layout,
* then inserts the remaining part into this embedding.
*/
virtual void callIncremental(UMLGraph ¨graph,
NodeArray<bool> &fixedNodes, const EdgeArray<bool> &fixedEdges);
/** @}
* @name Optional parameters
* @{
*/
/**
* \brief Returns the current setting of option pageRatio.
*
* This option specifies the desired ration width / height of the computed
* layout. It is currently only used for packing connected components.
*/
double pageRatio() const {
return m_pageRatio;
}
//! Sets the option pageRatio to \a ratio.
void pageRatio(double ratio) {
m_pageRatio = ratio;
}
//set the option field for the planar layouter
void setLayouterOptions(int ops) { m_planarLayouter.get().setOptions(ops); }
//draw hierarchy nodes corresponding to their level
void alignSons(bool b)
{
int opts = m_planarLayouter.get().getOptions();
if (b) m_planarLayouter.get().setOptions(opts | umlOpAlign);
else m_planarLayouter.get().setOptions(opts & ~umlOpAlign);
}
/** @}
* @name Module options
* @{
*/
//! Sets the module option for UML crossing minimization.
void setCrossMin(UMLCrossingMinimizationModule *pCrossMin) {
m_crossMin.set(pCrossMin);
}
/**
* \brief Sets the module option for the graph embedding algorithm.
*
* The result of the crossing minimization step is a planar graph,
* in which crossings are replaced by dummy nodes. The embedding
* module then computes a planar embedding of this planar graph.
*/
void setEmbedder(EmbedderModule *pEmbedder) {
m_embedder.set(pEmbedder);
}
/**
* \brief Sets the module option for the planar layout algorithm.
*
* The planar layout algorithm is used to compute a planar layout
* of the planarized representation resulting from the crossing
* minimization step. Planarized representation means that edge crossings
* are replaced by dummy nodes of degree four, so the actual layout
* algorithm obtains a planar graph as input. By default, the planar
* layout algorithm produces an orthogonal drawing.
*/
void setPlanarLayouter(LayoutPlanRepUMLModule *pPlanarLayouter) {
m_planarLayouter.set(pPlanarLayouter);
}
/**
* \brief Sets the module option for the arrangement of connected components.
*
* The planarization layout algorithm draws each connected component of
* the input graph seperately, and then arranges the resulting drawings
* using a packing algorithm.
*/
void setPacker(CCLayoutPackModule *pPacker) {
m_packer.set(pPacker);
}
/** @}
* @name Further information
* @{
*/
//! Returns the number of crossings in computed layout.
int numberOfCrossings() const {
return m_nCrossings;
}
//! Throws a PreconditionViolatedException if \a umlGraph violates a precondition of planarization layout.
void assureDrawability(UMLGraph& umlGraph);
//! @}
protected:
void doSimpleCall(GraphAttributes &GA);
//sorts the additional nodes for piecewise insertion
void sortIncrementalNodes(List<node> &addNodes, const NodeArray<bool> &fixedNodes);
void getFixationDistance(node startNode, HashArray<int, int> &distance,
const NodeArray<bool> &fixedNodes);
//reembeds already planarized PG in case of errors
void reembed(PlanRepUML &PG, int ccNumber, bool l_align = false,
bool l_gensExist = false);
virtual void preProcess(UMLGraph &UG);
virtual void postProcess(UMLGraph& UG); //redo changes at original
void arrangeCCs(PlanRep &PG, GraphAttributes &GA, Array<DPoint> &boundingBox);
private:
face findBestExternalFace(
const PlanRep &PG,
const CombinatorialEmbedding &E);
//! The moule for UML crossing minimization
ModuleOption<UMLCrossingMinimizationModule> m_crossMin;
//! The module for planar embedding.
ModuleOption<EmbedderModule> m_embedder;
//! The module for computing a planar layout.
ModuleOption<LayoutPlanRepUMLModule> m_planarLayouter;
//! The module for arranging connected components.
ModuleOption<CCLayoutPackModule> m_packer;
double m_pageRatio; //!< The desired page ratio.
int m_nCrossings; //!< The number of crossings in the computed layout.
bool m_arrangeLabels; //!< Option for re-arranging labels.
// temporary changes to avoid errors
List<edge> m_fakedGens; // made to associations
bool m_fakeTree;
};
//--------------------------------------------------------
//incremental part
//! Node comparer for sorting by decreasing int values.
class AddNodeComparer
{
HashArray<int, int> *m_indToDeg;
public:
AddNodeComparer(HashArray<int, int> &ha) : m_indToDeg(&ha) { }
int compare(const node &v1, const node &v2) const {
if ((*m_indToDeg)[v1->index()] < (*m_indToDeg)[v2->index()])
return 1;
else if ((*m_indToDeg)[v1->index()] > (*m_indToDeg)[v2->index()])
return -1;
else
return 0;
}
OGDF_AUGMENT_COMPARER(node)
};
} // end namespace ogdf
#endif
|