[geos-commits] r2058 - trunk/source/headers/geos/noding

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Dec 21 15:34:33 EST 2007


Author: benjubb
Date: 2007-12-21 15:34:32 -0500 (Fri, 21 Dec 2007)
New Revision: 2058

Added:
   trunk/source/headers/geos/noding/FastSegmentSetIntersectionFinder.h
   trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h
   trunk/source/headers/geos/noding/NodableSegmentString.h
   trunk/source/headers/geos/noding/NodedSegmentString.h
   trunk/source/headers/geos/noding/SegmentIntersectionDetector.h
   trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h
   trunk/source/headers/geos/noding/SegmentStringUtil.h
Log:
Added from JTS 1.9 to support prepared geometry 

Added: trunk/source/headers/geos/noding/FastSegmentSetIntersectionFinder.h
===================================================================
--- trunk/source/headers/geos/noding/FastSegmentSetIntersectionFinder.h	                        (rev 0)
+++ trunk/source/headers/geos/noding/FastSegmentSetIntersectionFinder.h	2007-12-21 20:34:32 UTC (rev 2058)
@@ -0,0 +1,72 @@
+/**********************************************************************
+ * $Id
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * 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.
+ *
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_FASTSEGMENTSETINTERSECTIONFINDER_H
+#define GEOS_NODING_FASTSEGMENTSETINTERSECTIONFINDER_H
+
+#include <geos/noding/SegmentString.h>
+#include <geos/noding/MCIndexSegmentSetMutualIntersector.h>
+
+
+//forward declarations
+namespace geos {
+	namespace noding { 
+		class SegmentIntersectionDetector;
+		class SegmentSetMutualIntersector;
+		//class MCIndexSegmentSetMutualIntersector : public SegmentSetMutualIntersector;
+	}
+}
+
+
+namespace geos {
+namespace noding { // geos::noding
+
+class FastSegmentSetIntersectionFinder
+{
+private:
+	MCIndexSegmentSetMutualIntersector * segSetMutInt; 
+	geos::algorithm::LineIntersector * lineIntersector;
+
+protected:
+public:
+	FastSegmentSetIntersectionFinder( SegmentString::ConstVect * baseSegStrings);
+
+	~FastSegmentSetIntersectionFinder();
+	
+	/**
+	 * Gets the segment set intersector used by this class.
+	 * This allows other uses of the same underlying indexed structure.
+	 * 
+	 * @return the segment set intersector used
+	 */
+	SegmentSetMutualIntersector * getSegmentSetIntersector()
+	{
+		return segSetMutInt;
+	}
+
+	bool intersects( SegmentString::ConstVect * segStrings);
+	bool intersects( SegmentString::ConstVect * segStrings, SegmentIntersectionDetector * intDetector);
+
+};
+
+} // geos::noding
+} // geos
+
+#endif // GEOS_NODING_FASTSEGMENTSETINTERSECTIONFINDER_H
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+


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

Added: trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h
===================================================================
--- trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h	                        (rev 0)
+++ trunk/source/headers/geos/noding/MCIndexSegmentSetMutualIntersector.h	2007-12-21 20:34:32 UTC (rev 2058)
@@ -0,0 +1,113 @@
+/**********************************************************************
+ * $Id
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * 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.
+ *
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_MCINDEXSEGMENTSETMUTUALINTERSECTOR_H
+#define GEOS_NODING_MCINDEXSEGMENTSETMUTUALINTERSECTOR_H
+
+#include <geos/noding/SegmentSetMutualIntersector.h> // inherited
+//#include <geos/noding/SegmentString.h>
+//#include <geos/noding/SegmentIntersector.h>
+//#include <geos/index/SpatialIndex.h>
+//#include <geos/index/strtree/STRtree.h> // for constructor
+//#include <geos/index/chain/MonotoneChain.h>
+#include <geos/index/chain/MonotoneChainOverlapAction.h> // inherited
+
+namespace geos {
+	namespace index {
+		class SpatialIndex;
+
+		namespace chain {
+			class MonotoneChain;
+		}
+		namespace strtree {
+			//class STRtree;
+		}
+	}
+	namespace noding {
+		class SegmentString;
+		class SegmentIntersector;
+	}
+}
+
+//using namespace geos::index::strtree;
+
+namespace geos {
+namespace noding { // geos::noding
+
+class MCIndexSegmentSetMutualIntersector : public SegmentSetMutualIntersector 
+{
+private:
+	std::vector<index::chain::MonotoneChain *> * monoChains;
+	/*
+	 * The {@link SpatialIndex} used should be something that supports
+	 * envelope (range) queries efficiently (such as a {@link Quadtree}
+	 * or {@link STRtree}.
+	 */
+	index::SpatialIndex * index;
+	int indexCounter;
+	int processCounter;
+	// statistics
+	int nOverlaps;
+
+	void addToIndex( SegmentString * segStr);
+
+	void intersectChains();
+
+	void addToMonoChains( SegmentString * segStr);
+
+protected:
+public:
+	MCIndexSegmentSetMutualIntersector();
+
+	~MCIndexSegmentSetMutualIntersector();
+
+	std::vector<index::chain::MonotoneChain *> * getMonotoneChains() 
+	{ 
+		return monoChains; 
+	}
+
+	index::SpatialIndex * getIndex() 
+	{ 
+		return index; 
+	}
+
+	void setBaseSegments( SegmentString::ConstVect * segStrings);
+  
+	void process( SegmentString::ConstVect * segStrings);
+
+
+	class SegmentOverlapAction : public index::chain::MonotoneChainOverlapAction
+	{
+	private:
+		SegmentIntersector & si;
+
+	public:
+		SegmentOverlapAction( SegmentIntersector & si) : si(si)
+		{ }
+
+		void overlap( index::chain::MonotoneChain * mc1, int start1, index::chain::MonotoneChain * mc2, int start2);
+	};
+
+};
+
+} // namespace geos::noding
+} // namespace geos
+
+#endif // GEOS_NODING_MCINDEXSEGMENTSETMUTUALINTERSECTOR_H
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+


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

