Browse Source

v.colors: fix 'random' color table

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47649 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 years ago
parent
commit
b10e9b2d6b

+ 5 - 2
vector/v.colors/local_proto.h

@@ -1,8 +1,11 @@
-/* scan_attr */
+/* make_colors.c */
+void make_colors(struct Colors *, const char *, DCELL, DCELL, int);
+
+/* scan_attr.c */
 int scan_attr(const struct Map_info *, int, const char *, const char *,
 	      const struct FPRange *, struct Colors *, int *, int *);
 
-/* scan_cats */
+/* scan_cats.c */
 void scan_cats(const struct Map_info *, int, const char *,
 	       const struct FPRange *, struct Colors *, int *, int *);
 

+ 0 - 20
vector/v.colors/main.c

@@ -15,7 +15,6 @@
  *
  **************************************************************/
 
-#include <string.h>
 #include <stdlib.h>
 
 #include <grass/gis.h>
@@ -246,25 +245,6 @@ int main(int argc, char *argv[])
 	    scan_attr(&Map, layer, attrcolumn, style, opt.range->answer ? &range : NULL,
 		      &colors, &cmin, &cmax);
 	}
-	
-	if (strcmp(style, "random") == 0) {
-	    Rast_make_random_colors(&colors, (CELL) cmin, (CELL) cmax);
-	} else if (strcmp(style, "grey.eq") == 0) {
-	    G_fatal_error(_("Color table <%s> not supported"), "grey.eq");
-	    /*
-	      if (!have_stats)
-	      have_stats = get_stats(name, mapset, &statf);
-	      Rast_make_histogram_eq_colors(&colors, &statf);
-	    */
-        } else if (strcmp(style, "grey.log") == 0) {
-	    G_fatal_error(_("Color table <%s> not supported"), "grey.log");
-	    /*
-	      if (!have_stats)
-	      have_stats = get_stats(name, mapset, &statf);
-	      Rast_make_histogram_log_colors(&colors, &statf, (CELL) min,
-	      (CELL) max);
-	    */
-	}
     }
     else if (rules) {
 	if (!Rast_load_colors(&colors, rules, (CELL) cmin, (CELL) cmax))

+ 39 - 0
vector/v.colors/make_colors.c

@@ -0,0 +1,39 @@
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+
+void make_colors(struct Colors *colors, const char *style, DCELL min, DCELL max, int is_fp)
+{
+
+    G_debug(3, "make_colors(): range=%f,%f is_fp=%d", min, max, is_fp);
+
+    if (strcmp(style, "random") == 0) {
+	if (is_fp)
+	    G_fatal_error(_("Color table '%s' is not supported for "
+			    "floating point attributes"), style);
+	Rast_make_random_colors(colors, (CELL) min, (CELL) max);
+    } else if (strcmp(style, "grey.eq") == 0) {
+	G_fatal_error(_("Color table <%s> not supported"), "grey.eq");
+	/*
+	  if (!have_stats)
+	  have_stats = get_stats(name, mapset, &statf);
+	  Rast_make_histogram_eq_colors(&colors, &statf);
+	*/
+    } else if (strcmp(style, "grey.log") == 0) {
+	G_fatal_error(_("Color table <%s> not supported"), "grey.log");
+	/*
+	  if (!have_stats)
+	  have_stats = get_stats(name, mapset, &statf);
+	  Rast_make_histogram_log_colors(&colors, &statf, (CELL) min,
+	  (CELL) max);
+	*/
+    }
+    else {
+	if (is_fp)
+	    Rast_make_fp_colors(colors, style, min, max);
+	else
+	    Rast_make_colors(colors, style, (CELL) min, (CELL) max);
+    }
+}

+ 2 - 7
vector/v.colors/scan_attr.c

@@ -68,9 +68,6 @@ int scan_attr(const struct Map_info *Map, int layer, const char *column_name,
 		G_warning(_("Max value (%f) is out of range %f,%f"),
 			  range->max, fmin, fmax);
 	}
-	
-	G_debug(3, "scan_attr(): range=%f,%f", fmin, fmax);
-	Rast_make_fp_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax);
     }
     else {
 	fmin = cvarr.value[0].val.i;
@@ -89,10 +86,8 @@ int scan_attr(const struct Map_info *Map, int layer, const char *column_name,
 		G_warning(_("Max value (%d) is out of range %d,%d"),
 			  (int) range->max, (int) fmin, (int) fmax);
 	}
-	
-	G_debug(3, "scan_attr(): range=%d,%d", (int) fmin, (int) fmax);
-	Rast_make_colors(&vcolors, style, (CELL) fmin, (CELL) fmax);
     }
+    make_colors(&vcolors, style, (DCELL) fmin, (DCELL) fmax, is_fp);
 
     /* color table for categories */
     for (i = 0; i < cvarr.n_values; i++) {
@@ -129,7 +124,7 @@ int scan_attr(const struct Map_info *Map, int layer, const char *column_name,
 		*cmax = cat;
 	}
     }
-	
+    
     db_close_database(driver);
 
     return is_fp;

+ 1 - 2
vector/v.colors/scan_cats.c

@@ -45,8 +45,7 @@ void scan_cats(const struct Map_info *Map, int field, const char *style,
 		      (int) range->max, *cmin, *cmax);
     }
     
-    G_debug(3, "scan_cats(): range=%d,%d", *cmin, *cmax);
-    Rast_make_colors(colors, style, (CELL) *cmin, (CELL) *cmax);
+    make_colors(colors, style, (DCELL) *cmin, (DCELL) *cmax, FALSE);
 
     Vect_destroy_cats_struct(Cats);
 }