diff --git a/include/geos/noding/snapround/HotPixelIndex.h b/include/geos/noding/snapround/HotPixelIndex.h index 2240a4fae..736c7d0c4 100644 --- a/include/geos/noding/snapround/HotPixelIndex.h +++ b/include/geos/noding/snapround/HotPixelIndex.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -63,8 +64,10 @@ class GEOS_DLL HotPixelIndex { /* members */ const geom::PrecisionModel* pm; double scaleFactor; - std::unique_ptr index; + //std::unique_ptr index; + index::strtree::TemplateSTRtree index; std::deque hotPixelQue; + std::map hotPixelMap; /* methods */ geom::Coordinate round(const geom::Coordinate& c); @@ -84,8 +87,15 @@ class GEOS_DLL HotPixelIndex { * The visitor must determine whether each hot pixel actually intersects * the segment. */ + template void query(const geom::Coordinate& p0, const geom::Coordinate& p1, - index::kdtree::KdNodeVisitor& visitor); + Visitor&& visitor) { + geom::Envelope queryEnv(p0, p1); + queryEnv.expandBy(1.0 / scaleFactor); + + index.query(queryEnv, visitor); + } + }; diff --git a/src/index/kdtree/KdTree.cpp b/src/index/kdtree/KdTree.cpp index a0c2dfbff..6a06e52f9 100644 --- a/src/index/kdtree/KdTree.cpp +++ b/src/index/kdtree/KdTree.cpp @@ -17,6 +17,7 @@ #include #include +#include #include using namespace geos::geom; diff --git a/src/noding/snapround/HotPixelIndex.cpp b/src/noding/snapround/HotPixelIndex.cpp index 254af6b9c..a54478740 100644 --- a/src/noding/snapround/HotPixelIndex.cpp +++ b/src/noding/snapround/HotPixelIndex.cpp @@ -35,8 +35,7 @@ namespace snapround { // geos.noding.snapround HotPixelIndex::HotPixelIndex(const PrecisionModel* p_pm) : pm(p_pm), - scaleFactor(p_pm->getScale()), - index(new KdTree()) + scaleFactor(p_pm->getScale()) { } @@ -72,8 +71,9 @@ HotPixelIndex::add(const Coordinate& p) // Pick up a pointer to the most recently added // HotPixel. hp = &(hotPixelQue.back()); + hotPixelMap[hp->getCoordinate()] = hp; - index->insert(hp->getCoordinate(), hp); + index.insert(Envelope(hp->getCoordinate()), hp); return hp; } @@ -140,11 +140,18 @@ HotPixelIndex::addNodes(const std::vector& pts) HotPixel* HotPixelIndex::find(const geom::Coordinate& pixelPt) { - index::kdtree::KdNode *kdNode = index->query(pixelPt); - if (kdNode == nullptr) { + auto it = hotPixelMap.find(pixelPt); + if (it != hotPixelMap.end()) { + return it->second; + } else { return nullptr; } - return (HotPixel*)(kdNode->getData()); + //HotPixel* ret = nullptr; + //index.query(Envelope(pixelPt, pixelPt), [&ret](HotPixel* hit) { + // ret = hit; + // return false; + //}); + //return ret; } /*private*/ @@ -157,15 +164,6 @@ HotPixelIndex::round(const Coordinate& pt) } -/*public*/ -void -HotPixelIndex::query(const Coordinate& p0, const Coordinate& p1, index::kdtree::KdNodeVisitor& visitor) -{ - Envelope queryEnv(p0, p1); - queryEnv.expandBy(1.0 / scaleFactor); - index->query(queryEnv, visitor); -} - } // namespace geos.noding.snapround } // namespace geos.noding diff --git a/src/noding/snapround/SnapRoundingNoder.cpp b/src/noding/snapround/SnapRoundingNoder.cpp index 0fd288c30..014cc66ef 100644 --- a/src/noding/snapround/SnapRoundingNoder.cpp +++ b/src/noding/snapround/SnapRoundingNoder.cpp @@ -208,6 +208,10 @@ SnapRoundingNoder::snapSegment(Coordinate& p0, Coordinate& p1, NodedSegmentStrin void visit(KdNode* node) override { HotPixel* hp = static_cast(node->getData()); + (*this)(hp); + } + + void operator()(HotPixel* hp) { /** * If the hot pixel is not a node, and it contains one of the segment vertices, * then that vertex is the source for the hot pixel. @@ -265,7 +269,10 @@ SnapRoundingNoder::snapVertexNode(const Coordinate& p0, NodedSegmentString* ss, void visit(KdNode* node) override { HotPixel* hp = static_cast(node->getData()); + (*this)(hp); + } + void operator()(const HotPixel* hp) { /** * If vertex pixel is a node, add it. */