GEOS  3.9.1dev
DiscreteHausdorffDistance.h
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2009 Sandro Santilli <strk@kbt.io>
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: algorithm/distance/DiscreteHausdorffDistance.java 1.5 (JTS-1.10)
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
20 #define GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
21 
22 #include <geos/export.h>
23 #include <geos/algorithm/distance/PointPairDistance.h> // for composition
24 #include <geos/algorithm/distance/DistanceToPoint.h> // for composition
25 #include <geos/util/IllegalArgumentException.h> // for inlines
26 #include <geos/geom/Geometry.h> // for inlines
27 #include <geos/util/math.h> // for inlines
28 #include <geos/geom/CoordinateFilter.h> // for inheritance
29 #include <geos/geom/CoordinateSequenceFilter.h> // for inheritance
30 
31 #include <cstddef>
32 #include <vector>
33 
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
37 #endif
38 
39 namespace geos {
40 namespace algorithm {
41 //class RayCrossingCounter;
42 }
43 namespace geom {
44 class Geometry;
45 class Coordinate;
46 //class CoordinateSequence;
47 }
48 namespace index {
49 namespace intervalrtree {
50 //class SortedPackedIntervalRTree;
51 }
52 }
53 }
54 
55 namespace geos {
56 namespace algorithm { // geos::algorithm
57 namespace distance { // geos::algorithm::distance
58 
101 public:
102 
103  static double distance(const geom::Geometry& g0,
104  const geom::Geometry& g1);
105 
106  static double distance(const geom::Geometry& g0,
107  const geom::Geometry& g1, double densifyFrac);
108 
110  const geom::Geometry& p_g1)
111  :
112  g0(p_g0),
113  g1(p_g1),
114  ptDist(),
115  densifyFrac(0.0)
116  {}
117 
126  void
127  setDensifyFraction(double dFrac)
128  {
129  if(dFrac > 1.0 || dFrac <= 0.0) {
131  "Fraction is not in range (0.0 - 1.0]");
132  }
133 
134  densifyFrac = dFrac;
135  }
136 
137  double
139  {
140  compute(g0, g1);
141  return ptDist.getDistance();
142  }
143 
144  double
146  {
147  computeOrientedDistance(g0, g1, ptDist);
148  return ptDist.getDistance();
149  }
150 
151  const std::array<geom::Coordinate, 2>
153  {
154  return ptDist.getCoordinates();
155  }
156 
158  public:
160  :
161  geom(p_geom)
162  {}
163 
164  void
165  filter_ro(const geom::Coordinate* pt) override
166  {
167  minPtDist.initialize();
168  DistanceToPoint::computeDistance(geom, *pt,
169  minPtDist);
170  maxPtDist.setMaximum(minPtDist);
171  }
172 
173  const PointPairDistance&
175  {
176  return maxPtDist;
177  }
178 
179  private:
184 
185  // Declare type as noncopyable
187  MaxPointDistanceFilter& operator=(const MaxPointDistanceFilter& rhs);
188  };
189 
192  public:
193 
195  const geom::Geometry& p_geom, double fraction)
196  :
197  geom(p_geom),
198  numSubSegs(std::size_t(util::round(1.0 / fraction)))
199  {
200  }
201 
202  void filter_ro(const geom::CoordinateSequence& seq,
203  std::size_t index) override;
204 
205  bool
206  isGeometryChanged() const override
207  {
208  return false;
209  }
210 
211  bool
212  isDone() const override
213  {
214  return false;
215  }
216 
217  const PointPairDistance&
219  {
220  return maxPtDist;
221  }
222 
223  private:
227  std::size_t numSubSegs; // = 0;
228 
229  // Declare type as noncopyable
232  };
233 
234 private:
235 
236  void
237  compute(const geom::Geometry& p_g0,
238  const geom::Geometry& p_g1)
239  {
240  computeOrientedDistance(p_g0, p_g1, ptDist);
241  computeOrientedDistance(p_g1, p_g0, ptDist);
242  }
243 
244  void computeOrientedDistance(const geom::Geometry& discreteGeom,
245  const geom::Geometry& geom,
246  PointPairDistance& ptDist);
247 
249 
251 
253 
255  double densifyFrac; // = 0.0;
256 
257  // Declare type as noncopyable
259  DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs) = delete;
260 };
261 
262 } // geos::algorithm::distance
263 } // geos::algorithm
264 } // geos
265 
266 #ifdef _MSC_VER
267 #pragma warning(pop)
268 #endif
269 
270 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
271 
DiscreteHausdorffDistance(const geom::Geometry &p_g0, const geom::Geometry &p_g1)
#define GEOS_DLL
Definition: export.h:28
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
bool isGeometryChanged() const override
Reports whether the execution of this filter has modified the coordinates of the geometry.
Interface for classes which provide operations that can be applied to the coordinates in a Coordinate...
void compute(const geom::Geometry &p_g0, const geom::Geometry &p_g1)
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
Indicates one or more illegal arguments.
An algorithm for computing a distance metric which is an approximation to the Hausdorff Distance base...
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
bool isDone() const override
Reports whether the application of this filter can be terminated.
double round(double val)
Definition: math.h:36
Basic namespace for all GEOS functionalities.
double densifyFrac
Value of 0.0 indicates that no densification should take place.
The internal representation of a list of coordinates inside a Geometry.
const std::array< geom::Coordinate, 2 > getCoordinates() const
void filter_ro(const geom::Coordinate *pt) override
Performs an operation with coord.