GEOS  3.3.5
Edge.h
00001 /**********************************************************************
00002  * $Id: Edge.h 3255 2011-03-01 17:56:10Z 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/Edge.java rev. 1.4 (JTS-1.10)
00018  *
00019  **********************************************************************/
00020 
00021 
00022 #ifndef GEOS_GEOMGRAPH_EDGE_H
00023 #define GEOS_GEOMGRAPH_EDGE_H
00024 
00025 #include <geos/export.h>
00026 #include <string>
00027 #include <cassert>
00028 
00029 #include <geos/geomgraph/GraphComponent.h> // for inheritance
00030 #include <geos/geomgraph/Depth.h> // for member
00031 #include <geos/geomgraph/EdgeIntersectionList.h> // for composition
00032 #include <geos/geom/CoordinateSequence.h> // for inlines
00033 
00034 #include <geos/inline.h>
00035 
00036 #ifdef _MSC_VER
00037 #pragma warning(push)
00038 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00039 #endif
00040 
00041 // Forward declarations
00042 namespace geos {
00043         namespace geom {
00044                 class Envelope;
00045                 class IntersectionMatrix;
00046                 class Coordinate;
00047         }
00048         namespace algorithm {
00049                 class LineIntersector;
00050         }
00051         namespace geomgraph {
00052                 class Node;
00053                 class EdgeEndStar;
00054                 class Label;
00055                 class NodeFactory;
00056                 namespace index {
00057                         class MonotoneChainEdge;
00058                 }
00059         }
00060 }
00061 
00062 namespace geos {
00063 namespace geomgraph { // geos.geomgraph
00064 
00065 class GEOS_DLL Edge: public GraphComponent{
00066 using GraphComponent::updateIM;
00067 
00068 private:
00069 
00070         std::string name;
00071 
00073         index::MonotoneChainEdge *mce;
00074 
00076         geom::Envelope *env;
00077 
00078         bool isIsolatedVar;
00079 
00080         Depth depth;
00081 
00082         int depthDelta;   // the change in area depth from the R to L side of this edge
00083 
00084 public:
00085 
00086         void testInvariant() const {
00087                 assert(pts);
00088                 assert(pts->size() > 1);
00089         }
00090 
00091 
00092         friend std::ostream& operator<< (std::ostream& os, const Edge& el);
00093 
00094         static void updateIM(Label *lbl,geom::IntersectionMatrix *im);
00095 
00097         geom::CoordinateSequence* pts;
00098 
00099         EdgeIntersectionList eiList;
00100 
00101         //Edge();
00102 
00103         Edge(geom::CoordinateSequence* newPts, Label *newLabel);
00104 
00105         Edge(geom::CoordinateSequence* newPts);
00106 
00107         virtual ~Edge();
00108 
00109         virtual int getNumPoints() const {
00110                 return static_cast<int>(pts->getSize());
00111         }
00112 
00113         virtual void setName(const std::string &newName) {
00114                 name=newName;
00115         }
00116 
00117         virtual const geom::CoordinateSequence* getCoordinates() const {
00118                 testInvariant();
00119                 return pts;
00120         }
00121 
00122         virtual const geom::Coordinate& getCoordinate(int i) const {
00123                 testInvariant();
00124                 return pts->getAt(i);
00125         }
00126 
00127         virtual const geom::Coordinate& getCoordinate() const {
00128                 testInvariant();
00129                 return pts->getAt(0);
00130         }
00131 
00132 
00133         virtual Depth &getDepth() { 
00134                 testInvariant();
00135                 return depth;
00136         }
00137 
00143         virtual int getDepthDelta() const {
00144                 testInvariant();
00145                 return depthDelta;
00146         }
00147 
00148         virtual void setDepthDelta(int newDepthDelta) {
00149                 depthDelta=newDepthDelta;
00150                 testInvariant();
00151         }
00152 
00153         virtual int getMaximumSegmentIndex() const {
00154                 testInvariant();
00155                 return getNumPoints()-1;
00156         }
00157 
00158         virtual EdgeIntersectionList& getEdgeIntersectionList() {
00159                 testInvariant();
00160                 return eiList;
00161         }
00162 
00167         virtual index::MonotoneChainEdge* getMonotoneChainEdge();
00168 
00169         virtual bool isClosed() const {
00170                 testInvariant();
00171                 return pts->getAt(0)==pts->getAt(getNumPoints()-1);
00172         }
00173 
00178         virtual bool isCollapsed() const;
00179 
00180         virtual Edge* getCollapsedEdge();
00181 
00182         virtual void setIsolated(bool newIsIsolated) {
00183                 isIsolatedVar=newIsIsolated;
00184                 testInvariant();
00185         }
00186 
00187         virtual bool isIsolated() const {
00188                 testInvariant();
00189                 return isIsolatedVar;
00190         }
00191 
00196         virtual void addIntersections(algorithm::LineIntersector *li, int segmentIndex,
00197                 int geomIndex);
00198 
00200         //
00204         virtual void addIntersection(algorithm::LineIntersector *li, int segmentIndex,
00205                 int geomIndex, int intIndex);
00206 
00208         //
00211         virtual void computeIM(geom::IntersectionMatrix *im) {
00212                 updateIM(label, im);
00213                 testInvariant();
00214         }
00215 
00217         virtual bool isPointwiseEqual(const Edge *e) const;
00218 
00219         virtual std::string print() const;
00220 
00221         virtual std::string printReverse() const;
00222 
00230         virtual bool equals(const Edge& e) const;
00231 
00232         virtual bool equals(const Edge* e) const {
00233                 assert(e);
00234                 return equals(*e);
00235         }
00236 
00237         virtual geom::Envelope* getEnvelope();
00238 };
00239 
00240 
00241 //Operators
00242 inline bool operator==(const Edge &a, const Edge &b) {
00243         return a.equals(b);
00244 }
00245 
00246 std::ostream& operator<< (std::ostream& os, const Edge& el);
00247 
00248 
00249 } // namespace geos.geomgraph
00250 } // namespace geos
00251 
00252 #ifdef _MSC_VER
00253 #pragma warning(pop)
00254 #endif
00255 
00256 //#ifdef GEOS_INLINE
00257 //# include "geos/geomgraph/Edge.inl"
00258 //#endif
00259 
00260 #endif // ifndef GEOS_GEOMGRAPH_EDGE_H
00261 
00262 /**********************************************************************
00263  * $Log$
00264  * Revision 1.4  2006/04/05 18:28:42  strk
00265  * Moved testInvariant() methods from private to public, added
00266  * some comments about them.
00267  *
00268  * Revision 1.3  2006/03/24 09:52:41  strk
00269  * USE_INLINE => GEOS_INLINE
00270  *
00271  * Revision 1.2  2006/03/14 11:03:14  strk
00272  * Added operator<< for Edge and EdgeList
00273  *
00274  * Revision 1.1  2006/03/09 16:46:49  strk
00275  * geos::geom namespace definition, first pass at headers split
00276  *
00277  **********************************************************************/
00278