GEOS
3.4.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net> 00007 * Copyright (C) 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 * 00018 * Last port: noding/NodedSegmentString.java r320 (JTS-1.12) 00019 * 00020 **********************************************************************/ 00021 00022 #ifndef GEOS_NODING_NODEDSEGMENTSTRING_H 00023 #define GEOS_NODING_NODEDSEGMENTSTRING_H 00024 00025 #include <geos/export.h> 00026 #include <geos/noding/NodableSegmentString.h> // for inheritance 00027 #include <geos/geom/CoordinateSequence.h> // for inlines 00028 #include <geos/algorithm/LineIntersector.h> 00029 #include <geos/noding/SegmentNode.h> 00030 #include <geos/noding/SegmentNodeList.h> 00031 #include <geos/noding/SegmentString.h> 00032 //#include <geos/noding/Octant.h> 00033 #include <geos/geom/Coordinate.h> 00034 00035 #include <cstddef> 00036 00037 #ifdef _MSC_VER 00038 #pragma warning(push) 00039 #pragma warning(disable: 4251 4355) // warning C4355: 'this' : used in base member initializer list 00040 #endif 00041 00042 namespace geos { 00043 namespace noding { // geos::noding 00044 00057 class GEOS_DLL NodedSegmentString : public NodableSegmentString 00058 { 00059 public: 00060 00061 // TODO: provide a templated method using an output iterator 00062 template <class II> 00063 static void getNodedSubstrings(II from, II too_far, 00064 SegmentString::NonConstVect* resultEdgelist) 00065 { 00066 for (II i=from; i != too_far; ++i) 00067 { 00068 NodedSegmentString * nss = dynamic_cast<NodedSegmentString*>(*i); 00069 assert(nss); 00070 nss->getNodeList().addSplitEdges(resultEdgelist); 00071 } 00072 } 00073 00074 template <class C> 00075 static void getNodedSubstrings(C *segStrings, 00076 SegmentString::NonConstVect* resultEdgelist) 00077 { 00078 getNodedSubstrings(segStrings->begin(), segStrings->end(), resultEdgelist); 00079 } 00080 00081 static void getNodedSubstrings(const SegmentString::NonConstVect& segStrings, 00082 SegmentString::NonConstVect* resultEdgeList); 00083 00085 static SegmentString::NonConstVect* getNodedSubstrings( 00086 const SegmentString::NonConstVect& segStrings); 00087 00088 00098 NodedSegmentString(geom::CoordinateSequence *newPts, const void* newContext) 00099 : NodableSegmentString(newContext) 00100 , nodeList(this) 00101 , pts(newPts) 00102 {} 00103 00104 ~NodedSegmentString() 00105 { 00106 delete pts; 00107 } 00108 00118 SegmentNode* addIntersectionNode( geom::Coordinate * intPt, std::size_t segmentIndex) 00119 { 00120 std::size_t normalizedSegmentIndex = segmentIndex; 00121 00122 // normalize the intersection point location 00123 std::size_t nextSegIndex = normalizedSegmentIndex + 1; 00124 if (nextSegIndex < size()) 00125 { 00126 geom::Coordinate const& nextPt = 00127 getCoordinate(static_cast<unsigned int>(nextSegIndex)); 00128 00129 // Normalize segment index if intPt falls on vertex 00130 // The check for point equality is 2D only - Z values are ignored 00131 if ( intPt->equals2D( nextPt )) 00132 { 00133 normalizedSegmentIndex = nextSegIndex; 00134 } 00135 } 00136 00137 // Add the intersection point to edge intersection list. 00138 SegmentNode * ei = getNodeList().add( *intPt, normalizedSegmentIndex); 00139 return ei; 00140 } 00141 00142 SegmentNodeList& getNodeList(); 00143 00144 const SegmentNodeList& getNodeList() const; 00145 00146 virtual unsigned int size() const 00147 { 00148 return static_cast<unsigned int>(pts->size()); 00149 } 00150 00151 virtual const geom::Coordinate& getCoordinate(unsigned int i) const; 00152 00153 virtual geom::CoordinateSequence* getCoordinates() const; 00154 00155 virtual bool isClosed() const; 00156 00157 virtual std::ostream& print(std::ostream& os) const; 00158 00159 00167 int getSegmentOctant(unsigned int index) const; 00168 00174 void addIntersections(algorithm::LineIntersector *li, 00175 unsigned int segmentIndex, int geomIndex); 00176 00184 void addIntersection(algorithm::LineIntersector *li, 00185 unsigned int segmentIndex, 00186 int geomIndex, int intIndex); 00187 00195 void addIntersection(const geom::Coordinate& intPt, 00196 unsigned int segmentIndex); 00197 00198 00199 private: 00200 00201 SegmentNodeList nodeList; 00202 00203 geom::CoordinateSequence *pts; 00204 00205 static int safeOctant(const geom::Coordinate& p0, const geom::Coordinate& p1); 00206 00207 }; 00208 00209 } // namespace geos::noding 00210 } // namespace geos 00211 00212 #ifdef _MSC_VER 00213 #pragma warning(pop) 00214 #endif 00215 00216 #endif // GEOS_NODING_NODEDSEGMENTSTRING_H