GEOS  3.3.2
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 
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 
65 
66 public:
67 
68  TaggedLineStringSimplifier(LineSegmentIndex* inputIndex,
69  LineSegmentIndex* outputIndex);
70 
79  void setDistanceTolerance(double d);
80 
81  void simplify(TaggedLineString* line);
82 
83 
84 private:
85 
86  // externally owned
87  LineSegmentIndex* inputIndex;
88 
89  // externally owned
90  LineSegmentIndex* outputIndex;
91 
92  std::auto_ptr<algorithm::LineIntersector> li;
93 
95  TaggedLineString* line;
96 
97  const geom::CoordinateSequence* linePts;
98 
99  double distanceTolerance;
100 
101  void simplifySection(std::size_t i, std::size_t j,
102  std::size_t depth);
103 
104  static std::size_t findFurthestPoint(
105  const geom::CoordinateSequence* pts,
106  std::size_t i, std::size_t j,
107  double& maxDistance);
108 
109  bool hasBadIntersection(const TaggedLineString* parentLine,
110  const std::vector<std::size_t>& sectionIndex,
111  const geom::LineSegment& candidateSeg);
112 
113  bool hasBadInputIntersection(const TaggedLineString* parentLine,
114  const std::vector<std::size_t>& sectionIndex,
115  const geom::LineSegment& candidateSeg);
116 
117  bool hasBadOutputIntersection(const geom::LineSegment& candidateSeg);
118 
119  bool hasInteriorIntersection(const geom::LineSegment& seg0,
120  const geom::LineSegment& seg1) const;
121 
122  std::auto_ptr<TaggedLineSegment> flatten(
123  std::size_t start, std::size_t end);
124 
133  static bool isInLineSection(
134  const TaggedLineString* parentLine,
135  const std::vector<std::size_t>& sectionIndex,
136  const TaggedLineSegment* seg);
137 
146  void remove(const TaggedLineString* line,
147  std::size_t start,
148  std::size_t end);
149 
150 };
151 
152 inline void
154 {
155  distanceTolerance = d;
156 }
157 
158 } // namespace geos::simplify
159 } // namespace geos
160 
161 #ifdef _MSC_VER
162 #pragma warning(pop)
163 #endif
164 
165 #endif // GEOS_SIMPLIFY_TAGGEDLINESTRINGSIMPLIFIER_H
166 
167 /**********************************************************************
168  * $Log$
169  * Revision 1.3 2006/04/13 21:52:34 strk
170  * Many debugging lines and assertions added. Fixed bug in TaggedLineString class.
171  *
172  * Revision 1.2 2006/04/13 10:39:12 strk
173  * Initial implementation of TaggedLinesSimplifier class
174  *
175  * Revision 1.1 2006/04/12 17:19:57 strk
176  * Ported TaggedLineStringSimplifier class, made LineSegment class
177  * polymorphic to fix derivation of TaggedLineSegment
178  *
179  **********************************************************************/