[GRASS-SVN] r41717 - grass/branches/develbranch_6/vector/v.hull

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 4 12:34:27 EDT 2010


Author: martinl
Date: 2010-04-04 12:34:26 -0400 (Sun, 04 Apr 2010)
New Revision: 41717

Modified:
   grass/branches/develbranch_6/vector/v.hull/description.html
   grass/branches/develbranch_6/vector/v.hull/main.c
Log:
v.hull: support for vector lines


Modified: grass/branches/develbranch_6/vector/v.hull/description.html
===================================================================
--- grass/branches/develbranch_6/vector/v.hull/description.html	2010-04-04 15:54:59 UTC (rev 41716)
+++ grass/branches/develbranch_6/vector/v.hull/description.html	2010-04-04 16:34:26 UTC (rev 41717)
@@ -1,56 +1,60 @@
-<H2>DESCRIPTION</H2>
+<h2>DESCRIPTION</h2>
 
-v.hull computes the convex hull of a vector points map and outputs the
-convex hull polygon as a vector area map. The convex hull, or convex envelope,
-for an object or a set of objects is the minimal convex set containing the
-given objects. This module creates a vector polygon containing all vector
-points of the input map.
-<P>
-In the case of 3D input points, the hull will be a 3D hull as well, unless the
-user specifies the <b>-f</b> flag. The 3D hull will be composed of triangular
-faces.
-<P>
+<em>v.hull</em> computes the convex hull of a vector map and outputs
+the convex hull polygon as a vector area map. The convex hull, or
+convex envelope, for an object or a set of objects is the minimal
+convex set containing the given objects. This module creates a vector
+polygon containing all vector points or lines of the input map.
 
-<BR>
-Example of <em>v.hull</em> output:
+<p>
+In the case of 3D input points, the hull will be a 3D hull as well,
+unless the user specifies the <b>-f</b> flag. The 3D hull will be
+composed of triangular faces.
+
 <center>
-<img src=v_hull.png border=1><BR>
+<img src=v_hull.png border=1><br>
 <table border=0 width=590>
 <tr><td><center>
-<i>Convex hull polygon created with v.hull</i>
+Fig: Convex hull polygon created with <em>v.hull</em>
 </center></td></tr>
 </table>
 </center>
 
-<H2>EXAMPLE</H2>
+<h2>EXAMPLE</h2>
 
 Example of <em>v.hull</em> 3D output (using two random 3D point clouds):
+
 <div class="code"><pre>
 g.region rural_1m -p
 r.mapcalc zero=0
-v.random -z out=random3d_a n=10 zmin=0 zmax=200
-v.random -z out=random3d_b n=15 zmin=400 zmax=600
-v.hull random3d_a out=random3d_a_hull
-v.hull random3d_b out=random3d_b_hull
-nviz zero vect=random3d_a_hull,random3d_b_hull
+v.random -z output=random3d_a n=10 zmin=0 zmax=200
+v.random -z output=random3d_b n=15 zmin=400 zmax=600
+v.hull input=random3d_a output=random3d_a_hull
+v.hull input=random3d_b output=random3d_b_hull
+nviz elevation=zero vect=random3d_a_hull,random3d_b_hull
 </pre></div>
 
-<H2>REFERENCES</H2>
-<EM>M. de Berg, M. van Kreveld, M. Overmars, O. Schwarzkopf,  (2000). 
- Computational geometry, chapter 1.1, 2-8.</EM>
+<h2>REFERENCES</h2>
 
-<BR>
+<ul>
+  <li>M. de Berg, M. van Kreveld, M. Overmars, O. Schwarzkopf,
+    (2000). Computational geometry, chapter 1.1, 2-8.
+  <li>J. O'Rourke, (1998). Computational Geometry in C (Second
+  Edition), chapter 4.
+</ul>
 
-<EM>J. O'Rourke, (1998). 
- Computational Geometry in C (Second Edition), chapter 4.</EM>
+<h2>SEE ALSO</h2>
 
-<H2>SEE ALSO</H2>
-<EM>
-<A HREF="v.delaunay.html">v.delaunay</A></EM>
+<em>
+<a href="v.delaunay.html">v.delaunay</a>
+</em>
 
-<H2>AUTHOR</H2>
+<h2>AUTHOR</h2>
+
 Andrea Aime, Modena, Italy<br>
 Markus Neteler, ITC-irst (update to 5.7)<br>
-Benjamin Ducke, CAU Kiel (3D hull support)
+Benjamin Ducke, CAU Kiel (3D hull support)<br>
+Martin Landa, CTU in Prague, Czech Republic (vector lines support)
 
