00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
00021 #define GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
00022
00023 #include <geos/export.h>
00024 #include <geos/algorithm/distance/PointPairDistance.h>
00025 #include <geos/algorithm/distance/DistanceToPoint.h>
00026 #include <geos/util/IllegalArgumentException.h>
00027 #include <geos/geom/Geometry.h>
00028 #include <geos/util/math.h>
00029 #include <geos/geom/CoordinateFilter.h>
00030 #include <geos/geom/CoordinateSequenceFilter.h>
00031
00032 #include <cstddef>
00033 #include <vector>
00034
00035 #ifdef _MSC_VER
00036 #pragma warning(push)
00037 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00038 #endif
00039
00040 namespace geos {
00041 namespace algorithm {
00042
00043 }
00044 namespace geom {
00045 class Geometry;
00046 class Coordinate;
00047
00048 }
00049 namespace index {
00050 namespace intervalrtree {
00051
00052 }
00053 }
00054 }
00055
00056 namespace geos {
00057 namespace algorithm {
00058 namespace distance {
00059
00101 class GEOS_DLL DiscreteHausdorffDistance
00102 {
00103 public:
00104
00105 static double distance(const geom::Geometry& g0,
00106 const geom::Geometry& g1);
00107
00108 static double distance(const geom::Geometry& g0,
00109 const geom::Geometry& g1, double densifyFrac);
00110
00111 DiscreteHausdorffDistance(const geom::Geometry& g0,
00112 const geom::Geometry& g1)
00113 :
00114 g0(g0),
00115 g1(g1),
00116 ptDist(),
00117 densifyFrac(0.0)
00118 {}
00119
00128 void setDensifyFraction(double dFrac)
00129 {
00130 if ( dFrac > 1.0 || dFrac <= 0.0 )
00131 {
00132 throw util::IllegalArgumentException(
00133 "Fraction is not in range (0.0 - 1.0]");
00134 }
00135
00136 densifyFrac = dFrac;
00137 }
00138
00139 double distance()
00140 {
00141 compute(g0, g1);
00142 return ptDist.getDistance();
00143 }
00144
00145 double orientedDistance()
00146 {
00147 computeOrientedDistance(g0, g1, ptDist);
00148 return ptDist.getDistance();
00149 }
00150
00151 const std::vector<geom::Coordinate> getCoordinates() const
00152 {
00153 return ptDist.getCoordinates();
00154 }
00155
00156 class MaxPointDistanceFilter : public geom::CoordinateFilter
00157 {
00158 public:
00159 MaxPointDistanceFilter(const geom::Geometry& geom)
00160 :
00161 geom(geom)
00162 {}
00163
00164 void filter_ro(const geom::Coordinate* pt)
00165 {
00166 minPtDist.initialize();
00167 DistanceToPoint::computeDistance(geom, *pt,
00168 minPtDist);
00169 maxPtDist.setMaximum(minPtDist);
00170 }
00171
00172 const PointPairDistance& getMaxPointDistance() const
00173 {
00174 return maxPtDist;
00175 }
00176
00177 private:
00178 PointPairDistance maxPtDist;
00179 PointPairDistance minPtDist;
00180 DistanceToPoint euclideanDist;
00181 const geom::Geometry& geom;
00182
00183
00184 MaxPointDistanceFilter(const MaxPointDistanceFilter& other);
00185 MaxPointDistanceFilter& operator=(const MaxPointDistanceFilter& rhs);
00186 };
00187
00188 class MaxDensifiedByFractionDistanceFilter
00189 : public geom::CoordinateSequenceFilter
00190 {
00191 public:
00192
00193 MaxDensifiedByFractionDistanceFilter(
00194 const geom::Geometry& geom, double fraction)
00195 :
00196 geom(geom),
00197 numSubSegs( std::size_t(util::round(1.0/fraction)) )
00198 {
00199 }
00200
00201 void filter_ro(const geom::CoordinateSequence& seq,
00202 std::size_t index);
00203
00204 bool isGeometryChanged() const { return false; }
00205
00206 bool isDone() const { return false; }
00207
00208 const PointPairDistance& getMaxPointDistance() const {
00209 return maxPtDist;
00210 }
00211
00212 private:
00213 PointPairDistance maxPtDist;
00214 PointPairDistance minPtDist;
00215 const geom::Geometry& geom;
00216 std::size_t numSubSegs;
00217
00218
00219 MaxDensifiedByFractionDistanceFilter(const MaxDensifiedByFractionDistanceFilter& other);
00220 MaxDensifiedByFractionDistanceFilter& operator=(const MaxDensifiedByFractionDistanceFilter& rhs);
00221 };
00222
00223 private:
00224
00225 void compute(const geom::Geometry& g0,
00226 const geom::Geometry& g1)
00227 {
00228 computeOrientedDistance(g0, g1, ptDist);
00229 computeOrientedDistance(g1, g0, ptDist);
00230 }
00231
00232 void computeOrientedDistance(const geom::Geometry& discreteGeom,
00233 const geom::Geometry& geom,
00234 PointPairDistance& ptDist);
00235
00236 const geom::Geometry& g0;
00237
00238 const geom::Geometry& g1;
00239
00240 PointPairDistance ptDist;
00241
00243 double densifyFrac;
00244
00245
00246 DiscreteHausdorffDistance(const DiscreteHausdorffDistance& other);
00247 DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs);
00248 };
00249
00250 }
00251 }
00252 }
00253
00254 #ifdef _MSC_VER
00255 #pragma warning(pop)
00256 #endif
00257
00258 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
00259
00260
00261
00262
00263