[GRASS-SVN] r31668 - grass-addons/visualization/nviz2/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 10 09:39:02 EDT 2008


Author: martinl
Date: 2008-06-10 09:39:02 -0400 (Tue, 10 Jun 2008)
New Revision: 31668

Added:
   grass-addons/visualization/nviz2/cmd/description.html
   grass-addons/visualization/nviz2/cmd/position.c
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/cmd/map_obj.c
   grass-addons/visualization/nviz2/cmd/nviz.c
   grass-addons/visualization/nviz2/cmd/nviz.h
Log:
nviz_cmd: color_map/value option added
template for manual page created


Modified: grass-addons/visualization/nviz2/cmd/args.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/args.c	2008-06-10 11:52:51 UTC (rev 31667)
+++ grass-addons/visualization/nviz2/cmd/args.c	2008-06-10 13:39:02 UTC (rev 31668)
@@ -38,8 +38,22 @@
     params->elev->description = _("Name of raster map(s) for elevation");
     params->elev->guisection = _("Raster");
 
+    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->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->key = "color_value";
+    params->color_const->answer = NULL;
+
     params->exag = G_define_option();
-    params->exag->key = "exag";
+    params->exag->key = "zexag";
     params->exag->key_desc = "value";
     params->exag->type = TYPE_DOUBLE;
     params->exag->required = NO;
@@ -48,6 +62,9 @@
     params->exag->answer = "1.0";
     params->exag->options = "0-10";
 
+    params->bgcolor = G_define_standard_option(G_OPT_C_BG);
+
+    /* viewpoint */
     params->pos = G_define_option();
     params->pos->key = "position";
     params->pos->key_desc = "x,y";
@@ -95,3 +112,23 @@
 
     return;
 }
+
+/*!
+  \brief Get color value from color string (name or RGB triplet)
+
+  \param color_str color string
+
+  \return color value
+*/
+int color_from_cmd(const char *color_str)
+{
+    int red, grn, blu;
+
+    if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
+	G_warning (_("Invalid color (%s), using \"white\" as default"),
+		   color_str);
+	red = grn = blu = 255;
+    }
+
+    return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) + ((int)((blu) << 16) & BLU_MASK);
+}

Added: grass-addons/visualization/nviz2/cmd/description.html
===================================================================
--- grass-addons/visualization/nviz2/cmd/description.html	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/description.html	2008-06-10 13:39:02 UTC (rev 31668)
@@ -0,0 +1,19 @@
+<h2>DESCRIPTION</h2>
+
+Experimental CLI prototype of NVIZ.
+
+<p>
+TODO
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a HREF="nviz.html">TCL/TK-based NVIZ</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Martin Landa (Google Summer of Code 2008)
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass-addons/visualization/nviz2/cmd/description.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Modified: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-10 11:52:51 UTC (rev 31667)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-10 13:39:02 UTC (rev 31668)
@@ -6,13 +6,14 @@
 
 /* module flags and parameters */
 struct GParams { 
-  struct Option *elev, /* data */
-    *exag, /* misc */
+  struct Option *elev, *color_map, *color_const, /* data */
+    *exag, *bgcolor, /* misc */
     *pos, *height, *persp, *twist; /* viewpoint */
 };
 
 /* args.c */
 void parse_command(int, char**, struct GParams *);
+int color_from_cmd(const char *);
 
 /* cplanes_obj.c */
 int cplane_new(nv_data *, int);
@@ -38,12 +39,13 @@
 /* map_obj.c */
 int new_map_obj(int, const char *,
 		nv_data *);
