GEOS  3.7.2
DiscreteFrechetDistance.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2016 Shinichi SUGIYAMA (shin.sugi@gmail.com)
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: original work
16  *
17  * Developed by Shinichi SUGIYAMA (shin.sugi@gmail.com)
18  * based on http://www.kr.tuwien.ac.at/staff/eiter/et-archive/cdtr9464.pdf
19  *
20  **********************************************************************/
21 
22 #ifndef GEOS_ALGORITHM_DISTANCE_DISCRETEFRECHETDISTANCE_H
23 #define GEOS_ALGORITHM_DISTANCE_DISCRETEFRECHETDISTANCE_H
24 
25 #include <geos/export.h>
26 #include <geos/algorithm/distance/PointPairDistance.h> // for composition
27 #include <geos/algorithm/distance/DistanceToPoint.h> // for composition
28 #include <geos/util/IllegalArgumentException.h> // for inlines
29 #include <geos/geom/Geometry.h> // for inlines
30 #include <geos/util/math.h> // for inlines
31 #include <geos/geom/CoordinateFilter.h> // for inheritance
32 #include <geos/geom/CoordinateSequence.h> // for inheritance
33 
34 #include <cstddef>
35 #include <vector>
36 
37 #ifdef _MSC_VER
38 #pragma warning(push)
39 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
40 #endif
41 
42 namespace geos {
43  namespace algorithm {
44  //class RayCrossingCounter;
45  }
46  namespace geom {
47  class Geometry;
48  class Coordinate;
49  //class CoordinateSequence;
50  }
51  namespace index {
52  namespace intervalrtree {
53  //class SortedPackedIntervalRTree;
54  }
55  }
56 }
57 
58 namespace geos {
59 namespace algorithm { // geos::algorithm
60 namespace distance { // geos::algorithm::distance
61 
107 {
108 public:
109 
110  static double distance(const geom::Geometry& g0,
111  const geom::Geometry& g1);
112 
113  static double distance(const geom::Geometry& g0,
114  const geom::Geometry& g1, double densifyFrac);
115 
117  const geom::Geometry& g1)
118  :
119  g0(g0),
120  g1(g1),
121  ptDist(),
122  densifyFrac(0.0)
123  {}
124 
133  void setDensifyFraction(double dFrac)
134  {
135  if ( dFrac > 1.0 || dFrac <= 0.0 )
136  {
138  "Fraction is not in range (0.0 - 1.0]");
139  }
140 
141  densifyFrac = dFrac;
142  }
143 
144  double distance()
145  {
146  compute(g0, g1);
147  return ptDist.getDistance();
148  }
149 
150  const std::vector<geom::Coordinate> getCoordinates() const
151  {
152  return ptDist.getCoordinates();
153  }
154 
155 private:
156  geom::Coordinate getSegementAt(const geom::CoordinateSequence& seq, size_t index);
157 
158  PointPairDistance& getFrecheDistance(std::vector< std::vector<PointPairDistance> >& ca, size_t i, size_t j, const geom::CoordinateSequence& p, const geom::CoordinateSequence& q);
159 
160  void compute(const geom::Geometry& discreteGeom, const geom::Geometry& geom);
161 
162  const geom::Geometry& g0;
163 
164  const geom::Geometry& g1;
165 
166  PointPairDistance ptDist;
167 
169  double densifyFrac; // = 0.0;
170 
171  // Declare type as noncopyable
172  DiscreteFrechetDistance(const DiscreteFrechetDistance& other) = delete;
173  DiscreteFrechetDistance& operator=(const DiscreteFrechetDistance& rhs) = delete;
174 };
175 
176 } // geos::algorithm::distance
177 } // geos::algorithm
178 } // geos
179 
180 #ifdef _MSC_VER
181 #pragma warning(pop)
182 #endif
183 
184 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEFRECHETDISTANCE_H
void setDensifyFraction(double dFrac)
Definition: DiscreteFrechetDistance.h:133
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:177
Indicates one or more illegal arguments.
Definition: IllegalArgumentException.h:34
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
An algorithm for computing a distance metric which is an approximation to the Frechet Distance based ...
Definition: DiscreteFrechetDistance.h:106