[GRASS-SVN] r56220 - grass/trunk/vector/v.extrude
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 12 08:46:41 PDT 2013
Author: martinl
Date: 2013-05-12 08:46:41 -0700 (Sun, 12 May 2013)
New Revision: 56220
Modified:
grass/trunk/vector/v.extrude/extrude.c
grass/trunk/vector/v.extrude/main.c
Log:
v.extrude: fix trace elevation logic
Modified: grass/trunk/vector/v.extrude/extrude.c
===================================================================
--- grass/trunk/vector/v.extrude/extrude.c 2013-05-12 14:18:44 UTC (rev 56219)
+++ grass/trunk/vector/v.extrude/extrude.c 2013-05-12 15:46:41 UTC (rev 56220)
@@ -3,7 +3,7 @@
#include <grass/vector.h>
static struct line_pnts *Points_wall, *Points_roof, *Points_floor;
-static struct line_cats *Cats_roof;
+static struct line_cats *Cats_floor;
/**
\brief Extrude 2D vector feature to 3D
@@ -35,7 +35,7 @@
int k; /* Points->n_points */
int nlines;
- double voffset_dem; /* minimal offset */
+ double voffset_dem; /* minimal offset */
double voffset_curr; /* offset of current point */
double voffset_next; /* offset of next point */
@@ -48,13 +48,13 @@
Points_wall = Vect_new_line_struct();
Points_roof = Vect_new_line_struct();
Points_floor = Vect_new_line_struct();
- Cats_roof = Vect_new_cats_struct();
+ Cats_floor = Vect_new_cats_struct();
}
else {
Vect_reset_line(Points_wall);
Vect_reset_line(Points_roof);
Vect_reset_line(Points_floor);
- Vect_reset_cats(Cats_roof);
+ Vect_reset_cats(Cats_floor);
}
voffset_dem = 0.0;
@@ -81,7 +81,6 @@
for (k = 0; ; k++) {
voffset_curr = voffset_next = 0.0;
- /* trace */
if (fdrast >= 0 && trace) {
voffset_curr = Rast_get_sample(fdrast, window, NULL,
Points->y[k], Points->x[k], 0, /* north, east */
@@ -97,50 +96,42 @@
if (Rast_is_d_null_value(&voffset_curr) ||
Rast_is_d_null_value(&voffset_next)) {
- if (type == GV_POINT)
- break;
- else if (type == GV_LINE) {
- if (k >= Points->n_points - 1)
- break;
- }
- else if (type == GV_AREA) {
- if (k >= Points->n_points - 2)
- break;
- }
- continue;
+ if (k >= Points->n_points - 2)
+ break;
+ else
+ continue;
}
- if (trace) {
- voffset_curr += voffset;
- voffset_next += voffset;
- }
- else {
- voffset_curr = voffset_dem + voffset;
- voffset_next = voffset_dem + voffset;
- }
+ if (trace) {
+ voffset_curr += voffset;
+ voffset_next += voffset;
+ }
+ else {
+ voffset_curr = voffset_dem + voffset;
+ voffset_next = voffset_dem + voffset;
+ }
if (type == GV_POINT) {
/* point -> 3d line (vertical) */
Vect_append_point(Points_wall, Points->x[k], Points->y[k],
Points->z[k] + voffset_curr);
Vect_append_point(Points_wall, Points->x[k], Points->y[k],
- Points->z[k] + objheight + voffset_curr);
- break;
+ Points->z[k] + objheight + (trace ? voffset_curr : 0.));
}
if (type & (GV_LINE | GV_AREA)) {
/* reset */
Vect_reset_line(Points_wall);
- /* boundary -> face */
+ /* line/boundary segment -> 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],
Points->z[k + 1] + voffset_next);
Vect_append_point(Points_wall, Points->x[k + 1], Points->y[k + 1],
- Points->z[k + 1] + objheight + voffset_next);
+ Points->z[k + 1] + objheight + (trace ? voffset_next : 0.));
Vect_append_point(Points_wall, Points->x[k], Points->y[k],
- Points->z[k] + objheight + voffset_curr);
+ Points->z[k] + objheight + (trace ? voffset_curr : 0.));
Vect_append_point(Points_wall, Points->x[k], Points->y[k],
Points->z[k] + voffset_curr);
@@ -150,23 +141,20 @@
if (type == GV_AREA) {
/* roof */
Vect_append_point(Points_roof, Points->x[k], Points->y[k],
- Points->z[k] + objheight + voffset_curr);
+ Points->z[k] + objheight + (trace ? voffset_curr : 0.));
/* floor */
Vect_append_point(Points_floor, Points->x[k], Points->y[k],
Points->z[k] + voffset_curr);
}
-
- if (k >= Points->n_points - 2)
- break;
}
+ if (k >= Points->n_points - 2)
+ break;
}
if (type == GV_POINT) {
Vect_write_line(Out, GV_LINE, Points_wall, Cats);
- return 1;
}
-
- if (type == GV_AREA && Points_roof->n_points > 3) {
+ 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],
@@ -177,14 +165,13 @@
/* write roof and floor */
Vect_write_line(Out, GV_FACE, Points_roof, Cats);
Vect_write_line(Out, GV_FACE, Points_floor, Cats);
+ nlines += 2;
- nlines++;
-
if (centroid > 0) {
/* centroid -> kernel */
- Vect_read_line(In, Points_roof, Cats_roof, centroid);
- Points->z[0] = Points_roof->z[0] / 2.0; /* TODO: do it better */
- Vect_write_line(Out, GV_KERNEL, Points_roof, Cats_roof);
+ Vect_read_line(In, Points_floor, Cats_floor, centroid);
+ Points_floor->z[0] = Points_roof->z[0] / 2.0; /* TODO: do it better */
+ Vect_write_line(Out, GV_KERNEL, Points_floor, Cats_floor);
nlines++;
}
}
Modified: grass/trunk/vector/v.extrude/main.c
===================================================================
--- grass/trunk/vector/v.extrude/main.c 2013-05-12 14:18:44 UTC (rev 56219)
+++ grass/trunk/vector/v.extrude/main.c 2013-05-12 15:46:41 UTC (rev 56220)
@@ -147,7 +147,7 @@
only_type = Vect_option_to_types(opt.type);
interp_method = Rast_option_to_interp_type(opt.interp);
- trace = (flag.trace->answer) ? TRUE : FALSE;
+ trace = flag.trace->answer ? TRUE : FALSE;
/* set input vector map name and mapset */
Vect_check_input_output_name(opt.input->answer, opt.output->answer, G_FATAL_EXIT);
More information about the grass-commit
mailing list