Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
37 namespace ogdf {
38 
42 public:
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.
78  void findSimple(const Array<RectRegion>& region, const Array<DPoint>& point,
79  Array<List<PairRectDist>>& nearest);
80 
81 private:
82  class CoordComparer;
83  class YCoordComparer;
84 
85  double m_maxAllowedDistance;
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 
97  double m_x, m_y, m_width, m_height;
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 
114  int m_index;
115  double m_distance;
116 };
117 
118 
119 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::NearestRectangleFinder::PairRectDist::PairRectDist
PairRectDist()
Definition: NearestRectangleFinder.h:102
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::NearestRectangleFinder::RectRegion::m_width
double m_width
Definition: NearestRectangleFinder.h:97
ogdf::NearestRectangleFinder::maxAllowedDistance
double maxAllowedDistance() const
Definition: NearestRectangleFinder.h:56
ogdf::NearestRectangleFinder::RectRegion::m_y
double m_y
Definition: NearestRectangleFinder.h:97
ogdf::NearestRectangleFinder::PairRectDist
Represents a rectangle (given by its index) and a distance value.
Definition: NearestRectangleFinder.h:101
ogdf::NearestRectangleFinder::PairRectDist::operator<<
friend std::ostream & operator<<(std::ostream &os, const PairRectDist &p)
Definition: NearestRectangleFinder.h:109
ogdf::NearestRectangleFinder::m_toleranceDistance
double m_toleranceDistance
Definition: NearestRectangleFinder.h:86
ogdf::NearestRectangleFinder::PairRectDist::m_index
int m_index
Definition: NearestRectangleFinder.h:114
ogdf::NearestRectangleFinder::RectRegion
Represents a rectangle given by center point, width and height.
Definition: NearestRectangleFinder.h:90
ogdf::NearestRectangleFinder::RectRegion::operator<<
friend std::ostream & operator<<(std::ostream &os, const RectRegion &rect)
Definition: NearestRectangleFinder.h:91
ogdf::NearestRectangleFinder
Finds in a given set of rectangles for each point in a given set of points the nearest rectangle.
Definition: NearestRectangleFinder.h:41
ogdf::NearestRectangleFinder::PairRectDist::PairRectDist
PairRectDist(int index, double distance)
Definition: NearestRectangleFinder.h:104
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:214
ogdf::NearestRectangleFinder::PairRectDist::m_distance
double m_distance
Definition: NearestRectangleFinder.h:115
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::NearestRectangleFinder::toleranceDistance
void toleranceDistance(double td)
Definition: NearestRectangleFinder.h:62
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::NearestRectangleFinder::toleranceDistance
double toleranceDistance() const
Definition: NearestRectangleFinder.h:64
ogdf::NearestRectangleFinder::RectRegion::m_x
double m_x
Definition: NearestRectangleFinder.h:97
ogdf::NearestRectangleFinder::NearestRectangleFinder
NearestRectangleFinder(double mad=20, double td=5)
Definition: NearestRectangleFinder.h:47
ogdf::NearestRectangleFinder::RectRegion::m_height
double m_height
Definition: NearestRectangleFinder.h:97
ogdf::NearestRectangleFinder::m_maxAllowedDistance
double m_maxAllowedDistance
Definition: NearestRectangleFinder.h:83
Minisat::Internal::find
static bool find(V &ts, const T &t)
Definition: Alg.h:47
ogdf::NearestRectangleFinder::maxAllowedDistance
void maxAllowedDistance(double mad)
Definition: NearestRectangleFinder.h:54