Open
Graph Drawing
Framework

 v.2010.10
 

GridLayoutMapped.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 2027 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2010-09-01 11:55:17 +0200 (Wed, 01 Sep 2010) $ 
00007  ***************************************************************/
00008  
00054 #ifdef _MSC_VER
00055 #pragma once
00056 #endif
00057 
00058 
00059 #ifndef OGDF_GRID_LAYOUT_MAPPED_H
00060 #define OGDF_GRID_LAYOUT_MAPPED_H
00061 
00062 
00063 #include <ogdf/basic/GridLayout.h>
00064 
00065 
00066 namespace ogdf {
00067 
00068     class OGDF_EXPORT PlanRep;
00069     class OGDF_EXPORT PlanRepUML;
00070     class OGDF_EXPORT OrthoRep;
00071 
00072 
00073 //---------------------------------------------------------
00074 // GridLayoutMapped
00075 // extends GridLayout by a grid mapping mechanism
00076 //---------------------------------------------------------
00077 class OGDF_EXPORT GridLayoutMapped : public GridLayout
00078 {
00079     //scaling to allow correct edge anchors
00080     enum { cGridScale = 2 };
00081 
00082 public:
00083 
00084     // construction (determines mapping factor)
00085     GridLayoutMapped(const PlanRep &PG,
00086         const OrthoRep &OR,
00087         double separation,
00088         double cOverhang,
00089         int fineness = 4);
00090 
00091 
00092     // writes grid layout to layout using re-mapping
00093     void remap(Layout &drawing);
00094 
00095     // transforms real coordinates to grid coordinates
00096     int toGrid(double x) const {
00097         return cGridScale*int(m_fMapping * x + 0.5);
00098     }
00099 
00100     // transforms grid coordinates to real coordinates
00101     double toDouble(int i) const {
00102         return (i/cGridScale) / m_fMapping;
00103     }
00104 
00105 
00106     const NodeArray<int> &width() const { return m_gridWidth; }
00107     // returns a reference to the array storing grid widths of nodes
00108     NodeArray<int> &width() { return m_gridWidth; }
00109 
00110     const NodeArray<int> &height() const { return m_gridHeight; }
00111     // returns a reference to the array storing grid heights of nodes
00112     NodeArray<int> &height() { return m_gridHeight; }
00113 
00114     const int &width(node v) const { return m_gridWidth[v]; }
00115     // returns grid width of node v
00116     int &width(node v) { return m_gridWidth[v]; }
00117 
00118     const int &height(node v) const { return m_gridWidth[v]; }
00119     // returns grid height of node v
00120     int &height(node v) { return m_gridWidth[v]; }
00121 
00122 
00123 private:
00124     NodeArray<int> m_gridWidth;  // grid width of nodes
00125     NodeArray<int> m_gridHeight; // grid heights of nodes
00126 
00127     const PlanRep *m_pPG;     // planarized representation of grid layout
00128     double m_fMapping;           // mapping factor
00129 };
00130 
00131 
00132 } // end namespace ogdf
00133 
00134 
00135 #endif