[geos-commits] r2728 - in trunk/source:
headers/geos/operation/polygonize operation/polygonize
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Nov 19 14:57:37 EST 2009
Author: strk
Date: 2009-11-19 14:57:36 -0500 (Thu, 19 Nov 2009)
New Revision: 2728
Modified:
trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h
trunk/source/headers/geos/operation/polygonize/Polygonizer.h
trunk/source/operation/polygonize/PolygonizeGraph.cpp
trunk/source/operation/polygonize/Polygonizer.cpp
Log:
Move heap-allocation of vector used for 'cut-lines' containment out of PolygonizeGraph (but into Polygonizer)
Modified: trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h
===================================================================
--- trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h 2009-11-19 19:31:43 UTC (rev 2727)
+++ trunk/source/headers/geos/operation/polygonize/PolygonizeGraph.h 2009-11-19 19:57:36 UTC (rev 2728)
@@ -106,9 +106,12 @@
* \brief
* Finds and removes all cut edges from the graph.
*
- * @return a list of the LineString forming the removed cut edges
+ * @param cutLines : the list of the LineString forming the removed
+ * cut edges will be pushed here.
+ *
+ * TODO: document ownership of the returned LineStrings
*/
- std::vector<const geom::LineString*>* deleteCutEdges();
+ void deleteCutEdges(std::vector<const geom::LineString*> &cutLines);
/** \brief
* Marks all edges from the graph which are "dangles".
Modified: trunk/source/headers/geos/operation/polygonize/Polygonizer.h
===================================================================
--- trunk/source/headers/geos/operation/polygonize/Polygonizer.h 2009-11-19 19:31:43 UTC (rev 2727)
+++ trunk/source/headers/geos/operation/polygonize/Polygonizer.h 2009-11-19 19:57:36 UTC (rev 2728)
@@ -191,7 +191,9 @@
/** \brief
* Get the list of cut edges found during polygonization.
*
- * @return a collection of the input LineStrings which are cut edges
+ * @return a (possibly empty) reference to collection of the input
+ * LineStrings which are cut edges. Ownership retained by
+ * this object.
*/
std::vector<const geom::LineString*>* getCutEdges();
Modified: trunk/source/operation/polygonize/PolygonizeGraph.cpp
===================================================================
--- trunk/source/operation/polygonize/PolygonizeGraph.cpp 2009-11-19 19:31:43 UTC (rev 2727)
+++ trunk/source/operation/polygonize/PolygonizeGraph.cpp 2009-11-19 19:57:36 UTC (rev 2728)
@@ -35,6 +35,9 @@
using namespace geos::planargraph;
using namespace geos::geom;
+// Define the following to add assertions on downcasts
+//#define GEOS_CAST_PARANOIA 1
+
namespace geos {
namespace operation { // geos.operation
namespace polygonize { // geos.operation.polygonize
@@ -260,17 +263,16 @@
}
}
-/*
- * Finds and removes all cut edges from the graph.
- * @return a list of the LineString forming the removed cut edges
- */
-std::vector<const LineString*> *
-PolygonizeGraph::deleteCutEdges()
+/* public */
+void
+PolygonizeGraph::deleteCutEdges(std::vector<const LineString*> &cutLines)
{
computeNextCWEdges();
+ typedef std::vector<PolygonizeDirectedEdge*> DirEdges;
+
// label the current set of edgerings
- std::vector<PolygonizeDirectedEdge*> junk;
+ DirEdges junk;
findLabeledEdgeRings(dirEdges, junk);
junk.clear(); // not needed anymore
@@ -278,20 +280,39 @@
* Cut Edges are edges where both dirEdges have the same label.
* Delete them, and record them
*/
- std::vector<const LineString*> *cutLines=new std::vector<const LineString*>();
- for(unsigned int i=0; i<dirEdges.size(); ++i) {
- PolygonizeDirectedEdge *de=(PolygonizeDirectedEdge*)dirEdges[i];
+ for (DirEdges::size_type i=0, in=dirEdges.size(); i<in; ++i)
+ {
+ DirectedEdge *de_ = dirEdges[i];
+#ifdef GEOS_CAST_PARANOIA
+ assert(dynamic_cast<PolygonizeDirectedEdge*>(de_));
+#endif
+ PolygonizeDirectedEdge *de =
+ static_cast<PolygonizeDirectedEdge*>(de_);
+
if (de->isMarked()) continue;
- PolygonizeDirectedEdge *sym=(PolygonizeDirectedEdge*) de->getSym();
- if (de->getLabel()==sym->getLabel()) {
+
+ DirectedEdge *sym_ = de->getSym();
+#ifdef GEOS_CAST_PARANOIA
+ assert(dynamic_cast<PolygonizeDirectedEdge*>(sym_));
+#endif
+ PolygonizeDirectedEdge *sym =
+ static_cast<PolygonizeDirectedEdge*>(sym_);
+
+ if (de->getLabel()==sym->getLabel())
+ {
de->setMarked(true);
sym->setMarked(true);
+
// save the line as a cut edge
- PolygonizeEdge *e=(PolygonizeEdge*) de->getEdge();
- cutLines->push_back(e->getLine());
+ Edge *e_ = de->getEdge();
+#ifdef GEOS_CAST_PARANOIA
+ assert(dynamic_cast<PolygonizeEdge*>(e_));
+#endif
+ PolygonizeEdge *e = static_cast<PolygonizeEdge*>(e_);
+
+ cutLines.push_back(e->getLine());
}
}
- return cutLines;
}
void
Modified: trunk/source/operation/polygonize/Polygonizer.cpp
===================================================================
--- trunk/source/operation/polygonize/Polygonizer.cpp 2009-11-19 19:31:43 UTC (rev 2727)
+++ trunk/source/operation/polygonize/Polygonizer.cpp 2009-11-19 19:57:36 UTC (rev 2728)
@@ -235,7 +235,11 @@
if (graph==NULL) return;
dangles=graph->deleteDangles();
- cutEdges=graph->deleteCutEdges();
+
+ // TODO: drop this heap allocation
+ cutEdges = new std::vector<const LineString*>();
+ graph->deleteCutEdges(*cutEdges);
+
vector<EdgeRing*> edgeRingList;
graph->getEdgeRings(edgeRingList);
#if GEOS_DEBUG
More information about the geos-commits
mailing list