[GRASS-SVN] r31388 - grass/trunk/display/d.vect

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 17 09:28:35 EDT 2008


Author: neteler
Date: 2008-05-17 09:28:35 -0400 (Sat, 17 May 2008)
New Revision: 31388

Modified:
   grass/trunk/display/d.vect/area.c
   grass/trunk/display/d.vect/description.html
   grass/trunk/display/d.vect/local_proto.h
   grass/trunk/display/d.vect/main.c
   grass/trunk/display/d.vect/plot1.c
Log:
support for z height (geometry) colors added (merge from devel_grass6)

Modified: grass/trunk/display/d.vect/area.c
===================================================================
--- grass/trunk/display/d.vect/area.c	2008-05-17 13:25:44 UTC (rev 31387)
+++ grass/trunk/display/d.vect/area.c	2008-05-17 13:28:35 UTC (rev 31388)
@@ -17,7 +17,7 @@
 	    const struct color_rgb *bcolor, const struct color_rgb *fcolor, 
 	    int chcat, int id_flag, int table_colors_flag, int cats_color_flag,
 	    struct Cell_head *window, char *rgb_column, int default_width,
-	    char *width_column, double width_scale) {
+	    char *width_column, double width_scale, int z_color_flag, char *style) {
 
     int    num, area, isle, n_isles, n_points;
     double xl, yl;
@@ -211,6 +211,23 @@
 	  continue;
 	}
 
+	/* z height colors */
+	if( z_color_flag && Vect_is_3d (Map)) {
+	  BOUND_BOX box;
+	  double zval;
+	  struct Colors colors;
+
+	  Vect_get_map_box (Map, &box );
+	  zval = Points->z[0];
+	  G_debug (3, "display area %d, centroid %d, cat %d, x: %f, y: %f, z: %f", area, centroid, 
+		cat, Points->x[0], Points->y[0], Points->z[0]);
+	  rgb = 1;
+	  G_make_fp_colors(&colors, style, box.B, box.T);
+	  G_get_raster_color(&zval, &red, &grn, &blu, &colors, DCELL_TYPE);
+	  G_debug (3, "b %d, g: %d, r %d", blu, grn, red);
+	}
+
+
 	if( table_colors_flag ) {
 	  centroid = Vect_get_area_centroid ( Map, area );
 	  if( cat >= 0 ) {
@@ -249,7 +266,7 @@
 	    rgb = 0;
 	  } 
 	} /* end if table_colors_flag */
- 	
+
 	/* random colors */
 	if( cats_color_flag ) {
 	  rgb = 0;
@@ -305,8 +322,8 @@
 	  D_line_width(width);
 	} /* end if nrec_width */
 
