Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 {
43 public:
44  struct RectRegion;
45  struct PairRectDist;
46  struct PairCoordId;
47 
48  explicit NearestRectangleFinder(double mad = 20, double td = 5) {
49  m_maxAllowedDistance = mad;
50  m_toleranceDistance = td;
51  }
52 
53  // the maximal allowed distance between a rectangle and a point
54  // rectangles with a greater distance are not considered
55  void maxAllowedDistance(double mad) { m_maxAllowedDistance = mad; }
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  double toleranceDistance() const { return m_toleranceDistance; }
64 
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(
72  const Array<RectRegion> &region, // given rectangles
73  const Array<DPoint> &point, // given points
74  Array<List<PairRectDist> > &nearest); // nearest rectangles
75 
76  // trivial implementation of find(). Can be used in order to check
77  // correctness. Computes only rectangle with minimum distance without
78  // considering maxAllowedDistance and toleranceDistance.
79  void findSimple(
80  const Array<RectRegion> &region,
81  const Array<DPoint> &point,
82  Array<List<PairRectDist> > &nearest);
83 
84 private:
85  class CoordComparer;
86  class YCoordComparer;
87 
88  double m_maxAllowedDistance;
90 };
91 
94 {
95  friend ostream &operator<<(ostream &os, const RectRegion &rect) {
96  os << "(" << rect.m_x << "," << rect.m_y << ":" <<
97  rect.m_width << "," << rect.m_height << ")";
98  return os;
99  }
100 
101  double m_x, m_y, m_width, m_height;
102 };
103 
104 
107 {
109 
110  PairRectDist(int index, double distance) {
111  m_index = index;
112  m_distance = distance;
113  }
114 
115  friend ostream &operator<<(ostream &os, const PairRectDist &p) {
116  os << "(" << p.m_index << "," << p.m_distance << ")";
117  return os;
118  }
119 
120  int m_index;
121  double m_distance;
122 };
123 
124 
125 
126 } // end namespace ogdf
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:56
Finds in a given set of rectangles for each point in a given set of points the nearest rectangle...
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
Represents a rectangle (given by its index) and a distance value.
friend ostream & operator<<(ostream &os, const PairRectDist &p)
NearestRectangleFinder(double mad=20, double td=5)
Declaration and implementation of Array class and Array algorithms.
friend ostream & operator<<(ostream &os, const RectRegion &rect)
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
Represents a rectangle given by center point, width and height.
static bool find(V &ts, const T &t)
Definition: Alg.h:47
The namespace for all OGDF objects.
Declaration of classes DPoint, DPolyline, DLine, DRect, DIntersectableRect, DScaler.