[GRASS-SVN] r31887 - in grass-addons/visualization/nviz2: cmd lib wxpython wxpython/nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 29 18:04:40 EDT 2008


Author: martinl
Date: 2008-06-29 18:04:40 -0400 (Sun, 29 Jun 2008)
New Revision: 31887

Modified:
   grass-addons/visualization/nviz2/cmd/args.c
   grass-addons/visualization/nviz2/cmd/local_proto.h
   grass-addons/visualization/nviz2/cmd/main.c
   grass-addons/visualization/nviz2/lib/draw.c
   grass-addons/visualization/nviz2/lib/map_obj.c
   grass-addons/visualization/nviz2/lib/nviz.h
   grass-addons/visualization/nviz2/wxpython/nviz.py
   grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i
   grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/load.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
   grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp
   grass-addons/visualization/nviz2/wxpython/preferences.py
Log:
nviz2: cmd prototype updated (surface attributes options)
wxGUI: all surface attributes implemented
Initial work on 'draw' section (mode, style, resolution)


Modified: grass-addons/visualization/nviz2/cmd/args.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/args.c	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/cmd/args.c	2008-06-29 22:04:40 UTC (rev 31887)
@@ -32,27 +32,94 @@
 */
 void parse_command(int argc, char* argv[], struct GParams *params)
 {
-    /* raster */
-    params->elev = G_define_standard_option(G_OPT_R_ELEV);
-    params->elev->required = NO;
-    params->elev->multiple = YES;
-    params->elev->description = _("Name of raster map(s) for elevation");
-    params->elev->guisection = _("Raster");
+    /* surface */
+    params->elev_map = G_define_standard_option(G_OPT_R_ELEV);
+    params->elev_map->required = NO;
+    params->elev_map->multiple = YES;
+    params->elev_map->description = _("Name of raster map(s) for elevation");
+    params->elev_map->guisection = _("Surface");
 
+    params->elev_const = G_define_option();
+    params->elev_const->key = "elevation_value";
+    params->elev_const->key_desc = "value";
+    params->elev_const->type = TYPE_INTEGER;
+    params->elev_const->required = NO;
+    params->elev_const->multiple = YES;
+    params->elev_const->description = _("Elevation value(s)");
+    params->elev_const->guisection = _("Surface");
+
     params->color_map = G_define_standard_option(G_OPT_R_MAP);
     params->color_map->multiple = YES;
     params->color_map->required = NO;
     params->color_map->description = _("Name of raster map(s) for color");
-    params->color_map->guisection = _("Raster");
+    params->color_map->guisection = _("Surface");
     params->color_map->key = "color_map";
 
     params->color_const = G_define_standard_option(G_OPT_C_FG);
     params->color_const->multiple = YES;
-    params->color_const->label = _("Color value");
-    params->color_const->guisection = _("Raster");
+    params->color_const->label = _("Color value(s)");
+    params->color_const->guisection = _("Surface");
     params->color_const->key = "color_value";
     params->color_const->answer = NULL;
 
+    params->mask_map = G_define_standard_option(G_OPT_R_MAP);
+    params->mask_map->multiple = YES;
+    params->mask_map->required = NO;
+    params->mask_map->description = _("Name of raster map(s) for mask");
+    params->mask_map->guisection = _("Surface");
+    params->mask_map->key = "mask_map";
+
+    params->transp_map = G_define_standard_option(G_OPT_R_MAP);
+    params->transp_map->multiple = YES;
+    params->transp_map->required = NO;
+    params->transp_map->description = _("Name of raster map(s) for transparency");
+    params->transp_map->guisection = _("Surface");
+    params->transp_map->key = "transparency_map";
+
+    params->transp_const = G_define_option();
+    params->transp_const->key = "transparency_value";
+    params->transp_const->key_desc = "value";
+    params->transp_const->type = TYPE_INTEGER;
+    params->transp_const->required = NO;
+    params->transp_const->multiple = YES;
+    params->transp_const->description = _("Transparency value(s)");
+    params->transp_const->guisection = _("Surface");
+    params->transp_const->options = "0-255";
+
+    params->shine_map = G_define_standard_option(G_OPT_R_MAP);
+    params->shine_map->multiple = YES;
+    params->shine_map->required = NO;
+    params->shine_map->description = _("Name of raster map(s) for shininess");
+    params->shine_map->guisection = _("Surface");
+    params->shine_map->key = "shininess_map";
+
+    params->shine_const = G_define_option();
+    params->shine_const->key = "shininess_value";
+    params->shine_const->key_desc = "value";
+    params->shine_const->type = TYPE_INTEGER;
+    params->shine_const->required = NO;
+    params->shine_const->multiple = YES;
+    params->shine_const->description = _("Shininess value(s)");
+    params->shine_const->guisection = _("Surface");
+    params->shine_const->options = "0-255";
+
+    params->emit_map = G_define_standard_option(G_OPT_R_MAP);
+    params->emit_map->multiple = YES;
+    params->emit_map->required = NO;
+    params->emit_map->description = _("Name of raster map(s) for emission");
+    params->emit_map->guisection = _("Surface");
+    params->emit_map->key = "emission_map";
+
+    params->emit_const = G_define_option();
+    params->emit_const->key = "emission_value";
+    params->emit_const->key_desc = "value";
+    params->emit_const->type = TYPE_INTEGER;
+    params->emit_const->required = NO;
+    params->emit_const->multiple = YES;
+    params->emit_const->description = _("Emission value(s)");
+    params->emit_const->guisection = _("Surface");
+    params->emit_const->options = "0-255";
+
     /* vector */
     params->vector = G_define_standard_option(G_OPT_V_MAP);
     params->vector->multiple = YES;
@@ -101,7 +168,7 @@
     params->persp->description = _("Viewpoint field of view (in degrees)");
     params->persp->guisection = _("Viewpoint");
     params->persp->answer = "40";
-    params->persp->options = "0-100";
+    params->persp->options = "1-100";
 
     params->twist = G_define_option();
     params->twist->key = "twist";

Modified: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-29 22:04:40 UTC (rev 31887)
@@ -5,11 +5,18 @@
 
 /* module flags and parameters */
 struct GParams { 
-  struct Option *elev, *color_map, *color_const, /* raster */
-    *vector, /* vector */
-    *exag, *bgcolor, /* misc */
-    *pos, *height, *persp, *twist, /* viewpoint */
-    *output, *format, *size; /* output */
+  /* raster */
+  struct Option *elev_map, *elev_const, *color_map, *color_const,
+    *mask_map, *transp_map, *transp_const, *shine_map, *shine_const,
+    *emit_map, *emit_const,
+  /* vector */
+    *vector, 
+  /* misc */
+    *exag, *bgcolor, 
+  /* viewpoint */
+    *pos, *height, *persp, *twist, 
+  /* output */
+    *output, *format, *size; 
 };
 
 /* args.c */

Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/cmd/main.c	2008-06-29 22:04:40 UTC (rev 31887)
@@ -25,6 +25,7 @@
 #include "local_proto.h"
 
 static void swap_gl();
+static int opt_get_num_answers(const struct Option *);
 
 int main (int argc, char *argv[])
 {
@@ -33,8 +34,11 @@
 
     char *mapset;
     unsigned int i;
+    unsigned int ncolor_map, ncolor_const, nmask_map;
+    unsigned int ntransp_map, ntransp_const, nshine_map, nshine_const;
+    unsigned int nemit_map, nemit_const;
+    int *surf_list, nsurfs;
     int id, ret;
-    unsigned int nelev, ncolor_map, ncolor_const, nvect;
     float vp_height, z_exag; /* calculated viewpoint height, z-exag */
     int width, height; /* output image size */
     char *output_name;
@@ -98,68 +102,134 @@
 			 1.0, 1.0, 1.0);
     Nviz_set_light_ambient(&data, 1,
 			   0.3, 0.3, 0.3);
-    
-    /* load data */
-    nelev = ncolor_map = ncolor_const = 0;
 
-    i = 0;
-    while(params->color_map->answer && params->color_map->answers[i++])
-	ncolor_map++;
-
-    i = 0;
-    while(params->color_const->answer && params->color_const->answers[i++])
-	ncolor_const++;
-
-    /* load rasters */
-    if (params->elev->answer) {
-	for (i = 0; params->elev->answers[i]; i++) {
-	    mapset = G_find_cell2 (params->elev->answers[i], "");
+    /*
+     * load raster maps (surface topography) map/constant
+     */
+    if (params->elev_map->answer) {
+	/* maps */
+	for (i = 0; params->elev_map->answers[i]; i++) {
+	    mapset = G_find_cell2 (params->elev_map->answers[i], "");
 	    if (mapset == NULL) {
 		G_fatal_error(_("Raster map <%s> not found"),
-			      params->elev->answers[i]);
+			      params->elev_map->answers[i]);
 	    }
 	    
 	    /* topography */
 	    id = Nviz_new_map_obj(MAP_OBJ_SURF,
-				  G_fully_qualified_name(params->elev->answers[i], mapset),
+				  G_fully_qualified_name(params->elev_map->answers[i], mapset), 0.0,
 				  &data);
+	}
+    }
 
-	    if (i < ncolor_map) { /* check for color map */
-		mapset = G_find_cell2 (params->color_map->answers[i], "");
-		if (mapset == NULL) {
-		    G_fatal_error(_("Raster map <%s> not found"),
-				  params->color_map->answers[i]);
-		}
+    ncolor_map = opt_get_num_answers(params->color_map);
+    ncolor_const = opt_get_num_answers(params->color_const);
+    if (params->elev_const->answer) {
+	/* constants */
+	float value;
+	surf_list = GS_get_surf_list(&nsurfs);
+	for (i = 0; params->elev_const->answers[i]; i++) {
+	    value = atof(params->elev_const->answers[i]);
+	    /* check for color */
+	    if (i + nsurfs >= ncolor_map + ncolor_const) {
+		G_fatal_error (_("Missing color settings for elevation value %f"),
+			       value);
+		/* topography */
+		id = Nviz_new_map_obj(MAP_OBJ_SURF,
+				      NULL, value,
+				      &data);
+	    }
+	}
+    }
 
-		Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
-			      G_fully_qualified_name(params->color_map->answers[i], mapset), -1.0,
-			      &data);
+    /* set surface attributes */
+    surf_list = GS_get_surf_list(&nsurfs);
+    nmask_map = opt_get_num_answers(params->mask_map);
+    ntransp_map = opt_get_num_answers(params->transp_map);
+    ntransp_const = opt_get_num_answers(params->transp_const);
+    nshine_map = opt_get_num_answers(params->shine_map);
+    nshine_const = opt_get_num_answers(params->shine_const);
+    nemit_map = opt_get_num_answers(params->emit_map);
+    nemit_const = opt_get_num_answers(params->emit_const);
+    for (i = 0; i < (unsigned int) nsurfs; i++) {
+	id = surf_list[i];
+	/* color */
+	if (i < ncolor_map) {
+	    mapset = G_find_cell2 (params->color_map->answers[i], "");
+	    if (mapset == NULL) {
+		G_fatal_error(_("Raster map <%s> not found"),
+			      params->color_map->answers[i]);
 	    }
-	    else if (i < ncolor_const) { /* check for color value */
-		Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
-			      NULL, Nviz_color_from_str(params->color_const->answers[i]),
-			      &data);
-	    }
-	    else { /* use by default elevation map for coloring */
-		Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
-			      G_fully_qualified_name(params->elev->answers[i], mapset), -1.0,
-			      &data);
-	    }
 	    
-	    /*
-	      if (i > 1)
-	      set_default_wirecolors(data, i);
-	    */
-	    nelev++;
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+			  G_fully_qualified_name(params->color_map->answers[i], mapset), -1.0,
+			  &data);
 	}
