[geos-commits] r3983 - in trunk: capi include/geos/triangulate include/geos/triangulate/quadedge src/triangulate src/triangulate/quadedge tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Wed May 21 07:21:02 PDT 2014


Author: strk
Date: 2014-05-21 07:21:02 -0700 (Wed, 21 May 2014)
New Revision: 3983

Modified:
   trunk/capi/geos_ts_c.cpp
   trunk/include/geos/triangulate/VoronoiDiagramBuilder.h
   trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h
   trunk/src/triangulate/VoronoiDiagramBuilder.cpp
   trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
   trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp
Log:
Fix GEOSVoronoiDiagram on requesting edges only

Before this fix asking for edges would return the edges of
the triangle used as abase for the Voronoi diagram.
After, we return the actual voronoi cell edges.

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2014-05-08 09:50:43 UTC (rev 3982)
+++ trunk/capi/geos_ts_c.cpp	2014-05-21 14:21:02 UTC (rev 3983)
@@ -6234,8 +6234,8 @@
 		VoronoiDiagramBuilder builder;
 		builder.setSites(*g1);
 		builder.setTolerance(tolerance);
-		if(onlyEdges) return builder.getSubdivision()->getEdges(*g1->getFactory()).release();
-		else return builder.getDiagram(*(g1->getFactory())).release();
+		if(onlyEdges) return builder.getDiagramEdges(*g1->getFactory()).release();
+		else return builder.getDiagram(*g1->getFactory()).release();
 	}    
 	catch(const std::exception &e)
 	{    

Modified: trunk/include/geos/triangulate/VoronoiDiagramBuilder.h
===================================================================
--- trunk/include/geos/triangulate/VoronoiDiagramBuilder.h	2014-05-08 09:50:43 UTC (rev 3982)
+++ trunk/include/geos/triangulate/VoronoiDiagramBuilder.h	2014-05-21 14:21:02 UTC (rev 3983)
@@ -95,7 +95,7 @@
 	 * @return the subdivision containing the triangulation
 	 */
 	std::auto_ptr<quadedge::QuadEdgeSubdivision> getSubdivision();
-	
+
 	/**
 	 * Gets the faces of the computed diagram as a {@link GeometryCollection} 
 	 * of {@link Polygon}s, clipped as specified.
@@ -105,6 +105,15 @@
 	 */
 	std::auto_ptr<geom::GeometryCollection> getDiagram(const geom::GeometryFactory& geomFact);
 
+	/**
+	 * Gets the faces of the computed diagram as a {@link GeometryCollection} 
+	 * of {@link LineString}s, clipped as specified.
+	 * 
+	 * @param geomFact the geometry factory to use to create the output
+	 * @return the faces of the diagram
+	 */
+	std::auto_ptr<geom::Geometry> getDiagramEdges(const geom::GeometryFactory& geomFact);
+
 private:
 
 	std::auto_ptr<geom::CoordinateSequence> siteCoords;

Modified: trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h
===================================================================
--- trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h	2014-05-08 09:50:43 UTC (rev 3982)
+++ trunk/include/geos/triangulate/quadedge/QuadEdgeSubdivision.h	2014-05-21 14:21:02 UTC (rev 3983)
@@ -35,6 +35,7 @@
 
 	class CoordinateSequence;
 	class GeometryCollection;
+	class MultiLineString;
 	class GeometryFactory;
 	class Coordinate;
 	class Geometry;
@@ -395,7 +396,7 @@
 	 * @return a GeometryCollection of triangular Polygons. The caller takes ownership of the returned object.
 	 */
 	std::auto_ptr<geom::GeometryCollection> getTriangles(const geom::GeometryFactory &geomFact);
-	
+
 	/**  
 	 * Gets the cells in the Voronoi diagram for this triangulation.
 	 * The cells are returned as a {@link GeometryCollection} of {@link Polygon}s
@@ -407,8 +408,20 @@
 	 * @return a GeometryCollection of Polygons
 	 */
 	std::auto_ptr<geom::GeometryCollection> getVoronoiDiagram(const geom::GeometryFactory& geomFact);
-	
+
 	/**  
+	 * Gets the cells in the Voronoi diagram for this triangulation.
+	 * The cells are returned as a {@link GeometryCollection} of {@link LineString}s
+	 * The userData of each polygon is set to be the {@link Coordinate}
+	 * of the cell site.  This allows easily associating external 
+	 * data associated with the sites to the cells.
+	 *
+	 * @param geomFact a geometry factory
+	 * @return a MultiLineString
+	 */
+	std::auto_ptr<geom::MultiLineString> getVoronoiDiagramEdges(const geom::GeometryFactory& geomFact);
+
+	/**  
 	 * Gets a List of {@link Polygon}s for the Voronoi cells 
 	 * of this triangulation.
 	 * The userData of each polygon is set to be the {@link Coordinate}
@@ -419,6 +432,18 @@
 	 * @return a List of Polygons
 	 */
 	std::auto_ptr< std::vector<geom::Geometry*> > getVoronoiCellPolygons(const geom::GeometryFactory& geomFact);
+
+	/**  
+	 * Gets a List of {@link LineString}s for the Voronoi cells 
+	 * of this triangulation.
+	 * The userData of each LineString is set to be the {@link Coordinate}
+	 * of the cell site.  This allows easily associating external 
+	 * data associated with the sites to the cells.
+	 *
+	 * @param geomFact a geometry factory
+	 * @return a List of LineString
+	 */
+	std::auto_ptr< std::vector<geom::Geometry*> > getVoronoiCellEdges(const geom::GeometryFactory& geomFact);
 	
 	/**
 	 * Gets a collection of {@link QuadEdge}s whose origin
@@ -437,7 +462,7 @@
 	 * @return a collection of QuadEdge with the vertices of the subdivision as their origins
 	 */
 	std::auto_ptr<QuadEdgeSubdivision::QuadEdgeList> getVertexUniqueEdges(bool includeFrame);
-	
+
 	/**
 	 * Gets the Voronoi cell around a site specified
 	 * by the origin of a QuadEdge.
@@ -450,6 +475,20 @@
 	 * @return a polygon indicating the cell extent
 	 */
 	std::auto_ptr<geom::Geometry> getVoronoiCellPolygon(QuadEdge* qe ,const geom::GeometryFactory& geomFact);
+
+	/**
+	 * Gets the Voronoi cell edge around a site specified
+	 * by the origin of a QuadEdge.
+	 * The userData of the LineString is set to be the {@link Coordinate}
+	 * of the site.  This allows attaching external 
+	 * data associated with the site to this cell polygon.
+	 *
+	 * @param qe a quadedge originating at the cell site
+	 * @param geomFact a factory for building the polygon
+	 * @return a polygon indicating the cell extent
+	 */
+	std::auto_ptr<geom::Geometry> getVoronoiCellEdge(QuadEdge* qe ,const geom::GeometryFactory& geomFact);
+
 };
 
 } //namespace geos.triangulate.quadedge

