6 * $Date: 2012-07-02 20:59:27 +0200 (Mon, 02 Jul 2012) $
7 ***************************************************************/
10 * \brief Declaration of class NearestRectangleFinder
12 * \author Carsten Gutwenger
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
49 #ifndef OGDF_NEAREST_RECTANGLE_FINDER_H
50 #define OGDF_NEAREST_RECTANGLE_FINDER_H
53 #include <ogdf/basic/Array.h>
54 #include <ogdf/basic/geometry.h>
60 //---------------------------------------------------------
61 // NearestRectangleFinder
62 // finds in a given set of rectangles for each point in a given
63 // set of points the nearest rectangle
64 //---------------------------------------------------------
65 class OGDF_EXPORT NearestRectangleFinder
72 NearestRectangleFinder(double mad
= 20, double td
= 5) {
73 m_maxAllowedDistance
= mad
;
74 m_toleranceDistance
= td
;
77 // the maximal allowed distance between a rectangle and a point
78 // rectangles with a greater distance are not considered
79 void maxAllowedDistance(double mad
) { m_maxAllowedDistance
= mad
; }
80 double maxAllowedDistance() const { return m_maxAllowedDistance
; }
82 // the tolerance in which rectangles are considered to be ambigous, i.e.
83 // if the rectangle with the minimum distance to point p has distance mindist
84 // and there is another rectangle with distance dist such that
85 // dist <= minDist + toleranceDistance, we say that the closest rectangle is not unique.
86 void toleranceDistance(double td
) { m_toleranceDistance
= td
; }
87 double toleranceDistance() const { return m_toleranceDistance
; }
90 // finds the nearest rectangles for a given set of points
91 // The nearest rectangles are passed in a list. If the list is empty, there
92 // is no rectangle within the ,aximal allowed distance. If the list contains
93 // more than one element, the nearest rectangle is not unique for the
96 const Array
<RectRegion
> ®ion
, // given rectangles
97 const Array
<DPoint
> &point
, // given points
98 Array
<List
<PairRectDist
> > &nearest
); // nearest rectangles
100 // trivial implementation of find(). Can be used in order to check
101 // correctness. Computes only rectangle with minimum distance without
102 // considering maxAllowedDistance and toleranceDistance.
104 const Array
<RectRegion
> ®ion
,
105 const Array
<DPoint
> &point
,
106 Array
<List
<PairRectDist
> > &nearest
);
110 class YCoordComparer
;
112 double m_maxAllowedDistance
;
113 double m_toleranceDistance
;
117 //---------------------------------------------------------
119 // represents a rectangle given by center point, width and height
120 //---------------------------------------------------------
121 struct NearestRectangleFinder::RectRegion
123 friend ostream
&operator<<(ostream
&os
, const RectRegion
&rect
) {
124 os
<< "(" << rect
.m_x
<< "," << rect
.m_y
<< ":" <<
125 rect
.m_width
<< "," << rect
.m_height
<< ")";
129 double m_x
, m_y
, m_width
, m_height
;
133 //---------------------------------------------------------
135 // represents a rectangle (given by its index) and a
137 //---------------------------------------------------------
138 struct OGDF_EXPORT
NearestRectangleFinder::PairRectDist
142 PairRectDist(int index
, double distance
) {
144 m_distance
= distance
;
147 friend ostream
&operator<<(ostream
&os
, const PairRectDist
&p
) {
148 os
<< "(" << p
.m_index
<< "," << p
.m_distance
<< ")";
158 } // end namespace ogdf