+	else if (i < ncolor_map + ncolor_const) { /* check for color value */
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
+			  NULL, Nviz_color_from_str(params->color_const->answers[i]),
+			  &data);
+	}
+	else { /* use by default elevation map for coloring */
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+			  G_fully_qualified_name(params->elev_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	/* mask */
+	if (i < nmask_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_MASK, MAP_ATT,
+			  G_fully_qualified_name(params->mask_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+
+	/* transparency */
+	if (i < ntransp_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, MAP_ATT,
+			  G_fully_qualified_name(params->transp_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	else if (i < ntransp_map + ntransp_const) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, CONST_ATT,
+			  NULL, atof(params->transp_const->answers[i-ntransp_map]),
+			  &data);
+	}
+
+	/* shininess */
+	if (i < nshine_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, MAP_ATT,
+			  G_fully_qualified_name(params->shine_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	else if (i < nshine_map + nshine_const) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, CONST_ATT,
+			  NULL, atof(params->shine_const->answers[i-nshine_map]),
+			  &data);
+	}
+
+	/* emission */
+	if (i < nemit_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, MAP_ATT,
+			  G_fully_qualified_name(params->emit_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	else if (i < nemit_map + nemit_const) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, CONST_ATT,
+			  NULL, atof(params->emit_const->answers[i-nemit_map]),
+			  &data);
+	}
+
+        /*
+	  if (i > 1)
+	  set_default_wirecolors(data, i);
+	*/
     }
 
     /* load vectors */
     if (params->vector->answer) {
-	if (!params->elev->answer && GS_num_surfs() == 0) { /* load base surface if no loaded */
+	if (!params->elev_map->answer && GS_num_surfs() == 0) { /* load base surface if no loaded */
 	    int *surf_list, nsurf;
 
-	    Nviz_new_map_obj(MAP_OBJ_SURF, NULL, &data);
+	    Nviz_new_map_obj(MAP_OBJ_SURF, NULL, 0.0, &data);
 
 	    surf_list = GS_get_surf_list(&nsurf);
 	    GS_set_att_const(surf_list[0], ATT_TRANSP, 255);
@@ -172,9 +242,9 @@
 			      params->vector->answers[i]);
 	    }
 	    Nviz_new_map_obj(MAP_OBJ_VECT,
-			     G_fully_qualified_name(params->vector->answers[i], mapset), &data);
+			     G_fully_qualified_name(params->vector->answers[i], mapset), 0.0,
+			     &data);
 	}
-	nvect++;
     }
 
     /* focus on loaded data */
@@ -186,7 +256,8 @@
     }
     else {
 	z_exag = Nviz_get_exag();
-	G_message(_("Vertical exaggeration, using calculated value %f"), z_exag);
+	G_message(_("Vertical exaggeration not given, using calculated value %f"),
+		  z_exag);
     }
     Nviz_change_exag(&data,
 		     z_exag);
