GEOS  3.3.2
NodedSegmentString.h
00001 /**********************************************************************
00002  * $Id: NodedSegmentString.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) 2011 Sandro Santilli <strk@keybit.net>
00008  * Copyright (C) 2006 Refractions Research Inc.
00009  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00010  *
00011  * This is free software; you can redistribute and/or modify it under
00012  * the terms of the GNU Lesser General Public Licence as published
00013  * by the Free Software Foundation. 
00014  * See the COPYING file for more information.
00015  *
00016  *
00017  **********************************************************************
00018  *
00019  * Last port: noding/NodedSegmentString.java r320 (JTS-1.12)
00020  *
00021  **********************************************************************/
00022 
00023 #ifndef GEOS_NODING_NODEDSEGMENTSTRING_H
00024 #define GEOS_NODING_NODEDSEGMENTSTRING_H
00025 
00026 #include <geos/export.h>
00027 #include <geos/noding/NodableSegmentString.h> // for inheritance
00028 #include <geos/geom/CoordinateSequence.h> // for inlines
00029 #include <geos/algorithm/LineIntersector.h>
00030 #include <geos/noding/SegmentNode.h>
00031 #include <geos/noding/SegmentNodeList.h>
00032 #include <geos/noding/SegmentString.h>
00033 //#include <geos/noding/Octant.h>
00034 #include <geos/geom/Coordinate.h>
00035 
00036 #include <cstddef>
00037 
00038 #ifdef _MSC_VER
00039 #pragma warning(push)
00040 #pragma warning(disable: 4251 4355) // warning C4355: 'this' : used in base member initializer list
00041 #endif
00042 
00043 namespace geos {
00044 namespace noding { // geos::noding
00045 
00058 class GEOS_DLL NodedSegmentString : public NodableSegmentString 
00059 {
00060 public:
00061 
00062     static void getNodedSubstrings(SegmentString::ConstVect* segStrings,
00063         SegmentString::NonConstVect* resultEdgelist)
00064     {
00065         for (ConstVect::size_type i=0, n=segStrings->size(); i<n; i++)
00066         {
00067             NodedSegmentString const* nss = 
00068                 static_cast<NodedSegmentString const*>((*segStrings)[i]);
00069 
00070             const_cast<NodedSegmentString*>(nss)->getNodeList().addSplitEdges( resultEdgelist);
00071         }
00072     }
00073 
00074         static void getNodedSubstrings(const SegmentString::NonConstVect& segStrings,
00075                         SegmentString::NonConstVect* resultEdgeList);
00076 
00078         static SegmentString::NonConstVect* getNodedSubstrings(
00079                         const SegmentString::NonConstVect& segStrings);
00080 
00081 
00091     NodedSegmentString(geom::CoordinateSequence *newPts, const void* newContext)
00092         : NodableSegmentString(newContext)
00093         , nodeList(this)
00094         , pts(newPts)
00095     {}
00096 
00097         ~NodedSegmentString()
00098         {}
00099 
00109         SegmentNode* addIntersectionNode( geom::Coordinate * intPt, std::size_t segmentIndex) 
00110         {
00111                 std::size_t normalizedSegmentIndex = segmentIndex;
00112 
00113                 // normalize the intersection point location
00114                 std::size_t nextSegIndex = normalizedSegmentIndex + 1;
00115                 if (nextSegIndex < size()) 
00116                 {
00117                         geom::Coordinate const& nextPt = 
00118                 getCoordinate(static_cast<unsigned int>(nextSegIndex));
00119 
00120                         // Normalize segment index if intPt falls on vertex
00121                         // The check for point equality is 2D only - Z values are ignored
00122                         if ( intPt->equals2D( nextPt )) 
00123                         {
00124                                 normalizedSegmentIndex = nextSegIndex;
00125                         }
00126                 }
00127 
00128                 // Add the intersection point to edge intersection list.
00129                 SegmentNode * ei = getNodeList().add( *intPt, normalizedSegmentIndex);
00130                 return ei;
00131         }
00132 
00133         SegmentNodeList& getNodeList();
00134 
00135         const SegmentNodeList& getNodeList() const;
00136 
00137         virtual unsigned int size() const
00138         {
00139                 return static_cast<unsigned int>(pts->size());
00140         }
00141 
00142         virtual const geom::Coordinate& getCoordinate(unsigned int i) const;
00143 
00144         virtual geom::CoordinateSequence* getCoordinates() const;
00145 
00146         virtual bool isClosed() const;
00147 
00148         virtual std::ostream& print(std::ostream& os) const;
00149 
00150 
00158         int getSegmentOctant(unsigned int index) const;
00159 
00165         void addIntersections(algorithm::LineIntersector *li,
00166                         unsigned int segmentIndex, int geomIndex);
00167 
00175         void addIntersection(algorithm::LineIntersector *li,
00176                         unsigned int segmentIndex,
00177                         int geomIndex, int intIndex);
00178 
00186         void addIntersection(const geom::Coordinate& intPt,
00187                         unsigned int segmentIndex);
00188 
00189 
00190 private:
00191 
00192         SegmentNodeList nodeList;
00193 
00194         geom::CoordinateSequence *pts;
00195 
00196         static int safeOctant(const geom::Coordinate& p0, const geom::Coordinate& p1);
00197 
00198 };
00199 
00200 } // namespace geos::noding
00201 } // namespace geos
00202 
00203 #ifdef _MSC_VER
00204 #pragma warning(pop)
00205 #endif
00206 
00207 #endif // GEOS_NODING_NODEDSEGMENTSTRING_H
00208 /**********************************************************************
00209  * $Log$
00210  **********************************************************************/
00211