GEOS  3.3.3
TaggedLineStringSimplifier.h
1 /**********************************************************************
2  * $Id: TaggedLineStringSimplifier.h 2958 2010-03-29 11:29:40Z mloskot $
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2006 Refractions Research Inc.
8  *
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.
13  *
14  **********************************************************************
15  *
16  * Last port: simplify/TaggedLineStringSimplifier.java rev. 1.8 (JTS-1.7.1)
17  *
18  **********************************************************************
19  *
20  * NOTES: This class can be optimized to work with vector<Coordinate*>
21  * rather then with CoordinateSequence
22  *
23  **********************************************************************/
24 
25 #ifndef GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
26 #define GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
27 
28 #include <geos/export.h>
29 #include <cstddef>
30 #include <vector>
31 #include <memory>
32 #include <cstddef>
33 
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
37 #endif
38 
39 // Forward declarations
40 namespace geos {
41  namespace algorithm {
42  class LineIntersector;
43  }
44  namespace geom {
45  class CoordinateSequence;
46  class LineSegment;
47  }
48  namespace simplify {
49  class TaggedLineSegment;
50  class TaggedLineString;
51  class LineSegmentIndex;
52  }
53 }
54 
55 namespace geos {
56 namespace simplify { // geos::simplify
57 
58 using namespace std;
59 
67 
68 public:
69 
70  TaggedLineStringSimplifier(LineSegmentIndex* inputIndex,
71  LineSegmentIndex* outputIndex);
72 
81  void setDistanceTolerance(double d);
82 
83  void simplify(TaggedLineString* line);
84 
85 
86 private:
87 
88  // externally owned
89  LineSegmentIndex* inputIndex;
90 
91  // externally owned
92  LineSegmentIndex* outputIndex;
93 
94  std::auto_ptr<algorithm::LineIntersector> li;
95 
97  TaggedLineString* line;
98 
99  const geom::CoordinateSequence* linePts;
100 
101  double distanceTolerance;
102 
103  void simplifySection(std::size_t i, std::size_t j,
104  std::size_t depth);
105 
106  static std::size_t findFurthestPoint(
107  const geom::CoordinateSequence* pts,
108  std::size_t i, std::size_t j,
109  double& maxDistance);
110 
111  bool hasBadIntersection(const TaggedLineString* parentLine,
112  const std::vector<std::size_t>& sectionIndex,
113  const geom::LineSegment& candidateSeg);
114 
115  bool hasBadInputIntersection(const TaggedLineString* parentLine,
116  const std::vector<std::size_t>& sectionIndex,
117  const geom::LineSegment& candidateSeg);
118 
119  bool hasBadOutputIntersection(const geom::LineSegment& candidateSeg);
120 
121  bool hasInteriorIntersection(const geom::LineSegment& seg0,
122  const geom::LineSegment& seg1) const;
123 
124  std::auto_ptr<TaggedLineSegment> flatten(
125  std::size_t start, std::size_t end);
126 
135  static bool isInLineSection(
136  const TaggedLineString* parentLine,
137  const std::vector<std::size_t>& sectionIndex,
138  const TaggedLineSegment* seg);
139 
148  void remove(const TaggedLineString* line,
149  std::size_t start,
150  std::size_t end);
151 
152 };
153 
154 inline void
156 {
157  distanceTolerance = d;
158 }
159 
160 } // namespace geos::simplify
161 } // namespace geos
162 
163 #ifdef _MSC_VER
164 #pragma warning(pop)
165 #endif
166 
167 #endif // GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
168 
169 /**********************************************************************
170  * $Log$
171  * Revision 1.3 2006/04/13 21:52:34 strk
172  * Many debugging lines and assertions added. Fixed bug in TaggedLineString class.
173  *
174  * Revision 1.2 2006/04/13 10:39:12 strk
175  * Initial implementation of TaggedLinesSimplifier class
176  *
177  * Revision 1.1 2006/04/12 17:19:57 strk
178  * Ported TaggedLineStringSimplifier class, made LineSegment class
179  * polymorphic to fix derivation of TaggedLineSegment
180  *
181  **********************************************************************/