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/algorithm/distance/PointPairDistance.h>
00024 #include <geos/algorithm/distance/DistanceToPoint.h>
00025 #include <geos/util/IllegalArgumentException.h>
00026 #include <geos/geom/Geometry.h>
00027 #include <geos/util/math.h>
00028 #include <geos/geom/CoordinateFilter.h>
00029 #include <geos/geom/CoordinateSequenceFilter.h>
00030
00031 #include <cstddef>
00032 #include <vector>
00033
00034 namespace geos {
00035 namespace algorithm {
00036
00037 }
00038 namespace geom {
00039 class Geometry;
00040 class Coordinate;
00041
00042 }
00043 namespace index {
00044 namespace intervalrtree {
00045
00046 }
00047 }
00048 }
00049
00050 namespace geos {
00051 namespace algorithm {
00052 namespace distance {
00053
00095 class DiscreteHausdorffDistance
00096 {
00097 public:
00098
00099 static double distance(const geom::Geometry& g0,
00100 const geom::Geometry& g1);
00101
00102 static double distance(const geom::Geometry& g0,
00103 const geom::Geometry& g1, double densifyFrac);
00104
00105 DiscreteHausdorffDistance(const geom::Geometry& g0,
00106 const geom::Geometry& g1)
00107 :
00108 g0(g0),
00109 g1(g1),
00110 ptDist(),
00111 densifyFrac(0.0)
00112 {}
00113
00122 void setDensifyFraction(double dFrac)
00123 {
00124 if ( dFrac > 1.0 || dFrac <= 0.0 )
00125 {
00126 throw util::IllegalArgumentException(
00127 "Fraction is not in range (0.0 - 1.0]");
00128 }
00129
00130 densifyFrac = dFrac;
00131 }
00132
00133 double distance()
00134 {
00135 compute(g0, g1);
00136 return ptDist.getDistance();
00137 }
00138
00139 double orientedDistance()
00140 {
00141 computeOrientedDistance(g0, g1, ptDist);
00142 return ptDist.getDistance();
00143 }
00144
00145 const std::vector<geom::Coordinate> getCoordinates() const
00146 {
00147 return ptDist.getCoordinates();
00148 }
00149
00150 class MaxPointDistanceFilter : public geom::CoordinateFilter
00151 {
00152 public:
00153 MaxPointDistanceFilter(const geom::Geometry& geom)
00154 :
00155 geom(geom)
00156 {}
00157
00158 void filter_ro(const geom::Coordinate* pt)
00159 {
00160 minPtDist.initialize();
00161 DistanceToPoint::computeDistance(geom, *pt,
00162 minPtDist);
00163 maxPtDist.setMaximum(minPtDist);
00164 }
00165
00166 const PointPairDistance& getMaxPointDistance() const
00167 {
00168 return maxPtDist;
00169 }
00170
00171 private:
00172 PointPairDistance maxPtDist;
00173 PointPairDistance minPtDist;
00174 DistanceToPoint euclideanDist;
00175 const geom::Geometry& geom;
00176 };
00177
00178 class MaxDensifiedByFractionDistanceFilter
00179 : public geom::CoordinateSequenceFilter
00180 {
00181 public:
00182
00183 MaxDensifiedByFractionDistanceFilter(
00184 const geom::Geometry& geom, double fraction)
00185 :
00186 geom(geom),
00187 numSubSegs( std::size_t(util::round(1.0/fraction)) )
00188 {
00189 }
00190
00191 void filter_ro(const geom::CoordinateSequence& seq,
00192 std::size_t index);
00193
00194 bool isGeometryChanged() const { return false; }
00195
00196 bool isDone() const { return false; }
00197
00198 const PointPairDistance& getMaxPointDistance() const {
00199 return maxPtDist;
00200 }
00201
00202 private:
00203 PointPairDistance maxPtDist;
00204 PointPairDistance minPtDist;
00205 const geom::Geometry& geom;
00206 std::size_t numSubSegs;
00207
00208 };
00209
00210 private:
00211
00212 void compute(const geom::Geometry& g0,
00213 const geom::Geometry& g1)
00214 {
00215 computeOrientedDistance(g0, g1, ptDist);
00216 computeOrientedDistance(g1, g0, ptDist);
00217 }
00218
00219 void computeOrientedDistance(const geom::Geometry& discreteGeom,
00220 const geom::Geometry& geom,
00221 PointPairDistance& ptDist);
00222
00223 const geom::Geometry& g0;
00224
00225 const geom::Geometry& g1;
00226
00227 PointPairDistance ptDist;
00228
00230 double densifyFrac;
00231
00232 };
00233
00234
00235
00236 }
00237 }
00238 }
00239
00240 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
00241
00242
00243
00244
00245