Modified: trunk/src/triangulate/VoronoiDiagramBuilder.cpp
===================================================================
--- trunk/src/triangulate/VoronoiDiagramBuilder.cpp	2014-05-08 09:50:43 UTC (rev 3982)
+++ trunk/src/triangulate/VoronoiDiagramBuilder.cpp	2014-05-21 14:21:02 UTC (rev 3983)
@@ -107,6 +107,17 @@
 	return clipGeometryCollection(*polys,diagramEnv);
 }
 
+std::auto_ptr<geom::Geometry>
+VoronoiDiagramBuilder::getDiagramEdges(const geom::GeometryFactory& geomFact)
+{
+	create();
+	std::auto_ptr<geom::MultiLineString> edges = subdiv->getVoronoiDiagramEdges(geomFact);
+  if ( edges->isEmpty() ) return std::auto_ptr<Geometry>(edges.release());
+  std::auto_ptr<geom::Geometry> clipPoly ( geomFact.toGeometry(&diagramEnv) );
+  std::auto_ptr<Geometry> clipped( clipPoly->intersection(edges.get()) );
+	return clipped;
+}
+
 std::auto_ptr<geom::GeometryCollection> 
 VoronoiDiagramBuilder::clipGeometryCollection(const geom::GeometryCollection& geom, const geom::Envelope& clipEnv)
 {

Modified: trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp
===================================================================
--- trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp	2014-05-08 09:50:43 UTC (rev 3982)
+++ trunk/src/triangulate/quadedge/QuadEdgeSubdivision.cpp	2014-05-21 14:21:02 UTC (rev 3983)
@@ -505,6 +505,13 @@
 	return std::auto_ptr<GeometryCollection>(geomFact.createGeometryCollection(vorCells.release()));
 }
 
