[GRASS-SVN] r41719 - grass/trunk/vector/v.hull

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 4 13:00:26 EDT 2010


Author: martinl
Date: 2010-04-04 13:00:25 -0400 (Sun, 04 Apr 2010)
New Revision: 41719

Modified:
   grass/trunk/vector/v.hull/main.c
   grass/trunk/vector/v.hull/read.c
   grass/trunk/vector/v.hull/v.hull.html
Log:
v.hull: support for vector lines
(merge r41717 from devbr6)


Modified: grass/trunk/vector/v.hull/main.c
===================================================================
--- grass/trunk/vector/v.hull/main.c	2010-04-04 16:38:22 UTC (rev 41718)
+++ grass/trunk/vector/v.hull/main.c	2010-04-04 17:00:25 UTC (rev 41719)
@@ -10,7 +10,7 @@
  *
  * PURPOSE:    Creates the convex hull surrounding a vector points.
  *
- * COPYRIGHT:  (C) 2001-2009 by the GRASS Development Team
+ * 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
@@ -50,14 +50,14 @@
     G_add_keyword(_("vector"));
     G_add_keyword(_("geometry"));
     module->description =
-	_("Creates convex hull for vector point map.");
-
+	_("Produces a convex hull for a given vector map.");
+    
     input = G_define_standard_option(G_OPT_V_INPUT);
-
+    
     field = G_define_standard_option(G_OPT_V_FIELD_ALL);
 
     output = G_define_standard_option(G_OPT_V_OUTPUT);
-
+    
     all = G_define_flag();
     all->key = 'a';
     all->description =
@@ -67,7 +67,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);
 
@@ -75,22 +75,23 @@
 
     Vect_check_input_output_name(input->answer, output->answer,
 				 GV_FATAL_EXIT);
-
+    
     Vect_set_open_level(1);
     if (Vect_open_old2(&Map, sitefile, "", field->answer) < 0)
 	G_fatal_error(_("Unable to open vector map <%s>"), sitefile);
-
+    
     /* load site coordinates */
     G_get_window(&window);
     numSitePoints = loadSiteCoordinates(&Map, &points, all->answer, &window,
 					Vect_get_field_number(&Map, field->answer));
     if (numSitePoints < 0)
-	G_fatal_error(_("Error loading vector points map <%s>"), sitefile);
-
+	G_fatal_error(_("Error loading vector points from <%s>"), sitefile);
+    
     if (numSitePoints < 3)
 	G_fatal_error(_("Convex hull calculation requires at least three points (%d found)"), numSitePoints);
-
-
+    
+    G_verbose_message(_("%d points read from vector map <%s>"), sitefile);
+    
     /* create a 2D or a 3D hull? */
     MODE2D = 1;
     if (Vect_is_3d(&Map)) {
@@ -100,23 +101,14 @@
 	MODE2D = 1;
     }
 
-
     /* create vector map */
-    if (MODE2D) {
-	if (0 > Vect_open_new(&Map, output->answer, 0)) {
-	    G_fatal_error(_("Unable to create 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(_("Unable to create vector map <%s>"), output->answer);
-	}
-    }
-
+    
     Vect_hist_command(&Map);
 
     if (MODE2D) {
-
 	/* compute convex hull */
 	numHullPoints = convexHull(points, numSitePoints, &hull);
 

Modified: grass/trunk/vector/v.hull/read.c
===================================================================
--- grass/trunk/vector/v.hull/read.c	2010-04-04 16:38:22 UTC (rev 41718)
+++ grass/trunk/vector/v.hull/read.c	2010-04-04 17:00:25 UTC (rev 41719)
@@ -5,7 +5,7 @@
 int loadSiteCoordinates(struct Map_info *Map, struct Point **points, int all,
 			struct Cell_head *window, int field)
 {
-    int pointIdx = 0;
+    int i, pointIdx;
     struct line_pnts *sites;
     struct line_cats *cats;
     struct bound_box box;
@@ -15,43 +15,42 @@
     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;
 
 	if (field != -1 && Vect_cat_get(cats, field, &cat) == 0)
 	    continue;
-
-	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++;
 	}
     }
 
     if (pointIdx > 0)
-	*points =
-	    (struct Point *)G_realloc(*points,
-				      (pointIdx + 1) * sizeof(struct Point));
+	*points = (struct Point *)G_realloc(*points,
+					    (pointIdx + 1) * sizeof(struct Point));
+    
     return pointIdx;
 }

Modified: grass/trunk/vector/v.hull/v.hull.html
===================================================================
--- grass/trunk/vector/v.hull/v.hull.html	2010-04-04 16:38:22 UTC (rev 41718)
+++ grass/trunk/vector/v.hull/v.hull.html	2010-04-04 17:00:25 UTC (rev 41719)
@@ -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
+r.mapcalc zero=0
+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>



More information about the grass-commit mailing list