Open
Graph Drawing
Framework

 v.2012.07
 

UniformGrid.h
Go to the documentation of this file.
1 /*
2  * $Revision: 2564 $
3  *
4  * last checkin:
5  * $Author: gutwenger $
6  * $Date: 2012-07-07 00:03:48 +0200 (Sa, 07. Jul 2012) $
7  ***************************************************************/
8 
48 #ifdef _MSC_VER
49 #pragma once
50 #endif
51 
52 #ifndef OGDF_UNIFORMGRID_H
53 #define OGDF_UNIFORMGRID_H
54 
55 #include<ogdf/basic/geometry.h>
56 #include<ogdf/basic/SList.h>
57 #include<ogdf/basic/Array2D.h>
61 #include<limits.h>
62 
63 namespace ogdf {
64 
65 
66  class UniformGrid{
67  public:
69  //This constructor takes an GraphAttributes and computes a grid for the given
70  //layout.
71  UniformGrid(const GraphAttributes &,const node, const DPoint&);
72  //This constructor gets the current layout, the node that may be
73  //moved and its new position and computes the data for the
74  //modified layout.
75  UniformGrid(const UniformGrid &, const node, const DPoint&);
76  //Takes a UniformGrid and produces a new grid for the updated layout
77  int numberOfCrossings() const {return m_crossNum;}
78  bool newGridNecessary(const node v, const DPoint& p) {
79  bool resize = false;
81  computeGridGeometry(v,p,ir);
82  double l = max(ir.width(),ir.height());
83  l/=m_edgeMultiplier*(m_graph).numberOfEdges();
84  if(l <= m_CellSize/2.0 || l >= m_CellSize*2.0) resize = true;
85  return resize;
86  }
87 
88  private:
89  void ModifiedBresenham(const IPoint &, const IPoint &, SList<IPoint> &) const;
90  //This takes two DPoints with and computes a list of points
91  //that are the lower left corners of the cells that may possibly contain points
92  //of the straight line segment connecting the two points
93  void DoubleModifiedBresenham(const DPoint &, const DPoint &, SList<IPoint> &) const;
94  //this function computes the grid coordinate of a point that depends on the
95  //coordiantes of the point, the lower left corner of the bounding rectangle
96  //and the size of a cell
97  IPoint computeGridPoint(const DPoint &dp) const {
98  double x = floor(dp.m_x/m_CellSize);
99  OGDF_ASSERT(isInt(x));
100  double y = floor(dp.m_y/m_CellSize);
101  OGDF_ASSERT(isInt(y));
102  return IPoint(int(x),int(y));
103  }
104  //computes for a grid point the corresponding DPoint
105  DPoint computeRealPoint(const IPoint &ip) const {
106  DPoint p;
107  p.m_x = ip.m_x*m_CellSize;
108  p.m_y = ip.m_y*m_CellSize;
109  return p;
110  }
111  //checks if a double number is an integer
112  bool isInt(double d) const {
113  if(d - floor(d) > 0) return false;
114  if(d < INT_MIN || d > INT_MAX) return false;
115  return true;
116  }
117  //computes the crossings of the given edges for the given layout
118  //with the node moved to the position given as argument
119  void computeCrossings(const List<edge>&, const node, const DPoint&);
120  //computes the geometry of the grid if the node is moved
121  //to the position given by the point
122  void computeGridGeometry(const node, const DPoint&, IntersectionRectangle&) const;
123  //Checks if two edges cross inside the given cell.
124  //The node and the point are the moved node and its
125  //new position
126  bool crossingTest(
127  const edge,
128  const edge,
129  const node,
130  const DPoint&,
131  const IPoint&);
132 
133 #ifdef OGDF_DEBUG
134  void markCells(SList<IPoint> &, Array2D<bool> &) const;
135  bool crossesCell(IPoint, IPoint, const IPoint &) const;
136  bool crossesCell(DPoint, DPoint, const IPoint &) const;
137  void checkBresenham(DPoint, DPoint) const;
138  void checkBresenham(IPoint, IPoint) const;
139  bool intervalIntersect(double,double,double,double) const;
140  friend ostream& operator<<(ostream &,const UniformGrid&);
141  int m_crossingTests;
142  int m_maxEdgesPerCell;
143  double m_time;
144 #endif
145  const GraphAttributes &m_layout; //the layout
146  const Graph &m_graph;
147  HashArray2D<int,int,List<edge> > m_grid; //stores for each grid cell
148  //the Array of edges that cross that cell
149  EdgeArray<List<edge> > m_crossings; //stores for each edge the edges
150  //its crossings in the current layout
151  EdgeArray<List<IPoint> > m_cells; //Contains for each edge the
152  //list of cells it crosses
153  double m_CellSize; //Sidelength of one cell
154  const static double m_epsilon; //tolerance fo double computation
155  const static double m_edgeMultiplier; //this controls the gridsize
156  int m_crossNum; //number of crossings
157 
158  UniformGrid& operator=(const UniformGrid& ug);
159  };
160 #ifdef OGDF_DEBUG
161 ostream &operator<<(ostream &, const IPoint &);
162 #endif
163 } //namespace
164 #endif