-<p><i>Last changed: $Date$</i></p>
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/branches/develbranch_6/vector/v.hull/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.hull/main.c	2010-04-04 15:54:59 UTC (rev 41716)
+++ grass/branches/develbranch_6/vector/v.hull/main.c	2010-04-04 16:34:26 UTC (rev 41717)
@@ -1,26 +1,22 @@
 
-/******************************************************************************
-* hull.c <s.hull>
-* Creates the convex hull surrounding a sites list
+/***************************************************************
+ *
+ * MODULE:       v.hull (based s.hull)
+ * 
+ * AUTHOR(S):    Andrea Aime <aaime at libero.it>
+ *               Updated by Markus Neteler to 5.7
+ *               Updated by Benjamin Ducke to support 3D hull creation
+ *               
+ * PURPOSE:      Creates the convex hull surrounding a vector points
+ *               
+ * COPYRIGHT:    (C) 2001, 2010 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General
+ *               Public License (>=v2).  Read the file COPYING that
+ *               comes with GRASS for details.
+ *
+ **************************************************************/
 
-* @Copyright Andrea Aime <aaime at libero.it>
-* 23 Sept. 2001
-* Updated 19 Dec 2003, Markus Neteler to 5.7
-* Last updated 16 jan 2007, Benjamin Ducke to support 3D hull creation
-
-* This file is part of GRASS GIS. It is free software. You can
-* redistribute it and/or modify it under the terms of
-* the GNU General Public License as published by the Free Software
-* Foundation; either version 2 of the License, or (at your option)
-* any later version.
-
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-******************************************************************************/
-
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>
@@ -89,13 +85,10 @@
 	}
     }
 
-    /*
-       printf("upPoints: %d\n", upPoints);
-       for(pointIdx = 0; pointIdx <= upPoints; pointIdx ++)
-       printf("%d ", upHull[pointIdx]);
-       printf("\n");
-     */
-
+    G_debug(3, "upPoints: %d", upPoints);
+    for(pointIdx = 0; pointIdx <= upPoints; pointIdx++)
+	G_debug(5, " %d", upHull[pointIdx]);
+    
     /* compute lower hull, overwrite last point of upper hull */
     loHull = &(upHull[upPoints]);
     loHull[0] = numPoints - 1;
@@ -115,23 +108,17 @@
 
     G_debug(3, "numPoints:%d loPoints:%d upPoints:%d",
 	    numPoints, loPoints, upPoints);
-    /*
-       printf("loPoints: %d\n", loPoints);
-       for(pointIdx = 0; pointIdx <= loPoints; pointIdx ++)
-       printf("%d ", loHull[pointIdx]);
-       printf("\n");
-     */
 
+    for (pointIdx = 0; pointIdx <= loPoints; pointIdx++) 
+	G_debug(5, " %d", loHull[pointIdx]);
+    
     /* reclaim uneeded memory */
     *hull = (int *)G_realloc(*hull, (loPoints + upPoints) * sizeof(int));
     return loPoints + upPoints;
 }
 
