Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00047 #ifdef _MSC_VER
00048 #pragma once
00049 #endif
00050
00051 #ifndef OGDF_UNIFORMGRID_H
00052 #define OGDF_UNIFORMGRID_H
00053
00054 #include<ogdf/basic/geometry.h>
00055 #include<ogdf/basic/SList.h>
00056 #include<ogdf/basic/Array2D.h>
00057 #include<ogdf/basic/GraphAttributes.h>
00058 #include<ogdf/basic/HashArray2D.h>
00059 #include<ogdf/internal/energybased/IntersectionRectangle.h>
00060 #include<limits.h>
00061
00062 namespace ogdf {
00063
00064
00065 class UniformGrid{
00066 public:
00067 UniformGrid(const GraphAttributes &);
00068
00069
00070 UniformGrid(const GraphAttributes &,const node, const DPoint&);
00071
00072
00073
00074 UniformGrid(const UniformGrid &, const node, const DPoint&);
00075
00076 int numberOfCrossings() const {return m_crossNum;}
00077 bool newGridNecessary(const node v, const DPoint& p) {
00078 bool resize = false;
00079 IntersectionRectangle ir;
00080 computeGridGeometry(v,p,ir);
00081 double l = max(ir.width(),ir.height());
00082 l/=m_edgeMultiplier*(m_graph).numberOfEdges();
00083 if(l <= m_CellSize/2.0 || l >= m_CellSize*2.0) resize = true;
00084 return resize;
00085 }
00086
00087 private:
00088 void ModifiedBresenham(const IPoint &, const IPoint &, SList<IPoint> &) const;
00089
00090
00091
00092 void DoubleModifiedBresenham(const DPoint &, const DPoint &, SList<IPoint> &) const;
00093
00094
00095
00096 IPoint computeGridPoint(const DPoint &dp) const {
00097 double x = floor(dp.m_x/m_CellSize);
00098 OGDF_ASSERT(isInt(x));
00099 double y = floor(dp.m_y/m_CellSize);
00100 OGDF_ASSERT(isInt(y));
00101 return IPoint(int(x),int(y));
00102 }
00103
00104 DPoint computeRealPoint(const IPoint &ip) const {
00105 DPoint p;
00106 p.m_x = ip.m_x*m_CellSize;
00107 p.m_y = ip.m_y*m_CellSize;
00108 return p;
00109 }
00110
00111 bool isInt(double d) const {
00112 if(d - floor(d) > 0) return false;
00113 if(d < INT_MIN || d > INT_MAX) return false;
00114 return true;
00115 }
00116
00117
00118 void computeCrossings(const List<edge>&, const node, const DPoint&);
00119
00120
00121 void computeGridGeometry(const node, const DPoint&, IntersectionRectangle&) const;
00122
00123
00124
00125 bool crossingTest(const edge, const edge, const node,
00126 const DPoint&, const IPoint&);
00127 #ifdef OGDF_DEBUG
00128 void markCells(SList<IPoint> &, Array2D<bool> &) const;
00129 bool crossesCell(IPoint, IPoint, const IPoint &) const;
00130 bool crossesCell(DPoint, DPoint, const IPoint &) const;
00131 void checkBresenham(DPoint, DPoint) const;
00132 void checkBresenham(IPoint, IPoint) const;
00133 bool intervalIntersect(double,double,double,double) const;
00134 friend ostream& operator<<(ostream &,const UniformGrid&);
00135 int m_crossingTests;
00136 int m_maxEdgesPerCell;
00137 double m_time;
00138 #endif
00139 const GraphAttributes &m_layout;
00140 const Graph &m_graph;
00141 HashArray2D<int,int,List<edge> > m_grid;
00142
00143 EdgeArray<List<edge> > m_crossings;
00144
00145 EdgeArray<List<IPoint> > m_cells;
00146
00147 double m_CellSize;
00148 const static double m_epsilon;
00149 const static double m_edgeMultiplier;
00150 int m_crossNum;
00151
00152 UniformGrid& operator=(const UniformGrid& ug);
00153 };
00154 #ifdef OGDF_DEBUG
00155 ostream &operator<<(ostream &, const IPoint &);
00156 #endif
00157 }
00158 #endif