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

DiscreteHausdorffDistance.h

00001 /**********************************************************************
00002  * $Id$
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 
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; // = 0;
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; // = 0.0;
00231         
00232 };
00233 
00234 
00235 
00236 } // geos::algorithm::distance
00237 } // geos::algorithm
00238 } // geos
00239 
00240 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
00241 
00242 /**********************************************************************
00243  * $Log$
00244  **********************************************************************/
00245 

Generated on Thu Jun 11 06:17:01 2009 for GEOS by  doxygen 1.4.4