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/basic.h>
36 #include <ogdf/basic/geometry.h>
37 
38 #include <ostream>
39 
40 namespace ogdf {
41 template<class E>
42 class List;
43 
47 public:
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 
86 private:
87  class CoordComparer;
88  class YCoordComparer;
89 
90  double m_maxAllowedDistance;
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 
102  double m_x, m_y, m_width, m_height;
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 
119  int m_index;
120  double m_distance;
121 };
122 
123 
124 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::NearestRectangleFinder::PairRectDist::PairRectDist
PairRectDist()
Definition: NearestRectangleFinder.h:107
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::NearestRectangleFinder::RectRegion::m_width
double m_width
Definition: NearestRectangleFinder.h:102
ogdf::NearestRectangleFinder::maxAllowedDistance
double maxAllowedDistance() const
Definition: NearestRectangleFinder.h:61
ogdf::NearestRectangleFinder::RectRegion::m_y
double m_y
Definition: NearestRectangleFinder.h:102
ogdf::NearestRectangleFinder::PairRectDist
Represents a rectangle (given by its index) and a distance value.
Definition: NearestRectangleFinder.h:106
ogdf::NearestRectangleFinder::PairRectDist::operator<<
friend std::ostream & operator<<(std::ostream &os, const PairRectDist &p)
Definition: NearestRectangleFinder.h:114
ogdf::NearestRectangleFinder::m_toleranceDistance
double m_toleranceDistance
Definition: NearestRectangleFinder.h:91
ogdf::NearestRectangleFinder::PairRectDist::m_index
int m_index
Definition: NearestRectangleFinder.h:119
ogdf::NearestRectangleFinder::RectRegion
Represents a rectangle given by center point, width and height.
Definition: NearestRectangleFinder.h:95
ogdf::NearestRectangleFinder::RectRegion::operator<<
friend std::ostream & operator<<(std::ostream &os, const RectRegion &rect)
Definition: NearestRectangleFinder.h:96
ogdf::NearestRectangleFinder
Finds in a given set of rectangles for each point in a given set of points the nearest rectangle.
Definition: NearestRectangleFinder.h:46
ogdf::NearestRectangleFinder::PairRectDist::PairRectDist
PairRectDist(int index, double distance)
Definition: NearestRectangleFinder.h:109
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:219
ogdf::NearestRectangleFinder::PairRectDist::m_distance
double m_distance
Definition: NearestRectangleFinder.h:120
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::NearestRectangleFinder::toleranceDistance
void toleranceDistance(double td)
Definition: NearestRectangleFinder.h:67
basic.h
Basic declarations, included by all source files.
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:69
ogdf::NearestRectangleFinder::RectRegion::m_x
double m_x
Definition: NearestRectangleFinder.h:102
ogdf::NearestRectangleFinder::NearestRectangleFinder
NearestRectangleFinder(double mad=20, double td=5)
Definition: NearestRectangleFinder.h:52
ogdf::NearestRectangleFinder::RectRegion::m_height
double m_height
Definition: NearestRectangleFinder.h:102
ogdf::NearestRectangleFinder::m_maxAllowedDistance
double m_maxAllowedDistance
Definition: NearestRectangleFinder.h:88
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:59