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

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


Author: strk
Date: 2009-11-19 14:06:53 -0500 (Thu, 19 Nov 2009)
New Revision: 2725

Modified:
   trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h
   trunk/source/operation/polygonize/PolygonizeGraph.cpp
Log:
Do not heap-allocate vector of Node when finding intersections


Modified: trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h
===================================================================
--- trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h	2009-11-19 18:52:45 UTC (rev 2724)
+++ trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h	2009-11-19 19:06:53 UTC (rev 2725)
@@ -141,24 +141,25 @@
 	 *
 	 * @param ringEdges
 	 * 	the list of start edges for the edgeRings to convert.
+	 *
+	 * TODO: take ringEdges by ref
 	 */
 	void convertMaximalToMinimalEdgeRings(
 			std::vector<PolygonizeDirectedEdge*> *ringEdges);
 
 	/**
 	 * \brief
-	 * Finds all nodes in a maximal edgering which are self-intersection
-	 * nodes
+	 * Finds all nodes in a maximal edgering
+	 * which are self-intersection nodes
 	 *
 	 * @param startDE
 	 * @param label
-	 * @return the list of intersection nodes found,
-	 * or <code>null</code> if no intersection nodes were found.
-	 * Ownership of returned vector goes to caller.
+	 * @param intNodes : intersection nodes found will be pushed here
+	 *                   the vector won't be cleared before pushing.
 	 */
-	static std::vector<planargraph::Node*>* findIntersectionNodes(
-			PolygonizeDirectedEdge *startDE,
-			long label);
+	static void findIntersectionNodes( PolygonizeDirectedEdge *startDE,
+			long label, std::vector<planargraph::Node*>& intNodes
+);
 
 	/**
 	 * @param dirEdges a List of the DirectedEdges in the graph
@@ -195,11 +196,11 @@
 	EdgeRing* findEdgeRing(PolygonizeDirectedEdge *startDE);
 
 	/* Tese are for memory management */
-	std::vector<planargraph::Edge *>newEdges;
-	std::vector<planargraph::DirectedEdge *>newDirEdges;
-	std::vector<planargraph::Node *>newNodes;
-	std::vector<EdgeRing *>newEdgeRings;
-	std::vector<geom::CoordinateSequence *>newCoords;
+	std::vector<planargraph::Edge *> newEdges;
+	std::vector<planargraph::DirectedEdge *> newDirEdges;
+	std::vector<planargraph::Node *> newNodes;
+	std::vector<EdgeRing *> newEdgeRings;
+	std::vector<geom::CoordinateSequence *> newCoords;
 };
 
 } // namespace geos::operation::polygonize

Modified: trunk/source/operation/polygonize/PolygonizeGraph.cpp
===================================================================
--- trunk/source/operation/polygonize/PolygonizeGraph.cpp	2009-11-19 18:52:45 UTC (rev 2724)
+++ trunk/source/operation/polygonize/PolygonizeGraph.cpp	2009-11-19 19:06:53 UTC (rev 2725)
@@ -168,61 +168,49 @@
 	delete pns;
 }
 
-/*
- * Convert the maximal edge rings found by the initial graph traversal
- * into the minimal edge rings required by JTS polygon topology rules.
- *
- * @param ringEdges the list of start edges for the edgeRings to convert.
- */
+/* private */
 void
-PolygonizeGraph::convertMaximalToMinimalEdgeRings(std::vector<PolygonizeDirectedEdge*> *ringEdges)
+PolygonizeGraph::convertMaximalToMinimalEdgeRings(
+		std::vector<PolygonizeDirectedEdge*> *ringEdges)
 {
-	for(int i=0;i<(int)ringEdges->size();i++)
+	typedef std::vector<Node*> IntersectionNodes;
+	typedef std::vector<PolygonizeDirectedEdge*> RingEdges;
+
+	IntersectionNodes intNodes;
+	for(RingEdges::size_type i=0, in=ringEdges->size();
+			i<in; ++i)
 	{
 		PolygonizeDirectedEdge *de=(*ringEdges)[i];
 		long label=de->getLabel();
-		std::vector<Node*> *intNodes=findIntersectionNodes(de, label);
-		if (intNodes==NULL) continue;
+		findIntersectionNodes(de, label, intNodes);
 
-		// flip the next pointers on the intersection nodes to
-		// create minimal edge rings
-		//std::vector<Node*> *pns=getNodes();
-
 		// set the next pointers for the edges around each node
-		for(int j=0;j<(int)intNodes->size();j++) {
-			Node *node=(*intNodes)[j];
+		for(IntersectionNodes::size_type j=0, jn=intNodes.size();
+				j<jn; ++j)
+		{
+			Node *node=intNodes[j];
 			computeNextCCWEdges(node, label);
 		}
 
-		delete intNodes;
+		intNodes.clear(); 
 	}
 }
 
-/*
- * Finds all nodes in a maximal edgering which are self-intersection nodes
- * @param startDE
- * @param label
- * @return the list of intersection nodes found,
- * or <code>NULL</code> if no intersection nodes were found.
- * Ownership of returned object goes to caller.
- */
-std::vector<Node*>*
-PolygonizeGraph::findIntersectionNodes(PolygonizeDirectedEdge *startDE, long label)
+/* private static */
+void
+PolygonizeGraph::findIntersectionNodes(PolygonizeDirectedEdge *startDE,
+		long label, std::vector<Node*>& intNodes)
 {
 	PolygonizeDirectedEdge *de=startDE;
-	std::vector<Node*> *intNodes=NULL;
 	do {
 		Node *node=de->getFromNode();
 		if (getDegree(node, label) > 1) {
-			if (intNodes==NULL)
-				intNodes=new std::vector<Node*>();
-			intNodes->push_back(node);
+			intNodes.push_back(node);
 		}
 		de=de->getNext();
 		assert(de!=NULL); // found NULL DE in ring
 		assert(de==startDE || !de->isInRing()); // found DE already in ring
 	} while (de!=startDE);
-	return intNodes;
 }
 
 /**



More information about the geos-commits mailing list