Quotes around otherwise ambiguous (underline containing) name
[geos.git] / include / geos / simplify / TaggedLineStringSimplifier.h
blob09e9c3d6bb2538cd104a0998b6098a76b234ba90
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>
28 #include <cstddef>
29 #include <vector>
30 #include <memory>
32 #ifdef _MSC_VER
33 #pragma warning(push)
34 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35 #endif
37 // Forward declarations
38 namespace geos {
39 namespace algorithm {
40 class LineIntersector;
42 namespace geom {
43 class CoordinateSequence;
44 class LineSegment;
46 namespace simplify {
47 class TaggedLineSegment;
48 class TaggedLineString;
49 class LineSegmentIndex;
53 namespace geos {
54 namespace simplify { // geos::simplify
57 /** \brief
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 {
65 public:
67 TaggedLineStringSimplifier(LineSegmentIndex* inputIndex,
68 LineSegmentIndex* outputIndex);
70 /** \brief
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);
80 /**
81 * Simplifies the given {@link TaggedLineString}
82 * using the distance tolerance specified.
84 * @param line the linestring to simplify
86 void simplify(TaggedLineString* line);
89 private:
91 // externally owned
92 LineSegmentIndex* inputIndex;
94 // externally owned
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,
107 std::size_t depth);
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);
130 /** \brief
131 * Tests whether a segment is in a section of a TaggedLineString
133 * @param line
134 * @param sectionIndex
135 * @param seg
136 * @return
138 static bool isInLineSection(
139 const TaggedLineString* parentLine,
140 const std::vector<std::size_t>& sectionIndex,
141 const TaggedLineSegment* seg);
143 /** \brief
144 * Remove the segs in the section of the line
146 * @param line
147 * @param pts
148 * @param sectionStartIndex
149 * @param sectionEndIndex
151 void remove(const TaggedLineString* line,
152 std::size_t start,
153 std::size_t end);
157 inline void
158 TaggedLineStringSimplifier::setDistanceTolerance(double d)
160 distanceTolerance = d;
163 } // namespace geos::simplify
164 } // namespace geos
166 #ifdef _MSC_VER
167 #pragma warning(pop)
168 #endif
170 #endif // GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H