Skip to content

Commit

Permalink
Use TemplateSTRTree for pair finding in tree, per @dbaston
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Aug 15, 2024
1 parent 220df45 commit 8405fcb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
6 changes: 0 additions & 6 deletions include/geos/index/chain/MonotoneChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ class GEOS_DLL MonotoneChain {
return context;
}

void setId(int p_id) { id = p_id; }
int getId() const { return id; }

private:

void computeSelect(const geom::Envelope& searchEnv,
Expand Down Expand Up @@ -201,9 +198,6 @@ class GEOS_DLL MonotoneChain {
/// Owned by this class
mutable geom::Envelope env;

/// Useful for optimizing chain comparisons
int id = 0;

};

} // namespace geos::index::chain
Expand Down
3 changes: 1 addition & 2 deletions include/geos/operation/relateng/EdgeSetIntersector.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GEOS_DLL EdgeSetIntersector {
// HPRtree index = new HPRtree();
const Envelope* envelope = nullptr;
std::deque<MonotoneChain> monoChains;
int idCounter = 0;
std::size_t overlapCounter = 0;


// Methods
Expand All @@ -76,7 +76,6 @@ class GEOS_DLL EdgeSetIntersector {
std::vector<const SegmentString*>& edgesB,
const Envelope* env)
: envelope(env)
, idCounter(0)
{
addEdges(edgesA);
addEdges(edgesB);
Expand Down
30 changes: 12 additions & 18 deletions src/operation/relateng/EdgeSetIntersector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <geos/operation/relateng/RelateSegmentString.h>
#include <geos/index/chain/MonotoneChain.h>
#include <geos/index/chain/MonotoneChainBuilder.h>
#include <geos/util/Interrupt.h>


using geos::geom::Geometry;
Expand Down Expand Up @@ -54,7 +55,7 @@ EdgeSetIntersector::addToIndex(const SegmentString* segStr)

for (MonotoneChain& mc : segChains) {
if (envelope == nullptr || envelope->intersects(mc.getEnvelope())) {
mc.setId(idCounter++);
// mc.setId(idCounter++);
monoChains.push_back(mc);
MonotoneChain* mcPtr = &(monoChains.back());
index.insert(mcPtr->getEnvelope(), mcPtr);
Expand All @@ -68,26 +69,19 @@ EdgeSetIntersector::process(EdgeSegmentIntersector& intersector)
{
EdgeSegmentOverlapAction overlapAction(intersector);

for (const MonotoneChain& queryChain : monoChains) {
// Replaces JTS implementation that manually iterates on the
// monoChains with the automatic queryPairs method in TemplateSTRTree
index.queryPairs([this, &overlapAction, &intersector](const MonotoneChain* queryChain, const MonotoneChain* testChain) {

std::vector<const MonotoneChain*> overlapChains;
index.query(queryChain.getEnvelope(), [&overlapChains](const MonotoneChain* mc) {
overlapChains.push_back(mc);
});
if (overlapCounter++ % 100000 == 0)
GEOS_CHECK_FOR_INTERRUPTS();

for (const MonotoneChain* testChain : overlapChains) {
/**
* following test makes sure we only compare each pair of chains once
* and that we don't compare a chain to itself
*/
if (testChain->getId() <= queryChain.getId())
continue;
testChain->computeOverlaps(queryChain, &overlapAction);

if (intersector.isDone())
return;
});

testChain->computeOverlaps(&queryChain, &overlapAction);
if (intersector.isDone())
return;
}
}
}


Expand Down

0 comments on commit 8405fcb

Please sign in to comment.