[GRASS-SVN] r34549 - in grass/branches/develbranch_6: include
lib/gis raster/r.colors
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Nov 27 16:05:46 EST 2008
Author: neteler
Date: 2008-11-27 16:05:46 -0500 (Thu, 27 Nov 2008)
New Revision: 34549
Modified:
grass/branches/develbranch_6/include/gis.h
grass/branches/develbranch_6/lib/gis/color_xform.c
grass/branches/develbranch_6/raster/r.colors/local_proto.h
grass/branches/develbranch_6/raster/r.colors/main.c
grass/branches/develbranch_6/raster/r.colors/stats.c
Log:
glynn: Add -a (log-abs) flag to r.colors (merge from trunk, r34415)
Modified: grass/branches/develbranch_6/include/gis.h
===================================================================
--- grass/branches/develbranch_6/include/gis.h 2008-11-27 20:59:04 UTC (rev 34548)
+++ grass/branches/develbranch_6/include/gis.h 2008-11-27 21:05:46 UTC (rev 34549)
@@ -532,6 +532,7 @@
struct FP_stats {
int geometric;
+ int geom_abs;
int flip;
int count;
DCELL min, max;
Modified: grass/branches/develbranch_6/lib/gis/color_xform.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/color_xform.c 2008-11-27 20:59:04 UTC (rev 34548)
+++ grass/branches/develbranch_6/lib/gis/color_xform.c 2008-11-27 21:05:46 UTC (rev 34549)
@@ -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/branches/develbranch_6/raster/r.colors/local_proto.h
===================================================================
--- grass/branches/develbranch_6/raster/r.colors/local_proto.h 2008-11-27 20:59:04 UTC (rev 34548)
+++ grass/branches/develbranch_6/raster/r.colors/local_proto.h 2008-11-27 21:05:46 UTC (rev 34549)
@@ -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/branches/develbranch_6/raster/r.colors/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.colors/main.c 2008-11-27 20:59:04 UTC (rev 34548)
+++ grass/branches/develbranch_6/raster/r.colors/main.c 2008-11-27 21:05:46 UTC (rev 34549)
@@ -151,7 +151,7 @@
struct GModule *module;
struct
{
- struct Flag *r, *w, *l, *g, *e, *i, *q, *n;
+ struct Flag *r, *w, *l, *g, *a, *e, *i, *q, *n;
} flag;
struct
{
@@ -219,6 +219,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");
@@ -278,6 +283,9 @@
rules = NULL;
}
+ if (flag.g->answer && flag.a->answer)
+ G_fatal_error(_("-g and -a flags are mutually exclusive"));
+
mapset = G_find_cell2(name, "");
if (mapset == NULL)
G_fatal_error(_("Raster map <%s> not found"), name);
@@ -374,7 +382,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 {
@@ -390,6 +398,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/branches/develbranch_6/raster/r.colors/stats.c
===================================================================
--- grass/branches/develbranch_6/raster/r.colors/stats.c 2008-11-27 20:59:04 UTC (rev 34548)
+++ grass/branches/develbranch_6/raster/r.colors/stats.c 2008-11-27 21:05:46 UTC (rev 34549)
@@ -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