# EdgeRing.h

    00001 /**********************************************************************
    00002  * $Id: EdgeRing.h 1820 2006-09-06 16:54:23Z mloskot $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2005-2006 Refractions Research Inc.
    00008  * Copyright (C) 2001-2002 Vivid Solutions Inc.
    00009  *
    00010  * This is free software; you can redistribute and/or modify it under
    00011  * the terms of the GNU Lesser General Public Licence as published
    00012  * by the Free Software Foundation.
    00013  * See the COPYING file for more information.
    00014  *
    00015  **********************************************************************
    00016  *
    00017  * Last port: geomgraph/EdgeRing.java rev. 1.9
    00018  *
    00019  **********************************************************************/
    00020
    00021
    00022 #ifndef GEOS_GEOMGRAPH_EDGERING_H
    00023 #define GEOS_GEOMGRAPH_EDGERING_H
    00024
    00025 #include <geos/geomgraph/Label.h> // for composition
    00026
    00027 #include <geos/inline.h>
    00028
    00029 #include <vector>
    00030 #include <cassert> // for testInvariant
    00031 #include <iosfwd> // for operator<<
    00032
    00033
    00034 // Forward declarations
    00035 namespace geos {
    00036         namespace geom {
    00037                 class GeometryFactory;
    00038                 class LinearRing;
    00039                 class Polygon;
    00040                 class Coordinate;
    00041                 class CoordinateSequence;
    00042         }
    00043         namespace geomgraph {
    00044                 class DirectedEdge;
    00045                 //class Label;
    00046                 class Edge;
    00047         }
    00048 }
    00049
    00050 namespace geos {
    00051 namespace geomgraph { // geos.geomgraph
    00052
    00053 class EdgeRing {
    00054
    00055 public:
    00056         friend std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
    00057
    00058         EdgeRing(DirectedEdge *newStart,
    00059                         const geom::GeometryFactory *newGeometryFactory);
    00060
    00061         virtual ~EdgeRing();
    00062
    00063         bool isIsolated();
    00064
    00065         bool isHole();
    00066
    00067         /*
    00068          * Return a pointer to the LinearRing owned by
    00069          * this object. Make a copy if you need it beyond
    00070          * this objects's lifetime.
    00071          */
    00072         geom::LinearRing* getLinearRing();
    00073
    00074         Label& getLabel();
    00075
    00076         bool isShell();
    00077
    00078         EdgeRing *getShell();
    00079
    00080         void setShell(EdgeRing *newShell);
    00081
    00082         void addHole(EdgeRing *edgeRing);
    00083
    00089         geom::Polygon* toPolygon(const geom::GeometryFactory* geometryFactory);
    00090
    00096         void computeRing();
    00097
    00098         virtual DirectedEdge* getNext(DirectedEdge *de)=0;
    00099
    00100         virtual void setEdgeRing(DirectedEdge *de, EdgeRing *er)=0;
    00101
    00105         std::vector<DirectedEdge*>& getEdges();
    00106
    00107         int getMaxNodeDegree();
    00108
    00109         void setInResult();
    00110
    00115         bool containsPoint(const geom::Coordinate& p);
    00116
    00117         void testInvariant()
    00118         {
    00119                 // pts are never NULL
    00120                 assert(pts);
    00121
    00122 #ifndef NDEBUG
    00123                 // If this is not an hole, check that
    00124                 // each hole is not null and
    00125                 // has 'this' as it's shell
    00126                 if ( ! shell )
    00127                 {
    00128                         for (std::vector<EdgeRing*>::const_iterator
    00129                                 it=holes.begin(), itEnd=holes.end();
    00130                                 it != itEnd;
    00131                                 ++it)
    00132                         {
    00133                                 EdgeRing* hole=*it;
    00134                                 assert(hole);
    00135                                 assert(hole->getShell()==this);
    00136                         }
    00137                 }
    00138 #endif // ndef NDEBUG
    00139         }
    00140
    00141 protected:
    00142
    00143         DirectedEdge *startDe; // the directed edge which starts the list of edges for this EdgeRing
    00144
    00145         const geom::GeometryFactory *geometryFactory;
    00146
    00147         void computePoints(DirectedEdge *newStart);
    00148
    00149         void mergeLabel(Label& deLabel);
    00150
    00163         void mergeLabel(Label& deLabel, int geomIndex);
    00164
    00165         void addPoints(Edge *edge, bool isForward, bool isFirstEdge);
    00166
    00168         std::vector<EdgeRing*> holes;
    00169
    00170 private:
    00171
    00172         int maxNodeDegree;
    00173
    00175         std::vector<DirectedEdge*> edges;
    00176
    00177         geom::CoordinateSequence* pts;
    00178
    00179         // label stores the locations of each geometry on the
    00180         // face surrounded by this ring
    00181         Label label;
    00182
    00183         geom::LinearRing *ring;  // the ring created for this EdgeRing
    00184
    00185         bool isHoleVar;
    00186
    00188         EdgeRing *shell;
    00189
    00190         void computeMaxNodeDegree();
    00191
    00192 };
    00193
    00194 std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
    00195
    00196 } // namespace geos.geomgraph
    00197 } // namespace geos
    00198
    00199 //#ifdef GEOS_INLINE
    00200 //# include "geos/geomgraph/EdgeRing.inl"
    00201 //#endif
    00202
    00203 #endif // ifndef GEOS_GEOMGRAPH_EDGERING_H
    00204
    00205 /**********************************************************************
    00206  * $Log$
    00207  * Revision 1.9  2006/07/08 00:33:55  strk
    00208  *         * configure.in: incremented CAPI minor version, to avoid                        falling behind any future version from the 2.2. branch.
    00209  *         * source/geom/Geometry.cpp, source/geom/GeometryFactory.cpp,
    00210  *         source/geomgraph/EdgeRing.cpp,
    00211  *         source/headers/geos/geom/Geometry.h,
    00212  *         source/headers/geos/geom/GeometryFactory.h,
    00213  *         source/headers/geos/geom/GeometryFactory.inl,
    00214  *         source/headers/geos/geomgraph/EdgeRing.h:
    00215  *         updated doxygen comments (sync with JTS head).
    00216  *         * source/headers/geos/platform.h.in: include <inttypes.h>
    00217  *         rather then <stdint.h>
    00218  *
    00219  * Revision 1.8  2006/04/06 09:41:55  strk
    00220  * Added operator<<, added pts!=NULL assertion in testInvariant() function
    00221  *
    00222  * Revision 1.7  2006/04/05 18:28:42  strk
    00223  * Moved testInvariant() methods from private to public, added
    00224  * some comments about them.
    00225  *
    00226  * Revision 1.6  2006/03/29 13:53:59  strk
    00227  * EdgeRing equipped with Invariant testing function and lots of exceptional assertions. Removed useless heap allocations, and pointers usages.
    00228  *
    00229  * Revision 1.5  2006/03/27 16:02:34  strk
    00230  * Added INL file for MinimalEdgeRing, added many debugging blocks,
    00231  * fixed memory leak in ConnectedInteriorTester (bug #59)
    00232  *
    00233  * Revision 1.4  2006/03/24 09:52:41  strk
    00234  * USE_INLINE => GEOS_INLINE
    00235  *
    00236  * Revision 1.3  2006/03/20 12:32:57  strk
    00237  * Added note about responsibility of return from ::toPolygon
    00238  *
    00239  * Revision 1.2  2006/03/15 17:17:41  strk
    00240  * Added missing forward declarations
    00241  *
    00242  * Revision 1.1  2006/03/09 16:46:49  strk
    00243  * geos::geom namespace definition, first pass at headers split
    00244  *
    00245  **********************************************************************/
    00246