GEOS 3.3.8

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

- File List

DiscreteHausdorffDistance.h
1 /**********************************************************************
2 * $Id: DiscreteHausdorffDistance.h 3255 2011-03-01 17:56:10Z mloskot $
3 *
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
6 *
7 * Copyright (C) 2009 Sandro Santilli <strk@keybit.net>
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: algorithm/distance/DiscreteHausdorffDistance.java 1.5 (JTS-1.10)
17 *
18 **********************************************************************/
19
20 #ifndef GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
21 #define GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
22
23 #include <geos/export.h>
24 #include <geos/algorithm/distance/PointPairDistance.h> // for composition
25 #include <geos/algorithm/distance/DistanceToPoint.h> // for composition
26 #include <geos/util/IllegalArgumentException.h> // for inlines
27 #include <geos/geom/Geometry.h> // for inlines
28 #include <geos/util/math.h> // for inlines
29 #include <geos/geom/CoordinateFilter.h> // for inheritance
30 #include <geos/geom/CoordinateSequenceFilter.h> // for inheritance
31
32 #include <cstddef>
33 #include <vector>
34
35 #ifdef _MSC_VER
36 #pragma warning(push)
37 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
38 #endif
39
40 namespace geos {
41 namespace algorithm {
42 //class RayCrossingCounter;
43 }
44 namespace geom {
45 class Geometry;
46 class Coordinate;
47 //class CoordinateSequence;
48 }
49 namespace index {
50 namespace intervalrtree {
51 //class SortedPackedIntervalRTree;
52 }
53 }
54 }
55
56 namespace geos {
57 namespace algorithm { // geos::algorithm
58 namespace distance { // geos::algorithm::distance
59
101 class GEOS_DLL DiscreteHausdorffDistance
102 {
103 public:
104
105 static double distance(const geom::Geometry& g0,
106 const geom::Geometry& g1);
107
108 static double distance(const geom::Geometry& g0,
109 const geom::Geometry& g1, double densifyFrac);
110
111 DiscreteHausdorffDistance(const geom::Geometry& g0,
112 const geom::Geometry& g1)
113 :
114 g0(g0),
115 g1(g1),
116 ptDist(),
117 densifyFrac(0.0)
118 {}
119
128 void setDensifyFraction(double dFrac)
129 {
130 if ( dFrac > 1.0 || dFrac <= 0.0 )
131 {
132 throw util::IllegalArgumentException(
133 "Fraction is not in range (0.0 - 1.0]");
134 }
135
136 densifyFrac = dFrac;
137 }
138
139 double distance()
140 {
141 compute(g0, g1);
142 return ptDist.getDistance();
143 }
144
145 double orientedDistance()
146 {
147 computeOrientedDistance(g0, g1, ptDist);
148 return ptDist.getDistance();
149 }
150
151 const std::vector<geom::Coordinate> getCoordinates() const
152 {
153 return ptDist.getCoordinates();
154 }
155
156 class MaxPointDistanceFilter : public geom::CoordinateFilter
157 {
158 public:
159 MaxPointDistanceFilter(const geom::Geometry& geom)
160 :
161 geom(geom)
162 {}
163
164 void filter_ro(const geom::Coordinate* pt)
165 {
166 minPtDist.initialize();
167 DistanceToPoint::computeDistance(geom, *pt,
168 minPtDist);
169 maxPtDist.setMaximum(minPtDist);
170 }
171
172 const PointPairDistance& getMaxPointDistance() const
173 {
174 return maxPtDist;
175 }
176
177 private:
178 PointPairDistance maxPtDist;
179 PointPairDistance minPtDist;
180 DistanceToPoint euclideanDist;
181 const geom::Geometry& geom;
182
183 // Declare type as noncopyable
184 MaxPointDistanceFilter(const MaxPointDistanceFilter& other);
185 MaxPointDistanceFilter& operator=(const MaxPointDistanceFilter& rhs);
186 };
187
188 class MaxDensifiedByFractionDistanceFilter
189 : public geom::CoordinateSequenceFilter
190 {
191 public:
192
193 MaxDensifiedByFractionDistanceFilter(
194 const geom::Geometry& geom, double fraction)
195 :
196 geom(geom),
197 numSubSegs( std::size_t(util::round(1.0/fraction)) )
198 {
199 }
200
201 void filter_ro(const geom::CoordinateSequence& seq,
202 std::size_t index);
203
204 bool isGeometryChanged() const { return false; }
205
206 bool isDone() const { return false; }
207
208 const PointPairDistance& getMaxPointDistance() const {
209 return maxPtDist;
210 }
211
212 private:
213 PointPairDistance maxPtDist;
214 PointPairDistance minPtDist;
215 const geom::Geometry& geom;
216 std::size_t numSubSegs; // = 0;
217
218 // Declare type as noncopyable
219 MaxDensifiedByFractionDistanceFilter(const MaxDensifiedByFractionDistanceFilter& other);
220 MaxDensifiedByFractionDistanceFilter& operator=(const MaxDensifiedByFractionDistanceFilter& rhs);
221 };
222
223 private:
224
225 void compute(const geom::Geometry& g0,
226 const geom::Geometry& g1)
227 {
228 computeOrientedDistance(g0, g1, ptDist);
229 computeOrientedDistance(g1, g0, ptDist);
230 }
231
232 void computeOrientedDistance(const geom::Geometry& discreteGeom,
233 const geom::Geometry& geom,
234 PointPairDistance& ptDist);
235
236 const geom::Geometry& g0;
237
238 const geom::Geometry& g1;
239
240 PointPairDistance ptDist;
241
243 double densifyFrac; // = 0.0;
244
245 // Declare type as noncopyable
246 DiscreteHausdorffDistance(const DiscreteHausdorffDistance& other);
247 DiscreteHausdorffDistance& operator=(const DiscreteHausdorffDistance& rhs);
248 };
249
250 } // geos::algorithm::distance
251 } // geos::algorithm
252 } // geos
253
254 #ifdef _MSC_VER
255 #pragma warning(pop)
256 #endif
257
258 #endif // GEOS_ALGORITHM_DISTANCE_DISCRETEHAUSDORFFDISTANCE_H
259
260 /**********************************************************************
261 * $Log$
262 **********************************************************************/
263