# SegmentNodeList.h

    00001 /**********************************************************************
    00002  * $Id: SegmentNodeList.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) 2006      Refractions Research Inc.
    00008  *
    00009  * This is free software; you can redistribute and/or modify it under
    00010  * the terms of the GNU Lesser General Public Licence as published
    00011  * by the Free Software Foundation.
    00012  * See the COPYING file for more information.
    00013  *
    00014  **********************************************************************/
    00015
    00016 #ifndef GEOS_NODING_SEGMENTNODELIST_H
    00017 #define GEOS_NODING_SEGMENTNODELIST_H
    00018
    00019 #include <geos/inline.h>
    00020
    00021 #include <cassert>
    00022 #include <iostream>
    00023 #include <vector>
    00024 #include <set>
    00025
    00026 #include <geos/noding/SegmentNode.h>
    00027
    00028 // Forward declarations
    00029 namespace geos {
    00030         namespace geom {
    00031                 class CoordinateSequence;
    00032         }
    00033         namespace noding {
    00034                 class SegmentString;
    00035         }
    00036 }
    00037
    00038 namespace geos {
    00039 namespace noding { // geos::noding
    00040
    00047 class SegmentNodeList {
    00048 private:
    00049         std::set<SegmentNode*,SegmentNodeLT> nodeMap;
    00050
    00051         // the parent edge
    00052         const SegmentString& edge;
    00053
    00054         // UNUSED
    00055         //std::vector<SegmentNode*> *sortedNodes;
    00056
    00057         // This vector is here to keep track of created splitEdges
    00058         std::vector<SegmentString*> splitEdges;
    00059
    00060         // This vector is here to keep track of created Coordinates
    00061         std::vector<geom::CoordinateSequence*> splitCoordLists;
    00062
    00069         void checkSplitEdgesCorrectness(std::vector<SegmentString*>& splitEdges);
    00070
    00077         SegmentString* createSplitEdge(SegmentNode *ei0, SegmentNode *ei1);
    00078
    00087         void addCollapsedNodes();
    00088
    00093         void findCollapsesFromExistingVertices(
    00094                         std::vector<size_t>& collapsedVertexIndexes);
    00095
    00103         void findCollapsesFromInsertedNodes(
    00104                 std::vector<size_t>& collapsedVertexIndexes);
    00105
    00106         bool findCollapseIndex(SegmentNode& ei0, SegmentNode& ei1,
    00107                 size_t& collapsedVertexIndex);
    00108 public:
    00109
    00110         friend std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
    00111
    00112         typedef std::set<SegmentNode*,SegmentNodeLT> container;
    00113         typedef container::iterator iterator;
    00114         typedef container::const_iterator const_iterator;
    00115
    00116         SegmentNodeList(const SegmentString* newEdge): edge(*newEdge) {}
    00117
    00118         SegmentNodeList(const SegmentString& newEdge): edge(newEdge) {}
    00119
    00120         const SegmentString& getEdge() const { return edge; }
    00121
    00122         // TODO: Is this a final class ?
    00123         // Should remove the virtual in that case
    00124         virtual ~SegmentNodeList();
    00125
    00136         SegmentNode* add(const geom::Coordinate& intPt, size_t segmentIndex);
    00137
    00138         SegmentNode* add(const geom::Coordinate *intPt, size_t segmentIndex) {
    00139                 return add(*intPt, segmentIndex);
    00140         }
    00141
    00142         /*
    00143          * returns the set of SegmentNodes
    00144          */
    00145         //replaces iterator()
    00146         // TODO: obsolete this function
    00147         std::set<SegmentNode*,SegmentNodeLT>* getNodes() { return &nodeMap; }
    00148
    00150         size_t size() const { return nodeMap.size(); }
    00151
    00152         container::iterator begin() { return nodeMap.begin(); }
    00153         container::const_iterator begin() const { return nodeMap.begin(); }
    00154         container::iterator end() { return nodeMap.end(); }
    00155         container::const_iterator end() const { return nodeMap.end(); }
    00156
    00160         void addEndpoints();
    00161
    00168         void addSplitEdges(std::vector<SegmentString*>& edgeList);
    00169
    00170         void addSplitEdges(std::vector<SegmentString*>* edgeList) {
    00171                 assert(edgeList);
    00172                 addSplitEdges(*edgeList);
    00173         }
    00174
    00175         //string print();
    00176 };
    00177
    00178 std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
    00179
    00180 } // namespace geos::noding
    00181 } // namespace geos
    00182
    00183 //#ifdef GEOS_INLINE
    00184 //# include "geos/noding/SegmentNodeList.inl"
    00185 //#endif
    00186
    00187 #endif
    00188
    00189 /**********************************************************************
    00190  * $Log$
    00191  * Revision 1.4  2006/06/12 11:29:23  strk
    00192  * unsigned int => size_t
    00193  *
    00194  * Revision 1.3  2006/05/04 07:41:56  strk
    00195  * const-correct size() method for SegmentNodeList
    00196  *
    00197  * Revision 1.2  2006/03/24 09:52:41  strk
    00198  * USE_INLINE => GEOS_INLINE
    00199  *
    00200  * Revision 1.1  2006/03/09 16:46:49  strk
    00201  * geos::geom namespace definition, first pass at headers split
    00202  *
    00203  **********************************************************************/
    00204