Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

DiscreteHausdorffDistance.h

00001 /**********************************************************************
00002  * $Id: DiscreteHausdorffDistance.h 3255 2011-03-01 17:56:10Z 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/export.h>
00024 #include <geos/algorithm/distance/PointPairDistance.h> // for composition
00025 #include <geos/algorithm/distance/DistanceToPoint.h> // for composition
00026 #include <geos/util/IllegalArgumentException.h> // for inlines
00027 #include <geos/geom/Geometry.h> // for inlines
00028 #include <geos/util/math.h> // for inlines
00029 #include <geos/geom/CoordinateFilter.h> // for inheritance
00030 #include <geos/geom/CoordinateSequenceFilter.h> // for inheritance
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                 //class RayCrossingCounter;
00043         }
00044         namespace geom {
00045                 class Geometry;
00046                 class Coordinate; 
00047                 //class CoordinateSequence; 
00048         }
00049         namespace index {
00050                 namespace intervalrtree {
00051                         //class SortedPackedIntervalRTree;
00052                 }
00053         }
00054 }
00055 
00056 namespace geos {
00057 namespace algorithm { // geos::algorithm
00058 namespace distance { // geos::algorithm::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         // Declare type as noncopyable
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; // = 0;
00217 
00218         // Declare type as noncopyable
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; // = 0.0;
00244 
00245     // Declare type as noncopyable
00246     DiscreteHausdorffDistance(const DiscreteHausdorffDistance& other);
00247     DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs);
00248 };
00249 
00250 } // geos::algorithm::distance
00251 } // geos::algorithm
00252 } // geos
00253 
00254 #ifdef _MSC_VER
00255 #pragma warning(pop)
00256 #endif
00257 
00258 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
00259 
00260 /**********************************************************************
00261  * $Log$
00262  **********************************************************************/
00263 

Generated on Tue Jun 5 11:39:09 2012 for GEOS by  doxygen 1.3.9.1