[GRASS-SVN] r47062 - grass/trunk/visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 8 09:34:04 EDT 2011
Author: annakrat
Date: 2011-07-08 06:34:04 -0700 (Fri, 08 Jul 2011)
New Revision: 47062
Modified:
grass/trunk/visualization/nviz2/cmd/args.c
grass/trunk/visualization/nviz2/cmd/local_proto.h
grass/trunk/visualization/nviz2/cmd/volume.c
Log:
nviz_cmd: volumes: add transparency, shininess, color, shading, position, resolution settings
Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c 2011-07-08 09:44:31 UTC (rev 47061)
+++ grass/trunk/visualization/nviz2/cmd/args.c 2011-07-08 13:34:04 UTC (rev 47062)
@@ -600,7 +600,61 @@
params->isosurf_level->multiple = YES;
params->isosurf_level->description = _("Isosurface level");
params->isosurf_level->guisection = _("Volumes");
+
+ /* isosurface color map */
+ params->isosurf_color_map = G_define_standard_option(G_OPT_R3_MAPS);
+ params->isosurf_color_map->key = "isosurf_color_map";
+ params->isosurf_color_map->required = NO;
+ params->isosurf_color_map->multiple = YES;
+ params->isosurf_color_map->description = _("Name of volume for isosurface color");
+ params->isosurf_color_map->guisection = _("Volumes");
+ /* isosurface color value */
+ params->isosurf_color_const = G_define_standard_option(G_OPT_C_FG);
+ params->isosurf_color_const->key = "isosurf_color_value";
+ params->isosurf_color_const->required = NO;
+ params->isosurf_color_const->multiple = YES;
+ params->isosurf_color_const->label = _("Isosurface color");
+ params->isosurf_color_const->guisection = _("Volumes");
+ params->isosurf_color_const->answer = NULL;
+
+ /* isosurface transparency */
+ params->isosurf_transp_map = G_define_standard_option(G_OPT_R3_MAP);
+ 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");
+ params->isosurf_transp_map->guisection = _("Volumes");
+ params->isosurf_transp_map->key = "isosurf_transparency_map";
+
+ params->isosurf_transp_const = G_define_option();
+ params->isosurf_transp_const->key = "isosurf_transparency_value";
+ params->isosurf_transp_const->key_desc = "value";
+ params->isosurf_transp_const->type = TYPE_INTEGER;
+ params->isosurf_transp_const->required = NO;
+ params->isosurf_transp_const->multiple = YES;
+ params->isosurf_transp_const->description = _("Transparency value(s)for isosurfaces");
+ params->isosurf_transp_const->guisection = _("Volumes");
+ params->isosurf_transp_const->options = "0-255";
+
+ /* isosurface shininess */
+ params->isosurf_shine_map = G_define_standard_option(G_OPT_R3_MAP);
+ params->isosurf_shine_map->multiple = YES;
+ params->isosurf_shine_map->required = NO;
+ params->isosurf_shine_map->description = _("Name of 3D raster map(s) for shininess");
+ params->isosurf_shine_map->guisection = _("Volumes");
+ params->isosurf_shine_map->key = "isosurf_shininess_map";
+
+ params->isosurf_shine_const = G_define_option();
+ params->isosurf_shine_const->key = "isosurf_shininess_value";
+ params->isosurf_shine_const->key_desc = "value";
+ params->isosurf_shine_const->type = TYPE_INTEGER;
+ params->isosurf_shine_const->required = NO;
+ params->isosurf_shine_const->multiple = YES;
+ params->isosurf_shine_const->description = _("Shininess value(s) for isosurfaces");
+ params->isosurf_shine_const->guisection = _("Volumes");
+ params->isosurf_shine_const->options = "0-255";
+
return;
}
@@ -671,7 +725,6 @@
params->cplane_rot->type = TYPE_DOUBLE;
params->cplane_rot->multiple = YES;
params->cplane_rot->required = NO;
- params->cplane_rot->label = _("Cutting plane rotation along the vertical axis");
params->cplane_rot->guisection = _("Cutting planes");
params->cplane_rot->description = _("Cutting plane rotation along the vertical axis");
params->cplane_rot->answer = "0";
@@ -683,7 +736,6 @@
params->cplane_tilt->type = TYPE_DOUBLE;
params->cplane_tilt->multiple = YES;
params->cplane_tilt->required = NO;
- params->cplane_tilt->label = _("Cutting plane tilt");
params->cplane_tilt->guisection = _("Cutting planes");
params->cplane_tilt->description = _("Cutting plane tilt");
params->cplane_tilt->answer = "0";
@@ -695,7 +747,6 @@
params->cplane_shading->type = TYPE_STRING;
params->cplane_shading->multiple = NO;
params->cplane_shading->required = NO;
- params->cplane_shading->label = _("Cutting plane color (between two surfaces)");
params->cplane_shading->guisection = _("Cutting planes");
params->cplane_shading->description = _("Cutting plane color (between two surfaces)");
params->cplane_shading->answer = "clear";
@@ -767,6 +818,8 @@
int nvlines;
int nvpoints;
+
+ int nvolumes, nisosurf;
/* topography */
nelev_map = opt_get_num_answers(params->elev_map);
@@ -911,14 +964,38 @@
params->vlines->key, nvlines, params->vline_pos->key,
nconsts);
- return;
-
/*
* vector points
*/
nvpoints = opt_get_num_answers(params->vpoints);
/* TODO */
+
+ /*
+ * volumes
+ */
+ nvolumes = opt_get_num_answers(params->volume);
+ nisosurf = opt_get_num_answers(params->isosurf_level);
+
+ /* transparency */
+ nmaps = opt_get_num_answers(params->isosurf_transp_map);
+ nconsts = opt_get_num_answers(params->isosurf_transp_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_transp_map->key, nmaps,
+ params->isosurf_transp_const->key, nconsts);
+
+ /* 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);
+
+ return;
}
void print_error(int nmaps, int nconsts, int nelevs,
Modified: grass/trunk/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h 2011-07-08 09:44:31 UTC (rev 47061)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h 2011-07-08 13:34:04 UTC (rev 47062)
@@ -22,6 +22,8 @@
*vpoint_layer, *vpoint_size_column, *vpoint_marker_column, *vpoint_color_column, *vpoint_width_column,
/* 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,
/* misc */
*exag, *bgcolor,
/* cutting planes */
Modified: grass/trunk/visualization/nviz2/cmd/volume.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/volume.c 2011-07-08 09:44:31 UTC (rev 47061)
+++ grass/trunk/visualization/nviz2/cmd/volume.c 2011-07-08 13:34:04 UTC (rev 47062)
@@ -29,7 +29,8 @@
*/
int load_rasters3d(const struct GParams *params, nv_data *data)
{
- int i, nvol, id;
+ int i, nvol, id;
+ float x, y, z;
char *mapset;
nvol = opt_get_num_answers(params->volume);
@@ -45,6 +46,20 @@
G_fully_qualified_name(params->volume->answers[i],
mapset),
0.0, data);
+
+ /* set position */
+ if (opt_get_num_answers(params->volume_pos) != 3 * nvol) {
+ x = atof(params->volume_pos->answers[0]);
+ y = atof(params->volume_pos->answers[1]);
+ z = atof(params->volume_pos->answers[2]);
+ }
+ else {
+ x = atof(params->volume_pos->answers[i*3+0]);
+ y = atof(params->volume_pos->answers[i*3+1]);
+ z = atof(params->volume_pos->answers[i*3+2]);
+ }
+
+ GVL_set_trans(id, x, y, z);
}
return 1;
@@ -62,7 +77,10 @@
{
int i;
int num, level, nvols, *vol_list, id, nisosurfs;
+ int ncolor_map, ncolor_const, ntransp_map, ntransp_const, nshine_map, nshine_const;
+ int res, draw_mode;
char **tokens;
+ const char *mapset, *style;
vol_list = GVL_get_vol_list(&nvols);
@@ -94,12 +112,98 @@
nisosurfs-1, ATT_TOPO, id);
}
+ /* 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_isosurf_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_isosurf_set_drawmode(id, draw_mode);
+
/* color */
- if (GVL_isosurf_set_att_map(id, nisosurfs-1, ATT_COLOR, params->volume->answers[0]) < 0) {
- G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
- nisosurfs-1, ATT_COLOR, id);
+ ncolor_map = opt_get_num_answers(params->isosurf_color_map);
+ ncolor_const = opt_get_num_answers(params->isosurf_color_const);
+
+ if (i < ncolor_map && strcmp(params->isosurf_color_map->answers[i], "")) {
+ mapset = G_find_grid3(params->isosurf_color_map->answers[i], "");
+
+ if (mapset == NULL) {
+ G_fatal_error(_("3d raster map <%s> not found"),
+ params->isosurf_color_map->answers[i]);
+ }
+
+ if (GVL_isosurf_set_att_map(id, nisosurfs-1, ATT_COLOR,
+ params->isosurf_color_map->answers[i]) < 0)
+ G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
+ nisosurfs-1, ATT_COLOR, id);
}
+ else if (i-ncolor_map < ncolor_const &&
+ strcmp(params->isosurf_color_const->answers[i-ncolor_map], "")) {
+
+ if (GVL_isosurf_set_att_const(id, nisosurfs-1, ATT_COLOR,
+ Nviz_color_from_str(params->isosurf_color_const->answers[i-ncolor_map])) < 0)
+ G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
+ nisosurfs-1, ATT_COLOR, id);
+ }
+ else { /* use by default 3d raster map for coloring */
+ GVL_isosurf_set_att_map(id, nisosurfs-1, ATT_COLOR, params->volume->answers[num-1]);
+ G_verbose_message(_("Color attribute not defined, using default <%s>"),
+ params->volume->answers[num-1]);
+ }
+
+ /* transparency */
+ ntransp_map = opt_get_num_answers(params->isosurf_transp_map);
+ ntransp_const = opt_get_num_answers(params->isosurf_transp_const);
+
+ if (i < ntransp_map && strcmp(params->isosurf_transp_map->answers[i], "")) {
+ if (GVL_isosurf_set_att_map(id, nisosurfs-1, ATT_TRANSP,
+ params->isosurf_transp_map->answers[i]) < 0)
+ G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
+ nisosurfs-1, ATT_TRANSP, id);
+ }
+ else if (i-ntransp_map < ntransp_const &&
+ strcmp(params->isosurf_transp_const->answers[i-ntransp_map], "")) {
+ if (GVL_isosurf_set_att_const(id, nisosurfs-1, ATT_TRANSP,
+ atof(params->isosurf_transp_const->answers[i-ntransp_map])) < 0)
+ G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
+ nisosurfs-1, ATT_TRANSP, id);
+ }
+
+ /* shine */
+ nshine_map = opt_get_num_answers(params->isosurf_shine_map);
+ nshine_const = opt_get_num_answers(params->isosurf_shine_const);
+
+ if (i < nshine_map && strcmp(params->isosurf_shine_map->answers[i], "")) {
+ if (GVL_isosurf_set_att_map(id, nisosurfs-1, ATT_SHINE,
+ params->isosurf_shine_map->answers[i]) < 0)
+ G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
+ nisosurfs-1, ATT_SHINE, id);
+ }
+ else if (i-nshine_map < nshine_const &&
+ strcmp(params->isosurf_shine_const->answers[i-nshine_map], "")) {
+ if (GVL_isosurf_set_att_const(id, nisosurfs-1, ATT_SHINE,
+ atof(params->isosurf_shine_const->answers[i-nshine_map])) < 0)
+ G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
+ nisosurfs-1, ATT_SHINE, id);
+ }
}
-
+
return 1;
}
More information about the grass-commit
mailing list