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/basic.h>
36#include <ogdf/basic/geometry.h>
37
38#include <ostream>
39
40namespace ogdf {
41template<class E>
42class List;
43
47public:
48 struct PairCoordId;
49 struct PairRectDist;
50 struct RectRegion;
51
52 explicit NearestRectangleFinder(double mad = 20, double td = 5) {
53 m_maxAllowedDistance = mad;
54 m_toleranceDistance = td;
55 }
56
57 // the maximal allowed distance between a rectangle and a point
58 // rectangles with a greater distance are not considered
59 void maxAllowedDistance(double mad) { m_maxAllowedDistance = mad; }
60
61 double maxAllowedDistance() const { return m_maxAllowedDistance; }
62
63 // the tolerance in which rectangles are considered to be ambigous, i.e.
64 // if the rectangle with the minimum distance to point p has distance mindist
65 // and there is another rectangle with distance dist such that
66 // dist <= minDist + toleranceDistance, we say that the closest rectangle is not unique.
67 void toleranceDistance(double td) { m_toleranceDistance = td; }
68
69 double toleranceDistance() const { return m_toleranceDistance; }
70
71 // finds the nearest rectangles for a given set of points
72 // The nearest rectangles are passed in a list. If the list is empty, there
73 // is no rectangle within the ,aximal allowed distance. If the list contains
74 // more than one element, the nearest rectangle is not unique for the
75 // given tolerance.
76 void find(const Array<RectRegion>& region, // given rectangles
77 const Array<DPoint>& point, // given points
78 Array<List<PairRectDist>>& nearest); // nearest rectangles
79
80 // trivial implementation of find(). Can be used in order to check
81 // correctness. Computes only rectangle with minimum distance without
82 // considering maxAllowedDistance and toleranceDistance.
83 void findSimple(const Array<RectRegion>& region, const Array<DPoint>& point,
84 Array<List<PairRectDist>>& nearest);
85
86private:
87 class CoordComparer;
88 class YCoordComparer;
89
92};
93
96 friend std::ostream& operator<<(std::ostream& os, const RectRegion& rect) {
97 os << "(" << rect.m_x << "," << rect.m_y << ":" << rect.m_width << "," << rect.m_height
98 << ")";
99 return os;
100 }
101
103};
104
108
109 PairRectDist(int index, double distance) {
110 m_index = index;
111 m_distance = distance;
112 }
113
114 friend std::ostream& operator<<(std::ostream& os, const PairRectDist& p) {
115 os << "(" << p.m_index << "," << p.m_distance << ")";
116 return os;
117 }
118
121};
122
123
124}
Declaration and implementation of Array class and Array algorithms.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
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 dynamic library (shared object / DLL),...
Definition config.h:117
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)