1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2006 Refractions Research Inc.
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
13 **********************************************************************
15 * Last port: simplify/TaggedLineStringSimplifier.java r536 (JTS-1.12+)
17 **********************************************************************
19 * NOTES: This class can be optimized to work with vector<Coordinate*>
20 * rather then with CoordinateSequence
22 **********************************************************************/
24 #ifndef GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
25 #define GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
27 #include <geos/export.h>
34 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
37 // Forward declarations
40 class LineIntersector
;
43 class CoordinateSequence
;
47 class TaggedLineSegment
;
48 class TaggedLineString
;
49 class LineSegmentIndex
;
54 namespace simplify
{ // geos::simplify
58 * Simplifies a TaggedLineString, preserving topology
59 * (in the sense that no new intersections are introduced).
60 * Uses the recursive Douglas-Peucker algorithm.
63 class GEOS_DLL TaggedLineStringSimplifier
{
67 TaggedLineStringSimplifier(LineSegmentIndex
* inputIndex
,
68 LineSegmentIndex
* outputIndex
);
71 * Sets the distance tolerance for the simplification.
73 * All vertices in the simplified geometry will be within this
74 * distance of the original geometry.
76 * @param d the approximation tolerance to use
78 void setDistanceTolerance(double d
);
81 * Simplifies the given {@link TaggedLineString}
82 * using the distance tolerance specified.
84 * @param line the linestring to simplify
86 void simplify(TaggedLineString
* line
);
92 LineSegmentIndex
* inputIndex
;
95 LineSegmentIndex
* outputIndex
;
97 std::auto_ptr
<algorithm::LineIntersector
> li
;
99 /// non-const as segments are possibly added to it
100 TaggedLineString
* line
;
102 const geom::CoordinateSequence
* linePts
;
104 double distanceTolerance
;
106 void simplifySection(std::size_t i
, std::size_t j
,
109 static std::size_t findFurthestPoint(
110 const geom::CoordinateSequence
* pts
,
111 std::size_t i
, std::size_t j
,
112 double& maxDistance
);
114 bool hasBadIntersection(const TaggedLineString
* parentLine
,
115 const std::vector
<std::size_t>& sectionIndex
,
116 const geom::LineSegment
& candidateSeg
);
118 bool hasBadInputIntersection(const TaggedLineString
* parentLine
,
119 const std::vector
<std::size_t>& sectionIndex
,
120 const geom::LineSegment
& candidateSeg
);
122 bool hasBadOutputIntersection(const geom::LineSegment
& candidateSeg
);
124 bool hasInteriorIntersection(const geom::LineSegment
& seg0
,
125 const geom::LineSegment
& seg1
) const;
127 std::auto_ptr
<TaggedLineSegment
> flatten(
128 std::size_t start
, std::size_t end
);
131 * Tests whether a segment is in a section of a TaggedLineString
134 * @param sectionIndex
138 static bool isInLineSection(
139 const TaggedLineString
* parentLine
,
140 const std::vector
<std::size_t>& sectionIndex
,
141 const TaggedLineSegment
* seg
);
144 * Remove the segs in the section of the line
148 * @param sectionStartIndex
149 * @param sectionEndIndex
151 void remove(const TaggedLineString
* line
,
158 TaggedLineStringSimplifier::setDistanceTolerance(double d
)
160 distanceTolerance
= d
;
163 } // namespace geos::simplify
170 #endif // GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H