-
-
 void convexHull3d(struct Point *P, const int numPoints, struct Map_info *Map)
 {
-
     int error;
     int i;
     double *px;
@@ -151,9 +138,9 @@
     /* make 3D hull */
     error = make3DHull(px, py, pz, numPoints, Map);
     if (error < 0) {
-	G_fatal_error("Simple planar hulls not implemented yet");
+	G_fatal_error(_("Simple planar hulls not implemented yet"));
     }
-
+    
     G_free(px);
     G_free(py);
     G_free(pz);
@@ -164,7 +151,7 @@
 int loadSiteCoordinates(struct Map_info *Map, struct Point **points, int all,
 			struct Cell_head *window)
 {
-    int pointIdx = 0;
+    int i, pointIdx;
     struct line_pnts *sites;
     struct line_cats *cats;
     BOUND_BOX box;
@@ -174,35 +161,34 @@
     cats = Vect_new_cats_struct();
 
     *points = NULL;
-
+    pointIdx = 0;
+    
     /* copy window to box */
     Vect_region_box(window, &box);
 
     while ((type = Vect_read_next_line(Map, sites, cats)) > -1) {
 
-	if (type != GV_POINT)
+	if (type != GV_POINT && !(type & GV_LINES))
 	    continue;
-
+	
 	Vect_cat_get(cats, 1, &cat);
-
-	G_debug(4, "Point: %f|%f|%f|#%d", sites->x[0], sites->y[0],
-		sites->z[0], cat);
-
-	if (all ||
-	    Vect_point_in_box(sites->x[0], sites->y[0], sites->z[0], &box)) {
-
+	
+	for (i = 0; i < sites->n_points; i++) {
+	    G_debug(4, "Point: %f|%f|%f|#%d", sites->x[i], sites->y[i],
+		    sites->z[i], cat);
+	    
+	    if (!all && !Vect_point_in_box(sites->x[i], sites->y[i], sites->z[i], &box))
+		continue;
+	    
 	    G_debug(4, "Point in the box");
 
 	    if ((pointIdx % ALLOC_CHUNK) == 0)
-		*points =
-		    (struct Point *)G_realloc(*points,
-					      (pointIdx +
-					       ALLOC_CHUNK) *
-					      sizeof(struct Point));
-
-	    (*points)[pointIdx].x = sites->x[0];
-	    (*points)[pointIdx].y = sites->y[0];
-	    (*points)[pointIdx].z = sites->z[0];
+		*points = (struct Point *) G_realloc(*points,
+						     (pointIdx + ALLOC_CHUNK) * sizeof(struct Point));
+	    
+	    (*points)[pointIdx].x = sites->x[i];
+	    (*points)[pointIdx].y = sites->y[i];
+	    (*points)[pointIdx].z = sites->z[i];
 	    pointIdx++;
 	}
     }
@@ -281,20 +267,19 @@
 
     int MODE2D;
 
-
     G_gisinit(argv[0]);
 
     module = G_define_module();
     module->keywords = _("vector, geometry");
     module->description =
-	_("Uses a GRASS vector points map to produce a convex hull vector map.");
+	_("Produces a convex hull for a given vector map.");
 
     input = G_define_standard_option(G_OPT_V_INPUT);
-    input->description = _("Name of input vector points map");
-
+    input->label = _("Name of input vector map");
+    input->description = _("For vector lines reads their vertices");
+    
     output = G_define_standard_option(G_OPT_V_OUTPUT);
-    output->description = _("Name of output vector area map");
-
+    
     all = G_define_flag();
     all->key = 'a';
     all->description =
@@ -304,7 +289,7 @@
     flat->key = 'f';
     flat->description =
 	_("Create a 'flat' 2D hull even if the input is 3D points");
-
+    
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -319,18 +304,22 @@
 
     /* open site file */
     if (Vect_open_old(&Map, sitefile, mapset) < 0)
-	G_fatal_error(_("Cannot open vector map <%s>"), sitefile);
-
+	G_fatal_error(_("Unable to open vector map <%s>"),
+		      G_fully_qualified_name(sitefile, mapset));
+    
     /* load site coordinates */
     G_get_window(&window);
     numSitePoints = loadSiteCoordinates(&Map, &points, all->answer, &window);
     if (numSitePoints < 0)
-	G_fatal_error(_("Error loading vector points map <%s>"), sitefile);
+	G_fatal_error(_("Error loading vector points from <%s>"),
+		      G_fully_qualified_name(sitefile, mapset));
 
     if (numSitePoints < 3)
-	G_fatal_error(_("Convex hull calculation requires at least three points"));
+	G_fatal_error(_("Convex hull calculation requires at least three points. Exiting."));
 
-
+    G_verbose_message(_("%d points read from vector map <%s>"),
+		      numSitePoints, G_fully_qualified_name(sitefile, mapset));
+    
     /* create a 2D or a 3D hull? */
     MODE2D = 1;
     if (Vect_is_3d(&Map)) {
@@ -340,38 +329,25 @@
 	MODE2D = 1;
     }
 
-
     /* create vector map */
-    if (MODE2D) {
-	if (0 > Vect_open_new(&Map, output->answer, 0)) {
-	    G_fatal_error(_("Cannot open vector map <%s>"), output->answer);
-	}
+    if (0 > Vect_open_new(&Map, output->answer, MODE2D ? WITHOUT_Z : WITH_Z)) {
+	G_fatal_error(_("Unable to create vector map <%s>"), output->answer);
     }
-    else {
-	if (0 > Vect_open_new(&Map, output->answer, 1)) {
-	    G_fatal_error(_("Cannot open vector map <%s>"), output->answer);
-	}
-    }
-
+    
     Vect_hist_command(&Map);
 
     if (MODE2D) {
-
 	/* compute convex hull */
 	numHullPoints = convexHull(points, numSitePoints, &hull);
 
 	/* output vector map */
 	outputHull(&Map, points, hull, numHullPoints);
-
     }
     else {
-
 	/* this does everything for the 3D hull including vector map creation */
 	convexHull3d(points, numSitePoints, &Map);
-
     }
-
-
+    
     /* clean up and bye bye */
     Vect_build(&Map);
     Vect_close(&Map);



More information about the grass-commit mailing list