-int set_attr(int, int, int, int, const char *,
+int set_attr(int, int, int, int, const char *, float,
 	     nv_data *);
 void set_att_default();
 
 /* nviz.c */
 void nv_data_init(nv_data *);
+void nv_data_set_bgcolor(nv_data *, int);
 
 /* lights.c */
 int light_set_position(nv_data *, int,
@@ -56,6 +58,11 @@
 int light_init(nv_data *, int);
 int light_new(nv_data *);
 
+/* position.c */
+void init_view();
+int focus_set_state(int);
+int focus_set_map(int, int);
+
 /* render.c */
 void render_window_init(render_window *);
 int render_window_create(render_window *, int, int);

Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c	2008-06-10 11:52:51 UTC (rev 31667)
+++ grass-addons/visualization/nviz2/cmd/main.c	2008-06-10 13:39:02 UTC (rev 31668)
@@ -5,6 +5,7 @@
  * AUTHOR(S):    Martin Landa <landa.martin gmail.com>
  *               
  * PURPOSE:      Experimental NVIZ CLI prototype
+ *               Google SoC 2008
  *               
  * COPYRIGHT:    (C) 2008 by the GRASS Development Team
  *
@@ -31,6 +32,7 @@
     char *mapset;
     unsigned int i;
     int id;
+    unsigned int nelev, ncolor_map, ncolor_const;
 
     nv_data data;
     render_window offscreen;
@@ -61,8 +63,20 @@
     nv_data_init(&data);
     /* define default attributes for map objects */
     set_att_default();
+    /* set background color */
+    nv_data_set_bgcolor(&data, color_from_cmd(params->bgcolor->answer)); 
 
     /* 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++;
+
     if (params->elev->answers) {
 	for (i = 0; params->elev->answers[i]; i++) {
 	    mapset = G_find_cell2 (params->elev->answers[i], "");
@@ -76,20 +90,72 @@
 			     G_fully_qualified_name(params->elev->answers[i], mapset),
 			     &data);
 
-	    /* color TODO: option */
-	    set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
-		     G_fully_qualified_name(params->elev->answers[i], mapset),
-		     &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]);
+		}
 
+		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_const) { /* check for color value */
+		set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
+			 NULL, color_from_cmd(params->color_const->answers[i]),
+			 &data);
+	    }
+	    else { /* use by default elevation map for coloring */
+		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++;
 	}
     }
 
+    /* init view */
+    init_view();
+    focus_set_map(MAP_OBJ_UNDEFINED, -1);
+
+    /* set lights */
+    /* TODO: add options */
+    light_set_position(&data, 0,
+		       0.68, -0.68, 0.80, 0.0);
+    light_set_bright(&data, 0,
+		     0.8);
+    light_set_color(&data, 0,
+		    1.0, 1.0, 1.0);
+    light_set_ambient(&data, 0,
+		      0.2, 0.2, 0.2);
+
+    /*
+    light_set_position(&data, 1,
+		       0.68, -0.68, 0.80, 0.0);
+    light_set_bright(&data, 1,
+		     0.8);
+    light_set_color(&data, 1,
+		    1.0, 1.0, 1.0);
+    light_set_ambient(&data, 1,
+		      0.2, 0.2, 0.2);
+    */
+
+    light_set_position(&data, 1,
+		       0.0, 0.0, 1.0, 0.0);
+    light_set_bright(&data, 1,
+		     0.5);
+    light_set_color(&data, 1,
+		    1.0, 1.0, 1.0);
+    light_set_ambient(&data, 1,
+		      0.3, 0.3, 0.3);
+    
     /* define view point */
-    GS_init_view();
     viewpoint_set_height(&data,
 			 atof(params->height->answer));
     change_exag(&data,
@@ -103,42 +169,15 @@
 			atoi(params->persp->answer));
 
 
-    /* resize_window(400, 400); */
+    // resize_window(600, 480);
 
