GEOS 3.4.2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

DiscreteHausdorffDistance.h
1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2009 Sandro Santilli <strk@keybit.net>
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
100 class GEOS_DLL DiscreteHausdorffDistance
101 {
102 public:
103
104 static double distance(const geom::Geometry& g0,
105 const geom::Geometry& g1);
106
107 static double distance(const geom::Geometry& g0,
108 const geom::Geometry& g1, double densifyFrac);
109
110 DiscreteHausdorffDistance(const geom::Geometry& g0,
111 const geom::Geometry& g1)
112 :
113 g0(g0),
114 g1(g1),
115 ptDist(),
116 densifyFrac(0.0)
117 {}
118
127 void setDensifyFraction(double dFrac)
128 {
129 if ( dFrac > 1.0 || dFrac <= 0.0 )
130 {
131 throw util::IllegalArgumentException(
132 "Fraction is not in range (0.0 - 1.0]");
133 }
134
135 densifyFrac = dFrac;
136 }
137
138 double distance()
139 {
140 compute(g0, g1);
141 return ptDist.getDistance();
142 }
143
144 double orientedDistance()
145 {
146 computeOrientedDistance(g0, g1, ptDist);
147 return ptDist.getDistance();
148 }
149
150 const std::vector<geom::Coordinate> getCoordinates() const
151 {
152 return ptDist.getCoordinates();
153 }
154
155 class MaxPointDistanceFilter : public geom::CoordinateFilter
156 {
157 public:
158 MaxPointDistanceFilter(const geom::Geometry& geom)
159 :
160 geom(geom)
161 {}
162
163 void filter_ro(const geom::Coordinate* pt)
164 {
165 minPtDist.initialize();
166 DistanceToPoint::computeDistance(geom, *pt,
167 minPtDist);
168 maxPtDist.setMaximum(minPtDist);
169 }
170
171 const PointPairDistance& getMaxPointDistance() const
172 {
173 return maxPtDist;
174 }
175
176 private:
177 PointPairDistance maxPtDist;
178 PointPairDistance minPtDist;
179 DistanceToPoint euclideanDist;
180 const geom::Geometry& geom;
181
182 // Declare type as noncopyable
183 MaxPointDistanceFilter(const MaxPointDistanceFilter& other);
184 MaxPointDistanceFilter& operator=(const MaxPointDistanceFilter& rhs);
185 };
186
187 class MaxDensifiedByFractionDistanceFilter
188 : public geom::CoordinateSequenceFilter
189 {
190 public:
191
192 MaxDensifiedByFractionDistanceFilter(
193 const geom::Geometry& geom, double fraction)
194 :
195 geom(geom),
196 numSubSegs( std::size_t(util::round(1.0/fraction)) )
197 {
198 }
199
200 void filter_ro(const geom::CoordinateSequence& seq,
201 std::size_t index);
202
203 bool isGeometryChanged() const { return false; }
204
205 bool isDone() const { return false; }
206
207 const PointPairDistance& getMaxPointDistance() const {
208 return maxPtDist;
209 }
210
211 private:
212 PointPairDistance maxPtDist;
213 PointPairDistance minPtDist;
214 const geom::Geometry& geom;
215 std::size_t numSubSegs; // = 0;
216
217 // Declare type as noncopyable
218 MaxDensifiedByFractionDistanceFilter(const MaxDensifiedByFractionDistanceFilter& other);
219 MaxDensifiedByFractionDistanceFilter& operator=(const MaxDensifiedByFractionDistanceFilter& rhs);
220 };
221
222 private:
223
224 void compute(const geom::Geometry& g0,
225 const geom::Geometry& g1)
226 {
227 computeOrientedDistance(g0, g1, ptDist);
228 computeOrientedDistance(g1, g0, ptDist);
229 }
230
231 void computeOrientedDistance(const geom::Geometry& discreteGeom,
232 const geom::Geometry& geom,
233 PointPairDistance& ptDist);
234
235 const geom::Geometry& g0;
236
237 const geom::Geometry& g1;
238
239 PointPairDistance ptDist;
240
242 double densifyFrac; // = 0.0;
243
244 // Declare type as noncopyable
245 DiscreteHausdorffDistance(const DiscreteHausdorffDistance& other);
246 DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs);
247 };
248
249 } // geos::algorithm::distance
250 } // geos::algorithm
251 } // geos
252
253 #ifdef _MSC_VER
254 #pragma warning(pop)
255 #endif
256
257 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
258