[GRASS-SVN] r32147 - grass/trunk/visualization/nviz2/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 17 06:01:10 EDT 2008


Author: martinl
Date: 2008-07-17 06:01:10 -0400 (Thu, 17 Jul 2008)
New Revision: 32147

Added:
   grass/trunk/visualization/nviz2/cmd/vector.c
Modified:
   grass/trunk/visualization/nviz2/cmd/args.c
   grass/trunk/visualization/nviz2/cmd/local_proto.h
   grass/trunk/visualization/nviz2/cmd/main.c
Log:
nviz2/cli: module updated -- vector lines supported

Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c	2008-07-17 09:21:17 UTC (rev 32146)
+++ grass/trunk/visualization/nviz2/cmd/args.c	2008-07-17 10:01:10 UTC (rev 32147)
@@ -240,6 +240,7 @@
     params->line_width->description = _("Vector line width");
     params->line_width->guisection = _("Vector");
     params->line_width->options = "1-100";
+    params->line_width->answer = "2";
 
     /* line color */
     params->line_color = G_define_standard_option(G_OPT_C_FG);
@@ -250,9 +251,9 @@
     params->line_color->answer = "blue";
     params->line_color->guisection = _("Vector");
 
-    /* shading */
+    /* line mode */
     params->line_mode = G_define_option();
-    params->line_mode->key = "line_display";
+    params->line_mode->key = "line_mode";
     params->line_mode->key_desc = "string";
     params->line_mode->type = TYPE_STRING;
     params->line_mode->required = YES;
@@ -262,6 +263,18 @@
     params->line_mode->answer = "surface";
     params->line_mode->guisection = _("Vector");
 
+    /* line height */
+    params->line_height = G_define_option();
+    params->line_height->key = "line_height";
+    params->line_height->key_desc = "value";
+    params->line_height->type = TYPE_INTEGER;
+    params->line_height->required = NO;
+    params->line_height->multiple = YES;
+    params->line_height->description = _("Vector line height");
+    params->line_height->guisection = _("Vector");
+    params->line_height->options = "0-1000";
+    params->line_height->answer = "0";
+
     /*
       misc
     */
@@ -372,10 +385,13 @@
     int i;
 
     i = 0;
-    if (non_zero)
+
+    if(non_zero)
 	*non_zero = 0;
-    if (all) 
+
+    if(all)
 	*all = 0;
+
     if (opt->answer) {
 	while (opt->answers[i]) {
 	    if (all)
@@ -401,6 +417,8 @@
     int nelev_map, nelev_const, nelev_map0, nelev_const0, nelevs0;
     int nmaps0, nconsts0;
 
+    int nvects;
+
     /* topography */
     opt_get_num_answers(params->elev_map, &nelev_map, &nelev_map0); 
     opt_get_num_answers(params->elev_const, &nelev_const, &nelev_const0);
@@ -431,7 +449,7 @@
     /* mask */
     opt_get_num_answers(params->mask_map, NULL, &nmaps0);
     if (nmaps0 > 0 && nelevs0 != nmaps0)
-	G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d"),
+	G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
 		      params->elev_map->key, params->elev_const->key, nelevs0,
 		      params->mask_map->key, nmaps0);
 
@@ -461,7 +479,7 @@
     if (!params->mode_all->answer) { /* use one mode for all surfaces */
 	opt_get_num_answers(params->mode, NULL, &nconsts0);
 	if (nconsts0 > 0 && nconsts0 != nelevs0)
-	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d"),
+	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
 			  params->elev_map->key, params->elev_const->key, nelevs0,
 			  params->mode->key, nconsts0);
 
@@ -473,29 +491,62 @@
 
 	opt_get_num_answers(params->res_coarse, NULL, &nconsts0);
 	if (nconsts0 > 0 && nconsts0 != nelevs0)
-	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d"),
+	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
 			  params->elev_map->key, params->elev_const->key, nelevs0,
 			  params->res_coarse->key, nconsts0);
 
 	opt_get_num_answers(params->style, NULL, &nconsts0);
 	if (nconsts0 > 0 && nconsts0 != nelevs0)
-	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d"),
+	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
 			  params->elev_map->key, params->elev_const->key, nelevs0,
 			  params->style->key, nconsts0);
 
 	opt_get_num_answers(params->shade, NULL, &nconsts0);
 	if (nconsts0 > 0 && nconsts0 != nelevs0)
-	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d"),
+	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
 			  params->elev_map->key, params->elev_const->key, nelevs0,
 			  params->shade->key, nconsts0);
 
 	opt_get_num_answers(params->wire_color, NULL, &nconsts0);
 	if (nconsts0 > 0 && nconsts0 != nelevs0)
-	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d"),
+	    G_fatal_error(_("Inconsistent number of attributes (<%s/%s> %d: <%s> %d)"),
 			  params->elev_map->key, params->elev_const->key, nelevs0,
 			  params->wire_color->key, nconsts0);
     }
 
+    /*
+     * vector
+     */
+    opt_get_num_answers(params->vector, &nvects, NULL);
+
+    /* width */
+    opt_get_num_answers(params->line_width, NULL, &nconsts0);
+    if (nvects > 0 && nconsts0 != nvects)
+      G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d)"),
+		    params->vector->key, nvects,
+		    params->line_width->key, nconsts0);
+
+    /* color */
+    opt_get_num_answers(params->line_color, NULL, &nconsts0);
+    if (nvects > 0 && nconsts0 != nvects)
+      G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d"),
+		    params->vector->key, nvects,
+		    params->line_color->key, nconsts0);
+
+    /* mode */
+    opt_get_num_answers(params->line_mode, NULL, &nconsts0);
+    if (nvects > 0 && nconsts0 != nvects)
+      G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d)"),
+		    params->vector->key, nvects,
+		    params->line_mode->key, nconsts0);
+
+    /* height */
+    opt_get_num_answers(params->line_height, NULL, &nconsts0);
+    if (nvects > 0 && nconsts0 != nvects)
+      G_fatal_error(_("Inconsistent number of attributes (<%s> %d: <%s> %d)"),
+		    params->vector->key, nvects,
+		    params->line_height->key, nconsts0);
+
     return;
 }
 