-	if ( fcolor ) {
-	  if (!table_colors_flag && !cats_color_flag) {
+	if ( fcolor || (z_color_flag && Vect_is_3d (Map)) ) {
+	  if (!table_colors_flag && !cats_color_flag && !z_color_flag) {
 	    R_RGB_color(fcolor->r, fcolor->g, fcolor->b);
 	    plot_polygon ( Points->x, Points->y, Points->n_points);
 	  }

Modified: grass/trunk/display/d.vect/description.html
===================================================================
--- grass/trunk/display/d.vect/description.html	2008-05-17 13:25:44 UTC (rev 31387)
+++ grass/trunk/display/d.vect/description.html	2008-05-17 13:28:35 UTC (rev 31388)
@@ -66,6 +66,27 @@
 d.vect -c soils where="label='VBF'" display=shape,attr attrcol=label
 </pre></div>
 
+<p>
+3D points, 3D lines and 3D polygons colorized according to z height:
+<div class="code"><pre>
+g.region rast=elevation.10m
+r.random elevation.10m n=5000 vector=random3d -d
+d.mon x0
+# display as black points
+d.vect random3d
+# display 3D points colorized according to z height
+d.vect -z random3d zcol=gyr
+
+# 3D contour lines
+r.contour elevation.10m out=contour20m step=20
+d.vect -z contour20m zcol=gyr
+
+# generate 3D triangles
+v.delaunay random3d out=random3d_del
+# display 3D polygons colorized according to z height
+d.vect -z random3d_del type=area zcol=gyr
+</pre></div>
+
 <h2>SEE ALSO</h2>
 
 <em>
@@ -78,8 +99,10 @@
 <a HREF="sql.html">GRASS SQL interface</a>
 </em>
 
-<h2>AUTHOR</h2>
+<h2>AUTHORS</h2>
 
-Radim Blazek, ITC-Irst, Trento, Italy
+CERL<br>
+Radim Blazek, ITC-Irst, Trento, Italy<br>
+other GRASS developers
 
 <p><i>Last changed: $Date$</i><p>

Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h	2008-05-17 13:25:44 UTC (rev 31387)
+++ grass/trunk/display/d.vect/local_proto.h	2008-05-17 13:28:35 UTC (rev 31388)
@@ -3,11 +3,11 @@
 
 FILE *open_vect(char *, char *);
 int close_vect(FILE *);
-int plot1(struct Map_info *, int, int, struct cat_list *, const struct color_rgb *, const struct color_rgb *, int, SYMBOL *, int, int, int, int, char *, int, char *, double);
+int plot1(struct Map_info *, int, int, struct cat_list *, const struct color_rgb *, const struct color_rgb *, int, SYMBOL *, int, int, int, int, char *, int, char *, double, int, char *);
 int label(struct Map_info *, int, int, struct cat_list *, LATTR *, int);
 int topo(struct Map_info *, int, int, LATTR *);
 int dir(struct Map_info *, int, struct cat_list *, int);
-int darea(struct Map_info *, struct cat_list *, const struct color_rgb *, const struct color_rgb *, int, int, int, int, struct Cell_head *, char *, int, char *, double);
+int darea(struct Map_info *, struct cat_list *, const struct color_rgb *, const struct color_rgb *, int, int, int, int, struct Cell_head *, char *, int, char *, double, int, char *);
 int attr(struct Map_info *, int, char *, struct cat_list *, LATTR *, int);
 int zcoor(struct Map_info *, int, LATTR *);
 int test_bg_color (const char*);

Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c	2008-05-17 13:25:44 UTC (rev 31387)
+++ grass/trunk/display/d.vect/main.c	2008-05-17 13:28:35 UTC (rev 31388)
@@ -3,9 +3,9 @@
  *
  * MODULE:       d.vect
  * AUTHOR(S):    CERL, Radim Blazek, others
- * PURPOSE:      Display the binary vector (dig) file that the user wants displayed 
+ * PURPOSE:      Display the binary vector file that the user wants displayed 
  *               on top of the current image.
- * COPYRIGHT:    (C) 2004-2006 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2004-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
@@ -95,7 +95,7 @@
 	char map_name[128] ;
 	struct GModule *module;
 	struct Option *map_opt;
-	struct Option *color_opt, *fcolor_opt, *rgbcol_opt;
+	struct Option *color_opt, *fcolor_opt, *rgbcol_opt, *zcol_opt;
 	struct Option *type_opt, *display_opt;
 	struct Option *icon_opt, *size_opt;
 	struct Option *where_opt;
@@ -106,7 +106,7 @@
 	struct Option *width_opt, *wcolumn_opt, *wscale_opt;
 	struct Option *render_opt;
 	struct Flag   *verbose_flag; /* please remove before GRASS 7 released */
-	struct Flag   *id_flag, *table_acolors_flag, *cats_acolors_flag, *x_flag;
+	struct Flag   *id_flag, *table_acolors_flag, *cats_acolors_flag, *x_flag, *zcol_flag;
 	struct cat_list *Clist;
 	int *cats, ncat;
 	LATTR lattr;
@@ -182,6 +182,15 @@
 	    _("Name of color definition column (for use with -a flag)");
 	rgbcol_opt->answer     = "GRASSRGB" ;
 
+	zcol_opt = G_define_option();
+	zcol_opt->key          = "zcolor";
+	zcol_opt->key_desc     = "style";
+	zcol_opt->type         = TYPE_STRING;
+	zcol_opt->required     = NO;
+	zcol_opt->description  = _("Type of color table (for use with -z flag)");
+	zcol_opt->answer       = "terrain";
+	zcol_opt->guisection   = _("Colors");
+
 	/* Lines */
 	width_opt = G_define_option() ;
 	width_opt->key        = "width";
@@ -352,6 +361,11 @@
 	    _("Don't add to list of vectors and commands in monitor "
 	      "(it won't be drawn if the monitor is refreshed)");
 
+	zcol_flag = G_define_flag ();
+	zcol_flag->key		= 'z';
+	zcol_flag->description	=
+	    _("Colorize polygons according to z height)");
+
 	/* Check command line */
 	if (G_parser(argc, argv))
 	    exit(EXIT_FAILURE);
@@ -650,7 +664,8 @@
 				       has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat,
 				       (int) id_flag->answer, table_acolors_flag->answer,
 				       cats_acolors_flag->answer, &window, rgbcol_opt->answer,
-				       default_width, wcolumn_opt->answer, width_scale );
+				       default_width, wcolumn_opt->answer, width_scale, 
+				       zcol_flag->answer, zcol_opt->answer );
 		    }
 	            if ( wcolumn_opt->answer )
 	                D_line_width(default_width);
