00001
00002
00003
00004
00005
00006
00007
00008
00052 #ifdef _MSC_VER
00053 #pragma once
00054 #endif
00055
00056 #ifndef OGDF_TREE_LAYOUT_H
00057 #define OGDF_TREE_LAYOUT_H
00058
00059 #include <ogdf/module/LayoutModule.h>
00060 #include <ogdf/basic/SList.h>
00061
00062 namespace ogdf {
00063
00117 class TreeLayout : public LayoutModule {
00118 public:
00120 enum RootSelectionType {
00121 rootIsSource,
00122 rootIsSink,
00123 rootByCoord
00124 };
00125
00126 private:
00127 double m_siblingDistance;
00128 double m_subtreeDistance;
00129 double m_levelDistance;
00130 double m_treeDistance;
00131
00132 bool m_orthogonalLayout;
00133 Orientation m_orientation;
00134 RootSelectionType m_selectRoot;
00135
00136 NodeArray<int> m_number;
00137
00138 NodeArray<node> m_parent;
00139 NodeArray<node> m_leftSibling;
00140 NodeArray<node> m_firstChild;
00141 NodeArray<node> m_lastChild;
00142 NodeArray<node> m_thread;
00143 NodeArray<node> m_ancestor;
00144
00145 NodeArray<double> m_preliminary;
00146 NodeArray<double> m_modifier;
00147 NodeArray<double> m_change;
00148 NodeArray<double> m_shift;
00149
00150 SListPure<edge> m_reversedEdges;
00151 Graph *m_pGraph;
00152
00153 public:
00155 TreeLayout();
00156
00158 TreeLayout(const TreeLayout &tl);
00159
00160
00161 ~TreeLayout();
00162
00163
00180 void call(GraphAttributes &GA);
00181
00192 void callSortByPositions(GraphAttributes &AG, Graph &G);
00193
00194
00200
00201 double siblingDistance() const { return m_siblingDistance; }
00202
00204 void siblingDistance(double x) { m_siblingDistance = x; }
00205
00207 double subtreeDistance() const { return m_subtreeDistance; }
00208
00210 void subtreeDistance(double x) { m_subtreeDistance = x; }
00211
00213 double levelDistance() const { return m_levelDistance; }
00214
00216 void levelDistance(double x) { m_levelDistance = x; }
00217
00219 double treeDistance() const { return m_treeDistance; }
00220
00222 void treeDistance(double x) { m_treeDistance = x; }
00223
00225 bool orthogonalLayout() const { return m_orthogonalLayout; }
00226
00228 void orthogonalLayout(bool b) { m_orthogonalLayout = b; }
00229
00231 Orientation orientation() const { return m_orientation; }
00232
00234 void orientation(Orientation orientation) { m_orientation = orientation; }
00235
00237 RootSelectionType rootSelection() const { return m_selectRoot; }
00238
00240 void rootSelection(RootSelectionType rootSelection) { m_selectRoot = rootSelection; }
00241
00242
00248
00249 TreeLayout &operator=(const TreeLayout &tl);
00250
00252
00253 private:
00254 class AdjComparer;
00255
00256 void adjustEdgeDirections(Graph &G, node v, node parent);
00257 void setRoot(GraphAttributes &AG, Graph &tree);
00258 void undoReverseEdges(GraphAttributes &AG);
00259
00260
00261
00262
00263
00264 void initializeTreeStructure(const Graph &tree, List<node> &roots);
00265
00266
00267 void deleteTreeStructure();
00268
00269
00270 int isLeaf(node v) const;
00271
00272
00273
00274 node nextOnLeftContour(node v) const;
00275 node nextOnRightContour(node v) const;
00276
00277
00278
00279 void firstWalk(node subtree,const GraphAttributes &AG,bool upDown);
00280
00281
00282
00283 void apportion(node subtree,
00284 node &defaultAncestor,
00285 const GraphAttributes &AG,
00286 bool upDown);
00287
00288
00289
00290 void secondWalkX(node subtree,
00291 double modifierSum,
00292 GraphAttributes &AG);
00293 void secondWalkY(node subtree,
00294 double modifierSum,
00295 GraphAttributes &AG);
00296
00297
00298 void computeYCoordinatesAndEdgeShapes(node root,GraphAttributes &AG);
00299 void computeXCoordinatesAndEdgeShapes(node root,GraphAttributes &AG);
00300
00301 void findMinX(GraphAttributes &AG, node root, double &minX);
00302 void findMinY(GraphAttributes &AG, node root, double &minY);
00303 void findMaxX(GraphAttributes &AG, node root, double &maxX);
00304 void findMaxY(GraphAttributes &AG, node root, double &maxY);
00305 void shiftTreeX(GraphAttributes &AG, node root, double shift);
00306 void shiftTreeY(GraphAttributes &AG, node root, double shift);
00307 };
00308
00309 }
00310
00311 #endif
00312