+std::auto_ptr<geom::MultiLineString> 
+QuadEdgeSubdivision::getVoronoiDiagramEdges(const geom::GeometryFactory& geomFact)
+{
+	std::auto_ptr< std::vector<geom::Geometry*> > vorCells = getVoronoiCellEdges(geomFact);
+	return std::auto_ptr<MultiLineString>(geomFact.createMultiLineString(vorCells.release()));
+}
+
 std::auto_ptr< std::vector<geom::Geometry*> >
 QuadEdgeSubdivision::getVoronoiCellPolygons(const geom::GeometryFactory& geomFact)
 {
@@ -524,6 +531,27 @@
 	delete tricircumVisitor;
 	return cells;
 }
+
+std::auto_ptr< std::vector<geom::Geometry*> >
+QuadEdgeSubdivision::getVoronoiCellEdges(const geom::GeometryFactory& geomFact)
+{
+	std::auto_ptr< std::vector<geom::Geometry*> > cells(new std::vector<geom::Geometry*>);
+	TriangleCircumcentreVisitor* tricircumVisitor = new TriangleCircumcentreVisitor();
+	visitTriangles((TriangleVisitor*)tricircumVisitor, true);
+
+	std::auto_ptr<QuadEdgeSubdivision::QuadEdgeList> edges = getVertexUniqueEdges(false);
+
+	for(QuadEdgeSubdivision::QuadEdgeList::iterator it=edges->begin() ; it!=edges->end() ; ++it)
+	{
+		QuadEdge *qe = *it;
+		std::auto_ptr<geom::Geometry> poly = getVoronoiCellEdge(qe,geomFact);
+
+		cells->push_back(poly.release());
+	}
+	delete tricircumVisitor;
+	return cells;
+}
+
 std::auto_ptr<geom::Geometry>
 QuadEdgeSubdivision::getVoronoiCellPolygon(QuadEdge* qe ,const geom::GeometryFactory& geomFact)
 {
@@ -559,6 +587,35 @@
 	return cellPoly;
 }
 
+std::auto_ptr<geom::Geometry>
+QuadEdgeSubdivision::getVoronoiCellEdge(QuadEdge* qe ,const geom::GeometryFactory& geomFact)
+{
+	std::vector<Coordinate> cellPts;
+	QuadEdge *startQE = qe;
+	do{
+		Coordinate cc = qe->rot().orig().getCoordinate();
+		cellPts.push_back(cc);
+		qe = &qe->oPrev();
+
+	}while ( qe != startQE);
+
+
+	//CoordList from a vector of Coordinates.
+	geom::CoordinateList coordList(cellPts);
+	//for checking close ring in CoordList class:
+	coordList.closeRing();
+
+	std::auto_ptr<Coordinate::Vect> pts = coordList.toCoordinateArray();
+	std::auto_ptr<geom::Geometry> cellEdge( 
+		geomFact.createLineString(new geom::CoordinateArraySequence(pts.release())));
+
+	Vertex v = startQE->orig();
+	Coordinate c(0,0);
+	c = v.getCoordinate();
+	cellEdge->setUserData(reinterpret_cast<void*>(&c));
+	return cellEdge;
+}
+
 std::auto_ptr<QuadEdgeSubdivision::QuadEdgeList>
 QuadEdgeSubdivision::getVertexUniqueEdges(bool includeFrame)
 {

Modified: trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp	2014-05-08 09:50:43 UTC (rev 3982)
+++ trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp	2014-05-21 14:21:02 UTC (rev 3983)
@@ -117,7 +117,7 @@
 	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
 	    std::string out(wkt_c);
 	    free(wkt_c);
-	    ensure_equals(out, "MULTILINESTRING ((280 300, 420 330), (280 300, 320 160), (320 160, 380 230), (380 230, 420 330), (280 300, 380 230))");
+	    ensure_equals(out, "MULTILINESTRING ((310.3571428571428 500, 353.515625 298.59375), (353.515625 298.59375, 306.875 231.9642857142857), (306.875 231.9642857142857, 110 175.7142857142857), (589.1666666666666 -10, 306.875 231.9642857142857), (353.515625 298.59375, 590 204))");
     }
     //Larger number of points:
     template<>
@@ -134,7 +134,9 @@
 	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_); 
 	    std::string out(wkt_c);
 	    free(wkt_c);
