[geos-commits] r2727 - in trunk/source: headers/geos/operation/polygonize operation/polygonize

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Nov 19 14:31:44 EST 2009


Author: strk
Date: 2009-11-19 14:31:43 -0500 (Thu, 19 Nov 2009)
New Revision: 2727

Modified:
   trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h
   trunk/source/operation/polygonize/PolygonizeGraph.cpp
Log:
Don't force heap-allocation of vectors for finding/labeling edge rings 


Modified: trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h
===================================================================
--- trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h	2009-11-19 19:19:39 UTC (rev 2726)
+++ trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h	2009-11-19 19:31:43 UTC (rev 2727)
@@ -143,10 +143,9 @@
 	 * @param ringEdges
 	 * 	the list of start edges for the edgeRings to convert.
 	 *
-	 * TODO: take ringEdges by ref
 	 */
 	void convertMaximalToMinimalEdgeRings(
-			std::vector<PolygonizeDirectedEdge*> *ringEdges);
+			std::vector<PolygonizeDirectedEdge*> &ringEdges);
 
 	/**
 	 * \brief
@@ -163,11 +162,17 @@
 );
 
 	/**
-	 * @param dirEdges a List of the DirectedEdges in the graph
-	 * @return a List of DirectedEdges, one for each edge ring found
+	 * Finds and labels all edgerings in the graph.
+	 *
+	 * The edge rings are labelling with unique integers.
+	 * The labelling allows detecting cut edges.
+	 *
+	 * @param dirEdgesIn  a list of the DirectedEdges in the graph
+	 * @param dirEdgesOut each ring found will be pushed here
 	 */
-	static std::vector<PolygonizeDirectedEdge*>* findLabeledEdgeRings(
-			std::vector<planargraph::DirectedEdge*> &dirEdges);
+	static void findLabeledEdgeRings(
+			std::vector<planargraph::DirectedEdge*> &dirEdgesIn,
+			std::vector<PolygonizeDirectedEdge*> &dirEdgesOut);
 
 	static void label(std::vector<planargraph::DirectedEdge*> &dirEdges, long label);
 

Modified: trunk/source/operation/polygonize/PolygonizeGraph.cpp
===================================================================
--- trunk/source/operation/polygonize/PolygonizeGraph.cpp	2009-11-19 19:19:39 UTC (rev 2726)
+++ trunk/source/operation/polygonize/PolygonizeGraph.cpp	2009-11-19 19:31:43 UTC (rev 2727)
@@ -171,16 +171,16 @@
 /* private */
 void
 PolygonizeGraph::convertMaximalToMinimalEdgeRings(
-		std::vector<PolygonizeDirectedEdge*> *ringEdges)
+		std::vector<PolygonizeDirectedEdge*> &ringEdges)
 {
 	typedef std::vector<Node*> IntersectionNodes;
 	typedef std::vector<PolygonizeDirectedEdge*> RingEdges;
 
 	IntersectionNodes intNodes;
-	for(RingEdges::size_type i=0, in=ringEdges->size();
+	for(RingEdges::size_type i=0, in=ringEdges.size();
 			i<in; ++i)
 	{
-		PolygonizeDirectedEdge *de=(*ringEdges)[i];
+		PolygonizeDirectedEdge *de = ringEdges[i];
 		long label=de->getLabel();
 		findIntersectionNodes(de, label, intNodes);
 
@@ -224,9 +224,10 @@
 
 	// clear labels of all edges in graph
 	label(dirEdges, -1);
-	std::vector<PolygonizeDirectedEdge*> *maximalRings=findLabeledEdgeRings(dirEdges);
+	std::vector<PolygonizeDirectedEdge*> maximalRings;
+	findLabeledEdgeRings(dirEdges, maximalRings);
 	convertMaximalToMinimalEdgeRings(maximalRings);
-	delete maximalRings;
+	maximalRings.clear(); // not needed anymore
 
 	// find all edgerings
 	for(unsigned int i=0; i<dirEdges.size(); ++i)
@@ -239,15 +240,11 @@
 	}
 }
 
-/**
-*
-* @param dirEdges a List of the DirectedEdges in the graph
-* @return a List of DirectedEdges, one for each edge ring found
-*/
-std::vector<PolygonizeDirectedEdge*>*
-PolygonizeGraph::findLabeledEdgeRings(std::vector<DirectedEdge*> &dirEdges)
+/* static private */
+void
+PolygonizeGraph::findLabeledEdgeRings(std::vector<DirectedEdge*> &dirEdges,
+		std::vector<PolygonizeDirectedEdge*> &edgeRingStarts)
 {
-	std::vector<PolygonizeDirectedEdge*> *edgeRingStarts=new std::vector<PolygonizeDirectedEdge*>();
 	// label the edge rings formed
 	long currLabel=1;
 	for(unsigned int i=0; i<dirEdges.size(); ++i)
@@ -255,13 +252,12 @@
 		PolygonizeDirectedEdge *de=(PolygonizeDirectedEdge*)dirEdges[i];
 		if (de->isMarked()) continue;
 		if (de->getLabel() >= 0) continue;
-		edgeRingStarts->push_back(de);
+		edgeRingStarts.push_back(de);
 		std::vector<DirectedEdge*> *edges=findDirEdgesInRing(de);
 		label(*edges, currLabel);
 		delete edges;
 		++currLabel;
 	}
-	return edgeRingStarts;
 }
 
 /*
@@ -274,7 +270,9 @@
 	computeNextCWEdges();
 
 	// label the current set of edgerings
-	delete findLabeledEdgeRings(dirEdges);
+	std::vector<PolygonizeDirectedEdge*> junk;
+	findLabeledEdgeRings(dirEdges, junk);
+	junk.clear(); // not needed anymore
 
 	/*
 	 * Cut Edges are edges where both dirEdges have the same label.



More information about the geos-commits mailing list