@@ -239,3 +310,25 @@
 {
     return;
 }
+
+/*!
+  \brief Get number of answers of given option
+
+  \param pointer to option
+
+  \return number
+*/
+int opt_get_num_answers(const struct Option *opt)
+{
+    int i, num;
+    i = num = 0;
+    if (opt->answer) {
+	while (opt->answers[i]) {
+	    if (strcmp(opt->answers[i++], "")) {
+		num++; /* skip empty values */
+	    }
+	}
+    }
+
+    return i;
+}

Modified: grass-addons/visualization/nviz2/lib/draw.c
===================================================================
--- grass-addons/visualization/nviz2/lib/draw.c	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/lib/draw.c	2008-06-29 22:04:40 UTC (rev 31887)
@@ -363,3 +363,23 @@
 
     return 1;
 }
+
+/*!
+  \brief Set draw mode
+
+  Draw modes:
+   - DRAW_COARSE
+   - DRAW_FINE
+   - DRAW_BOTH
+
+  \param mode draw mode
+*/
+void Nviz_set_draw_mode(nv_data *data, int mode)
+{
+    if (mode == DRAW_COARSE) {
+	data->draw_coarse = 1;
+    }
+    else {
+	data->draw_coarse = 0;
+    }
+}

Modified: grass-addons/visualization/nviz2/lib/map_obj.c
===================================================================
--- grass-addons/visualization/nviz2/lib/map_obj.c	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/lib/map_obj.c	2008-06-29 22:04:40 UTC (rev 31887)
@@ -38,13 +38,14 @@
   set attributes such as topology, color, etc.
 
   \param type map object type
