[geos-commits] r2065 - trunk/source/noding

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Dec 21 15:41:50 EST 2007


Author: benjubb
Date: 2007-12-21 15:41:50 -0500 (Fri, 21 Dec 2007)
New Revision: 2065

Added:
   trunk/source/noding/FastSegmentSetIntersectionFinder.cpp
   trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp
   trunk/source/noding/NodedSegmentString.cpp
   trunk/source/noding/SegmentIntersectionDetector.cpp
   trunk/source/noding/SegmentStringUtil.cpp
Log:
Added from JTS 1.9 to support prepared geometry 

Added: trunk/source/noding/FastSegmentSetIntersectionFinder.cpp
===================================================================
--- trunk/source/noding/FastSegmentSetIntersectionFinder.cpp	                        (rev 0)
+++ trunk/source/noding/FastSegmentSetIntersectionFinder.cpp	2007-12-21 20:41:50 UTC (rev 2065)
@@ -0,0 +1,79 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions 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.
+ *
+ **********************************************************************/
+
+#include <geos/noding/FastSegmentSetIntersectionFinder.h>
+#include <geos/noding/SegmentString.h>
+#include <geos/noding/SegmentIntersectionDetector.h>
+#include <geos/noding/SegmentSetMutualIntersector.h>
+#include <geos/noding/MCIndexSegmentSetMutualIntersector.h>
+#include <geos/algorithm/LineIntersector.h>
+
+namespace geos {
+namespace noding { // geos::noding
+
+/*
+ * private:
+ */
+
+/*
+ * protected:
+ */
+
+/*
+ * public:
+ */
+FastSegmentSetIntersectionFinder::
+FastSegmentSetIntersectionFinder( noding::SegmentString::ConstVect * baseSegStrings)
+:	segSetMutInt( new MCIndexSegmentSetMutualIntersector()),
+	lineIntersector( new LineIntersector())
+{
+	segSetMutInt->setBaseSegments( baseSegStrings);
+}
+
+FastSegmentSetIntersectionFinder::
+~FastSegmentSetIntersectionFinder()
+{
+	delete lineIntersector;
+	delete segSetMutInt;
+}
+
+
+bool 
+FastSegmentSetIntersectionFinder::
+intersects( noding::SegmentString::ConstVect * segStrings)
+{
+	SegmentIntersectionDetector intFinder( lineIntersector);
+
+	return this->intersects( segStrings, &intFinder);
+}
+
+bool 
+FastSegmentSetIntersectionFinder::
+intersects( noding::SegmentString::ConstVect * segStrings, 
+			SegmentIntersectionDetector * intDetector)
+{
+	segSetMutInt->setSegmentIntersector( intDetector);
+	segSetMutInt->process( segStrings);
+
+	return intDetector->hasIntersection();
+}
+
+} // geos::noding
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/


Property changes on: trunk/source/noding/FastSegmentSetIntersectionFinder.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp
===================================================================
--- trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp	                        (rev 0)
+++ trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp	2007-12-21 20:41:50 UTC (rev 2065)
@@ -0,0 +1,155 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions 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.
+ *
+ **********************************************************************/
+
+
+#include <geos/noding/MCIndexSegmentSetMutualIntersector.h>
+#include <geos/noding/SegmentSetMutualIntersector.h>
+#include <geos/noding/SegmentString.h>
+#include <geos/noding/SegmentIntersector.h>
+#include <geos/index/SpatialIndex.h>
+#include <geos/index/chain/MonotoneChain.h>
+#include <geos/index/chain/MonotoneChainBuilder.h>
+#include <geos/index/chain/MonotoneChainOverlapAction.h>
+#include <geos/index/strtree/STRtree.h>
+
+using namespace geos::index::chain;
+
+namespace geos {
+namespace noding { // geos::noding
+//
+// private:
+//
+
+void 
+MCIndexSegmentSetMutualIntersector::addToIndex( SegmentString * segStr)
+{
+	std::vector<MonotoneChain *> * segChains; 
+	segChains = MonotoneChainBuilder::getChains( segStr->getCoordinates(), segStr);
+
+	for (size_t i=0, n=segChains->size(); i<n; i++)
+	{
+		MonotoneChain * mc = (*segChains)[ i ];
+		mc->setId(indexCounter++);
+		index->insert(mc->getEnvelope(), mc);
+	}
+
+	for ( std::vector<MonotoneChain *>::iterator i = segChains->begin(), e = segChains->end(); i != e; i++ )
+		delete *i;
+	delete segChains;
+}
+
+void 
+MCIndexSegmentSetMutualIntersector::intersectChains()
+{
+	MCIndexSegmentSetMutualIntersector::SegmentOverlapAction overlapAction( *segInt);
+
+	for (size_t i = 0, ni = monoChains->size(); i < ni; i++)
+	{
+		MonotoneChain * queryChain = (MonotoneChain *)((*monoChains)[i]);
+		
+		std::vector<void*> overlapChains;
+		index->query( queryChain->getEnvelope(), overlapChains);
+
+		for (size_t j = 0, nj = overlapChains.size(); j < nj; j++)
+		{
+			MonotoneChain * testChain = (MonotoneChain *)(overlapChains[j]);
+
+			queryChain->computeOverlaps( testChain, &overlapAction);
+			nOverlaps++;
+			if (segInt->isDone()) 
+				return;
+		}
+	}
+}
+
+void 
+MCIndexSegmentSetMutualIntersector::addToMonoChains( SegmentString * segStr)
+{
+	std::vector<MonotoneChain *> * segChains; 
+	segChains = MonotoneChainBuilder::getChains( segStr->getCoordinates(), segStr);
+
+	for (size_t i = 0, ni = segChains->size(); i < ni; i++)
+	{
+		MonotoneChain * mc = (*segChains)[ i ];
+		mc->setId( processCounter++ );
+		monoChains->push_back( mc);
+	}
+
+	delete segChains;
+}
+
+//
+// public:
+//
+
+MCIndexSegmentSetMutualIntersector::MCIndexSegmentSetMutualIntersector() 
+:	monoChains( new std::vector<index::chain::MonotoneChain *>()),
+	index(new geos::index::strtree::STRtree()),
+	indexCounter(0),
+	processCounter(0),
+	nOverlaps(0)
+{ }
+
+MCIndexSegmentSetMutualIntersector::~MCIndexSegmentSetMutualIntersector() 
+{
+	delete index;
+	for ( int i = 0, ni = monoChains->size(); i < ni; i++ )
+		delete (*monoChains)[ i ];
+	delete monoChains;
+}
+
+void 
+MCIndexSegmentSetMutualIntersector::setBaseSegments( SegmentString::ConstVect * segStrings)
+{
+	for (size_t i=0, n=segStrings->size(); i<n; i++)
+	{
+		SegmentString * ss = (SegmentString *)((*segStrings)[i]);
+		addToIndex( ss);
+	}
+}
+
+void 
+MCIndexSegmentSetMutualIntersector::process( SegmentString::ConstVect * segStrings)
+{
+	processCounter = indexCounter + 1;
+	nOverlaps = 0;
+	monoChains->clear();
+
+	for (size_t i=0, n=segStrings->size(); i<n; i++)
+	{
+		SegmentString * seg = (SegmentString *)((*segStrings)[i]);
+		addToMonoChains( seg);
+	}
+	intersectChains();
+}
+
+
+void 
+MCIndexSegmentSetMutualIntersector::SegmentOverlapAction::overlap( MonotoneChain * mc1, int start1, MonotoneChain * mc2, int start2)
+{
+	SegmentString * ss1 = (SegmentString *)(mc1->getContext());
+	SegmentString * ss2 = (SegmentString *)(mc2->getContext());
+
+	si.processIntersections(ss1, start1, ss2, start2);
+}
+
+
+} // geos::noding
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/


Property changes on: trunk/source/noding/MCIndexSegmentSetMutualIntersector.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/source/noding/NodedSegmentString.cpp
===================================================================
--- trunk/source/noding/NodedSegmentString.cpp	                        (rev 0)
+++ trunk/source/noding/NodedSegmentString.cpp	2007-12-21 20:41:50 UTC (rev 2065)
@@ -0,0 +1,28 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions 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.
+ *
+ **********************************************************************/
+
+
+#include <geos/noding/NodedSegmentString.h>
+
+namespace geos {
+namespace noding { // geos::noding
+
+} // geos::noding
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/


Property changes on: trunk/source/noding/NodedSegmentString.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/source/noding/SegmentIntersectionDetector.cpp
===================================================================
--- trunk/source/noding/SegmentIntersectionDetector.cpp	                        (rev 0)
+++ trunk/source/noding/SegmentIntersectionDetector.cpp	2007-12-21 20:41:50 UTC (rev 2065)
@@ -0,0 +1,85 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions 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.
+ *
+ **********************************************************************/
+
+
+#include <geos/noding/SegmentIntersectionDetector.h>
+#include <geos/noding/SegmentIntersector.h>
+#include <geos/algorithm/LineIntersector.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateArraySequence.h>
+#include <geos/noding/SegmentString.h>
+
+
+namespace geos {
+namespace noding { // geos::noding
+
+void 
+SegmentIntersectionDetector::processIntersections(	
+	noding::SegmentString * e0, int segIndex0,
+	noding::SegmentString * e1, int segIndex1 )
+{  	
+	// don't bother intersecting a segment with itself
+	if (e0 == e1 && segIndex0 == segIndex1) return;
+
+	const geom::Coordinate & p00 = (*e0->getCoordinates())[ segIndex0 ];
+	const geom::Coordinate & p01 = (*e0->getCoordinates())[ segIndex0 + 1 ];
+	const geom::Coordinate & p10 = (*e1->getCoordinates())[ segIndex1 ];
+	const geom::Coordinate & p11 = (*e1->getCoordinates())[ segIndex1 + 1 ];
+
+	li->computeIntersection( p00, p01, p10, p11);
+
+	if (li->hasIntersection()) 
+	{
+		// record intersection info
+		_hasIntersection = true;
+
+		bool isProper = li->isProper();
+
+		if (isProper)
+			_hasProperIntersection = true;
+		else
+			_hasNonProperIntersection = true;
+
+		// If this is the kind of intersection we are searching for
+		// OR no location has yet been recorded
+		// save the location data
+		bool saveLocation = true;
+		
+		if (findProper && !isProper) 
+			saveLocation = false;
+
+		if (!intPt || saveLocation) 
+		{
+			// record intersection location (approximate)
+			intPt = &li->getIntersection(0);
+
+			// record intersecting segments
+			intSegments = new geom::CoordinateArraySequence();
+			intSegments->add( p00, true);
+			intSegments->add( p01, true);
+			intSegments->add( p10, true);
+			intSegments->add( p11, true);
+		}
+	}
+}
+  
+
+} // geos::noding
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/


Property changes on: trunk/source/noding/SegmentIntersectionDetector.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/source/noding/SegmentStringUtil.cpp
===================================================================
--- trunk/source/noding/SegmentStringUtil.cpp	                        (rev 0)
+++ trunk/source/noding/SegmentStringUtil.cpp	2007-12-21 20:41:50 UTC (rev 2065)
@@ -0,0 +1,28 @@
+/**********************************************************************
+ * $Id:
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2001-2002 Vivid Solutions 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.
+ *
+ **********************************************************************/
+
+
+#include <geos/noding/SegmentStringUtil.h>
+
+namespace geos {
+namespace noding { // geos::noding
+
+} // geos::noding
+} // geos
+
+/**********************************************************************
+ * $Log$
+ *
+ **********************************************************************/


Property changes on: trunk/source/noding/SegmentStringUtil.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the geos-commits mailing list