-    /*
-    light_set_position(&data, 0,
-		       0.68, -0.68, 0.80, 0.0);
-    light_set_position(&data, 1,
-		       0.68, -0.68, 0.80, 0.0);
-    light_set_position(&data, 2,
-		       0.0, 0.0, 1.0, 0.0);
-    light_set_bright(&data, 0,
-		     0.8);
-    light_set_bright(&data, 1,
-		     0.8);
-    light_set_bright(&data, 2,
-		     0.5);
-    light_set_color(&data, 0,
-		    1.0, 1.0, 1.0);
-    light_set_color(&data, 1,
-		    1.0, 1.0, 1.0);
-    light_set_color(&data, 2,
-		    1.0, 1.0, 1.0);
-    light_set_ambient(&data, 0,
-		      0.2, 0.2, 0.2);
-    light_set_ambient(&data, 1,
-		      0.2, 0.2, 0.2);
-    light_set_ambient(&data, 2,
-		      0.3, 0.3, 0.3);
-    */
-
-
     GS_clear(data.bgcolor);
 
+    /* draw */
     cplane_draw(&data, -1, -1);
     draw_all (&data);
 
-    write_ppm("test.ppm");
+    write_ppm("test.ppm"); /* TODO: option 'format' */
 
     render_window_destroy(&offscreen);
 