-  \param name map name
+  \param name map name (NULL for constant)
+  \param value constant (used if <i>name</i> is NULL)
   \param data nviz data
 
   \return map object id
   \return -1 on error
 */
-int Nviz_new_map_obj(int type, const char *name,
+int Nviz_new_map_obj(int type, const char *name, float value,
 		     nv_data *data)
 {
     int new_id, i;
@@ -81,7 +82,7 @@
 	}
 	else {
 	    /* constant */
-	    if (!Nviz_set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, NULL, 0.0,
+	    if (!Nviz_set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, NULL, value,
 			       data)) {
 		return -1;
 	    }
@@ -154,8 +155,8 @@
 
   \param id map object id
   \param type map object type (MAP_OBJ_SURF, MAP_OBJ_VECT, ...)
-  \param desc attribute descriptors
-  \param src attribute sources
+  \param desc attribute descriptor
+  \param src attribute source
   \param str_value attribute value as string (if NULL, check for <i>num_value</i>)
   \param num_value attribute value as float 
 
@@ -273,3 +274,21 @@
     return;
 }
 
+/*!
+  Unset map object attribute
+
+  \param id map object id
+  \param type map object type (MAP_OBJ_SURF, MAP_OBJ_VECT, ...)
+  \param desc attribute descriptor
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz_unset_attr(int id, int type, int desc)
+{
+    if (type == MAP_OBJ_SURF) {
+	return GS_unset_att(id, desc);
+    }
+    
+    return 0;
+}

Modified: grass-addons/visualization/nviz2/lib/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.h	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/lib/nviz.h	2008-06-29 22:04:40 UTC (rev 31887)
@@ -39,6 +39,10 @@
 #define MAP_OBJ_VOL 2
 #define MAP_OBJ_VECT 3
 
+#define DRAW_COARSE 0
+#define DRAW_FINE 1
+#define DRAW_BOTH 2
+
 #define RANGE (5 * GS_UNIT_SIZE)
 #define RANGE_OFFSET (2 * GS_UNIT_SIZE)
 #define ZRANGE (3 * GS_UNIT_SIZE)
@@ -77,6 +81,9 @@
     
     /* background color */
     int bgcolor;
+
+    /* draw */
+    int draw_coarse;
 } nv_data;
 
 /* The following structure is used to associate client data with surfaces.
@@ -131,6 +138,7 @@
 int Nviz_draw_all(nv_data *);
 int Nviz_draw_quick(nv_data *);
 int Nviz_draw_all_vect(nv_data *);
+void Nviz_set_draw_mode(nv_data *, int);
 
 /* exag.c */
 int Nviz_get_exag_height(float *, float *, float *);
