Open
Graph Drawing
Framework

 v.2007.11
 

NearestRectangleFinder.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 1.3 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2007-11-08 16:10:37 +0100 (Do, 08 Nov 2007) $ 
00007  ***************************************************************/
00008  
00051 #ifdef _MSC_VER
00052 #pragma once
00053 #endif
00054 
00055 
00056 #ifndef OGDF_NEAREST_RECTANGLE_FINDER_H
00057 #define OGDF_NEAREST_RECTANGLE_FINDER_H
00058 
00059 
00060 #include <ogdf/basic/Array.h>
00061 #include <ogdf/basic/geometry.h>
00062 
00063 
00064 namespace ogdf {
00065 
00066 
00067 //---------------------------------------------------------
00068 // NearestRectangleFinder
00069 // finds in a given set of rectangles for each point in a given
00070 // set of points the nearest rectangle
00071 //---------------------------------------------------------
00072 class NearestRectangleFinder
00073 {
00074 public:
00075     struct RectRegion;
00076     struct PairRectDist;
00077     struct PairCoordId;
00078 
00079     NearestRectangleFinder(double mad = 20, double td = 5) {
00080         m_maxAllowedDistance = mad;
00081         m_toleranceDistance = td;
00082     }
00083 
00084     // the maximal allowed distance between a rectangle and a point
00085     // rectangles with a greater distance are not considered
00086     void maxAllowedDistance(double mad) { m_maxAllowedDistance = mad; }
00087     double maxAllowedDistance() const { return m_maxAllowedDistance; }
00088 
00089     // the tolerance in which rectangles are considered to be ambigous, i.e.
00090     // if the rectangle with the minimum distance to point p has distance mindist
00091     // and there is another rectangle with distance dist such that
00092     // dist <= minDist + toleranceDistance, we say that the closest rectangle is not unique.
00093     void toleranceDistance(double td) { m_toleranceDistance = td; }
00094     double toleranceDistance() const { return m_toleranceDistance; }
00095 
00096 
00097     // finds the nearest rectangles for a given set of points
00098     // The nearest rectangles are passed in a list. If the list is empty, there
00099     // is no rectangle within the ,aximal allowed distance. If the list contains
00100     // more than one element, the nearest rectangle is not unique for the
00101     // given tolerance.
00102     void find(
00103         const Array<RectRegion> &region, // given rectangles
00104         const Array<DPoint> &point,      // given points
00105         Array<List<PairRectDist> > &nearest); // nearest rectangles
00106 
00107     // trivial implementation of find(). Can be used in order to check
00108     // correctness. Computes only rectangle with minimum distance without
00109     // considering maxAllowedDistance and toleranceDistance.
00110     void findSimple(
00111         const Array<RectRegion> &region,
00112         const Array<DPoint> &point,
00113         Array<List<PairRectDist> > &nearest);
00114 
00115 private:
00116     class CoordComparer;
00117     class YCoordComparer;
00118 
00119     double m_maxAllowedDistance;
00120     double m_toleranceDistance;
00121 };
00122 
00123 
00124 //---------------------------------------------------------
00125 // RectRegion
00126 // represents a rectangle given by center point, width and height
00127 //---------------------------------------------------------
00128 struct NearestRectangleFinder::RectRegion
00129 {
00130     friend ostream &operator<<(ostream &os, const RectRegion &rect) {
00131         os << "(" << rect.m_x << "," << rect.m_y << ":" <<
00132             rect.m_width << "," << rect.m_height << ")";
00133         return os;
00134     }
00135 
00136     double m_x, m_y, m_width, m_height;
00137 };
00138 
00139 
00140 //---------------------------------------------------------
00141 // PairRectDist
00142 // represents a rectangle (given by its index) and a
00143 // distance value
00144 //---------------------------------------------------------
00145 struct NearestRectangleFinder::PairRectDist
00146 {
00147     PairRectDist() { }
00148 
00149     PairRectDist(int index, double distance) {
00150         m_index = index;
00151         m_distance = distance;
00152     }
00153 
00154     friend ostream &operator<<(ostream &os, const PairRectDist &p) {
00155         os << "(" << p.m_index << "," << p.m_distance << ")";
00156         return os;
00157     }
00158 
00159     int m_index;
00160     double m_distance;
00161 };
00162 
00163 
00164 
00165 } // end namespace ogdf
00166 
00167 
00168 #endif


© 1999-2007 by oreas GmbH, © 2005-2007 by University Dortmund and University Cologne.

Generated on Thu Nov 22 19:40:01 2007 by doxygen 1.5.4.