[geos-commits] r2731 - in trunk/source: headers/geos/operation/overlay headers/geos/operation/valid operation/overlay operation/valid

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Nov 19 16:06:16 EST 2009


Author: strk
Date: 2009-11-19 16:06:16 -0500 (Thu, 19 Nov 2009)
New Revision: 2731

Modified:
   trunk/source/headers/geos/operation/overlay/MaximalEdgeRing.h
   trunk/source/headers/geos/operation/valid/ConnectedInteriorTester.h
   trunk/source/operation/overlay/MaximalEdgeRing.cpp
   trunk/source/operation/valid/ConnectedInteriorTester.cpp
Log:
Don't force heap allocation when building edge rings for isValidOp

Modified: trunk/source/headers/geos/operation/overlay/MaximalEdgeRing.h
===================================================================
--- trunk/source/headers/geos/operation/overlay/MaximalEdgeRing.h	2009-11-19 20:29:01 UTC (rev 2730)
+++ trunk/source/headers/geos/operation/overlay/MaximalEdgeRing.h	2009-11-19 21:06:16 UTC (rev 2731)
@@ -82,6 +82,8 @@
 	/// This function returns a newly allocated vector of
 	/// pointers to newly allocated MinimalEdgeRing objects.
 	///
+	/// @deprecated pass the vector yourself instead
+	///
 	std::vector<MinimalEdgeRing*>* buildMinimalRings();
 
 	/// \brief
@@ -89,6 +91,7 @@
 	/// objects to the provided vector.
 	///
 	void buildMinimalRings(std::vector<MinimalEdgeRing*>& minEdgeRings);
+	void buildMinimalRings(std::vector<EdgeRing*>& minEdgeRings);
 
 	/// \brief
 	/// For all nodes in this EdgeRing,

Modified: trunk/source/headers/geos/operation/valid/ConnectedInteriorTester.h
===================================================================
--- trunk/source/headers/geos/operation/valid/ConnectedInteriorTester.h	2009-11-19 20:29:01 UTC (rev 2730)
+++ trunk/source/headers/geos/operation/valid/ConnectedInteriorTester.h	2009-11-19 21:06:16 UTC (rev 2731)
@@ -91,15 +91,18 @@
 
 	
 	/**
+	 * \brief
 	 * Form DirectedEdges in graph into Minimal EdgeRings.
-	 * (Minimal Edgerings must be used, because only they are guaranteed to provide
-	 * a correct isHole computation)
 	 *
-	 * The returned vector and its contents are allocated on the
-	 * heap; deletion responsibility is left to caller.
+	 * Minimal Edgerings must be used, because only they are
+	 * guaranteed to provide a correct isHole computation.
+	 *
+	 * @param minEdgeRings : newly allocated minimal edge rings will
+	 *                       be push_back'ed here.
+	 *                       deletion responsibility is left to caller.
 	 */
-	std::vector<geomgraph::EdgeRing*>* buildEdgeRings(
-			std::vector<geomgraph::EdgeEnd*> *dirEdges);
+	void buildEdgeRings(std::vector<geomgraph::EdgeEnd*> *dirEdges,
+	                    std::vector<geomgraph::EdgeRing*>& minEdgeRings);
 
 	/**
 	 * Mark all the edges for the edgeRings corresponding to the shells

Modified: trunk/source/operation/overlay/MaximalEdgeRing.cpp
===================================================================
--- trunk/source/operation/overlay/MaximalEdgeRing.cpp	2009-11-19 20:29:01 UTC (rev 2730)
+++ trunk/source/operation/overlay/MaximalEdgeRing.cpp	2009-11-19 21:06:16 UTC (rev 2731)
@@ -124,6 +124,20 @@
 	} while(de!=startDe);
 }
 
+/*public*/
+void
+MaximalEdgeRing::buildMinimalRings(vector<EdgeRing*>& minEdgeRings)
+{
+	DirectedEdge *de=startDe;
+	do {
+		if(de->getMinEdgeRing()==NULL) {
+			MinimalEdgeRing *minEr=new MinimalEdgeRing(de, geometryFactory);
+			minEdgeRings.push_back(minEr);
+		}
+		de=de->getNext();
+	} while(de!=startDe);
+}
+
 } // namespace geos.operation.overlay
 } // namespace geos.operation
 } // namespace geos

Modified: trunk/source/operation/valid/ConnectedInteriorTester.cpp
===================================================================
--- trunk/source/operation/valid/ConnectedInteriorTester.cpp	2009-11-19 20:29:01 UTC (rev 2730)
+++ trunk/source/operation/valid/ConnectedInteriorTester.cpp	2009-11-19 21:06:16 UTC (rev 2731)
@@ -53,6 +53,8 @@
 #define GEOS_DEBUG 0
 #endif
 