@@ -148,11 +156,12 @@
 int Nviz_new_light(nv_data *);
 
 /* map_obj.c */
-int Nviz_new_map_obj(int, const char *,
+int Nviz_new_map_obj(int, const char *, float,
 		     nv_data *);
 int Nviz_set_attr(int, int, int, int, const char *, float,
 		  nv_data *);
 void Nviz_set_attr_default();
+int Nviz_unset_attr(int, int, int);
 
 /* nviz.c */
 void Nviz_init_data(nv_data *);

Modified: grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i	2008-06-29 22:04:40 UTC (rev 31887)
@@ -21,3 +21,7 @@
 #define VIEW_DEFAULT_PERSP 40.0
 #define VIEW_DEFAULT_TWIST 0.0
 #define VIEW_DEFAULT_ZEXAG 1.0
+
+#define DRAW_COARSE 0
+#define DRAW_FINE 1
+#define DRAW_BOTH 2

Modified: grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp	2008-06-29 22:04:40 UTC (rev 31887)
@@ -30,10 +30,18 @@
     
     Nviz_draw_cplane(data, -1, -1);
 
-    if (!quick)
-	Nviz_draw_all (data);
-    else
-	Nviz_draw_quick(data);
+    if (data->draw_coarse) { /* coarse */
+	GS_set_draw(GSD_BACK);
+	GS_ready_draw();
+	GS_alldraw_wire();
+	GS_done_draw();
+    }
+    else { /* fine / both */
+	if (!quick)
+	    Nviz_draw_all (data);
+	else
+	    Nviz_draw_quick(data);
+    }
 
     G_debug(1, "Nviz::Draw(): quick=%d", quick);
 
@@ -51,3 +59,20 @@
 
     return;
 }