Added: trunk/source/headers/geos/noding/NodableSegmentString.h
===================================================================
--- trunk/source/headers/geos/noding/NodableSegmentString.h	                        (rev 0)
+++ trunk/source/headers/geos/noding/NodableSegmentString.h	2007-12-21 20:34:32 UTC (rev 2058)
@@ -0,0 +1,62 @@
+/**********************************************************************
+ * $Id
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * 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.
+ *
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_NODABLESEGMENTSTRING_H
+#define GEOS_NODING_NODABLESEGMENTSTRING_H
+
+#include <geos/noding/SegmentString.h>
+
+namespace geos {
+	namespace geom {
+		class Coordinate;
+	}
+}
+
+namespace geos {
+namespace noding { // geos::noding
+
+/**
+ * An interface for classes which support adding nodes to
+ * a segment string.
+ * 
+ * @author Martin Davis
+ */
+class NodableSegmentString : public SegmentString 
+{
+private:
+protected:
+public:
+	NodableSegmentString( geom::CoordinateSequence *newPts, const void* newContext)
+		: SegmentString( newPts, newContext ) 
+	{ }
+
+	/**
+	 * Adds an intersection node for a given point and segment to this segment string.
+	 * 
+	 * @param intPt the location of the intersection
+	 * @param segmentIndex the index of the segment containing the intersection
+	 */
+	//virtual void addIntersection( const geom::Coordinate * intPt, int segmentIndex) =0;
+};
+
+} // namespace geos::noding
+} // namespace geos
+
+#endif // GEOS_NODING_NODABLESEGMENTSTRING_H
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+


Property changes on: trunk/source/headers/geos/noding/NodableSegmentString.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/source/headers/geos/noding/NodedSegmentString.h
===================================================================
--- trunk/source/headers/geos/noding/NodedSegmentString.h	                        (rev 0)
+++ trunk/source/headers/geos/noding/NodedSegmentString.h	2007-12-21 20:34:32 UTC (rev 2058)
@@ -0,0 +1,101 @@
+/**********************************************************************
+ * $Id
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * 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.
+ *
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_NODEDSEGMENTSTRING_H
+#define GEOS_NODING_NODEDSEGMENTSTRING_H
+
+#include <geos/algorithm/LineIntersector.h>
+#include <geos/noding/NodableSegmentString.h>
+#include <geos/noding/SegmentNode.h>
+#include <geos/noding/SegmentNodeList.h>
+#include <geos/noding/SegmentString.h>
+//#include <geos/noding/Octant.h>
+#include <geos/geom/Coordinate.h>
+
+//using namespace 
+
+namespace geos {
+namespace noding { // geos::noding
+
+class NodedSegmentString : public NodableSegmentString 
+{
+private:
+protected:
+public:
+	static void getNodedSubstrings( SegmentString::ConstVect * segStrings, SegmentString::NonConstVect * resultEdgelist)
+	{
+		for (size_t i=0, n=segStrings->size(); i<n; i++)
+		{
+			NodedSegmentString * nss = (NodedSegmentString *)((*segStrings)[i]);
+			nss->getNodeList().addSplitEdges( resultEdgelist);
+		}
+	}
+
+	/**
+	 * Creates a new segment string from a list of vertices.
+	 *
+	 * @param pts the vertices of the segment string
+	 * @param data the user-defined data of this segment string (may be null)
+	 */
+	NodedSegmentString( geom::CoordinateSequence *newPts, const void* newContext)
+		: NodableSegmentString( newPts, newContext ) 
+	{ }
+
+	~NodedSegmentString()
+	{ }
+
+	/**
+	 * Adds an intersection node for a given point and segment to this segment string.
+	 * If an intersection already exists for this exact location, the existing
+	 * node will be returned.
+	 * 
+	 * @param intPt the location of the intersection
+	 * @param segmentIndex the index of the segment containing the intersection
+	 * @return the intersection node for the point
+	 */
+	SegmentNode * addIntersectionNode( geom::Coordinate * intPt, int segmentIndex) 
+	{
+		int normalizedSegmentIndex = segmentIndex;
+
+		// normalize the intersection point location
+		int nextSegIndex = normalizedSegmentIndex + 1;
+		if (nextSegIndex < size()) 
+		{
+			const geom::Coordinate &nextPt = getCoordinate( nextSegIndex);
+
+			// Normalize segment index if intPt falls on vertex
+			// The check for point equality is 2D only - Z values are ignored
+			if ( intPt->equals2D( nextPt )) 
+			{
+				normalizedSegmentIndex = nextSegIndex;
+			}
+		}
+
+		// Add the intersection point to edge intersection list.
+		SegmentNode * ei = getNodeList().add( *intPt, normalizedSegmentIndex);
+		return ei;
+	}
+
+};
+
+} // namespace geos::noding
+} // namespace geos
+
+#endif // GEOS_NODING_NODEDSEGMENTSTRING_H
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+


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

