Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
UniformGrid.h
Go to the documentation of this file.
1
36#pragma once
37
38#include <ogdf/basic/Array2D.h>
41#include <ogdf/basic/SList.h>
42#include <ogdf/basic/geometry.h>
43
44namespace ogdf {
45namespace davidson_harel {
46
48public:
49 // This constructor takes a GraphAttributes and computes a grid for the given layout.
50 explicit UniformGrid(const GraphAttributes&);
51
52 // This constructor gets the current layout, the node that may be
53 // moved and its new position and computes the data for the
54 // modified layout.
55 UniformGrid(const GraphAttributes&, const node, const DPoint&);
56
57 // Takes a UniformGrid and produces a new grid for the updated layout
58 UniformGrid(const UniformGrid&, const node, const DPoint&);
59
60 int numberOfCrossings() const { return m_crossNum; }
61
62 bool newGridNecessary(const node v, const DPoint& p) {
63 bool resize = false;
66 double size = max(ir.width(), ir.height());
67 size /= m_edgeMultiplier * (m_graph).numberOfEdges();
69 resize = true;
70 }
71 return resize;
72 }
73
74private:
75 void ModifiedBresenham(const IPoint&, const IPoint&, SList<IPoint>&) const;
76
77 // This takes two DPoints with and computes a list of points
78 // that are the lower left corners of the cells that may possibly contain points
79 // of the straight line segment connecting the two points
80 void DoubleModifiedBresenham(const DPoint&, const DPoint&, SList<IPoint>&) const;
81
82 // this function computes the grid coordinate of a point that depends on the
83 // coordiantes of the point, the lower left corner of the bounding rectangle
84 // and the size of a cell
86 double x = floor(dp.m_x / m_CellSize);
88 double y = floor(dp.m_y / m_CellSize);
90 return IPoint(int(x), int(y));
91 }
92
93 // computes for a grid point the corresponding DPoint
95 DPoint p;
96 p.m_x = ip.m_x * m_CellSize;
97 p.m_y = ip.m_y * m_CellSize;
98 return p;
99 }
100
101 // checks if a double number is an integer
102 bool isInt(double d) const {
103 if (d - floor(d) > 0) {
104 return false;
105 }
106 if (d < std::numeric_limits<int>::min() || d > std::numeric_limits<int>::max()) {
107 return false;
108 }
109 return true;
110 }
111
112 // computes the crossings of the given edges for the given layout
113 // with the node moved to the position given as argument
114 void computeCrossings(const List<edge>&, const node, const DPoint&);
115
116 // computes the geometry of the grid if the node is moved
117 // to the position given by the point
119
120 // Checks if two edges cross inside the given cell.
121 // The node and the point are the moved node and its/new position
122 bool crossingTest(const edge, const edge, const node, const DPoint&, const IPoint&);
123
124#ifdef OGDF_DEBUG
126
127 template<typename TPoint, typename TNum>
129 const IPoint& CellAdr) const {
130 bool crosses;
131 if (A.m_x == B.m_x) { // line segment is vertical
132 crosses = A.m_x >= xlow && A.m_x < xhigh && intervalIntersect(A.m_y, B.m_y, ylow, yhigh);
133 } else { // line segment not vertical
134 if (A.m_x > B.m_x) {
135 std::swap(A, B);
136 }
137 double m = (B.m_y - A.m_y) / (B.m_x - A.m_x);
138 double c = A.m_y - A.m_x * m;
139 double y1 = m * xlow + c;
140 double y2 = m * xhigh + c;
141 crosses = intervalIntersect(A.m_x, B.m_x, xlow, xhigh)
142 && intervalIntersect(min(A.m_y, B.m_y), max(A.m_y, B.m_y), ylow, yhigh)
144 }
145 return crosses;
146 }
147
148 bool crossesCell(IPoint, IPoint, const IPoint&) const;
149 bool crossesCell(DPoint, DPoint, const IPoint&) const;
150
151 void checkBresenham(DPoint, DPoint) const;
152 void checkBresenham(IPoint, IPoint) const;
153 bool intervalIntersect(double, double, double, double) const;
154 friend std::ostream& operator<<(std::ostream&, const UniformGrid&);
155 int m_crossingTests;
157 double m_time;
158#endif
159 const GraphAttributes& m_layout; // the layout
161 HashArray2D<int, int, List<edge>> m_grid; // stores for each grid cell
162 // the Array of edges that cross that cell
163 EdgeArray<List<edge>> m_crossings; // stores for each edge the edges
164 //its crossings in the current layout
165 EdgeArray<List<IPoint>> m_cells; //Contains for each edge the list of cells it crosses
166 double m_CellSize; // Sidelength of one cell
167 const static double m_epsilon; // tolerance fo double computation
168 const static double m_edgeMultiplier; // this controls the gridsize
169 int m_crossNum; // number of crossings
170
172};
173
174}
175}
Declaration and implementation of class Array2D which implements dynamic two dimensional arrays.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declaration of class HashArray2D.
Declaration of singly linked lists and iterators.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
The parameterized class Array2D implements dynamic two-dimensional arrays.
Definition Array2D.h:47
Rectangles with real coordinates.
Definition geometry.h:914
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
T m_y
The y-coordinate.
Definition geometry.h:79
T m_x
The x-coordinate.
Definition geometry.h:78
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Indexed 2-dimensional arrays using hashing for element access.
Definition HashArray2D.h:59
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Class for the representation of nodes.
Definition Graph_d.h:177
Singly linked lists (maintaining the length of the list).
Definition SList.h:833
UniformGrid(const GraphAttributes &)
UniformGrid(const GraphAttributes &, const node, const DPoint &)
UniformGrid & operator=(const UniformGrid &ug)
void computeGridGeometry(const node, const DPoint &, DIntersectableRect &) const
static const double m_edgeMultiplier
bool newGridNecessary(const node v, const DPoint &p)
Definition UniformGrid.h:62
IPoint computeGridPoint(const DPoint &dp) const
Definition UniformGrid.h:85
EdgeArray< List< IPoint > > m_cells
HashArray2D< int, int, List< edge > > m_grid
const GraphAttributes & m_layout
void DoubleModifiedBresenham(const DPoint &, const DPoint &, SList< IPoint > &) const
EdgeArray< List< edge > > m_crossings
DPoint computeRealPoint(const IPoint &ip) const
Definition UniformGrid.h:94
bool crossingTest(const edge, const edge, const node, const DPoint &, const IPoint &)
void ModifiedBresenham(const IPoint &, const IPoint &, SList< IPoint > &) const
UniformGrid(const UniformGrid &, const node, const DPoint &)
void computeCrossings(const List< edge > &, const node, const DPoint &)
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
GenericPoint< double > DPoint
Representing two-dimensional point with real coordinates.
Definition geometry.h:236
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:978
GenericPoint< int > IPoint
Representing a two-dimensional point with integer coordinates.
Definition geometry.h:233