+//#define GEOS_CAST_PARANOIA 1
+
 #if GEOS_DEBUG
 #include <iostream>
 #endif
@@ -114,12 +116,11 @@
 	setInteriorEdgesInResult(graph);
 	graph.linkResultDirectedEdges();
 
-	// Someone has to delete the returned vector and its contents
-	std::vector<EdgeRing*>* edgeRings=buildEdgeRings(graph.getEdgeEnds());
-	assert(edgeRings);
+	std::vector<EdgeRing*> edgeRings;
+	buildEdgeRings(graph.getEdgeEnds(), edgeRings);
 
 #if GEOS_DEBUG
-	cerr << "buildEdgeRings constructed " << edgeRings->size() << " edgeRings." << endl;
+	cerr << "buildEdgeRings constructed " << edgeRings.size() << " edgeRings." << endl;
 #endif
 
 	/*
@@ -132,7 +133,7 @@
 	visitShellInteriors(geomGraph.getGeometry(), graph);
 
 #if GEOS_DEBUG
-	cerr << "after visitShellInteriors edgeRings are " << edgeRings->size() << " edgeRings." << endl;
+	cerr << "after visitShellInteriors edgeRings are " << edgeRings.size() << " edgeRings." << endl;
 #endif
 
 	/*
@@ -142,16 +143,15 @@
 	 * this means that one or more holes must have split the interior of the
 	 * polygon into at least two pieces.  The polygon is thus invalid.
 	 */
-	bool res=!hasUnvisitedShellEdge(edgeRings);
+	bool res=!hasUnvisitedShellEdge(&edgeRings);
 
-	assert(edgeRings);
 #if GEOS_DEBUG
-	cerr << "releasing " << edgeRings->size() << " edgeRings." << endl;
+	cerr << "releasing " << edgeRings.size() << " edgeRings." << endl;
 #endif
 	// Release memory allocated by buildEdgeRings
-	for(size_t i=0, n=edgeRings->size(); i<n; ++i)
+	for(size_t i=0, n=edgeRings.size(); i<n; ++i)
 	{
-		EdgeRing* er = (*edgeRings)[i];
+		EdgeRing* er = edgeRings[i];
 #if GEOS_DEBUG
 		cerr<<*er<<endl;
 #endif
@@ -161,7 +161,7 @@
 	cerr << "releasing edgeRing at " << er << endl;
 #endif
 	}
-	delete edgeRings;
+	edgeRings.clear();
 
 	// Release memory allocated by MaximalEdgeRings
 	// There should be no more references to this object
@@ -193,16 +193,22 @@
 }
 
 /*private*/
-std::vector<EdgeRing*>*
-ConnectedInteriorTester::buildEdgeRings(std::vector<EdgeEnd*> *dirEdges)
+void
+ConnectedInteriorTester::buildEdgeRings(std::vector<EdgeEnd*> *dirEdges,
+                                        std::vector<EdgeRing*>& minEdgeRings)
 {
 #if GEOS_DEBUG
 	cerr << __FUNCTION__ << " got " << dirEdges->size() << " EdgeEnd vector" << endl;
 #endif
-	std::vector<MinimalEdgeRing*> minEdgeRings;
-	for(size_t i=0, n=dirEdges->size(); i<n; ++i)
+
+	typedef std::vector<EdgeEnd*> EdgeEnds;
+
+	//std::vector<MinimalEdgeRing*> minEdgeRings;
+	for(EdgeEnds::size_type i=0, n=dirEdges->size(); i<n; ++i)
 	{
+#ifdef GEOS_CAST_PARANOIA 
 		assert(dynamic_cast<DirectedEdge*>((*dirEdges)[i]));
+#endif
 		DirectedEdge *de=static_cast<DirectedEdge*>((*dirEdges)[i]);
 
 #if GEOS_DEBUG
@@ -212,10 +218,8 @@
 		// if this edge has not yet been processed
 		if(de->isInResult() && de->getEdgeRing()==NULL)
 		{
-			//EdgeRing *er=new MaximalEdgeRing(de,geometryFactory);
-			//edgeRings->push_back(er);
-
-			MaximalEdgeRing* er=new MaximalEdgeRing(de, geometryFactory);
+			MaximalEdgeRing* er = new MaximalEdgeRing(de,
+			                                   geometryFactory);
 			// We track MaximalEdgeRings allocations
 			// using the private maximalEdgeRings vector
 			maximalEdgeRings.push_back(er);
@@ -224,9 +228,11 @@
 			er->buildMinimalRings(minEdgeRings);
 		}
 	}
+/*
 	std::vector<EdgeRing*> *edgeRings=new std::vector<EdgeRing*>();
 	edgeRings->assign(minEdgeRings.begin(), minEdgeRings.end());
 	return edgeRings;
+*/
 }
 
 /**



More information about the geos-commits mailing list