-	    ensure_equals(out, "MULTILINESTRING ((250 340, 315 318), (180 330, 250 340), (170 270, 180 330), (170 270, 240 170), (240 170, 330 260), (315 318, 330 260), (270 270, 330 260), (270 270, 315 318), (250 340, 270 270), (230 310, 270 270), (230 310, 250 340), (180 330, 230 310), (170 270, 230 310), (220 220, 230 310), (170 270, 220 220), (220 220, 240 170), (220 220, 270 220), (240 170, 270 220), (270 220, 330 260), (270 220, 270 270), (220 220, 270 270))");
+	    ensure_equals(out, 
+"MULTILINESTRING ((190 510, 213.9473684210526 342.3684210526316), (213.9473684210526 342.3684210526316, 195.625 296.5625), (195.625 296.5625, 0 329.1666666666667), (195.625 296.5625, 216 266), (216 266, 88.33333333333333 138.3333333333333), (88.33333333333333 138.3333333333333, 0 76.50000000000001), (213.9473684210526 342.3684210526316, 267 307), (267 307, 225 265), (225 265, 216 266), (245 245, 225 265), (267 307, 275.9160583941606 309.5474452554744), (275.9160583941606 309.5474452554744, 303.1666666666667 284), (303.1666666666667 284, 296.6666666666667 245), (296.6666666666667 245, 245 245), (245 245, 245 201), (245 201, 88.33333333333333 138.3333333333333), (245 201, 380 120), (380 120, 500 0), (343.7615384615385 510, 275.9160583941606 309.5474452554744), (296.6666666666667 245, 380 120), (500 334.9051724137931, 303.1666666666667 284))"
+      );
     }
     //Test with non-zero Tolerance value
     template<>
@@ -151,7 +153,9 @@
 	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_); 
 	    std::string out(wkt_c);
 	    free(wkt_c);
-	    ensure_equals(out,"MULTILINESTRING ((150 220, 210 270), (150 210, 150 220), (150 210, 220 210), (210 270, 220 210), (150 220, 220 210))");
+	    ensure_equals(out,
+"MULTILINESTRING ((185 215, 187.9268292682927 235.4878048780488), (187.9268292682927 235.4878048780488, 290 252.5), (185 140, 185 215), (185 215, 80 215), (100.8333333333334 340, 187.9268292682927 235.4878048780488))"
+      );
     }
     template<>
     template<>
@@ -167,7 +171,9 @@
 	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
 	    std::string out(wkt_c);
 	    free(wkt_c);
-	    ensure_equals(out,"MULTILINESTRING ((50 420, 300 360), (40 420, 50 420), (40 420, 134 135), (134 135, 170 70), (170 70, 350 150), (300 360, 350 150), (210 290, 350 150), (210 290, 300 360), (50 420, 210 290), (134 135, 210 290), (50 420, 134 135), (134 135, 350 150))");
+	    ensure_equals(out,
+"MULTILINESTRING ((45 770, 45 263.6473684210526), (45 263.6473684210526, -310 146.559649122807), (45 263.6473684210526, 59.16911764705881 267.8235294117647), (59.16911764705881 267.8235294117647, 239.4350649350649 179.4350649350649), (239.4350649350649 179.4350649350649, 241.3415637860082 151.9814814814815), (241.3415637860082 151.9814814814815, -310 -153.376923076923), (266.2 770, 181.9432314410481 418.9301310043668), (181.9432314410481 418.9301310043668, 59.16911764705881 267.8235294117647), (181.9432314410481 418.9301310043668, 311.875 251.875), (311.875 251.875, 239.4350649350649 179.4350649350649), (241.3415637860082 151.9814814814815, 433.3333333333333 -280), (701 344.5238095238096, 311.875 251.875))"
+	    );
     }
     template<>
     template<>
@@ -179,7 +185,9 @@
 	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
 	    std::string out(wkt_c);
 	    free(wkt_c);
-	    ensure_equals(out , "MULTILINESTRING ((240 310, 260 260), (165 313, 240 310), (123 245, 165 313), (123 245, 180 210), (180 210, 240 210), (240 210, 260 260), (180 210, 260 260), (180 210, 240 310), (165 313, 180 210))");
+	    ensure_equals(out,
+"MULTILINESTRING ((-14 376.5882352941176, 172.3651328095773 261.4803591470258), (172.3651328095773 261.4803591470258, 56.63157894736844 73), (172.3651328095773 261.4803591470258, 200.6640625 265.6015625), (200.6640625 265.6015625, 201 265.4), (201 265.4, 210 251), (210 251, 210 73), (208.04 450, 200.6640625 265.6015625), (397 343.8, 201 265.4), (210 251, 397 176.2))"
+	    );
     }
 } // namespace tut
 



More information about the geos-commits mailing list