@@ -666,7 +681,7 @@
 			has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat, Symb,
 			size, (int) id_flag->answer, table_acolors_flag->answer,
 			cats_acolors_flag->answer, rgbcol_opt->answer, default_width,
-			wcolumn_opt->answer, width_scale) ;
+			wcolumn_opt->answer, width_scale, zcol_flag->answer, zcol_opt->answer) ;
 	            if ( wcolumn_opt->answer )
 	                D_line_width(default_width);
 		}

Modified: grass/trunk/display/d.vect/plot1.c
===================================================================
--- grass/trunk/display/d.vect/plot1.c	2008-05-17 13:25:44 UTC (rev 31387)
+++ grass/trunk/display/d.vect/plot1.c	2008-05-17 13:28:35 UTC (rev 31388)
@@ -135,7 +135,7 @@
     const struct color_rgb *color, const struct color_rgb *fcolor,
     int chcat, SYMBOL *Symb, int size, int id_flag,
     int table_colors_flag, int cats_color_flag, char *rgb_column,
-    int default_width, char *width_column, double width_scale)
+    int default_width, char *width_column, double width_scale, int z_color_flag, char *style)
 {
     int i, ltype, nlines = 0, line, cat = -1;
     double *x, *y;
@@ -323,7 +323,22 @@
 	        if (Cats->n_cats > 0 && !found) continue;
 	}
 
+	/* z height colors */
+	if( z_color_flag && Vect_is_3d (Map)) {
+	  BOUND_BOX box;
+	  double zval;
+	  struct Colors colors;
 
+	  Vect_get_map_box (Map, &box );
+	  zval = Points->z[0];
+	  G_debug (3, "display line %d, cat %d, x: %f, y: %f, z: %f", line,
+		cat, Points->x[0], Points->y[0], Points->z[0]);
+	  custom_rgb = TRUE;
+	  G_make_fp_colors(&colors, style, box.B, box.T);
+	  G_get_raster_color(&zval, &red, &grn, &blu, &colors, DCELL_TYPE);
+	  G_debug (3, "b %d, g: %d, r %d", blu, grn, red);
+	}
+
 	if( table_colors_flag ) {
 
 	  /* only first category */
@@ -461,8 +476,8 @@
 		D_symbol(Symb, x0, y0, line_color, fill_color);
 
 
-	} else if (color || custom_rgb) {
-	    if (!table_colors_flag && !cats_color_flag)
+	} else if (color || custom_rgb || (z_color_flag && Vect_is_3d (Map))) {
+	    if (!table_colors_flag && !cats_color_flag && !z_color_flag)
 		R_RGB_color(color->r, color->g, color->b);
 	    else {
 		if (custom_rgb)



More information about the grass-commit mailing list