Modified: grass/trunk/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h	2008-07-17 09:21:17 UTC (rev 32146)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h	2008-07-17 10:01:10 UTC (rev 32147)
@@ -13,7 +13,7 @@
   /* draw */
     *mode, *res_fine, *res_coarse, *style, *shade, *wire_color,
   /* vector */
-    *vector, *line_width, *line_color, *line_mode,
+    *vector, *line_width, *line_color, *line_mode, *line_height,
   /* misc */
     *exag, *bgcolor, 
   /* viewpoint */
@@ -30,9 +30,14 @@
 
 /* surface.c */
 int load_rasters(const struct GParams *,
-		 nv_data *data);
+		 nv_data *);
 void set_draw_mode(const struct GParams *);
 
+/* vector.c */
+int load_vectors(const struct GParams *,
+		 nv_data *);
+int set_lines_attrb(const struct GParams *);
+
 /* write_img.c */
 int write_img(const char *, int);
 

Modified: grass/trunk/visualization/nviz2/cmd/main.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/main.c	2008-07-17 09:21:17 UTC (rev 32146)
+++ grass/trunk/visualization/nviz2/cmd/main.c	2008-07-17 10:01:10 UTC (rev 32147)
@@ -31,8 +31,7 @@
     struct GModule *module;
     struct GParams *params;
 
-    char *mapset;
-    int i, ret;
+    int ret;
     float vp_height, z_exag; /* calculated viewpoint height, z-exag */
     int width, height; /* output image size */
     char *output_name;
@@ -102,30 +101,14 @@
 
     /* load raster maps (surface topography) & set attributes (map/constant) */
     load_rasters(params, &data);
-    /* set draw mode for loaded surfaces */
+    /* set draw mode of loaded surfaces */
     set_draw_mode(params);
 
-    /* load vectors */
+    /* load vector maps & set line mode */
     if (params->vector->answer) {
-	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, 0.0, &data);
-
-	    surf_list = GS_get_surf_list(&nsurf);
-	    GS_set_att_const(surf_list[0], ATT_TRANSP, 255);
-	}
-
-	for (i = 0; params->vector->answers[i]; i++) {
-	    mapset = G_find_vector2 (params->vector->answers[i], "");
-	    if (mapset == NULL) {
-		G_fatal_error(_("Vector map <%s> not found"),
-			      params->vector->answers[i]);
-	    }
-	    Nviz_new_map_obj(MAP_OBJ_VECT,
-			     G_fully_qualified_name(params->vector->answers[i], mapset), 0.0,
-			     &data);
-	}
+	load_vectors(params, &data);
+	/* set attributes for 2d lines */
+	set_lines_attrb(params);
     }
 
     /* focus on loaded data */

Added: grass/trunk/visualization/nviz2/cmd/vector.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/vector.c	                        (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/vector.c	2008-07-17 10:01:10 UTC (rev 32147)
@@ -0,0 +1,100 @@
+/*!
+  \file vector.c
+ 
+  \brief Vector subroutines
+  
+  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.
+
+  \author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+/*!
+  \brief Load vector maps and set attributes
+  
+  \param params module parameters
+  \param data nviz data
+
+  \return number of loaded vectors
+*/
+int load_vectors(const struct GParams *params,
+		 nv_data *data)
+{
+    int i;
+    int nvects;
+
+    char *mapset;
+
+    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, 0.0, data);
+	
+	surf_list = GS_get_surf_list(&nsurf);
+	GS_set_att_const(surf_list[0], ATT_TRANSP, 255);
+    }
+
+    nvects = 0;
+
+    for (i = 0; params->vector->answers[i]; i++) {
+	mapset = G_find_vector2 (params->vector->answers[i], "");
+	if (mapset == NULL) {
+	    G_fatal_error(_("Vector map <%s> not found"),
+			  params->vector->answers[i]);
+	}
+	Nviz_new_map_obj(MAP_OBJ_VECT,
+			 G_fully_qualified_name(params->vector->answers[i], mapset), 0.0,
+			 data);
+
+	nvects++;
+    }
+
+    return nvects;
+}
+
+/*!
+  \brief Set vector mode
+
+  \param params parameters
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int set_lines_attrb(const struct GParams *params)
+{
+    int i, color, width, flat, height;
+    int *vect_list, nvects;
+
+    vect_list = GV_get_vect_list(&nvects);
+    
+    for(i = 0; i < nvects; i++) {
+	/* mode -- use memory by default */
+	color =  Nviz_color_from_str(params->line_color->answers[i]);
+	width = atoi(params->line_width->answers[i]);
+	if (strcmp(params->line_mode->answers[i], "flat") == 0)
+	    flat = 1;
+	else
+	    flat = 0;
+	if (GV_set_vectmode(vect_list[i], 1, color, width, flat) < 0)
+	    return 0;
+
+	/* height */
+	height = atoi(params->line_height->answers[i]);
+	if (height > 0)
+	    GV_set_trans(vect_list[i], 0.0, 0.0, height);
+    }
+
+    return 1;
+}


Property changes on: grass/trunk/visualization/nviz2/cmd/vector.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