GEOS
3.2.3
|
00001 /********************************************************************** 00002 * $Id: DiscreteHausdorffDistance.h 2809 2009-12-06 01:05:24Z mloskot $ 00003 * 00004 * GEOS - Geometry Engine Open Source 00005 * http://geos.refractions.net 00006 * 00007 * Copyright (C) 2009 Sandro Santilli <strk@keybit.net> 00008 * 00009 * This is free software; you can redistribute and/or modify it under 00010 * the terms of the GNU Lesser General Public Licence as published 00011 * by the Free Software Foundation. 00012 * See the COPYING file for more information. 00013 * 00014 ********************************************************************** 00015 * 00016 * Last port: algorithm/distance/DiscreteHausdorffDistance.java 1.5 (JTS-1.10) 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> // for composition 00024 #include <geos/algorithm/distance/DistanceToPoint.h> // for composition 00025 #include <geos/util/IllegalArgumentException.h> // for inlines 00026 #include <geos/geom/Geometry.h> // for inlines 00027 #include <geos/util/math.h> // for inlines 00028 #include <geos/geom/CoordinateFilter.h> // for inheritance 00029 #include <geos/geom/CoordinateSequenceFilter.h> // for inheritance 00030 00031 #include <cstddef> 00032 #include <vector> 00033 00034 namespace geos { 00035 namespace algorithm { 00036 //class RayCrossingCounter; 00037 } 00038 namespace geom { 00039 class Geometry; 00040 class Coordinate; 00041 //class CoordinateSequence; 00042 } 00043 namespace index { 00044 namespace intervalrtree { 00045 //class SortedPackedIntervalRTree; 00046 } 00047 } 00048 } 00049 00050 namespace geos { 00051 namespace algorithm { // geos::algorithm 00052 namespace distance { // geos::algorithm::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 // Declare type as noncopyable 00178 MaxPointDistanceFilter(const MaxPointDistanceFilter& other); 00179 MaxPointDistanceFilter& operator=(const MaxPointDistanceFilter& rhs); 00180 }; 00181 00182 class MaxDensifiedByFractionDistanceFilter 00183 : public geom::CoordinateSequenceFilter 00184 { 00185 public: 00186 00187 MaxDensifiedByFractionDistanceFilter( 00188 const geom::Geometry& geom, double fraction) 00189 : 00190 geom(geom), 00191 numSubSegs( std::size_t(util::round(1.0/fraction)) ) 00192 { 00193 } 00194 00195 void filter_ro(const geom::CoordinateSequence& seq, 00196 std::size_t index); 00197 00198 bool isGeometryChanged() const { return false; } 00199 00200 bool isDone() const { return false; } 00201 00202 const PointPairDistance& getMaxPointDistance() const { 00203 return maxPtDist; 00204 } 00205 00206 private: 00207 PointPairDistance maxPtDist; 00208 PointPairDistance minPtDist; 00209 const geom::Geometry& geom; 00210 std::size_t numSubSegs; // = 0; 00211 00212 // Declare type as noncopyable 00213 MaxDensifiedByFractionDistanceFilter(const MaxDensifiedByFractionDistanceFilter& other); 00214 MaxDensifiedByFractionDistanceFilter& operator=(const MaxDensifiedByFractionDistanceFilter& rhs); 00215 }; 00216 00217 private: 00218 00219 void compute(const geom::Geometry& g0, 00220 const geom::Geometry& g1) 00221 { 00222 computeOrientedDistance(g0, g1, ptDist); 00223 computeOrientedDistance(g1, g0, ptDist); 00224 } 00225 00226 void computeOrientedDistance(const geom::Geometry& discreteGeom, 00227 const geom::Geometry& geom, 00228 PointPairDistance& ptDist); 00229 00230 const geom::Geometry& g0; 00231 00232 const geom::Geometry& g1; 00233 00234 PointPairDistance ptDist; 00235 00237 double densifyFrac; // = 0.0; 00238 00239 // Declare type as noncopyable 00240 DiscreteHausdorffDistance(const DiscreteHausdorffDistance& other); 00241 DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs); 00242 }; 00243 00244 00245 00246 } // geos::algorithm::distance 00247 } // geos::algorithm 00248 } // geos 00249 00250 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H 00251 00252 /********************************************************************** 00253 * $Log$ 00254 **********************************************************************/ 00255