[GRASS-SVN] r32651 - in grass/branches/develbranch_6: lib/ogsf
visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Aug 9 05:37:38 EDT 2008
Author: martinl
Date: 2008-08-09 05:37:38 -0400 (Sat, 09 Aug 2008)
New Revision: 32651
Modified:
grass/branches/develbranch_6/lib/ogsf/GVL2.c
grass/branches/develbranch_6/lib/ogsf/gvl.c
grass/branches/develbranch_6/lib/ogsf/gvl_calc.c
grass/branches/develbranch_6/visualization/nviz2/cmd/args.c
grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h
grass/branches/develbranch_6/visualization/nviz2/cmd/main.c
grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c
grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c
Log:
nviz2/cli: volume support in progress (fundamental attributes: topo, color)
some doxygen/debug messages in ogsflib
Modified: grass/branches/develbranch_6/lib/ogsf/GVL2.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/GVL2.c 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/lib/ogsf/GVL2.c 2008-08-09 09:37:38 UTC (rev 32651)
@@ -620,7 +620,7 @@
geovol *gvl;
geovol_isosurf *isosurf;
- G_debug(3, "GVL_isosurf_add");
+ G_debug(3, "GVL_isosurf_add() id=%d", id);
gvl = gvl_get_vol(id);
@@ -630,8 +630,8 @@
if (gvl->n_isosurfs == MAX_ISOSURFS)
return (-1);
- if (NULL ==
- (isosurf = (geovol_isosurf *) G_malloc(sizeof(geovol_isosurf)))) {
+ isosurf = (geovol_isosurf *) G_malloc(sizeof(geovol_isosurf));
+ if (!isosurf) {
return (-1);
}
@@ -821,19 +821,29 @@
/*!
\brief Set constant isosurface attribute
+ Attributes:
+ - ATT_NORM
+ - ATT_TOPO topography (level) constant
+ - ATT_COLOR color map/constant
+ - ATT_MASK mask map
+ - ATT_TRANSP transparency map/constant
+ - ATT_SHINE shininess map/constant
+ - ATT_EMIT emission map/constant
+
\param id volume set id
- \param isosurf_id isosurface id
- \param att attribute id
+ \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+ \param att attribute descriptor
\param constant constant value
- \return ?
+ \return 1 on success
\return -1 on error
*/
int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
{
geovol_isosurf *isosurf;
- G_debug(3, "GVL_isosurf_set_att_const");
+ G_debug(3, "GVL_isosurf_set_att_const() id=%d isosurf_id=%d "
+ "att=%d const=%f", id, isosurf_id, att, constant);
isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
@@ -847,12 +857,21 @@
/*!
\brief Set isosurface map attribute
+ Attributes:
+ - ATT_NORM
+ - ATT_TOPO topography (level) constant
+ - ATT_COLOR color map/constant
+ - ATT_MASK mask map
+ - ATT_TRANSP transparency map/constant
+ - ATT_SHINE shininess map/constant
+ - ATT_EMIT emission map/constant
+
\param id volume set id
- \param isosurf_id isosurface id
- \param att attribute id
+ \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
+ \param att attribute descriptor
\param filename map name
- \return ?
+ \return 1 on success
\return -1 on error
*/
int GVL_isosurf_set_att_map(int id, int isosurf_id, int att,
@@ -860,7 +879,8 @@
{
geovol_isosurf *isosurf;
- G_debug(3, "GVL_isosurf_set_att_map");
+ G_debug(3, "GVL_isosurf_set_att_map(): id=%d, isosurf_id=%d "
+ "att=%d map=%s", id, isosurf_id, att, filename);
isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
Modified: grass/branches/develbranch_6/lib/ogsf/gvl.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/gvl.c 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/lib/ogsf/gvl.c 2008-08-09 09:37:38 UTC (rev 32651)
@@ -527,6 +527,9 @@
isosurf->att[i].att_src = NOTSET_ATT;
isosurf->att[i].constant = 0.;
isosurf->att[i].hfile = -1;
+ isosurf->att[i].user_func = NULL;
+ isosurf->att[i].att_data = NULL;
+ isosurf->att[i].changed = 0;
}
isosurf->data = NULL;
@@ -563,10 +566,10 @@
}
/*!
- \brief Get geovol_isosurf struct of given volume set
+ \brief Get isosurface of given volume set
\param id volume set id
- \param isosurf_id isosurface id
+ \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
\return pointer to geovol_isosurf struct
\return NULL on failure
@@ -575,6 +578,9 @@
{
geovol *gvl;
+ G_debug(5, "gvl_isosurf_get_isosurf(): id=%d isosurf=%d",
+ id, isosurf_id);
+
gvl = gvl_get_vol(id);
if (gvl) {
@@ -645,10 +651,10 @@
}
/*!
- \brief Set attribute constant
+ \brief Set isosurface attribute constant
\param isosurf pointer to geovol_isosurf struct
- \param desc attribute id
+ \param desc attribute descriptor
\param constant attribute value
\return -1 on failure
@@ -657,7 +663,8 @@
int gvl_isosurf_set_att_const(geovol_isosurf * isosurf, int desc,
float constant)
{
- G_debug(5, "gvl_isosurf_set_att_const");
+ G_debug(5, "gvl_isosurf_set_att_const(): att=%d, const=%f",
+ desc, constant);
if (isosurf) {
isosurf->att[desc].constant = constant;
@@ -685,7 +692,7 @@
{
int hfile;
- G_debug(5, "gvl_isosurf_set_att_map(): att_map: %s", filename);
+ G_debug(5, "gvl_isosurf_set_att_map(): att=%d map=%s", desc, filename);
if (isosurf) {
if (0 > (hfile = gvl_file_newh(filename, VOL_FTYPE_G3D)))
Modified: grass/branches/develbranch_6/lib/ogsf/gvl_calc.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/gvl_calc.c 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/lib/ogsf/gvl_calc.c 2008-08-09 09:37:38 UTC (rev 32651)
@@ -751,10 +751,14 @@
\param pos position index
\param data data buffer
- \param char
+ \return char on success
+ \return NULL on failure
*/
unsigned char gvl_read_char(int pos, const unsigned char *data)
{
+ if (!data)
+ return NULL;
+
return data[pos];
}
Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/args.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/args.c 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/args.c 2008-08-09 09:37:38 UTC (rev 32651)
@@ -289,7 +289,7 @@
params->vlines->required = NO;
params->vlines->description = _("Name of line vector overlay map(s)");
params->vlines->guisection = _("Vector lines");
- params->vlines->key = "vlines";
+ params->vlines->key = "vline";
/* line width */
params->vline_width = G_define_option();
@@ -346,7 +346,7 @@
params->vpoints->required = NO;
params->vpoints->description = _("Name of point vector overlay map(s)");
params->vpoints->guisection = _("Vector points");
- params->vpoints->key = "vpoints";
+ params->vpoints->key = "vpoint";
/* point width */
params->vpoint_size = G_define_option();
@@ -462,8 +462,64 @@
params->volume = G_define_standard_option(G_OPT_R3_MAPS);
params->volume->required = NO;
params->volume->guisection = _("Volume");
- params->volume->key = "rast3d";
+ params->volume->key = "volume";
+ /* mode */
+ params->volume_mode = G_define_option();
+ params->volume_mode->key = "volume_mode";
+ params->volume_mode->key_desc = "string";
+ params->volume_mode->type = TYPE_STRING;
+ params->volume_mode->required = YES;
+ params->volume_mode->multiple = YES;
+ params->volume_mode->description = _("Volume draw mode");
+ params->volume_mode->options = "isosurface,slice";
+ params->volume_mode->answer = "isosurface";
+ params->volume_mode->guisection = _("Draw");
+
+ /* shading */
+ params->volume_shade = G_define_option();
+ params->volume_shade->key = "volume_shading";
+ params->volume_shade->key_desc = "string";
+ params->volume_shade->type = TYPE_STRING;
+ params->volume_shade->required = YES;
+ params->volume_shade->multiple = YES;
+ params->volume_shade->description = _("Volume shading");
+ params->volume_shade->options = "flat,gouraud";
+ params->volume_shade->answer = "gouraud";
+ params->volume_shade->guisection = _("Draw");
+
+ /* position */
+ params->volume_pos = G_define_option();
+ params->volume_pos->key = "volume_position";
+ params->volume_pos->key_desc = "x,y,z";
+ params->volume_pos->type = TYPE_INTEGER;
+ params->volume_pos->required = YES;
+ params->volume_pos->multiple = YES;
+ params->volume_pos->description = _("Volume position");
+ params->volume_pos->guisection = _("Volume");
+ params->volume_pos->answer = "0,0,0";
+
+ /* resolution */
+ params->volume_res = G_define_option();
+ params->volume_res->key = "volume_resolution";
+ params->volume_res->key_desc = "value";
+ params->volume_res->type = TYPE_INTEGER;
+ params->volume_res->required = YES;
+ params->volume_res->multiple = YES;
+ params->volume_res->description = _("Volume resolution");
+ params->volume_res->answer = "3";
+ params->volume_res->guisection = _("Volume");
+
+ /* isosurface level */
+ params->isosurf_level = G_define_option();
+ params->isosurf_level->key = "isosurf_level";
+ params->isosurf_level->key_desc = "volume:value";
+ params->isosurf_level->type = TYPE_STRING;
+ params->isosurf_level->required = NO;
+ params->isosurf_level->multiple = YES;
+ params->isosurf_level->description = _("Isosurface level");
+ params->isosurf_level->guisection = _("Volume");
+
return;
}
Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h 2008-08-09 09:37:38 UTC (rev 32651)
@@ -20,7 +20,7 @@
/* vector points */
*vpoints, *vpoint_size, *vpoint_marker, *vpoint_color, *vpoint_width,
/* volumes */
- *volume,
+ *volume, *volume_mode, *volume_shade, *volume_pos, *volume_res, *isosurf_level,
/* misc */
*exag, *bgcolor,
/* viewpoint */
@@ -40,13 +40,14 @@
void surface_set_draw_mode(const struct GParams *);
/* vector.c */
-int load_vector_lines(const struct GParams *, nv_data *);
-int load_vector_points(const struct GParams *, nv_data *);
+int load_vlines(const struct GParams *, nv_data *);
+int load_vpoints(const struct GParams *, nv_data *);
int vlines_set_attrb(const struct GParams *);
int vpoints_set_attrb(const struct GParams *);
/* volume.c */
-int load_volume(const struct GParams *, nv_data *);
+int load_rasters3d(const struct GParams *, nv_data *);
+int add_isosurfs(const struct GParams *, nv_data *);
/* write_img.c */
int write_img(const char *, int);
Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/main.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/main.c 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/main.c 2008-08-09 09:37:38 UTC (rev 32651)
@@ -43,7 +43,7 @@
G_gisinit(argv[0]);
module = G_define_module();
- module->keywords = _("visualization, raster, vector");
+ module->keywords = _("visualization, raster, vector, raster3d");
module->description = _("Experimental NVIZ CLI prototype.");
params = (struct GParams *)G_malloc(sizeof(struct GParams));
@@ -99,23 +99,28 @@
/* load line vector maps */
if (params->vlines->answer) {
- load_vector_lines(params, &data);
+ load_vlines(params, &data);
/* set attributes of 2d lines */
vlines_set_attrb(params);
}
/* load point vector maps */
if (params->vpoints->answer) {
- load_vector_points(params, &data);
+ load_vpoints(params, &data);
/* set attributes for 2d lines */
vpoints_set_attrb(params);
}
/* load volumes */
if (params->volume->answer) {
- load_volume(params, &data);
+ load_rasters3d(params, &data);
}
+ /* define isosurfaces for displaying volumes */
+ if (params->isosurf_level->answer) {
+ add_isosurfs(params, &data);
+ }
+
/* focus on loaded data */
Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c 2008-08-09 09:37:38 UTC (rev 32651)
@@ -32,7 +32,7 @@
\return number of loaded vectors
*/
-int load_vector_lines(const struct GParams *params, nv_data * data)
+int load_vlines(const struct GParams *params, nv_data * data)
{
return load_vectors(params->elev_map, params->elev_const,
params->vlines, MAP_OBJ_VECT, data);
@@ -46,7 +46,7 @@
\return number of loaded vectors
*/
-int load_vector_points(const struct GParams *params, nv_data * data)
+int load_vpoints(const struct GParams *params, nv_data * data)
{
return load_vectors(params->elev_map, params->elev_const,
params->vpoints, MAP_OBJ_SITE, data);
Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c 2008-08-09 07:05:29 UTC (rev 32650)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c 2008-08-09 09:37:38 UTC (rev 32651)
@@ -14,6 +14,8 @@
\date 2008
*/
+#include <stdlib.h>
+
#include <grass/G3d.h>
#include <grass/glocale.h>
@@ -27,9 +29,9 @@
\return number of loaded volumes
*/
-int load_volume(const struct GParams *params, nv_data *data)
+int load_rasters3d(const struct GParams *params, nv_data *data)
{
- int i, nvol;
+ int i, nvol, id;
char *mapset;
nvol = opt_get_num_answers(params->volume);
@@ -41,11 +43,65 @@
params->volume->answers[i]);
}
- Nviz_new_map_obj(MAP_OBJ_VOL,
- G_fully_qualified_name(params->volume->answers[i],
- mapset),
- 0.0, data);
+ id = Nviz_new_map_obj(MAP_OBJ_VOL,
+ G_fully_qualified_name(params->volume->answers[i],
+ mapset),
+ 0.0, data);
}
return 1;
}
+
+/*!
+ \brief Add isosurfaces and set their attributes
+
+ \param params module parameters
+ \param data nviz data
+
+ \return number of defined isosurfaces
+*/
+int add_isosurfs(const struct GParams *params, nv_data *data)
+{
+ int i;
+ int num, level, nvols, *vol_list, id, nisosurfs;
+ char **tokens;
+
+ vol_list = GVL_get_vol_list(&nvols);
+
+ for (i = 0; params->isosurf_level->answers[i]; i++) {
+ tokens = G_tokenize(params->isosurf_level->answers[i], ":");
+ if (G_number_of_tokens(tokens) != 2)
+ G_fatal_error(_("Error tokenize '%s'"),
+ params->isosurf_level->answers[i]);
+ num = atoi(tokens[0]);
+ level = atoi(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_isosurf_add(id) < 0) {
+ G_fatal_error(_("Unable to add isosurface (volume set %d)"),
+ id);
+ }
+
+ nisosurfs = GVL_isosurf_num_isosurfs(id);
+
+ /* topography (level) */
+ if (GVL_isosurf_set_att_const(id, nisosurfs-1, ATT_TOPO, level) < 0) {
+ G_fatal_error(_("Unable to set isosurface (%d) attribute (%d) of volume %d"),
+ nisosurfs-1, ATT_TOPO, id);
+ }
+
+ /* 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);
+ }
+ }
+
+ return 1;
+}
More information about the grass-commit
mailing list