[GRASS-SVN] r47106 - grass/trunk/visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 14 03:45:20 EDT 2011
Author: annakrat
Date: 2011-07-14 00:45:20 -0700 (Thu, 14 Jul 2011)
New Revision: 47106
Modified:
grass/trunk/visualization/nviz2/cmd/args.c
grass/trunk/visualization/nviz2/cmd/local_proto.h
grass/trunk/visualization/nviz2/cmd/main.c
grass/trunk/visualization/nviz2/cmd/volume.c
Log:
nviz_cmd: volume slices implemented
Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c 2011-07-14 06:17:07 UTC (rev 47105)
+++ grass/trunk/visualization/nviz2/cmd/args.c 2011-07-14 07:45:20 UTC (rev 47106)
@@ -627,7 +627,7 @@
params->isosurf_transp_map->multiple = YES;
params->isosurf_transp_map->required = NO;
params->isosurf_transp_map->description =
- _("Name of 3D raster map(s) for transparency");
+ _("Name of 3D raster map(s) for isosurface transparency");
params->isosurf_transp_map->guisection = _("Volumes");
params->isosurf_transp_map->key = "isosurf_transparency_map";
@@ -659,6 +659,40 @@
params->isosurf_shine_const->guisection = _("Volumes");
params->isosurf_shine_const->options = "0-255";
+ /* slices */
+ /* slice axis */
+ params->slice = G_define_option();
+ params->slice->key = "slice";
+ params->slice->key_desc = "volume:axis";
+ params->slice->type = TYPE_STRING;
+ params->slice->required = NO;
+ params->slice->multiple = YES;
+ params->slice->description = _("Volume slice parallel to given axis (x, y, z)");
+ params->slice->guisection = _("Volumes");
+
+ /* slice position */
+ params->slice_pos = G_define_option();
+ params->slice_pos->key = "slice_position";
+ params->slice_pos->key_desc = "x1,x2,y1,y2,z1,z2";
+ params->slice_pos->type = TYPE_DOUBLE;
+ params->slice_pos->required = NO;
+ params->slice_pos->multiple = YES;
+ params->slice_pos->description = _("Volume slice position");
+ params->slice_pos->guisection = _("Volumes");
+ params->slice_pos->answer = "0,1,0,1,0,1";
+
+ /* slice transparency */
+ params->slice_transp = G_define_option();
+ params->slice_transp->key = "slice_transparency";
+ params->slice_transp->key_desc = "value";
+ params->slice_transp->type = TYPE_INTEGER;
+ params->slice_transp->required = NO;
+ params->slice_transp->multiple = YES;
+ params->slice_transp->description = _("Volume slice transparency");
+ params->slice_transp->guisection = _("Volumes");
+ params->slice_transp->answer = "0";
+ params->slice_transp->options = "0-255";
+
return;
}
@@ -852,7 +886,7 @@
int nvpoints;
- int nvolumes, nisosurf;
+ int nvolumes, nisosurf, nslices;
/* topography */
nelev_map = opt_get_num_answers(params->elev_map);
@@ -1009,8 +1043,9 @@
*/
nvolumes = opt_get_num_answers(params->volume);
nisosurf = opt_get_num_answers(params->isosurf_level);
+ nslices = opt_get_num_answers(params->slice);
- /* transparency */
+ /* isosurface transparency */
nmaps = opt_get_num_answers(params->isosurf_transp_map);
nconsts = opt_get_num_answers(params->isosurf_transp_const);
@@ -1019,15 +1054,27 @@
params->isosurf_level->key, nisosurf, params->isosurf_transp_map->key, nmaps,
params->isosurf_transp_const->key, nconsts);
- /* shininess */
+ /* isosurface shininess */
nmaps = opt_get_num_answers(params->isosurf_shine_map);
nconsts = opt_get_num_answers(params->isosurf_shine_const);
if ((nmaps + nconsts > 0) && (nisosurf != nmaps + nconsts))
- G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d, <%s> %d"),
- params->isosurf_level->key, nisosurf, params->isosurf_shine_map->key, nmaps,
- params->isosurf_shine_const->key, nconsts);
+ G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d, <%s> %d"),
+ params->isosurf_level->key, nisosurf, params->isosurf_shine_map->key, nmaps,
+ params->isosurf_shine_const->key, nconsts);
+ /* slice transparency */
+ nconsts = opt_get_num_answers(params->slice_transp);
+ if (nslices != nconsts)
+ G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d)"),
+ params->slice->key, nslices, params->slice_transp->key, nconsts);
+
+ /* slice position */
+ ncoords = opt_get_num_answers(params->slice_pos);
+ if (ncoords != 6 * nslices)
+ G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d x 6)"),
+ params->slice->key, nslices, params->slice_pos->key, ncoords/6);
+
return;
}
Modified: grass/trunk/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h 2011-07-14 06:17:07 UTC (rev 47105)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h 2011-07-14 07:45:20 UTC (rev 47106)
@@ -23,7 +23,7 @@
/* volumes */
*volume, *volume_mode, *volume_shade, *volume_pos, *volume_res, *isosurf_level,
*isosurf_color_map, *isosurf_color_const, *isosurf_transp_map, *isosurf_transp_const,
- *isosurf_shine_map, *isosurf_shine_const,
+ *isosurf_shine_map, *isosurf_shine_const, *slice_pos, *slice, *slice_transp,
/* misc */
*exag, *bgcolor,
/* cutting planes */
@@ -60,6 +60,7 @@
/* volume.c */
int load_rasters3d(const struct GParams *, nv_data *);
int add_isosurfs(const struct GParams *, nv_data *);
+int add_slices(const struct GParams *, nv_data *);
/* cutting planes */
void draw_cplane(const struct GParams *, nv_data *);
Modified: grass/trunk/visualization/nviz2/cmd/main.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/main.c 2011-07-14 06:17:07 UTC (rev 47105)
+++ grass/trunk/visualization/nviz2/cmd/main.c 2011-07-14 07:45:20 UTC (rev 47106)
@@ -33,7 +33,7 @@
struct GParams *params;
int i, ret;
- int red, grn, blu, sx, sy;
+ int red, grn, blu;
float size;
double vp_height, z_exag; /* calculated viewpoint height, z-exag */
int width, height; /* output image size */
@@ -120,6 +120,11 @@
add_isosurfs(params, &data);
}
+ /* define slices for displaying volumes */
+ if (params->slice->answer) {
+ add_slices(params, &data);
+ }
+
/* focus on loaded data */
Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
Modified: grass/trunk/visualization/nviz2/cmd/volume.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/volume.c 2011-07-14 06:17:07 UTC (rev 47105)
+++ grass/trunk/visualization/nviz2/cmd/volume.c 2011-07-14 07:45:20 UTC (rev 47106)
@@ -214,3 +214,93 @@
return 1;
}
+
+int add_slices(const struct GParams *params, nv_data *data)
+{
+ int i;
+ int num, nvols, *vol_list, id, nslices, axis;
+ int res, draw_mode;
+ char **tokens;
+ const char* style;
+
+ vol_list = GVL_get_vol_list(&nvols);
+
+ for (i = 0; params->slice->answers[i]; i++) {
+ tokens = G_tokenize(params->slice->answers[i], ":");
+ if (G_number_of_tokens(tokens) != 2)
+ G_fatal_error(_("Error tokenize '%s'"),
+ params->slice->answers[i]);
+ num = atoi(tokens[0]);
+
+ if (!strcmp(tokens[1],"x") || !strcmp(tokens[1],"X"))
+ axis = 0;
+ else if (!strcmp(tokens[1],"y") || !strcmp(tokens[1],"Y"))
+ axis = 1;
+ else if (!strcmp(tokens[1],"z") || !strcmp(tokens[1],"Z"))
+ axis = 2;
+ else
+ G_fatal_error(_("Wrong name for axis: %s"),
+ tokens[1]);
+ G_free_tokens(tokens);
+
+ if (num > nvols) {
+ G_fatal_error(_("Volume set number %d is not available"),
+ num);
+ }
+
+ id = vol_list[num-1];
+ if (GVL_slice_add(id) < 0) {
+ G_fatal_error(_("Unable to add slice (volume set %d)"),
+ id);
+ }
+
+ nslices = GVL_slice_num_slices(id);
+
+ if (GVL_slice_set_pos(id, nslices-1, atof(params->slice_pos->answers[i*6+0]),
+ atof(params->slice_pos->answers[i*6+1]),
+ atof(params->slice_pos->answers[i*6+2]),
+ atof(params->slice_pos->answers[i*6+3]),
+ atof(params->slice_pos->answers[i*6+4]),
+ atof(params->slice_pos->answers[i*6+5]),
+ axis) < 0)
+ G_fatal_error(_("Unable to set slice (%d) position of volume %d"),
+ nslices-1, id);
+
+ /* set transparency */
+ if (GVL_slice_set_transp(id, nslices-1, atoi(params->slice_transp->answers[i])) < 0)
+ G_fatal_error(_("Unable to set slice (%d) transparency of volume %d"),
+ nslices-1, id);
+ }
+
+ /* set draw resolution and shading after slices are added*/
+ for (i = 0; i < nvols; i++) {
+
+ id = vol_list[i];
+ /* set resolution */
+ if (opt_get_num_answers(params->volume_res) != nvols)
+ res = atof(params->volume_res->answers[0]);
+ else
+ res = atof(params->volume_res->answers[i]);
+
+ GVL_slice_set_drawres(id, res, res, res);
+
+ /* set shading */
+ if (opt_get_num_answers(params->volume_shade) != nvols)
+ style = params->volume_shade->answers[0];
+ else
+ style = params->volume_shade->answers[i];
+
+ draw_mode = 0;
+
+ if (strcmp(style, "flat") == 0) {
+ draw_mode |= DM_FLAT;
+ }
+ else {
+ draw_mode |= DM_GOURAUD;
+ }
+
+ GVL_slice_set_drawmode(id, draw_mode);
+ }
+
+ return 1;
+}
More information about the grass-commit
mailing list