1 /**********************************************************************
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
7 * Copyright (C) 2006 Refractions Research Inc.
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
14 **********************************************************************
16 * Last port: simplify/TaggedLineStringSimplifier.java r536 (JTS-1.12+)
18 **********************************************************************
20 * NOTES: This class can be optimized to work with vector<Coordinate*>
21 * rather then with CoordinateSequence
23 **********************************************************************/
25 #ifndef GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
26 #define GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
28 #include <geos/export.h>
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
38 // Forward declarations
41 class LineIntersector
;
44 class CoordinateSequence
;
48 class TaggedLineSegment
;
49 class TaggedLineString
;
50 class LineSegmentIndex
;
55 namespace simplify
{ // geos::simplify
59 * Simplifies a TaggedLineString, preserving topology
60 * (in the sense that no new intersections are introduced).
61 * Uses the recursive Douglas-Peucker algorithm.
64 class GEOS_DLL TaggedLineStringSimplifier
{
68 TaggedLineStringSimplifier(LineSegmentIndex
* inputIndex
,
69 LineSegmentIndex
* outputIndex
);
72 * Sets the distance tolerance for the simplification.
74 * All vertices in the simplified geometry will be within this
75 * distance of the original geometry.
77 * @param d the approximation tolerance to use
79 void setDistanceTolerance(double d
);
82 * Simplifies the given {@link TaggedLineString}
83 * using the distance tolerance specified.
85 * @param line the linestring to simplify
87 void simplify(TaggedLineString
* line
);
93 LineSegmentIndex
* inputIndex
;
96 LineSegmentIndex
* outputIndex
;
98 std::auto_ptr
<algorithm::LineIntersector
> li
;
100 /// non-const as segments are possibly added to it
101 TaggedLineString
* line
;
103 const geom::CoordinateSequence
* linePts
;
105 double distanceTolerance
;
107 void simplifySection(std::size_t i
, std::size_t j
,
110 static std::size_t findFurthestPoint(
111 const geom::CoordinateSequence
* pts
,
112 std::size_t i
, std::size_t j
,
113 double& maxDistance
);
115 bool hasBadIntersection(const TaggedLineString
* parentLine
,
116 const std::vector
<std::size_t>& sectionIndex
,
117 const geom::LineSegment
& candidateSeg
);
119 bool hasBadInputIntersection(const TaggedLineString
* parentLine
,
120 const std::vector
<std::size_t>& sectionIndex
,
121 const geom::LineSegment
& candidateSeg
);
123 bool hasBadOutputIntersection(const geom::LineSegment
& candidateSeg
);
125 bool hasInteriorIntersection(const geom::LineSegment
& seg0
,
126 const geom::LineSegment
& seg1
) const;
128 std::auto_ptr
<TaggedLineSegment
> flatten(
129 std::size_t start
, std::size_t end
);
132 * Tests whether a segment is in a section of a TaggedLineString
135 * @param sectionIndex
139 static bool isInLineSection(
140 const TaggedLineString
* parentLine
,
141 const std::vector
<std::size_t>& sectionIndex
,
142 const TaggedLineSegment
* seg
);
145 * Remove the segs in the section of the line
149 * @param sectionStartIndex
150 * @param sectionEndIndex
152 void remove(const TaggedLineString
* line
,
159 TaggedLineStringSimplifier::setDistanceTolerance(double d
)
161 distanceTolerance
= d
;
164 } // namespace geos::simplify
171 #endif // GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H