Added: trunk/source/headers/geos/noding/SegmentIntersectionDetector.h
===================================================================
--- trunk/source/headers/geos/noding/SegmentIntersectionDetector.h	                        (rev 0)
+++ trunk/source/headers/geos/noding/SegmentIntersectionDetector.h	2007-12-21 20:34:32 UTC (rev 2058)
@@ -0,0 +1,156 @@
+/**********************************************************************
+ * $Id
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * 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.
+ *
+ *
+ **********************************************************************/
+
+#ifndef GEOS_GEOM_PREP_SEGMENTINTERSECTIONDETECTOR_H
+#define GEOS_GEOM_PREP_SEGMENTINTERSECTIONDETECTOR_H
+
+#include <geos/noding/SegmentIntersector.h>
+#include <geos/algorithm/LineIntersector.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/noding/SegmentString.h>
+
+using namespace geos::algorithm;
+
+namespace geos {
+namespace noding { // geos::noding
+
+class SegmentIntersectionDetector : public SegmentIntersector 
+{
+private:
+	LineIntersector * li;
+
+	bool findProper;
+	bool findAllTypes;
+
+	bool _hasIntersection;
+	bool _hasProperIntersection;
+	bool _hasNonProperIntersection;
+
+	const geom::Coordinate * intPt;
+	geom::CoordinateSequence * intSegments;
+
+protected:
+public:
+	SegmentIntersectionDetector( LineIntersector * li) 
+		:
+		li( li),
+		findProper(false),
+		findAllTypes(false),
+		_hasIntersection(false),
+		_hasProperIntersection(false),
+		_hasNonProperIntersection(false),
+		intPt( NULL),
+		intSegments( NULL)
+	{ }
+
+	void setFindProper( bool findProper)
+	{
+		this->findProper = findProper;
+	}
+  
+	void setFindAllIntersectionTypes( bool findAllTypes)
+	{
+		this->findAllTypes = findAllTypes;
+	}
+  
+	/**
+	 * Tests whether an intersection was found.
+	 * 
+	 * @return true if an intersection was found
+	 */
+	bool hasIntersection() const
+	{ 
+		return _hasIntersection; 
+	}
+  
+	/**
+	 * Tests whether a proper intersection was found.
+	 * 
+	 * @return true if a proper intersection was found
+	 */
+	bool hasProperIntersection() const 
+	{ 
+		return _hasProperIntersection; 
+	}
+  
+	/**
+	 * Tests whether a non-proper intersection was found.
+	 * 
+	 * @return true if a non-proper intersection was found
+	 */
+	bool hasNonProperIntersection() const
+	{ 
+		return _hasNonProperIntersection; 
+	}
+  
+	/**
+	* Gets the computed location of the intersection.
+	* Due to round-off, the location may not be exact.
+	* 
+	* @return the coordinate for the intersection location
+	*/
+	const geom::Coordinate * const getIntersection()  const
+	{    
+		return intPt;  
+	}
+
+
+	/**
+	 * Gets the endpoints of the intersecting segments.
+	 * 
+	 * @return an array of the segment endpoints (p00, p01, p10, p11)
+	 */
+	const geom::CoordinateSequence * getIntersectionSegments() const
+	{
+		return intSegments;
+	}
+  
+	bool isDone() const
+	{ 
+		// If finding all types, we can stop
+		// when both possible types have been found.
+		if (findAllTypes)
+			return _hasProperIntersection && _hasNonProperIntersection;
+
+		// If searching for a proper intersection, only stop if one is found
+		if (findProper)
+			return _hasProperIntersection;
+
+		return _hasIntersection;
+	}
+
+	/**
+	 * This method is called by clients
+	 * of the {@link SegmentIntersector} class to process
+	 * intersections for two segments of the {@link SegmentStrings} being intersected.
+	 * Note that some clients (such as {@link MonotoneChain}s) may optimize away
+	 * this call for segment pairs which they have determined do not intersect
+	 * (e.g. by an disjoint envelope test).
+	 */
+	void processIntersections(	noding::SegmentString * e0, int segIndex0,
+								noding::SegmentString * e1, int segIndex1 );
+  
+};
+
+} // namespace geos::noding
+} // namespace geos
+
+#endif // GEOS_GEOM_PREP_SEGMENTINTERSECTIONDETECTOR_H
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+


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

