[GRASS-SVN] r34415 - in grass/trunk: include lib/gis raster/r.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 20 17:31:12 EST 2008


Author: glynn
Date: 2008-11-20 17:31:12 -0500 (Thu, 20 Nov 2008)
New Revision: 34415

Modified:
   grass/trunk/include/gis.h
   grass/trunk/lib/gis/color_xform.c
   grass/trunk/raster/r.colors/local_proto.h
   grass/trunk/raster/r.colors/main.c
   grass/trunk/raster/r.colors/stats.c
Log:
Add -a (log-abs) flag to r.colors


Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h	2008-11-20 21:37:39 UTC (rev 34414)
+++ grass/trunk/include/gis.h	2008-11-20 22:31:12 UTC (rev 34415)
@@ -533,6 +533,7 @@
 
 struct FP_stats {
     int geometric;
+    int geom_abs;
     int flip;
     int count;
     DCELL min, max;

Modified: grass/trunk/lib/gis/color_xform.c
===================================================================
--- grass/trunk/lib/gis/color_xform.c	2008-11-20 21:37:39 UTC (rev 34414)
+++ grass/trunk/lib/gis/color_xform.c	2008-11-20 22:31:12 UTC (rev 34415)
@@ -162,9 +162,10 @@
 	val2 = statf->min + (statf->max - statf->min) * i / statf->count;
 	if (statf->geometric)
 	    val2 = exp(val2);
+	if (statf->geom_abs)
+	    val2 = exp(val2) - 1;
 	if (statf->flip)
 	    val2 = -val2;
-
 	x = min + (max - min) * sum / statf->total;
 	G_get_d_raster_color(&x, &red2, &grn2, &blu2, src);
 
@@ -297,10 +298,17 @@
 	    x = exp(lx);
 	}
 
-	if (i > 0)
-	    G_add_d_raster_color_rule(&prev, red, grn, blu,
-				      &x, red2, grn2, blu2,
+	if (i > 0) {
+	    DCELL x0 = prev, x1 = x;
+	    G_add_d_raster_color_rule(&x0, red, grn, blu,
+				      &x1, red2, grn2, blu2,
 				      dst);
+	    x0 = -x0;
+	    x1 = -x1;
+	    G_add_d_raster_color_rule(&x0, red, grn, blu,
+				      &x1, red2, grn2, blu2,
+				      dst);
+	}
 
 	prev = x;
 

Modified: grass/trunk/raster/r.colors/local_proto.h
===================================================================
--- grass/trunk/raster/r.colors/local_proto.h	2008-11-20 21:37:39 UTC (rev 34414)
+++ grass/trunk/raster/r.colors/local_proto.h	2008-11-20 22:31:12 UTC (rev 34415)
@@ -26,7 +26,7 @@
 int get_stats(const char *, const char *, struct Cell_stats *);
 void get_fp_stats(const char *name, const char *mapset,
 		  struct FP_stats *statf,
-		  DCELL min, DCELL max, int geometric);
+		  DCELL min, DCELL max, int geometric, int geom_abs);
 
 /* main.c */
 int main(int, char *[]);

Modified: grass/trunk/raster/r.colors/main.c
===================================================================
--- grass/trunk/raster/r.colors/main.c	2008-11-20 21:37:39 UTC (rev 34414)
+++ grass/trunk/raster/r.colors/main.c	2008-11-20 22:31:12 UTC (rev 34415)
@@ -150,7 +150,7 @@
     struct GModule *module;
     struct
     {
-	struct Flag *r, *w, *l, *g, *e, *n;
+	struct Flag *r, *w, *l, *g, *a, *e, *n;
     } flag;
     struct
     {
@@ -218,6 +218,11 @@
     flag.g->description = _("Logarithmic scaling");
     flag.g->guisection = _("Colors");
 
+    flag.a = G_define_flag();
+    flag.a->key = 'a';
+    flag.a->description = _("Logarithmic-absolute scaling");
+    flag.a->guisection = _("Colors");
+
     flag.e = G_define_flag();
     flag.e->key = 'e';
     flag.e->description = _("Histogram equalization");
@@ -248,6 +253,9 @@
     if (!!style + !!cmap + !!rules > 1)
 	G_fatal_error(_("\"color\", \"rules\", and \"raster\" options are mutually exclusive"));
 
+    if (flag.g->answer && flag.a->answer)
+	G_fatal_error(_("-g and -a flags are mutually exclusive"));
+
     is_from_stdin = rules && strcmp(rules, "-") == 0;
     if (is_from_stdin)
 	rules = NULL;
@@ -344,7 +352,7 @@
     if (flag.e->answer) {
 	if (fp) {
 	    struct FP_stats fpstats;
-	    get_fp_stats(name, mapset, &fpstats, min, max, flag.g->answer);
+	    get_fp_stats(name, mapset, &fpstats, min, max, flag.g->answer, flag.a->answer);
 	    G_histogram_eq_colors_fp(&colors_tmp, &colors, &fpstats);
 	}
 	else {
@@ -360,6 +368,11 @@
 	colors = colors_tmp;
     }
 
+    if (flag.a->answer) {
+	G_abs_log_colors(&colors_tmp, &colors, 100);
+	colors = colors_tmp;
+    }
+
     if (fp)
 	G_mark_colors_as_fp(&colors);
 

Modified: grass/trunk/raster/r.colors/stats.c
===================================================================
--- grass/trunk/raster/r.colors/stats.c	2008-11-20 21:37:39 UTC (rev 34414)
+++ grass/trunk/raster/r.colors/stats.c	2008-11-20 22:31:12 UTC (rev 34415)
@@ -56,7 +56,7 @@
 
 void get_fp_stats(const char *name, const char *mapset,
 		  struct FP_stats *statf,
-		  DCELL min, DCELL max, int geometric)
+		  DCELL min, DCELL max, int geometric, int geom_abs)
 {
     DCELL *dcell;
     int row, col, nrows, ncols;
@@ -71,6 +71,7 @@
     ncols = G_window_cols();
 
     statf->geometric = geometric;
+    statf->geom_abs = geom_abs;
     statf->flip = 0;
 
     if (statf->geometric) {
@@ -87,6 +88,13 @@
 	max = log(max);
     }
 
+    if (statf->geom_abs) {
+	double a = log(fabs(min) + 1);
+	double b = log(fabs(max) + 1);
+	min = a < b ? a : b;
+	max = a > b ? a : b;
+    }
+
     statf->count = 1000;
     statf->min = min;
     statf->max = max;
@@ -114,6 +122,8 @@
 		x = -x;
 	    if (statf->geometric)
 		x = log(x);
+	    if (statf->geom_abs)
+		x = log(fabs(x) + 1);
 
 	    i = (int) floor(statf->count * (x - statf->min) / (statf->max - statf->min));
 	    statf->stats[i]++;



More information about the grass-commit mailing list