[GRASS-SVN] r56217 - grass/trunk/vector/v.extrude

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 12 06:30:55 PDT 2013


Author: martinl
Date: 2013-05-12 06:30:55 -0700 (Sun, 12 May 2013)
New Revision: 56217

Modified:
   grass/trunk/vector/v.extrude/extrude.c
Log:
v.extrude: close a volume (write also floor)


Modified: grass/trunk/vector/v.extrude/extrude.c
===================================================================
--- grass/trunk/vector/v.extrude/extrude.c	2013-05-12 13:12:15 UTC (rev 56216)
+++ grass/trunk/vector/v.extrude/extrude.c	2013-05-12 13:30:55 UTC (rev 56217)
@@ -2,15 +2,15 @@
 #include <grass/raster.h>
 #include <grass/vector.h>
 
-struct line_pnts *Points_wall, *Points_roof;
-struct line_cats *Cats_roof;
+static struct line_pnts *Points_wall, *Points_roof, *Points_floor;
+static struct line_cats *Cats_roof;
 
 /**
-  \brief Extrude vector object
+  \brief Extrude 2D vector feature to 3D
 
   - point -> 3d line (vertical)
-  - boundary -> face
-  - area -> face + kernel
+  - boundary -> faces
+  - area -> faces + kernel
 
   \param In input vector map
   \param[in,out] Out output vector map
@@ -45,13 +45,15 @@
 	return nlines;
 
     if (!Points_wall) {
-        Points_wall = Vect_new_line_struct();
-        Points_roof = Vect_new_line_struct();
-        Cats_roof = Vect_new_cats_struct();
+        Points_wall  = Vect_new_line_struct();
+        Points_roof  = Vect_new_line_struct();
+        Points_floor = Vect_new_line_struct();
+        Cats_roof    = Vect_new_cats_struct();
     }
     else {
         Vect_reset_line(Points_wall);
-        Vect_reset_line(Points_roof);        
+        Vect_reset_line(Points_roof);
+        Vect_reset_line(Points_floor);
         Vect_reset_cats(Cats_roof);
     }
 
@@ -63,7 +65,7 @@
                                            Points->y[k], Points->x[k], 0, /* north, east */
                                            interp_method);
 	    if (Rast_is_d_null_value(&voffset_curr))
-		continue;
+		continue; /* skip null values */
 
 	    if (k == 0) {
 		voffset_dem = voffset_curr;
@@ -76,7 +78,7 @@
     }
 
     
-    /* walls */
+    /* build walls, roof and floor */
     for (k = 0; ; k++) {
 	voffset_curr = voffset_next = 0.0;
 
@@ -137,7 +139,7 @@
 	    /* reset */
 	    Vect_reset_line(Points_wall);
 
-	    /* boudary -> face */
+	    /* boundary -> face */
 	    Vect_append_point(Points_wall, Points->x[k], Points->y[k],
 			      Points->z[k] + voffset_curr);
 	    Vect_append_point(Points_wall, Points->x[k + 1], Points->y[k + 1],
@@ -156,6 +158,9 @@
 		/* roof */
 		Vect_append_point(Points_roof, Points->x[k], Points->y[k],
 				  Points->z[k] + objheight + voffset_curr);
+                /* floor */
+		Vect_append_point(Points_floor, Points->x[k], Points->y[k],
+				  Points->z[k] + voffset_curr);
 	    }
 
 	    if (k >= Points->n_points - 2)
@@ -168,16 +173,23 @@
 	nlines++;
     }
     else if (type == GV_AREA && Points_roof->n_points > 3) {
+        /* close roof and floor */
 	Vect_append_point(Points_roof,
 			  Points_roof->x[0], Points_roof->y[0],
 			  Points_roof->z[0]);
-	Vect_write_line(Out, GV_FACE, Points_roof, Cats);
+	Vect_append_point(Points_floor,
+			  Points_floor->x[0], Points_floor->y[0],
+			  Points_floor->z[0]);
+        /* write roof and floor */
+        Vect_write_line(Out, GV_FACE, Points_roof, Cats);
+        Vect_write_line(Out, GV_FACE, Points_floor, Cats);
+
 	nlines++;
 
 	if (centroid > 0) {
 	    /* centroid -> kernel */
             Vect_read_line(In, Points_roof, Cats_roof, centroid);
-	    Points->z[0] = Points_roof->z[0] / 2.0;
+	    Points->z[0] = Points_roof->z[0] / 2.0; /* TODO: do it better */
 	    Vect_write_line(Out, GV_KERNEL, Points_roof, Cats_roof);
 	    nlines++;
 	}



More information about the grass-commit mailing list