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/Graph.h>
40#include <ogdf/basic/List.h>
41#include <ogdf/basic/basic.h>
42#include <ogdf/basic/geometry.h>
43
44#include <algorithm>
45#include <cmath>
46#include <iosfwd>
47#include <limits>
48
49namespace ogdf {
50class GraphAttributes;
51template<class E>
52class Array2D;
53template<class E>
54class SList;
55
56namespace davidson_harel {
57
59public:
60 // This constructor takes a GraphAttributes and computes a grid for the given layout.
61 explicit UniformGrid(const GraphAttributes&);
62
63 // This constructor gets the current layout, the node that may be
64 // moved and its new position and computes the data for the
65 // modified layout.
66 UniformGrid(const GraphAttributes&, const node, const DPoint&);
67
68 // Takes a UniformGrid and produces a new grid for the updated layout
69 UniformGrid(const UniformGrid&, const node, const DPoint&);
70
71 int numberOfCrossings() const { return m_crossNum; }
72
73 bool newGridNecessary(const node v, const DPoint& p) {
74 bool resize = false;
76 computeGridGeometry(v, p, ir);
77 double size = max(ir.width(), ir.height());
78 size /= m_edgeMultiplier * (m_graph).numberOfEdges();
79 if (size <= m_CellSize / 2.0 || size >= m_CellSize * 2.0) {
80 resize = true;
81 }
82 return resize;
83 }
84
85private:
86 void ModifiedBresenham(const IPoint&, const IPoint&, SList<IPoint>&) const;
87
88 // This takes two DPoints with and computes a list of points
89 // that are the lower left corners of the cells that may possibly contain points
90 // of the straight line segment connecting the two points
91 void DoubleModifiedBresenham(const DPoint&, const DPoint&, SList<IPoint>&) const;
92
93 // this function computes the grid coordinate of a point that depends on the
94 // coordiantes of the point, the lower left corner of the bounding rectangle
95 // and the size of a cell
96 IPoint computeGridPoint(const DPoint& dp) const {
97 double x = floor(dp.m_x / m_CellSize);
99 double y = floor(dp.m_y / m_CellSize);
100 OGDF_ASSERT(isInt(y));
101 return IPoint(int(x), int(y));
102 }
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
112 // checks if a double number is an integer
113 bool isInt(double d) const {
114 if (d - floor(d) > 0) {
115 return false;
116 }
117 if (d < std::numeric_limits<int>::min() || d > std::numeric_limits<int>::max()) {
118 return false;
119 }
120 return true;
121 }
122
123 // computes the crossings of the given edges for the given layout
124 // with the node moved to the position given as argument
125 void computeCrossings(const List<edge>&, const node, const DPoint&);
126
127 // computes the geometry of the grid if the node is moved
128 // to the position given by the point
130
131 // Checks if two edges cross inside the given cell.
132 // The node and the point are the moved node and its/new position
133 bool crossingTest(const edge, const edge, const node, const DPoint&, const IPoint&);
134
135#ifdef OGDF_DEBUG
137
138 template<typename TPoint, typename TNum>
139 bool crossesCell(TPoint& A, TPoint& B, TNum xlow, TNum xhigh, TNum ylow, TNum yhigh,
140 const IPoint& CellAdr) const {
141 bool crosses;
142 if (A.m_x == B.m_x) { // line segment is vertical
143 crosses = A.m_x >= xlow && A.m_x < xhigh && intervalIntersect(A.m_y, B.m_y, ylow, yhigh);
144 } else { // line segment not vertical
145 if (A.m_x > B.m_x) {
146 std::swap(A, B);
147 }
148 double m = (B.m_y - A.m_y) / (B.m_x - A.m_x);
149 double c = A.m_y - A.m_x * m;
150 double y1 = m * xlow + c;
151 double y2 = m * xhigh + c;
152 crosses = intervalIntersect(A.m_x, B.m_x, xlow, xhigh)
153 && intervalIntersect(min(A.m_y, B.m_y), max(A.m_y, B.m_y), ylow, yhigh)
154 && intervalIntersect(y1, y2, ylow, yhigh);
155 }
156 return crosses;
157 }
158
159 bool crossesCell(IPoint, IPoint, const IPoint&) const;
160 bool crossesCell(DPoint, DPoint, const IPoint&) const;
161
164 bool intervalIntersect(double, double, double, double) const;
165 friend std::ostream& operator<<(std::ostream&, const UniformGrid&);
168 double m_time;
169#endif
170 const GraphAttributes& m_layout; // the layout
172 HashArray2D<int, int, List<edge>> m_grid; // stores for each grid cell
173 // the Array of edges that cross that cell
174 EdgeArray<List<edge>> m_crossings; // stores for each edge the edges
175 //its crossings in the current layout
176 EdgeArray<List<IPoint>> m_cells; //Contains for each edge the list of cells it crosses
177 double m_CellSize; // Sidelength of one cell
178 const static double m_epsilon; // tolerance fo double computation
179 const static double m_edgeMultiplier; // this controls the gridsize
180 int m_crossNum; // number of crossings
181
183};
184
185}
186}
Includes declaration of graph class.
Declaration of class HashArray2D.
Declaration of doubly linked lists and iterators.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
Basic declarations, included by all source files.
The parameterized class Array2D implements dynamic two-dimensional arrays.
Definition Array2D.h:53
Rectangles with real coordinates.
Definition geometry.h:922
double height() const
Returns the height of the rectangle.
Definition geometry.h:842
double width() const
Returns the width of the rectangle.
Definition geometry.h:839
Class for the representation of edges.
Definition Graph_d.h:364
T m_y
The y-coordinate.
Definition geometry.h:87
T m_x
The x-coordinate.
Definition geometry.h:86
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
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:1451
Class for the representation of nodes.
Definition Graph_d.h:241
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
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 crossesCell(TPoint &A, TPoint &B, TNum xlow, TNum xhigh, TNum ylow, TNum yhigh, const IPoint &CellAdr) const
bool intervalIntersect(double, double, double, double) const
friend std::ostream & operator<<(std::ostream &, const UniformGrid &)
void checkBresenham(IPoint, IPoint) const
bool newGridNecessary(const node v, const DPoint &p)
Definition UniformGrid.h:73
IPoint computeGridPoint(const DPoint &dp) const
Definition UniformGrid.h:96
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
bool crossesCell(IPoint, IPoint, const IPoint &) const
EdgeArray< List< edge > > m_crossings
bool crossesCell(DPoint, DPoint, const IPoint &) const
void markCells(SList< IPoint > &, Array2D< bool > &) const
DPoint computeRealPoint(const IPoint &ip) const
bool crossingTest(const edge, const edge, const node, const DPoint &, const IPoint &)
void checkBresenham(DPoint, DPoint) const
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 &)
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.
GenericPoint< int > IPoint
Representing a two-dimensional point with integer coordinates.
Definition geometry.h:241