SegmentNodeList.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: noding/SegmentNodeList.java rev. 1.8 (JTS-1.10)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <cassert>
#include <iostream>
#include <vector>
#include <set>
#include <memory>
#include <geos/noding/SegmentNode.h> // for composition
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
// Forward declarations
namespace geos {
namespace geom {
class CoordinateSequence;
}
namespace noding {
class SegmentString;
class NodedSegmentString;
}
}
namespace geos {
namespace noding { // geos::noding
class GEOS_DLL SegmentNodeList {
private:
// Since we are adding frequently to the SegmentNodeList and
// iterating infrequently, it is faster to store all the
// SegmentNodes in a vector and sort/remove duplicates
// before iteration, rather than storing them in a set
// and continuously maintaining a sorted order.
mutable std::vector<SegmentNode> nodeMap;
mutable bool ready = false;
bool constructZ;
bool constructM;
void prepare() const;
// the parent edge
const NodedSegmentString& edge;
void checkSplitEdgesCorrectness(const std::vector<SegmentString*>& splitEdges) const;
std::unique_ptr<SegmentString> createSplitEdge(const SegmentNode* ei0, const SegmentNode* ei1) const;
std::unique_ptr<geom::CoordinateSequence> createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1) const;
void addCollapsedNodes();
void findCollapsesFromExistingVertices(
std::vector<std::size_t>& collapsedVertexIndexes) const;
void findCollapsesFromInsertedNodes(
std::vector<std::size_t>& collapsedVertexIndexes) const;
static bool findCollapseIndex(const SegmentNode& ei0, const SegmentNode& ei1,
size_t& collapsedVertexIndex);
void addEdgeCoordinates(const SegmentNode* ei0, const SegmentNode* ei1, geom::CoordinateSequence& coordList) const;
public:
// Declare type as noncopyable
SegmentNodeList(const SegmentNodeList& other) = delete;
SegmentNodeList& operator=(const SegmentNodeList& rhs) = delete;
friend std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
using container = decltype(nodeMap);
using iterator = container::iterator;
using const_iterator = container::const_iterator;
explicit SegmentNodeList(const NodedSegmentString& newEdge,
bool p_constructZ,
bool p_constructM)
: constructZ(p_constructZ)
, constructM(p_constructM)
, edge(newEdge) {}
~SegmentNodeList() = default;
const NodedSegmentString&
getEdge() const
{
return edge;
}
bool getConstructZ() const {
return constructZ;
}
bool getConstructM() const {
return constructM;
}
template<typename CoordType>
void add(const CoordType& intPt, std::size_t segmentIndex) {
// Cast edge to SegmentString to avoid circular dependency between NodedSegmentString and SegmentNodeList
nodeMap.emplace_back(edge, intPt, segmentIndex, reinterpret_cast<const SegmentString&>(edge).getSegmentOctant(segmentIndex));
ready = false;
}
size_t
size() const
{
prepare();
return nodeMap.size();
}
iterator begin() {
prepare();
return nodeMap.begin();
}
const_iterator begin() const {
prepare();
return nodeMap.begin();
}
iterator end() {
prepare();
return nodeMap.end();
}
const_iterator end() const {
prepare();
return nodeMap.end();
}
void addEndpoints();
void addSplitEdges(std::vector<SegmentString*>& edgeList);
void
addSplitEdges(std::vector<SegmentString*>* edgeList)
{
assert(edgeList);
addSplitEdges(*edgeList);
}
std::unique_ptr<geom::CoordinateSequence> getSplitCoordinates();
};
std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
} // namespace geos::noding
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::noding::NodedSegmentString
Represents a list of contiguous line segments, and supports noding the segments.
Definition NodedSegmentString.h:58
geos::noding::SegmentNodeList
A list of the SegmentNode present along a NodedSegmentString.
Definition SegmentNodeList.h:54
geos::noding::SegmentNodeList::getSplitCoordinates
std::unique_ptr< geom::CoordinateSequence > getSplitCoordinates()
geos::noding::SegmentNodeList::addSplitEdges
void addSplitEdges(std::vector< SegmentString * > &edgeList)
geos::noding::SegmentNodeList::add
void add(const CoordType &intPt, std::size_t segmentIndex)
Definition SegmentNodeList.h:177
geos::noding::SegmentNodeList::addEndpoints
void addEndpoints()
geos::noding::SegmentNodeList::size
size_t size() const
Return the number of nodes in this list.
Definition SegmentNodeList.h:185
geos::noding::SegmentNode
Represents an intersection point between two NodedSegmentString.
Definition SegmentNode.h:38
geos::noding::SegmentString
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
geos::geom
Definition Angle.h:26
geos::noding
Classes to compute nodings for arrangements of line segments and line segment sequences.
Definition CoverageCleaner.h:42
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38