+
+/*!
+  \brief Set draw mode
+
+  Draw modes:
+   - DRAW_COARSE
+   - DRAW_FINE
+   - DRAW_BOTH
+
+  \param mode draw mode
+*/
+void Nviz::SetDrawMode(int mode)
+{
+    Nviz_set_draw_mode(data, mode);
+
+    return;
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz/load.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/load.cpp	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/wxpython/nviz/load.cpp	2008-06-29 22:04:40 UTC (rev 31887)
@@ -46,7 +46,7 @@
 	    
     /* topography */
     id = Nviz_new_map_obj(MAP_OBJ_SURF,
-			  G_fully_qualified_name(name, mapset),
+			  G_fully_qualified_name(name, mapset), 0.0,
 			  data);
 
     if (color_name) { /* check for color map */

Modified: grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-29 22:04:40 UTC (rev 31887)
@@ -37,6 +37,7 @@
 
     /* surface.cpp */
     int SetSurfaceAttr(int, int, bool, const char *);
+    int UnsetSurfaceAttr(int, int);
 
 public:
     /* constructor */
@@ -66,11 +67,18 @@
     /* draw.cpp */
     void Draw(bool);
     void EraseMap();
+    void SetDrawMode(int);
 
     /* surface.cpp */
     int SetSurfaceTopo(int, bool, const char *);
     int SetSurfaceColor(int, bool, const char *);
+    int SetSurfaceMask(int, bool, const char *);
+    int SetSurfaceTransp(int, bool, const char *);
     int SetSurfaceShine(int, bool, const char *);
+    int SetSurfaceEmit(int, bool, const char *);
+    int UnsetSurfaceMask(int);
+    int UnsetSurfaceTransp(int);
+    int UnsetSurfaceEmit(int);
 };
 
 #endif /* __NVIZ_H__ */

Modified: grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp	2008-06-29 22:04:40 UTC (rev 31887)
@@ -49,6 +49,40 @@
 }
 
 /*!
+  \brief Set surface mask
+
+  @todo invert
+
+  \param id surface id
+  \param invert if true invert mask 
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceMask(int id, bool invert, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_MASK, true, value);
+}
+
+/*!
+  \brief Set surface mask
+
+  @todo invert
+
+  \param id surface id
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceTransp(int id, bool map, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_TRANSP, map, value);
+}
+
+/*!
   \brief Set surface shininess
 
   \param id surface id
@@ -64,6 +98,21 @@
 }
 
 /*!
+  \brief Set surface emission
+
+  \param id surface id
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceEmit(int id, bool map, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_EMIT, map, value);
+}
+
+/*!
   \brief Set surface attribute
 
   \param id surface id
@@ -101,3 +150,59 @@
 
     return ret;
 }
+
+/*!
+  \brief Unset surface mask
+
+  \param id surface id
+
+  \return 1 on success
+  \return 0 on failure
+*/
+
+int Nviz::UnsetSurfaceMask(int id)
+{
+    return UnsetSurfaceAttr(id, ATT_MASK);
+}
+
+/*!
+  \brief Unset surface transparency
+
+  \param id surface id
+
+  \return 1 on success
+  \return 0 on failure
+*/
+
+int Nviz::UnsetSurfaceTransp(int id)
+{
+    return UnsetSurfaceAttr(id, ATT_TRANSP);
+}
+
+/*!
+  \brief Unset surface emission
+
+  \param id surface id
+
+  \return 1 on success
+  \return 0 on failure
+*/
+
+int Nviz::UnsetSurfaceEmit(int id)
+{
+    return UnsetSurfaceAttr(id, ATT_EMIT);
+}
+
+/*!
+  \brief Unset surface attribute
+
+  \param id surface id
+  \param attr attribute descriptor
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::UnsetSurfaceAttr(int id, int attr)
+{
+    return Nviz_unset_attr(id, MAP_OBJ_SURF, attr);
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-29 22:04:40 UTC (rev 31887)
@@ -139,8 +139,8 @@
         if not self.init:
             self.nvizClass.InitView()
             self.LoadDataLayers()
-            (self.view['z-exag']['value'],
-             self.view['height']['value']) = self.nvizClass.SetViewDefault()
+            self.view['z-exag']['value'], \
+                self.view['height']['value'] = self.nvizClass.SetViewDefault()
             
             if hasattr(self.parent, "nvizToolWin"):
                 self.parent.nvizToolWin.UpdatePage('view')
@@ -312,10 +312,10 @@
         """Reset to default view"""
         self.view['pos']['x'] = wxnviz.VIEW_DEFAULT_POS_X
         self.view['pos']['y'] = wxnviz.VIEW_DEFAULT_POS_Y
-        self.view['height']['value'] = self.nvizClass.SetViewDefault()
+        self.view['z-exag']['value'], \
+            self.view['height']['value'] = self.nvizClass.SetViewDefault()
         self.view['persp']['value'] = wxnviz.VIEW_DEFAULT_PERSP
         self.view['twist']['value'] = wxnviz.VIEW_DEFAULT_TWIST
-        self.view['z-exag']['value'] = wxnviz.VIEW_DEFAULT_ZEXAG
 
         self.update['view'] = None
         self.update['z-exag'] = None
@@ -532,19 +532,23 @@
         self.win['surface']['attr'] = {}
         row = 0
         for code, attr in (('topo', _("Topography")),
-                     ('color', _("Color")),
-                     ('mask', _("Mask")),
-                     ('transp', _("Transparency")),
-                     ('shine', _("Shininess")),
-                     ('emis', _("Emission"))):
+                           ('color', _("Color")),
+                           ('mask', _("Mask")),
+                           ('transp', _("Transparency")),
+                           ('shine', _("Shininess")),
+                           ('emit', _("Emission"))):
             self.win['surface'][code] = {} 
             gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
                                              label=attr + ':'),
                           pos=(row, 0), flag=wx.ALIGN_CENTER_VERTICAL)
             use = wx.Choice (parent=panel, id=wx.ID_ANY, size=(100, -1),
-                             choices = [_("map"),
-                                        _("constant")])
+                             choices = [_("map")])
+            if code not in ('topo', 'color', 'shine'):
+                use.Insert(item=_("unset"), pos=0)
+            if code != 'mask':
+                use.Append(item=_('constant'))
             self.win['surface'][code]['use'] = use.GetId()
+            use.SetSelection(0) # unset
             use.Bind(wx.EVT_CHOICE, self.OnSurfaceUse)
             gridSizer.Add(item=use, flag=wx.ALIGN_CENTER_VERTICAL,
                           pos=(row, 1))
@@ -570,7 +574,7 @@
                                     initial=0)
                 if code == 'topo':
                     value.SetRange(minVal=-1e9, maxVal=1e9)
-                elif code in ('shine', 'transp', 'emis'):
+                elif code in ('shine', 'transp', 'emit'):
                     value.SetRange(minVal=0, maxVal=255)
                 else:
                     value.SetRange(minVal=0, maxVal=100)
@@ -581,10 +585,11 @@
                 value.Enable(False)
                 gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
                               pos=(row, 3))
-                self.SetSurfaceUseMap(code) # -> enable map / disable constant
             else:
-                use.Delete(1) # delete 'constant' from list
+                self.win['surface'][code]['constant'] = None
 
+            self.SetSurfaceUseMap(code) # -> enable map / disable constant
+                
             row += 1
 
         boxSizer.Add(item=gridSizer, proportion=1,
@@ -610,7 +615,7 @@
                           choices = [_("coarse"),
                                      _("fine"),
                                      _("both")])
-        mode.SetSelection(0)
+        mode.SetSelection(UserSettings.Get(group='nviz', key='surface', subkey=['draw', 'mode']))
         mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
         gridSizer.Add(item=mode, flag=wx.ALIGN_CENTER_VERTICAL,
                       pos=(0, 1))
@@ -782,7 +787,7 @@
                         'twist',
                         'z-exag'):
             for win in self.win['view'][control].itervalues():
-                self.FindWindowById(win).SetValue(self.settings[control]['value'])
+                self.FindWindowById(win).SetValue(int(self.settings[control]['value']))
 
         self.FindWindowById(self.win['view']['pos']).Draw()
         self.FindWindowById(self.win['view']['pos']).Refresh(False)
@@ -874,18 +879,45 @@
         layer = self.mapWindow.GetSelectedLayer()
         id = self.mapWindow.GetMapObjId(layer)
 
+        # surface attributes
         for attr in ('topo', 'color', 'mask',
-                     'transp', 'shine', 'emis'):
+                     'transp', 'shine', 'emit'):
             if self.mapWindow.update.has_key(attr):
                 map, value = self.mapWindow.update[attr]
-                if attr == 'topo':
-                    self.mapWindow.nvizClass.SetSurfaceTopo(id, map, str(value)) 
-                elif attr == 'color':
-                    self.mapWindow.nvizClass.SetSurfaceColor(id, map, str(value)) 
-                elif attr == 'shine':
-                    self.mapWindow.nvizClass.SetSurfaceShine(id, map, str(value)) 
+                if map is None: # unset
+                    # only optional attributes
+                    if attr == 'mask':
+                        # TODO: invert mask
+                        # TODO: broken in NVIZ
+                        self.mapWindow.nvizClass.UnsetSurfaceMask(id)
+                    elif attr == 'transp':
+                        self.mapWindow.nvizClass.UnsetSurfaceTransp(id)
+                    elif attr == 'emit':
+                        self.mapWindow.nvizClass.UnsetSurfaceEmit(id) 
+                else:
+                    if len(value) <= 0: # ignore empty values (TODO: warning)
+                        continue
+                    if attr == 'topo':
+                        self.mapWindow.nvizClass.SetSurfaceTopo(id, map, str(value)) 
+                    elif attr == 'color':
+                        self.mapWindow.nvizClass.SetSurfaceColor(id, map, str(value))
+                    elif attr == 'mask':
+                        # TODO: invert mask
+                        # TODO: broken in NVIZ
+                        self.mapWindow.nvizClass.SetSurfaceMask(id, False, str(value))
+                    elif attr == 'transp':
+                        self.mapWindow.nvizClass.SetSurfaceTransp(id, map, str(value)) 
+                    elif attr == 'shine':
+                        self.mapWindow.nvizClass.SetSurfaceShine(id, map, str(value)) 
+                    elif attr == 'emit':
+                        self.mapWindow.nvizClass.SetSurfaceEmit(id, map, str(value)) 
+
                 del self.mapWindow.update[attr]
 
+        # drawing mode
+        if self.update.has_key('draw-mode'):
+            self.mapWindow.nvizClass.SetDrawMode(self.update['draw-mode'])
+
         self.mapWindow.Refresh(False)
 
     def OnClose(self, event):
@@ -905,10 +937,16 @@
         if not attrName:
             return
 
-        if event.GetSelection() == 0:
+        selection = event.GetSelection()
+        if attrName in ('topo', 'color'): # no 'unset'
+            selection += 1
+        if selection == 0: # unset
+            useMap = None
+            value = ''
+        elif selection == 1: # map
             useMap = True
             value = self.FindWindowById(self.win['surface'][attrName]['map']).GetValue()
-        else:
+        elif selection == 2: # constant
             useMap = False
             if attrName == 'color':
                 value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetColour()
@@ -917,20 +955,32 @@
                 value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetValue()
 
         self.SetSurfaceUseMap(attrName, useMap)
-
+        
         self.mapWindow.update[attrName] = (useMap, str(value))
         if self.parent.autoRender.IsChecked():
             self.OnApply(None)
 
-    def SetSurfaceUseMap(self, attrName, map=True):
-        if map: # map
+    def SetSurfaceUseMap(self, attrName, map=None):
+        if attrName in ('topo', 'color', 'shine'):
+            incSel = -1 # decrement selection (no 'unset')
+        else:
+            incSel = 0
+
+        if map is True: # map
             self.FindWindowById(self.win['surface'][attrName]['map']).Enable(True)
-            self.FindWindowById(self.win['surface'][attrName]['constant']).Enable(False)
+            if self.win['surface'][attrName]['constant']:
+                self.FindWindowById(self.win['surface'][attrName]['constant']).Enable(False)
+            self.FindWindowById(self.win['surface'][attrName]['use']).SetSelection(1 + incSel)
+        elif map is False: # constant
+            self.FindWindowById(self.win['surface'][attrName]['map']).Enable(False)
+            if self.win['surface'][attrName]['constant']:
+                self.FindWindowById(self.win['surface'][attrName]['constant']).Enable(True)
+            self.FindWindowById(self.win['surface'][attrName]['use']).SetSelection(2 + incSel)
+        else: # unset
+            self.FindWindowById(self.win['surface'][attrName]['map']).Enable(False)
+            if self.win['surface'][attrName]['constant']:
+                self.FindWindowById(self.win['surface'][attrName]['constant']).Enable(False)
             self.FindWindowById(self.win['surface'][attrName]['use']).SetSelection(0)
-        else: # constant
-            self.FindWindowById(self.win['surface'][attrName]['map']).Enable(False)
-            self.FindWindowById(self.win['surface'][attrName]['constant']).Enable(True)
-            self.FindWindowById(self.win['surface'][attrName]['use']).SetSelection(1)
 
     def OnSurfaceMap(self, event):
         """Set surface attribute"""
@@ -941,10 +991,14 @@
         if not attrName:
             return
 
-        if self.FindWindowById(self.win['surface'][attrName]['use']).GetSelection() == 0:
+        selection = self.FindWindowById(self.win['surface'][attrName]['use']).GetSelection()
+        if selection == 0: # unset
+            map = None
+            value = ''
+        elif selection == 1: # map
             value = self.FindWindowById(self.win['surface'][attrName]['map']).GetValue()
             map = True
-        else:
+        else: # constant
             if attrName == 'color':
                 value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetColour()
                 value = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
@@ -958,8 +1012,17 @@
             self.OnApply(None)
 
     def OnSurfaceMode(self, event):
-        pass
+        """Drawing mode changed"""
+        selection = event.GetSelection()
+        if selection == 0: # coarse
+            self.mapWindow.update['draw-mode'] = wxnviz.DRAW_COARSE
+        elif selection == 1: # fine
+            self.mapWindow.update['draw-mode'] = wxnviz.DRAW_FINE
+        elif selection == 2: # both
+            self.mapWindow.update['draw-mode'] = wxnviz.DRAW_BOTH
 
+        event.Skip()
+
     def OnSurfaceStyle(self, event):
         pass
 
@@ -979,6 +1042,7 @@
         elif pageId == 'surface':
             if nvizLayer is None:
                 for attr in ('topo', 'color'):
+                    self.SetSurfaceUseMap(attr, True) # -> map
                     self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)
                 if UserSettings.Get(group='nviz', key='surface', subkey=['shininess', 'map']) is False:
                     self.SetSurfaceUseMap('shine', False)

Modified: grass-addons/visualization/nviz2/wxpython/preferences.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/preferences.py	2008-06-29 21:58:52 UTC (rev 31886)
+++ grass-addons/visualization/nviz2/wxpython/preferences.py	2008-06-29 22:04:40 UTC (rev 31887)
@@ -198,7 +198,7 @@
                 },
             'nviz' : {
                 'view' : {'persp' : { 'value' : 40,
-                                      'min' : 0,
+                                      'min' : 1,
                                       'max' : 100,
                                       'step' : 5,
                                       'update' : False,



More information about the grass-commit mailing list