[GRASS-SVN] r46774 - grass/trunk/raster/r.colors
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jun 24 09:17:31 EDT 2011
Author: huhabla
Date: 2011-06-24 06:17:31 -0700 (Fri, 24 Jun 2011)
New Revision: 46774
Added:
grass/trunk/raster/r.colors/edit_colors.c
grass/trunk/raster/r.colors/r3.colors.html
grass/trunk/raster/r.colors/raster3d_main.c
grass/trunk/raster/r.colors/raster_main.c
grass/trunk/raster/r.colors/test_elev_double_default.ref
grass/trunk/raster/r.colors/test_volume_double_default.ref
Removed:
grass/trunk/raster/r.colors/main.c
Modified:
grass/trunk/raster/r.colors/Makefile
grass/trunk/raster/r.colors/local_proto.h
grass/trunk/raster/r.colors/r.colors.html
grass/trunk/raster/r.colors/test.r.colors.sh
Log:
Do not use hacks while implementing r3.colors!
Modified: grass/trunk/raster/r.colors/Makefile
===================================================================
--- grass/trunk/raster/r.colors/Makefile 2011-06-23 22:30:34 UTC (rev 46773)
+++ grass/trunk/raster/r.colors/Makefile 2011-06-24 13:17:31 UTC (rev 46774)
@@ -1,16 +1,19 @@
MODULE_TOPDIR = ../..
-PGM = r.colors
+LIBES = $(G3DLIB) $(RASTERLIB) $(GISLIB)
+DEPENDENCIES = $(G3DDEP) $(GISDEP) $(RASTERDEP)
-LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB) $(G3DLIB)
-DEPENDENCIES = $(RASTERDEP) $(GISDEP) $(G3DDEP)
+PROGRAMS = r.colors r3.colors
-include $(MODULE_TOPDIR)/include/Make/Module.make
+r_colors_OBJS = raster_main.o edit_colors.o rules.o stats.o
+r3_colors_OBJS = raster3d_main.o edit_colors.o rules.o stats.o
-default: cmd
+include $(MODULE_TOPDIR)/include/Make/Multi.make
+default: multi
+
# Insert thumbnail previews
-r.colors.tmp.html: $(HTMLSRC) thumbnails.py
+r.colors.tmp.html: $(BIN)/r.colors$(EXE) thumbnails.py
$(call htmldesc,$<,$@)
sed 's!^<DD><b>\([a-z0-9.]*\)</b>:!<DD><img width="80" height="12" src="Colortable_\1.png"> <b>\1</b>:!' "$@" > "$@.tmp"
mv -f "$@.tmp" "$@"
@@ -25,3 +28,5 @@
.PHONY: thumbnails
.INTERMEDIATE: r.colors.tmp.html
+
+
Copied: grass/trunk/raster/r.colors/edit_colors.c (from rev 46750, grass/trunk/raster/r.colors/main.c)
===================================================================
--- grass/trunk/raster/r.colors/edit_colors.c (rev 0)
+++ grass/trunk/raster/r.colors/edit_colors.c 2011-06-24 13:17:31 UTC (rev 46774)
@@ -0,0 +1,447 @@
+/****************************************************************************
+ *
+ * MODULE: r.colors
+ *
+ * AUTHOR(S): Michael Shapiro - CERL
+ * David Johnson
+ *
+ * PURPOSE: Allows creation and/or modification of the color table
+ * for a raster map layer.
+ *
+ * COPYRIGHT: (C) 2006-2008, 2010 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.
+ *
+ ***************************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <grass/glocale.h>
+#include "local_proto.h"
+#include <grass/G3d.h>
+
+static char **rules;
+static int nrules;
+
+static int cmp(const void *aa, const void *bb)
+{
+ char *const *a = (char *const *) aa;
+ char *const *b = (char *const *) bb;
+
+ return strcmp(*a, *b);
+}
+
+static void scan_rules(void)
+{
+ char path[GPATH_MAX];
+
+ sprintf(path, "%s/etc/colors", G_gisbase());
+
+ rules = G__ls(path, &nrules);
+
+ rules = G_realloc(rules, (nrules + 3) * sizeof (const char *));
+
+ rules[nrules++] = G_store("random");
+ rules[nrules++] = G_store("grey.eq");
+ rules[nrules++] = G_store("grey.log");
+
+ qsort(rules, nrules, sizeof (char *), cmp);
+}
+
+static char *rules_list(void)
+{
+ char *list = NULL;
+ int size = 0;
+ int len = 0;
+ int i;
+
+ for (i = 0; i < nrules; i++) {
+ const char *name = rules[i];
+ int n = strlen(name);
+
+ if (size < len + n + 2) {
+ size = len + n + 200;
+ list = G_realloc(list, size);
+ }
+
+ if (len > 0)
+ list[len++] = ',';
+
+ memcpy(&list[len], name, n + 1);
+ len += n;
+ }
+
+ return list;
+}
+
+static char *rules_descriptions(void)
+{
+ char path[GPATH_MAX];
+ struct Key_Value *kv;
+ int result_len = 0;
+ int result_max = 2000;
+ char *result = G_malloc(result_max);
+ int i;
+
+ sprintf(path, "%s/etc/colors.desc", G_gisbase());
+ kv = G_read_key_value_file(path);
+ if (!kv)
+ return NULL;
+
+ for (i = 0; i < nrules; i++) {
+ const char *name = rules[i];
+ const char *desc = G_find_key_value(name, kv);
+ int len;
+
+ if (!desc)
+ desc = "no description";
+
+ desc = _(desc);
+
+ len = strlen(name) + strlen(desc) + 2;
+ if (result_len + len >= result_max) {
+ result_max = result_len + len + 1000;
+ result = G_realloc(result, result_max);
+ }
+
+ sprintf(result + result_len, "%s;%s;", name, desc);
+ result_len += len;
+ }
+
+ G_free_key_value(kv);
+
+ return result;
+}
+
+static void list_rules(void)
+{
+ int i;
+
+ for (i = 0; i < nrules; i++)
+ printf("%s\n", rules[i]);
+}
+
+static int find_rule(const char *name)
+{
+ int i;
+
+ for (i = 0; i < nrules; i++)
+ if (strcmp(name, rules[i]) == 0)
+ return 1;
+
+ return 0;
+}
+
+int edit_colors(int argc, char **argv, int type, const char *maptype, const char* Maptype)
+{
+ int overwrite;
+ int is_from_stdin;
+ int remove;
+ int have_colors;
+ struct Colors colors, colors_tmp;
+ struct Cell_stats statf;
+ int have_stats = 0;
+ struct FPRange range;
+ DCELL min, max;
+ const char *name = NULL, *mapset = NULL;
+ const char *style = NULL, *cmap = NULL, *cmapset = NULL;
+ const char *rules = NULL;
+ int fp;
+ struct GModule *module;
+
+ struct {
+ struct Flag *r, *w, *l, *g, *a, *n, *e; /* Flag e is not available in r3.colors*/
+ } flag;
+
+ struct {
+ struct Option *map, *colr, *rast, *volume, *rules;
+ } opt;
+
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ G_add_keyword(_("raster3d"));
+ G_add_keyword(_("raster"));
+ G_add_keyword(_("color table"));
+
+ if (type == RASTER3D_TYPE) {
+ module->description =
+ _("Creates/modifies the color table associated with a raster3d map.");
+ } else {
+ module->description =
+ _("Creates/modifies the color table associated with a raster map.");
+ }
+
+ if (type == RASTER3D_TYPE) {
+ opt.map = G_define_standard_option(G_OPT_R3_MAP);
+ } else {
+ opt.map = G_define_standard_option(G_OPT_R_MAP);
+ }
+ scan_rules();
+
+ opt.colr = G_define_option();
+ opt.colr->key = "color";
+ opt.colr->key_desc = "style";
+ opt.colr->type = TYPE_STRING;
+ opt.colr->required = NO;
+ opt.colr->options = rules_list();
+ opt.colr->description = _("Type of color table");
+ opt.colr->descriptions = rules_descriptions();
+ opt.colr->guisection = _("Define");
+
+ opt.rast = G_define_standard_option(G_OPT_R_INPUT);
+ opt.rast->key = "raster";
+ opt.rast->required = NO;
+ opt.rast->description =
+ _("Raster map from which to copy color table");
+ opt.rast->guisection = _("Define");
+
+ opt.volume = G_define_standard_option(G_OPT_R3_INPUT);
+ opt.volume->key = "volume";
+ opt.volume->required = NO;
+ opt.volume->description =
+ _("Raster3d map from which to copy color table");
+ opt.volume->guisection = _("Define");
+
+ opt.rules = G_define_standard_option(G_OPT_F_INPUT);
+ opt.rules->key = "rules";
+ opt.rules->required = NO;
+ opt.rules->label = _("Path to rules file");
+ opt.rules->description = _("\"-\" to read rules from stdin");
+ opt.rules->guisection = _("Define");
+
+ flag.r = G_define_flag();
+ flag.r->key = 'r';
+ flag.r->description = _("Remove existing color table");
+ flag.r->guisection = _("Remove");
+
+ flag.w = G_define_flag();
+ flag.w->key = 'w';
+ flag.w->description =
+ _("Only write new color table if one doesn't already exist");
+
+ flag.l = G_define_flag();
+ flag.l->key = 'l';
+ flag.l->description = _("List available rules then exit");
+ flag.l->suppress_required = YES;
+ flag.l->guisection = _("Print");
+
+ flag.n = G_define_flag();
+ flag.n->key = 'n';
+ flag.n->description = _("Invert colors");
+ flag.n->guisection = _("Define");
+
+ flag.g = G_define_flag();
+ flag.g->key = 'g';
+ flag.g->description = _("Logarithmic scaling");
+ flag.g->guisection = _("Define");
+
+ flag.a = G_define_flag();
+ flag.a->key = 'a';
+ flag.a->description = _("Logarithmic-absolute scaling");
+ flag.a->guisection = _("Define");
+
+ /* The histogram equalization is currently only available for
+ * raster map. Therefor no flag is defined for r3.colors.
+ */
+ if (type == RASTER_TYPE) {
+ flag.e = G_define_flag();
+ flag.e->key = 'e';
+ flag.e->description = _("Histogram equalization");
+ flag.e->guisection = _("Define");
+ }
+
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
+
+ if (flag.l->answer) {
+ list_rules();
+ return EXIT_SUCCESS;
+ }
+
+ overwrite = !flag.w->answer;
+ remove = flag.r->answer;
+ name = opt.map->answer;
+ style = opt.colr->answer;
+ rules = opt.rules->answer;
+
+ if (!name)
+ G_fatal_error(_("No %s map specified"), maptype);
+
+ if (opt.rast->answer && opt.volume->answer)
+ G_fatal_error(_("\raster\" and \"volume\" options are mutually exclusive"));
+
+ if (opt.rast->answer)
+ cmap = opt.rast->answer;
+ if (opt.volume->answer)
+ cmap = opt.volume->answer;
+
+ if (!cmap && !style && !rules && !remove)
+ G_fatal_error(_("One of \"-r\" or options \"color\", \"raster\" or \"rules\" must be specified!"));
+
+ 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;
+ /* Switch between raster and volume */
+ if (type == RASTER3D_TYPE) {
+ mapset = G_find_grid3(name, "");
+ } else {
+ mapset = G_find_raster2(name, "");
+ }
+ if (mapset == NULL)
+ G_fatal_error(_("%s map <%s> not found"), Maptype, name);
+
+ int stat = -1;
+ if (remove) {
+ if (type == RASTER3D_TYPE) {
+ stat = G3d_removeColor(name);
+ } else {
+ stat = Rast_remove_colors(name, mapset);
+ }
+ if (stat < 0)
+ G_fatal_error(_("Unable to remove color table of %s map <%s>"), maptype, name);
+ if (stat == 0)
+ G_warning(_("Color table of %s map <%s> not found"), maptype, name);
+ return EXIT_SUCCESS;
+ }
+
+ G_suppress_warnings(1);
+ if (type == RASTER3D_TYPE) {
+ have_colors = G3d_readColors(name, mapset, &colors);
+ } else {
+ have_colors = Rast_read_colors(name, mapset, &colors);
+ }
+ /*
+ if (have_colors >= 0)
+ Rast_free_colors(&colors);
+ */
+
+ if (have_colors > 0 && !overwrite) {
+ G_warning(_("Color table exists. Exiting."));
+ exit(EXIT_FAILURE);
+ }
+
+ G_suppress_warnings(0);
+
+ if (type == RASTER3D_TYPE) {
+ fp = 1; /* g3d maps are always floating point */
+ G3d_readRange(name, mapset, &range);
+ } else {
+ fp = Rast_map_is_fp(name, mapset);
+ Rast_read_fp_range(name, mapset, &range);
+ }
+ Rast_get_fp_range_min_max(&range, &min, &max);
+
+ if (is_from_stdin) {
+ if (!read_color_rules(stdin, &colors, min, max, fp))
+ exit(EXIT_FAILURE);
+ } else if (style) {
+ /*
+ * here the predefined color-table color-styles are created by GRASS library calls.
+ */
+ if (strcmp(style, "random") == 0) {
+ if (fp)
+ G_fatal_error(_("Color table 'random' is not supported for floating point %s map"), maptype);
+ Rast_make_random_colors(&colors, (CELL) min, (CELL) max);
+ } else if (strcmp(style, "grey.eq") == 0) {
+ if (fp)
+ G_fatal_error(_("Color table 'grey.eq' is not supported for floating point %s map"), maptype);
+ if (!have_stats)
+ have_stats = get_stats(name, mapset, &statf);
+ Rast_make_histogram_eq_colors(&colors, &statf);
+ } else if (strcmp(style, "grey.log") == 0) {
+ if (fp)
+ G_fatal_error(_("Color table 'grey.log' is not supported for floating point %s map"), maptype);
+ if (!have_stats)
+ have_stats = get_stats(name, mapset, &statf);
+ Rast_make_histogram_log_colors(&colors, &statf, (CELL) min,
+ (CELL) max);
+ } else if (find_rule(style))
+ Rast_make_fp_colors(&colors, style, min, max);
+ else
+ G_fatal_error(_("Unknown color request '%s'"), style);
+ } else if (rules) {
+ if (!Rast_load_fp_colors(&colors, rules, min, max)) {
+ /* for backwards compatibility try as std name; remove for GRASS 7 */
+ char path[GPATH_MAX];
+
+ /* don't bother with native dirsep as not needed for backwards compatibility */
+ sprintf(path, "%s/etc/colors/%s", G_gisbase(), rules);
+
+ if (!Rast_load_fp_colors(&colors, path, min, max))
+ G_fatal_error(_("Unable to load rules file <%s>"), rules);
+ }
+ } else {
+ /* use color from another map (cmap) */
+ if (opt.rast->answer) {
+ cmapset = G_find_raster2(cmap, "");
+ if (cmapset == NULL)
+ G_fatal_error(_("Raster map <%s> not found"), cmap);
+
+ if (Rast_read_colors(cmap, cmapset, &colors) < 0)
+ G_fatal_error(_("Unable to read color table for raster map <%s>"), cmap);
+ } else {
+ cmapset = G_find_grid3(cmap, "");
+ if (cmapset == NULL)
+ G_fatal_error(_("Raster3d map <%s> not found"), cmap);
+
+ if (G3d_readColors(cmap, cmapset, &colors) < 0)
+ G_fatal_error(_("Unable to read color table for raster3d map <%s>"), cmap);
+ }
+ }
+
+ if (fp)
+ Rast_mark_colors_as_fp(&colors);
+
+ if (flag.n->answer)
+ Rast_invert_colors(&colors);
+
+ /* This is not avilable for raster3d maps yet */
+
+ if (type == RASTER_TYPE) {
+ if (flag.e->answer) {
+ if (fp) {
+ struct FP_stats fpstats;
+ get_fp_stats(name, mapset, &fpstats, min, max, flag.g->answer, flag.a->answer);
+ Rast_histogram_eq_fp_colors(&colors_tmp, &colors, &fpstats);
+ } else {
+ if (!have_stats)
+ have_stats = get_stats(name, mapset, &statf);
+ Rast_histogram_eq_colors(&colors_tmp, &colors, &statf);
+ }
+ colors = colors_tmp;
+ }
+ }
+
+ if (flag.g->answer) {
+ Rast_log_colors(&colors_tmp, &colors, 100);
+ colors = colors_tmp;
+ }
+
+ if (flag.a->answer) {
+ Rast_abs_log_colors(&colors_tmp, &colors, 100);
+ colors = colors_tmp;
+ }
+
+ if (fp)
+ Rast_mark_colors_as_fp(&colors);
+ if (type == RASTER3D_TYPE) {
+ G3d_writeColors(name, mapset, &colors);
+ } else {
+ Rast_write_colors(name, mapset, &colors);
+ }
+ G_message(_("Color table for %s map <%s> set to '%s'"), maptype, name,
+ is_from_stdin ? "rules" : style ? style : rules ? rules :
+ cmap);
+
+ exit(EXIT_SUCCESS);
+}
Modified: grass/trunk/raster/r.colors/local_proto.h
===================================================================
--- grass/trunk/raster/r.colors/local_proto.h 2011-06-23 22:30:34 UTC (rev 46773)
+++ grass/trunk/raster/r.colors/local_proto.h 2011-06-24 13:17:31 UTC (rev 46774)
@@ -21,15 +21,19 @@
#define __LOCAL_PROTO_H__
#include <grass/gis.h>
+#include <grass/raster.h>
+#define RASTER_TYPE 1
+#define RASTER3D_TYPE 2
+
/* stats.c */
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, int geom_abs);
-/* main.c */
-int main(int, char *[]);
+/* edit_colors.c */
+int edit_colors(int, char **, int, const char *, const char*);
/* rules.c */
int read_color_rules(FILE *, struct Colors *, DCELL, DCELL, int);
Deleted: grass/trunk/raster/r.colors/main.c
===================================================================
--- grass/trunk/raster/r.colors/main.c 2011-06-23 22:30:34 UTC (rev 46773)
+++ grass/trunk/raster/r.colors/main.c 2011-06-24 13:17:31 UTC (rev 46774)
@@ -1,462 +0,0 @@
-/****************************************************************************
- *
- * MODULE: r.colors
- *
- * AUTHOR(S): Michael Shapiro - CERL
- * David Johnson
- *
- * PURPOSE: Allows creation and/or modification of the color table
- * for a raster map layer.
- *
- * COPYRIGHT: (C) 2006-2008, 2010 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.
- *
- ***************************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-#include <grass/G3d.h>
-
-static char **rules;
-static int nrules;
-
-static int cmp(const void *aa, const void *bb)
-{
- char *const *a = (char *const *)aa;
- char *const *b = (char *const *)bb;
-
- return strcmp(*a, *b);
-}
-
-static void scan_rules(void)
-{
- char path[GPATH_MAX];
-
- sprintf(path, "%s/etc/colors", G_gisbase());
-
- rules = G__ls(path, &nrules);
-
- rules = G_realloc(rules, (nrules + 3) * sizeof(const char *));
-
- rules[nrules++] = G_store("random");
- rules[nrules++] = G_store("grey.eq");
- rules[nrules++] = G_store("grey.log");
-
- qsort(rules, nrules, sizeof(char *), cmp);
-}
-
-static char *rules_list(void)
-{
- char *list = NULL;
- int size = 0;
- int len = 0;
- int i;
-
- for (i = 0; i < nrules; i++) {
- const char *name = rules[i];
- int n = strlen(name);
-
- if (size < len + n + 2) {
- size = len + n + 200;
- list = G_realloc(list, size);
- }
-
- if (len > 0)
- list[len++] = ',';
-
- memcpy(&list[len], name, n + 1);
- len += n;
- }
-
- return list;
-}
-
-static char *rules_descriptions(void)
-{
- char path[GPATH_MAX];
- struct Key_Value *kv;
- int result_len = 0;
- int result_max = 2000;
- char *result = G_malloc(result_max);
- int i;
-
- sprintf(path, "%s/etc/colors.desc", G_gisbase());
- kv = G_read_key_value_file(path);
- if (!kv)
- return NULL;
-
- for (i = 0; i < nrules; i++) {
- const char *name = rules[i];
- const char *desc = G_find_key_value(name, kv);
- int len;
-
- if (!desc)
- desc = "no description";
-
- desc = _(desc);
-
- len = strlen(name) + strlen(desc) + 2;
- if (result_len + len >= result_max) {
- result_max = result_len + len + 1000;
- result = G_realloc(result, result_max);
- }
-
- sprintf(result + result_len, "%s;%s;", name, desc);
- result_len += len;
- }
-
- G_free_key_value(kv);
-
- return result;
-}
-
-static void list_rules(void)
-{
- int i;
-
- for (i = 0; i < nrules; i++)
- printf("%s\n", rules[i]);
-}
-
-static int find_rule(const char *name)
-{
- int i;
-
- for (i = 0; i < nrules; i++)
- if (strcmp(name, rules[i]) == 0)
- return 1;
-
- return 0;
-}
-
-int main(int argc, char **argv)
-{
- int overwrite;
- int is_from_stdin;
- int remove;
- int have_colors;
- struct Colors colors, colors_tmp;
- struct Cell_stats statf;
- int have_stats = 0;
- struct FPRange range;
- DCELL min, max;
- const char *name = NULL, *mapset = NULL;
- const char *style = NULL, *cmap = NULL, *cmapset = NULL;
- const char *rules = NULL;
- int fp;
- struct GModule *module;
- struct
- {
- struct Flag *r, *w, *l, *g, *a,*n;
-#ifndef USE_RASTER3D
- struct Flag *e;
-#endif
- } flag;
- struct
- {
- struct Option *map, *colr, *rast, *volume, *rules;
- } opt;
-#ifdef USE_RASTER3D
- const char *maptype = "raster3d";
- const char *Maptype = "Raster3d";
-#else
- const char *maptype = "raster";
- const char *Maptype = "Raster";
-#endif
- G_gisinit(argv[0]);
-
- module = G_define_module();
- G_add_keyword(_("raster3d"));
- G_add_keyword(_("raster"));
- G_add_keyword(_("color table"));
-#ifdef USE_RASTER3D
- module->description =
- _("Creates/modifies the color table associated with a raster3d map.");
-#else
- module->description =
- _("Creates/modifies the color table associated with a raster map.");
-#endif
-
-#ifdef USE_RASTER3D
- opt.map = G_define_standard_option(G_OPT_R3_MAP);
-#else
- opt.map = G_define_standard_option(G_OPT_R_MAP);
-#endif
- scan_rules();
-
- opt.colr = G_define_option();
- opt.colr->key = "color";
- opt.colr->key_desc = "style";
- opt.colr->type = TYPE_STRING;
- opt.colr->required = NO;
- opt.colr->options = rules_list();
- opt.colr->description = _("Type of color table");
- opt.colr->descriptions = rules_descriptions();
- opt.colr->guisection = _("Define");
-
- opt.rast = G_define_standard_option(G_OPT_R_INPUT);
- opt.rast->key = "raster";
- opt.rast->required = NO;
- opt.rast->description =
- _("Raster map from which to copy color table");
- opt.rast->guisection = _("Define");
-
- opt.volume = G_define_standard_option(G_OPT_R3_INPUT);
- opt.volume->key = "volume";
- opt.volume->required = NO;
- opt.volume->description =
- _("Raster3d map from which to copy color table");
- opt.volume->guisection = _("Define");
-
- opt.rules = G_define_standard_option(G_OPT_F_INPUT);
- opt.rules->key = "rules";
- opt.rules->required = NO;
- opt.rules->label = _("Path to rules file");
- opt.rules->description = _("\"-\" to read rules from stdin");
- opt.rules->guisection = _("Define");
-
- flag.r = G_define_flag();
- flag.r->key = 'r';
- flag.r->description = _("Remove existing color table");
- flag.r->guisection = _("Remove");
-
- flag.w = G_define_flag();
- flag.w->key = 'w';
- flag.w->description =
- _("Only write new color table if one doesn't already exist");
-
- flag.l = G_define_flag();
- flag.l->key = 'l';
- flag.l->description = _("List available rules then exit");
- flag.l->suppress_required = YES;
- flag.l->guisection = _("Print");
-
- flag.n = G_define_flag();
- flag.n->key = 'n';
- flag.n->description = _("Invert colors");
- flag.n->guisection = _("Define");
-
- flag.g = G_define_flag();
- flag.g->key = 'g';
- flag.g->description = _("Logarithmic scaling");
- flag.g->guisection = _("Define");
-
- flag.a = G_define_flag();
- flag.a->key = 'a';
- flag.a->description = _("Logarithmic-absolute scaling");
- flag.a->guisection = _("Define");
-
-#ifndef USE_RASTER3D
- flag.e = G_define_flag();
- flag.e->key = 'e';
- flag.e->description = _("Histogram equalization");
- flag.e->guisection = _("Define");
-#endif
-
- if (G_parser(argc, argv))
- exit(EXIT_FAILURE);
-
- if (flag.l->answer) {
- list_rules();
- return EXIT_SUCCESS;
- }
-
- overwrite = !flag.w->answer;
- remove = flag.r->answer;
-
- name = opt.map->answer;
-
- if (!name)
- G_fatal_error(_("No %s map specified"), maptype);
-
- if(opt.rast->answer && opt.volume->answer)
- G_fatal_error(_("\raster\" and \"volume\" options are mutually exclusive"));
-
- style = opt.colr->answer;
-
- if(opt.rast->answer)
- cmap = opt.rast->answer;
- if(opt.volume->answer)
- cmap = opt.volume->answer;
-
- rules = opt.rules->answer;
-
-
- if (!cmap && !style && !rules && !remove)
- G_fatal_error(_("One of \"-r\" or options \"color\", \"raster\" or \"rules\" must be specified!"));
-
- 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;
-#ifdef USE_RASTER3D
- mapset = G_find_grid3(name, "");
-#else
- mapset = G_find_raster2(name, "");
-#endif
- if (mapset == NULL)
- G_fatal_error(_("%s map <%s> not found"), Maptype, name);
-
- if (remove) {
-#ifdef USE_RASTER3D
- int stat = G3d_removeColor(name);
-#else
- int stat = Rast_remove_colors(name, mapset);
-#endif
- if (stat < 0)
- G_fatal_error(_("Unable to remove color table of %s map <%s>"), maptype, name);
- if (stat == 0)
- G_warning(_("Color table of %s map <%s> not found"), maptype, name);
- return EXIT_SUCCESS;
- }
-
- G_suppress_warnings(1);
-#ifdef USE_RASTER3D
- have_colors = G3d_readColors(name, mapset, &colors);
-#else
- have_colors = Rast_read_colors(name, mapset, &colors);
-#endif
- /*
- if (have_colors >= 0)
- Rast_free_colors(&colors);
- */
-
- if (have_colors > 0 && !overwrite) {
- G_warning(_("Color table exists. Exiting."));
- exit(EXIT_FAILURE);
- }
-
- G_suppress_warnings(0);
-
-#ifdef USE_RASTER3D
- fp = 1; /* g3d maps are always floating point */
- G3d_readRange(name, mapset, &range);
-#else
- fp = Rast_map_is_fp(name, mapset);
- Rast_read_fp_range(name, mapset, &range);
-#endif
- Rast_get_fp_range_min_max(&range, &min, &max);
-
- if (is_from_stdin) {
- if (!read_color_rules(stdin, &colors, min, max, fp))
- exit(EXIT_FAILURE);
- }
- else if (style) {
- /*
- * here the predefined color-table color-styles are created by GRASS library calls.
- */
- if (strcmp(style, "random") == 0) {
- if (fp)
- G_fatal_error(_("Color table 'random' is not supported for floating point %s map"), maptype);
- Rast_make_random_colors(&colors, (CELL) min, (CELL) max);
- }
- else if (strcmp(style, "grey.eq") == 0) {
- if (fp)
- G_fatal_error(_("Color table 'grey.eq' is not supported for floating point %s map"), maptype);
- if (!have_stats)
- have_stats = get_stats(name, mapset, &statf);
- Rast_make_histogram_eq_colors(&colors, &statf);
- }
- else if (strcmp(style, "grey.log") == 0) {
- if (fp)
- G_fatal_error(_("Color table 'grey.log' is not supported for floating point %s map"), maptype);
- if (!have_stats)
- have_stats = get_stats(name, mapset, &statf);
- Rast_make_histogram_log_colors(&colors, &statf, (CELL) min,
- (CELL) max);
- }
- else if (find_rule(style))
- Rast_make_fp_colors(&colors, style, min, max);
- else
- G_fatal_error(_("Unknown color request '%s'"), style);
- }
- else if (rules) {
- if (!Rast_load_fp_colors(&colors, rules, min, max)) {
- /* for backwards compatibility try as std name; remove for GRASS 7 */
- char path[GPATH_MAX];
-
- /* don't bother with native dirsep as not needed for backwards compatibility */
- sprintf(path, "%s/etc/colors/%s", G_gisbase(), rules);
-
- if (!Rast_load_fp_colors(&colors, path, min, max))
- G_fatal_error(_("Unable to load rules file <%s>"), rules);
- }
- }
- else {
- /* use color from another map (cmap) */
- if(opt.rast->answer) {
- cmapset = G_find_raster2(cmap, "");
- if (cmapset == NULL)
- G_fatal_error(_("Raster map <%s> not found"), cmap);
-
- if (Rast_read_colors(cmap, cmapset, &colors) < 0)
- G_fatal_error(_("Unable to read color table for raster map <%s>"), cmap);
- } else {
- cmapset = G_find_grid3(cmap, "");
- if (cmapset == NULL)
- G_fatal_error(_("Raster3d map <%s> not found"), cmap);
-
- if (G3d_readColors(cmap, cmapset, &colors) < 0)
- G_fatal_error(_("Unable to read color table for raster3d map <%s>"), cmap);
- }
- }
-
- if (fp)
- Rast_mark_colors_as_fp(&colors);
-
- if (flag.n->answer)
- Rast_invert_colors(&colors);
-
- /* This is not avilable for raster3d maps yet */
-#ifndef USE_RASTER3D
- if (flag.e->answer) {
- if (fp) {
- struct FP_stats fpstats;
- get_fp_stats(name, mapset, &fpstats, min, max, flag.g->answer, flag.a->answer);
- Rast_histogram_eq_fp_colors(&colors_tmp, &colors, &fpstats);
- }
- else {
- if (!have_stats)
- have_stats = get_stats(name, mapset, &statf);
- Rast_histogram_eq_colors(&colors_tmp, &colors, &statf);
- }
- colors = colors_tmp;
- }
-#endif
-
- if (flag.g->answer) {
- Rast_log_colors(&colors_tmp, &colors, 100);
- colors = colors_tmp;
- }
-
- if (flag.a->answer) {
- Rast_abs_log_colors(&colors_tmp, &colors, 100);
- colors = colors_tmp;
- }
-
- if (fp)
- Rast_mark_colors_as_fp(&colors);
-#ifdef USE_RASTER3D
- G3d_writeColors(name, mapset, &colors);
-#else
- Rast_write_colors(name, mapset, &colors);
-#endif
- G_message(_("Color table for %s map <%s> set to '%s'"), maptype, name,
- is_from_stdin ? "rules" : style ? style : rules ? rules :
- cmap);
-
- exit(EXIT_SUCCESS);
-}
Modified: grass/trunk/raster/r.colors/r.colors.html
===================================================================
--- grass/trunk/raster/r.colors/r.colors.html 2011-06-23 22:30:34 UTC (rev 46773)
+++ grass/trunk/raster/r.colors/r.colors.html 2011-06-24 13:17:31 UTC (rev 46774)
@@ -9,6 +9,10 @@
to copy the color map.
<p>
+The <b>volume</b> option allows user to specify a volume (3d raster) map
+<i>name</i> from which to copy the color map.
+
+<p>
All color tables are stored in $GISBASE/etc/colors/. Further user-defined color tables
can also be stored in this directory for access from the <em>color</em> parameter.
<p>
Added: grass/trunk/raster/r.colors/r3.colors.html
===================================================================
--- grass/trunk/raster/r.colors/r3.colors.html (rev 0)
+++ grass/trunk/raster/r.colors/r3.colors.html 2011-06-24 13:17:31 UTC (rev 46774)
@@ -0,0 +1,17 @@
+<h2>DESCRIPTION</h2>
+
+<i>r3.colors</i> has exactly the same functionality as <i>r.colors</i> but for volume maps.
+With the exception that the <b>-e</b> flag, which equalizes the original raster's color table,
+only works for raster maps. Please refer to <a href="r.colors.html">r.colors</a>.
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.colors.html">r.colors</a>
+</em>
+
+<h2>AUTHORS</h2>
+Michael Shapiro and David Johnson
+
+<p>
+<i>Last changed: $Date: 2011-01-03 14:54:24 +0100 (Mo, 03. Jan 2011) $</i>
Added: grass/trunk/raster/r.colors/raster3d_main.c
===================================================================
--- grass/trunk/raster/r.colors/raster3d_main.c (rev 0)
+++ grass/trunk/raster/r.colors/raster3d_main.c 2011-06-24 13:17:31 UTC (rev 46774)
@@ -0,0 +1,26 @@
+
+/****************************************************************************
+ *
+ * MODULE: r3.colors
+ *
+ * AUTHOR(S): Michael Shapiro - CERL
+ * David Johnson
+ *
+ * PURPOSE: Allows creation and/or modification of the color table
+ * for a raster map layer.
+ *
+ * COPYRIGHT: (C) 2006 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.
+ *
+ ***************************************************************************/
+
+#include "local_proto.h"
+
+/* This is the main function for r3.colors*/
+int main(int argc, char **argv)
+{
+ return edit_colors(argc, argv, RASTER3D_TYPE, "raster3d", "Raster3d");
+}
\ No newline at end of file
Added: grass/trunk/raster/r.colors/raster_main.c
===================================================================
--- grass/trunk/raster/r.colors/raster_main.c (rev 0)
+++ grass/trunk/raster/r.colors/raster_main.c 2011-06-24 13:17:31 UTC (rev 46774)
@@ -0,0 +1,26 @@
+
+/****************************************************************************
+ *
+ * MODULE: r.colors
+ *
+ * AUTHOR(S): Michael Shapiro - CERL
+ * David Johnson
+ *
+ * PURPOSE: Allows creation and/or modification of the color table
+ * for a raster map layer.
+ *
+ * COPYRIGHT: (C) 2006 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.
+ *
+ ***************************************************************************/
+
+#include "local_proto.h"
+
+/* This is the main function for r3.colors*/
+int main(int argc, char **argv)
+{
+ return edit_colors(argc, argv, RASTER_TYPE, "raster", "Raster");
+}
\ No newline at end of file
Modified: grass/trunk/raster/r.colors/test.r.colors.sh
===================================================================
--- grass/trunk/raster/r.colors/test.r.colors.sh 2011-06-23 22:30:34 UTC (rev 46773)
+++ grass/trunk/raster/r.colors/test.r.colors.sh 2011-06-24 13:17:31 UTC (rev 46774)
@@ -1,5 +1,5 @@
# This script tests r.colors and r.colors.out as well
-# as r3.colors and r3.colors.out
+# as r3.colors and r3.colors.out which have the same code base
# Color rules are set with r/r3.colors and exported using r/r3.colors.out
# We specific a small region in the
@@ -49,6 +49,7 @@
r.colors -a map=test_elev_double rules=example3 && r.colors.out --o map=test_elev_double rules=test_elev_double_example3_logabs.txt
r.colors map=test_elev_double rules=example4 && r.colors.out --o map=test_elev_double rules=test_elev_double_example4.txt
r.colors -n map=test_elev_double rast=test_elev_double && r.colors.out --o map=test_elev_double rules=test_elev_double_example4_inv.txt
+
# The volume maps using r3.colors and r3.colors.out
r3.colors map=volume_double_null rules=example1 && r3.colors.out --o map=volume_double_null rules=test_volume_double_example1.txt
r3.colors map=volume_double_null rules=example2 && r3.colors.out --o map=volume_double_null rules=test_volume_double_example2.txt
@@ -57,4 +58,10 @@
r3.colors -a map=volume_double_null rules=example3 && r3.colors.out --o map=volume_double_null rules=test_volume_double_example3_logabs.txt
r3.colors map=volume_double_null rules=example4 && r3.colors.out --o map=volume_double_null rules=test_volume_double_example4.txt
r3.colors -n map=volume_double_null volume=volume_double_null && r3.colors.out --o map=volume_double_null rules=test_volume_double_example4_inv.txt
+# Apply a raster color table to the volume map
r3.colors map=volume_double_null raster=test_elev_double && r3.colors.out --o map=volume_double_null rules=test_volume_double_example5.txt
+
+# Test the removement the raster3d color table, a default color table will be created
+r3.colors -r map=volume_double_null && r3.colors.out --o map=volume_double_null rules=test_volume_double_default.txt
+# Test the removement the raster color table, a default color table will be created
+r.colors -r map=test_elev_double && r.colors.out --o map=test_elev_double rules=test_elev_double_default.txt
\ No newline at end of file
Added: grass/trunk/raster/r.colors/test_elev_double_default.ref
===================================================================
--- grass/trunk/raster/r.colors/test_elev_double_default.ref (rev 0)
+++ grass/trunk/raster/r.colors/test_elev_double_default.ref 2011-06-24 13:17:31 UTC (rev 46774)
@@ -0,0 +1,8 @@
+1.5 255:255:0
+3.1 0:255:0
+4.7 0:255:255
+6.3 0:0:255
+7.9 255:0:255
+9.5 255:0:0
+nv 255:255:255
+default 255:255:255
Added: grass/trunk/raster/r.colors/test_volume_double_default.ref
===================================================================
--- grass/trunk/raster/r.colors/test_volume_double_default.ref (rev 0)
+++ grass/trunk/raster/r.colors/test_volume_double_default.ref 2011-06-24 13:17:31 UTC (rev 46774)
@@ -0,0 +1,8 @@
+4 255:255:0
+8 0:255:0
+12 0:255:255
+16 0:0:255
+20 255:0:255
+24 255:0:0
+nv 255:255:255
+default 255:255:255
More information about the grass-commit
mailing list