GEOS  3.3.3
geomgraph/EdgeRing.h
1 /**********************************************************************
2  * $Id: EdgeRing.h 3255 2011-03-01 17:56:10Z mloskot $
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: geomgraph/EdgeRing.java rev. 1.10 (JTS-1.10)
18  *
19  **********************************************************************/
20 
21 
22 #ifndef GEOS_GEOMGRAPH_EDGERING_H
23 #define GEOS_GEOMGRAPH_EDGERING_H
24 
25 #include <geos/export.h>
26 #include <geos/geomgraph/Label.h> // for composition
27 
28 #include <geos/inline.h>
29 
30 #include <vector>
31 #include <cassert> // for testInvariant
32 #include <iosfwd> // for operator<<
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 geom {
42  class GeometryFactory;
43  class LinearRing;
44  class Polygon;
45  class Coordinate;
46  class CoordinateSequence;
47  }
48  namespace geomgraph {
49  class DirectedEdge;
50  //class Label;
51  class Edge;
52  }
53 }
54 
55 namespace geos {
56 namespace geomgraph { // geos.geomgraph
57 
58 class GEOS_DLL EdgeRing {
59 
60 public:
61  friend std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
62 
63  EdgeRing(DirectedEdge *newStart,
64  const geom::GeometryFactory *newGeometryFactory);
65 
66  virtual ~EdgeRing();
67 
68  bool isIsolated();
69 
70  bool isHole();
71 
72  /*
73  * Return a pointer to the LinearRing owned by
74  * this object. Make a copy if you need it beyond
75  * this objects's lifetime.
76  */
77  geom::LinearRing* getLinearRing();
78 
79  Label& getLabel();
80 
81  bool isShell();
82 
83  EdgeRing *getShell();
84 
85  void setShell(EdgeRing *newShell);
86 
87  void addHole(EdgeRing *edgeRing);
88 
94  geom::Polygon* toPolygon(const geom::GeometryFactory* geometryFactory);
95 
101  void computeRing();
102 
103  virtual DirectedEdge* getNext(DirectedEdge *de)=0;
104 
105  virtual void setEdgeRing(DirectedEdge *de, EdgeRing *er)=0;
106 
110  std::vector<DirectedEdge*>& getEdges();
111 
112  int getMaxNodeDegree();
113 
114  void setInResult();
115 
120  bool containsPoint(const geom::Coordinate& p);
121 
122  void testInvariant()
123  {
124  // pts are never NULL
125  assert(pts);
126 
127 #ifndef NDEBUG
128  // If this is not an hole, check that
129  // each hole is not null and
130  // has 'this' as it's shell
131  if ( ! shell )
132  {
133  for (std::vector<EdgeRing*>::const_iterator
134  it=holes.begin(), itEnd=holes.end();
135  it != itEnd;
136  ++it)
137  {
138  EdgeRing* hole=*it;
139  assert(hole);
140  assert(hole->getShell()==this);
141  }
142  }
143 #endif // ndef NDEBUG
144  }
145 
146 protected:
147 
148  DirectedEdge *startDe; // the directed edge which starts the list of edges for this EdgeRing
149 
150  const geom::GeometryFactory *geometryFactory;
151 
153  void computePoints(DirectedEdge *newStart);
154 
155  void mergeLabel(Label& deLabel);
156 
169  void mergeLabel(Label& deLabel, int geomIndex);
170 
171  void addPoints(Edge *edge, bool isForward, bool isFirstEdge);
172 
174  std::vector<EdgeRing*> holes;
175 
176 private:
177 
178  int maxNodeDegree;
179 
181  std::vector<DirectedEdge*> edges;
182 
183  geom::CoordinateSequence* pts;
184 
185  // label stores the locations of each geometry on the
186  // face surrounded by this ring
187  Label label;
188 
189  geom::LinearRing *ring; // the ring created for this EdgeRing
190 
191  bool isHoleVar;
192 
194  EdgeRing *shell;
195 
196  void computeMaxNodeDegree();
197 
198 };
199 
200 std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
201 
202 } // namespace geos.geomgraph
203 } // namespace geos
204 
205 #ifdef _MSC_VER
206 #pragma warning(pop)
207 #endif
208 
209 //#ifdef GEOS_INLINE
210 //# include "geos/geomgraph/EdgeRing.inl"
211 //#endif
212 
213 #endif // ifndef GEOS_GEOMGRAPH_EDGERING_H
214 
215 /**********************************************************************
216  * $Log$
217  * Revision 1.9 2006/07/08 00:33:55 strk
218  * * configure.in: incremented CAPI minor version, to avoid falling behind any future version from the 2.2. branch.
219  * * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp,
220  * source/geomgraph/EdgeRing.cpp,
221  * source/headers/geos/geom/Geometry.h,
222  * source/headers/geos/geom/GeometryFactory.h,
223  * source/headers/geos/geom/GeometryFactory.inl,
224  * source/headers/geos/geomgraph/EdgeRing.h:
225  * updated doxygen comments (sync with JTS head).
226  * * source/headers/geos/platform.h.in: include <inttypes.h>
227  * rather then <stdint.h>
228  *
229  * Revision 1.8 2006/04/06 09:41:55 strk
230  * Added operator<<, added pts!=NULL assertion in testInvariant() function
231  *
232  * Revision 1.7 2006/04/05 18:28:42 strk
233  * Moved testInvariant() methods from private to public, added
234  * some comments about them.
235  *
236  * Revision 1.6 2006/03/29 13:53:59 strk
237  * EdgeRing equipped with Invariant testing function and lots of exceptional assertions. Removed useless heap allocations, and pointers usages.
238  *
239  * Revision 1.5 2006/03/27 16:02:34 strk
240  * Added INL file for MinimalEdgeRing, added many debugging blocks,
241  * fixed memory leak in ConnectedInteriorTester (bug #59)
242  *
243  * Revision 1.4 2006/03/24 09:52:41 strk
244  * USE_INLINE => GEOS_INLINE
245  *
246  * Revision 1.3 2006/03/20 12:32:57 strk
247  * Added note about responsibility of return from ::toPolygon
248  *
249  * Revision 1.2 2006/03/15 17:17:41 strk
250  * Added missing forward declarations
251  *
252  * Revision 1.1 2006/03/09 16:46:49 strk
253  * geos::geom namespace definition, first pass at headers split
254  *
255  **********************************************************************/
256