Modified: grass-addons/visualization/nviz2/cmd/map_obj.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/map_obj.c	2008-06-10 11:52:51 UTC (rev 31667)
+++ grass-addons/visualization/nviz2/cmd/map_obj.c	2008-06-10 13:39:02 UTC (rev 31668)
@@ -82,14 +82,14 @@
 	
 	if (name) {
 	    /* map */
-	    if (!set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, MAP_ATT, name,
+	    if (!set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, MAP_ATT, name, -1.0,
 			  data)) {
 		return -1;
 	    }
 	}
 	else {
 	    /* constant */
-	    if (!set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, "0",
+	    if (!set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, NULL, 0.0,
 			  data)) {
 		return -1;
 	    }
@@ -136,12 +136,14 @@
   \param type map object type (MAP_OBJ_SURF, MAP_OBJ_VECT, ...)
   \param desc attribute descriptors
   \param src attribute sources
-  \param str_value attribute value as string
+  \param str_value attribute value as string (if NULL, check for <i>num_value</i>)
+  \param num_value attribute value as float 
 
   \return 1 on success
   \return 0 on failure
 */
-int set_attr(int id, int type, int desc, int src, const char *str_value,
+int set_attr(int id, int type, int desc, int src,
+	     const char *str_value, float num_value,
 	     nv_data *data)
 {
     int ret;
@@ -157,7 +159,10 @@
 	    /* Get the value for the constant
 	     * Note that we require the constant to be an integer
 	     */
-	    value = (float) atof(str_value);
+	    if (str_value)
+		value = (float) atof(str_value);
+	    else
+		value = num_value;
 	    
 	    /* Only special case is setting constant color.
 	     * In this case we have to decode the constant Tcl
@@ -165,13 +170,14 @@
 	     */
 	    if (desc == ATT_COLOR) {
 		/* TODO check this - sometimes gets reversed when save state
-		   saves a surface with constant color */
-		/* Tcl code and C code reverse RGB to BGR (sigh) */
+		   saves a surface with constant color
+
 		int r, g, b;
-		r = (((int) value) & 0xff0000) >> 16;
-		g = (((int) value) & 0x00ff00) >> 8;
-		b = (((int) value) & 0x0000ff);
+		r = (((int) value) & RED_MASK) >> 16;
+		g = (((int) value) & GRN_MASK) >> 8;
+		b = (((int) value) & BLU_MASK);
 		value = r + (g << 8) + (b << 16);
+		*/
 	    }
 	    
 	    /* Once the value is parsed, set it */

Modified: grass-addons/visualization/nviz2/cmd/nviz.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.c	2008-06-10 11:52:51 UTC (rev 31667)
+++ grass-addons/visualization/nviz2/cmd/nviz.c	2008-06-10 13:39:02 UTC (rev 31668)
@@ -37,8 +37,6 @@
 	cplane_off(data, i);
     }
     
-    data->bgcolor = 16777215; /* TODO: option bgcolor */
-
     /* lights */
     for (i = 0; i < MAX_LIGHTS; i++) {
 	light_new(data);
@@ -46,3 +44,15 @@
 
     return;
 }
+
+/*!
+  \brief Set background color
+
+  \param color color value
+*/
+void nv_data_set_bgcolor(nv_data *data, int color)
+{
+    data->bgcolor = color;
+    
+    return;
+}

Modified: grass-addons/visualization/nviz2/cmd/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.h	2008-06-10 11:52:51 UTC (rev 31667)
+++ grass-addons/visualization/nviz2/cmd/nviz.h	2008-06-10 13:39:02 UTC (rev 31668)
@@ -3,7 +3,9 @@
 
 #include <grass/gsurf.h>
 
+#define MAP_OBJ_UNDEFINED 0
 #define MAP_OBJ_SURF 1
+#define MAP_OBJ_VOL 2
 
 #define RANGE (5 * GS_UNIT_SIZE)
 #define RANGE_OFFSET (2 * GS_UNIT_SIZE)
@@ -12,6 +14,10 @@
 
 #define DEFAULT_SURF_COLOR 0x33BBFF
 
+#define RED_MASK 0x000000FF
+#define GRN_MASK 0x0000FF00
+#define BLU_MASK 0x00FF0000
+
 /* data structures */
 typedef struct{
     int id;

Added: grass-addons/visualization/nviz2/cmd/position.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/position.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/position.c	2008-06-10 13:39:02 UTC (rev 31668)
@@ -0,0 +1,108 @@
+/*!
+  \file position.c
+ 
+  \brief Position, focus settings
+  
+  COPYRIGHT: (C) 2008 by the GRASS Development Team
+
+  This program is free software under the GNU General Public
+  License (>=v2). Read the file COPYING that comes with GRASS
+  for details.
+
+  Based on visualization/nviz/src/position.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com>
+
+  \date 2008
+*/
+
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+/*!
+  Initialize view and position settings (focus)
+
+  Set position to center of view
+*/
+void init_view()
+{
+    GS_init_view();
+    focus_set_state(1); /* center of view */
+
+    return;
+}
+
+/*!
+  \brief Set focus state
+
+  \param state_flag 1 for center view, 0 use viewdir
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int focus_set_state(int state_flag)
+{
+    if (state_flag == 1)
+	GS_set_infocus(); /* return center of view */
+    else if (state_flag == 0)
+	GS_set_nofocus(); /* no center of view -- use viewdir */
+    else {
+	G_warning (_("Unable to set focus"));
+	return 0;
+    }
+    
+    return 1;
+}
+
+/*!
+  \brief Set focus based on loaded map
+
+  If <i>map</i> is MAP_OBJ_UNDEFINED, set focus from first
+  surface/volume in the list.
+
+  \param type map object type
+  \param id map object id
+
+  \return 0 on no focus
+  \return id id of map object used for setting focus
+*/
+int focus_set_map(int type, int id)
+{
+    if (GS_num_surfs() < 0 && GVL_num_vols() < 0) {
+	GS_set_nofocus();
+	return 0;
+    }
+
+    if (type == MAP_OBJ_UNDEFINED) {
+	int *surf_list, num_surfs, *vol_list;
+
+	if (GS_num_surfs() > 0) {
+	    surf_list = GS_get_surf_list(&num_surfs);
+	    id = surf_list[0];
+	    G_free (surf_list);
+	    
+	    GS_set_focus_center_map(id);
+	}
+
+	if (GVL_num_vols() > 0) {
+	    vol_list = GVL_get_vol_list(&num_surfs);
+	    id = vol_list[0];
+	    G_free (vol_list);
+	    
+	    GVL_set_focus_center_map(id);
+	}
+	return id;
+    }
+
+    if (type == MAP_OBJ_SURF) {
+	GS_set_focus_center_map(id);
+    }
+    else if (type == MAP_OBJ_VOL) {
+	GVL_set_focus_center_map(id);
+    }
+    
+    return id;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/position.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native



More information about the grass-commit mailing list