Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
NearestRectangleFinder.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
35#include <ogdf/basic/geometry.h>
36
37namespace ogdf {
38
42public:
43 struct RectRegion;
44 struct PairRectDist;
45 struct PairCoordId;
46
47 explicit NearestRectangleFinder(double mad = 20, double td = 5) {
48 m_maxAllowedDistance = mad;
49 m_toleranceDistance = td;
50 }
51
52 // the maximal allowed distance between a rectangle and a point
53 // rectangles with a greater distance are not considered
54 void maxAllowedDistance(double mad) { m_maxAllowedDistance = mad; }
55
56 double maxAllowedDistance() const { return m_maxAllowedDistance; }
57
58 // the tolerance in which rectangles are considered to be ambigous, i.e.
59 // if the rectangle with the minimum distance to point p has distance mindist
60 // and there is another rectangle with distance dist such that
61 // dist <= minDist + toleranceDistance, we say that the closest rectangle is not unique.
62 void toleranceDistance(double td) { m_toleranceDistance = td; }
63
64 double toleranceDistance() const { return m_toleranceDistance; }
65
66 // finds the nearest rectangles for a given set of points
67 // The nearest rectangles are passed in a list. If the list is empty, there
68 // is no rectangle within the ,aximal allowed distance. If the list contains
69 // more than one element, the nearest rectangle is not unique for the
70 // given tolerance.
71 void find(const Array<RectRegion>& region, // given rectangles
72 const Array<DPoint>& point, // given points
73 Array<List<PairRectDist>>& nearest); // nearest rectangles
74
75 // trivial implementation of find(). Can be used in order to check
76 // correctness. Computes only rectangle with minimum distance without
77 // considering maxAllowedDistance and toleranceDistance.
80
81private:
82 class CoordComparer;
83 class YCoordComparer;
84
87};
88
91 friend std::ostream& operator<<(std::ostream& os, const RectRegion& rect) {
92 os << "(" << rect.m_x << "," << rect.m_y << ":" << rect.m_width << "," << rect.m_height
93 << ")";
94 return os;
95 }
96
98};
99
103
104 PairRectDist(int index, double distance) {
105 m_index = index;
106 m_distance = distance;
107 }
108
109 friend std::ostream& operator<<(std::ostream& os, const PairRectDist& p) {
110 os << "(" << p.m_index << "," << p.m_distance << ")";
111 return os;
112 }
113
116};
117
118
119}
Declaration and implementation of Array class and Array algorithms.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Finds in a given set of rectangles for each point in a given set of points the nearest rectangle.
void findSimple(const Array< RectRegion > &region, const Array< DPoint > &point, Array< List< PairRectDist > > &nearest)
NearestRectangleFinder(double mad=20, double td=5)
void find(const Array< RectRegion > &region, const Array< DPoint > &point, Array< List< PairRectDist > > &nearest)
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Represents a rectangle (given by its index) and a distance value.
friend std::ostream & operator<<(std::ostream &os, const PairRectDist &p)
Represents a rectangle given by center point, width and height.
friend std::ostream & operator<<(std::ostream &os, const RectRegion &rect)