GEOS  3.4.2
TaggedLineStringSimplifier.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
7  *
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.
12  *
13  **********************************************************************
14  *
15  * Last port: simplify/TaggedLineStringSimplifier.java r536 (JTS-1.12+)
16  *
17  **********************************************************************
18  *
19  * NOTES: This class can be optimized to work with vector<Coordinate*>
20  * rather then with CoordinateSequence
21  *
22  **********************************************************************/
23 
24 #ifndef GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
25 #define GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
26 
27 #include <geos/export.h>
28 #include <cstddef>
29 #include <vector>
30 #include <memory>
31 #include <cstddef>
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40  namespace algorithm {
41  class LineIntersector;
42  }
43  namespace geom {
44  class CoordinateSequence;
45  class LineSegment;
46  }
47  namespace simplify {
48  class TaggedLineSegment;
49  class TaggedLineString;
50  class LineSegmentIndex;
51  }
52 }
53 
54 namespace geos {
55 namespace simplify { // geos::simplify
56 
57 using namespace std;
58 
66 
67 public:
68 
69  TaggedLineStringSimplifier(LineSegmentIndex* inputIndex,
70  LineSegmentIndex* outputIndex);
71 
80  void setDistanceTolerance(double d);
81 
88  void simplify(TaggedLineString* line);
89 
90 
91 private:
92 
93  // externally owned
94  LineSegmentIndex* inputIndex;
95 
96  // externally owned
97  LineSegmentIndex* outputIndex;
98 
99  std::auto_ptr<algorithm::LineIntersector> li;
100 
102  TaggedLineString* line;
103 
104  const geom::CoordinateSequence* linePts;
105 
106  double distanceTolerance;
107 
108  void simplifySection(std::size_t i, std::size_t j,
109  std::size_t depth);
110 
111  static std::size_t findFurthestPoint(
112  const geom::CoordinateSequence* pts,
113  std::size_t i, std::size_t j,
114  double& maxDistance);
115 
116  bool hasBadIntersection(const TaggedLineString* parentLine,
117  const std::vector<std::size_t>& sectionIndex,
118  const geom::LineSegment& candidateSeg);
119 
120  bool hasBadInputIntersection(const TaggedLineString* parentLine,
121  const std::vector<std::size_t>& sectionIndex,
122  const geom::LineSegment& candidateSeg);
123 
124  bool hasBadOutputIntersection(const geom::LineSegment& candidateSeg);
125 
126  bool hasInteriorIntersection(const geom::LineSegment& seg0,
127  const geom::LineSegment& seg1) const;
128 
129  std::auto_ptr<TaggedLineSegment> flatten(
130  std::size_t start, std::size_t end);
131 
140  static bool isInLineSection(
141  const TaggedLineString* parentLine,
142  const std::vector<std::size_t>& sectionIndex,
143  const TaggedLineSegment* seg);
144 
153  void remove(const TaggedLineString* line,
154  std::size_t start,
155  std::size_t end);
156 
157 };
158 
159 inline void
161 {
162  distanceTolerance = d;
163 }
164 
165 } // namespace geos::simplify
166 } // namespace geos
167 
168 #ifdef _MSC_VER
169 #pragma warning(pop)
170 #endif
171 
172 #endif // GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
173 
Definition: LineSegment.h:57
Simplifies a TaggedLineString, preserving topology (in the sense that no new intersections are introd...
Definition: TaggedLineStringSimplifier.h:65
A geom::LineSegment which is tagged with its location in a geom::Geometry.
Definition: TaggedLineSegment.h:54
Contains and owns a list of TaggedLineSegments.
Definition: TaggedLineString.h:62
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
void setDistanceTolerance(double d)
Sets the distance tolerance for the simplification.
Definition: TaggedLineStringSimplifier.h:160