GEOS 3.14.1
DiscreteHausdorffDistance.h
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#pragma once
20
21#include <geos/export.h>
22#include <geos/algorithm/distance/PointPairDistance.h> // for composition
23#include <geos/algorithm/distance/DistanceToPoint.h> // for composition
24#include <geos/util/IllegalArgumentException.h> // for inlines
25#include <geos/geom/Geometry.h> // for inlines
26#include <geos/util/math.h> // for inlines
27#include <geos/geom/CoordinateFilter.h> // for inheritance
28#include <geos/geom/CoordinateSequenceFilter.h> // for inheritance
29
30#include <cstddef>
31#include <vector>
32
33#ifdef _MSC_VER
34#pragma warning(push)
35#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36#endif
37
38namespace geos {
39namespace geom {
40class Geometry;
41class Coordinate;
42//class CoordinateSequence;
43}
44}
45
46namespace geos {
47namespace algorithm { // geos::algorithm
48namespace distance { // geos::algorithm::distance
49
91class GEOS_DLL DiscreteHausdorffDistance {
92public:
93
94 static double distance(const geom::Geometry& g0,
95 const geom::Geometry& g1);
96
97 static double distance(const geom::Geometry& g0,
98 const geom::Geometry& g1, double densifyFrac);
99
100 DiscreteHausdorffDistance(const geom::Geometry& p_g0,
101 const geom::Geometry& p_g1)
102 :
103 g0(p_g0),
104 g1(p_g1),
105 ptDist(),
106 densifyFrac(0.0)
107 {}
108
117 void setDensifyFraction(double dFrac);
118
119 double
120 distance()
121 {
122 compute(g0, g1);
123 return ptDist.getDistance();
124 }
125
126 double
127 orientedDistance()
128 {
129 computeOrientedDistance(g0, g1, ptDist);
130 return ptDist.getDistance();
131 }
132
133 const std::array<geom::CoordinateXY, 2>
134 getCoordinates() const
135 {
136 return ptDist.getCoordinates();
137 }
138
139 class MaxPointDistanceFilter : public geom::CoordinateFilter {
140 public:
141 MaxPointDistanceFilter(const geom::Geometry& p_geom)
142 :
143 geom(p_geom)
144 {}
145
146 void
147 filter_ro(const geom::CoordinateXY* pt) override;
148
149 const PointPairDistance&
150 getMaxPointDistance() const
151 {
152 return maxPtDist;
153 }
154
155 private:
156 PointPairDistance maxPtDist;
157 PointPairDistance minPtDist;
158 DistanceToPoint euclideanDist;
159 const geom::Geometry& geom;
160
161 // Declare type as noncopyable
162 MaxPointDistanceFilter(const MaxPointDistanceFilter& other);
163 MaxPointDistanceFilter& operator=(const MaxPointDistanceFilter& rhs);
164 };
165
166 class MaxDensifiedByFractionDistanceFilter
167 : public geom::CoordinateSequenceFilter {
168 public:
169
170 MaxDensifiedByFractionDistanceFilter(
171 const geom::Geometry& p_geom, double fraction)
172 :
173 geom(p_geom),
174 // Validity of the cast to size_t has been verified in setDensifyFraction()
175 numSubSegs(std::size_t(util::round(1.0 / fraction)))
176 {
177 }
178
179 void filter_ro(const geom::CoordinateSequence& seq,
180 std::size_t index) override;
181
182 bool
183 isGeometryChanged() const override
184 {
185 return false;
186 }
187
188 bool
189 isDone() const override
190 {
191 return false;
192 }
193
194 const PointPairDistance&
195 getMaxPointDistance() const
196 {
197 return maxPtDist;
198 }
199
200 private:
201 PointPairDistance maxPtDist;
202 PointPairDistance minPtDist;
203 const geom::Geometry& geom;
204 std::size_t numSubSegs; // = 0;
205
206 // Declare type as noncopyable
207 MaxDensifiedByFractionDistanceFilter(const MaxDensifiedByFractionDistanceFilter& other);
208 MaxDensifiedByFractionDistanceFilter& operator=(const MaxDensifiedByFractionDistanceFilter& rhs);
209 };
210
211private:
212
213 void
214 compute(const geom::Geometry& p_g0,
215 const geom::Geometry& p_g1)
216 {
217 computeOrientedDistance(p_g0, p_g1, ptDist);
218 computeOrientedDistance(p_g1, p_g0, ptDist);
219 }
220
221 void computeOrientedDistance(const geom::Geometry& discreteGeom,
222 const geom::Geometry& geom,
223 PointPairDistance& ptDist);
224
225 const geom::Geometry& g0;
226
227 const geom::Geometry& g1;
228
229 PointPairDistance ptDist;
230
232 double densifyFrac; // = 0.0;
233
234 // Declare type as noncopyable
235 DiscreteHausdorffDistance(const DiscreteHausdorffDistance& other) = delete;
236 DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs) = delete;
237};
238
239} // geos::algorithm::distance
240} // geos::algorithm
241} // geos
242
243#ifdef _MSC_VER
244#pragma warning(pop)
245#endif
246
Geometry classes support the concept of applying a coordinate filter to every coordinate in the Geome...
Definition CoordinateFilter.h:43
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
Classes to compute distance metrics between geometries.
Definition DiscreteFrechetDistance.h:40
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
Definition Angle.h:26
double round(double val)
Definition math.h:36
Basic namespace for all GEOS functionalities.
Definition geos.h:38