Added: trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h
===================================================================
--- trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h	                        (rev 0)
+++ trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h	2007-12-21 20:34:32 UTC (rev 2058)
@@ -0,0 +1,74 @@
+/**********************************************************************
+ * $Id
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * 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.
+ *
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_SEGMENTSETMUTUALINTERSECTOR_H
+#define GEOS_NODING_SEGMENTSETMUTUALINTERSECTOR_H
+
+#include <geos/noding/SegmentString.h>
+#include <geos/noding/SegmentIntersector.h>
+
+namespace geos {
+namespace noding { // geos::noding
+
+class SegmentSetMutualIntersector
+{
+private:
+protected:
+	SegmentIntersector * segInt;
+
+public:
+	SegmentSetMutualIntersector() 
+	:	segInt( NULL)
+	{ }
+
+	virtual ~SegmentSetMutualIntersector() 
+	{ }
+
+	/**
+	 * Sets the {@link SegmentIntersector} to use with this intersector.
+	 * The SegmentIntersector will either rocord or add intersection nodes
+	 * for the input segment strings.
+	 *
+	 * @param segInt the segment intersector to use
+	 */
+	void setSegmentIntersector( SegmentIntersector * si)
+	{
+		segInt = si;
+	}
+
+	/**
+	 * 
+	 * @param segStrings0 a collection of {@link SegmentString}s to node
+	 */
+	virtual void setBaseSegments( SegmentString::ConstVect * segStrings) =0; 
+
+	/**
+	 * Computes the intersections for two collections of {@link SegmentString}s.
+	 *
+	 * @param segStrings1 a collection of {@link SegmentString}s to node
+	 */
+	virtual void process( SegmentString::ConstVect * segStrings) =0;
+
+};
+
+} // geos::noding
+} // geos
+
+#endif // GEOS_NODING_SEGMENTSETMUTUALINTERSECTOR_H
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+


Property changes on: trunk/source/headers/geos/noding/SegmentSetMutualIntersector.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/source/headers/geos/noding/SegmentStringUtil.h
===================================================================
--- trunk/source/headers/geos/noding/SegmentStringUtil.h	                        (rev 0)
+++ trunk/source/headers/geos/noding/SegmentStringUtil.h	2007-12-21 20:34:32 UTC (rev 2058)
@@ -0,0 +1,65 @@
+/**********************************************************************
+ * $Id
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * 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.
+ *
+ *
+ **********************************************************************/
+
+#ifndef GEOS_NODING_SEGMENTSTRINGUTIL_H
+#define GEOS_NODING_SEGMENTSTRINGUTIL_H
+
+#include <geos/noding/NodedSegmentString.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/util/LinearComponentExtracter.h>
+
+namespace geos {
+namespace noding { // geos::noding
+
+class SegmentStringUtil
+{
+private:
+protected:
+public:
+	/**
+	 * Extracts all linear components from a given {@link Geometry}
+	 * to {@link SegmentString}s.
+	 * The SegmentString data item is set to be the source Geometry.
+	 * 
+	 * @param geom the geometry to extract from
+	 * @return a List of SegmentStrings
+	 */
+	static void extractSegmentStrings( const geom::Geometry * g, SegmentString::ConstVect & segStr)
+	{
+		geom::LineString::ConstVect lines;
+		geom::util::LinearComponentExtracter::getLines( *g, lines);
+
+		for (size_t i=0, n=lines.size(); i<n; i++)
+		{
+			geom::LineString * line = (geom::LineString *)(lines[i]);
+
+			geom::CoordinateSequence * pts = line->getCoordinates();
+
+			segStr.push_back( new NodedSegmentString( pts, g));
+		}
+	}
+
+};
+
+} // geos::noding
+} // geos
+
+#endif // GEOS_NODING_SEGMENTSTRINGUTIL_H
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+


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



More information about the geos-commits mailing list