Bläddra i källkod

ogsflib: support for vector color tables

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47620 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 år sedan
förälder
incheckning
24885b5a94
5 ändrade filer med 50 tillägg och 28 borttagningar
  1. 5 4
      include/ogsf_proto.h
  2. 8 6
      lib/ogsf/GP2.c
  3. 13 14
      lib/ogsf/GV2.c
  4. 12 3
      lib/ogsf/Gp3.c
  5. 12 1
      lib/ogsf/Gv3.c

+ 5 - 4
include/ogsf_proto.h

@@ -63,7 +63,8 @@ int GP_load_site(int, const char *);
 int GP_get_sitename(int, char **);
 int GP_get_sitename(int, char **);
 int GP_get_style(int, int *, int *, float *, int *);
 int GP_get_style(int, int *, int *, float *, int *);
 int GP_set_style(int, int, int, float, int);
 int GP_set_style(int, int, int, float, int);
-int GP_set_style_thematic(int, int, const char *, const char *, const char *, const char *);
+int GP_set_style_thematic(int, int, const char *, const char *, const char *,
+			  const char *, struct Colors *);
 int GP_unset_style_thematic(int);
 int GP_unset_style_thematic(int);
 int GP_attmode_color(int, const char *);
 int GP_attmode_color(int, const char *);
 int GP_attmode_none(int);
 int GP_attmode_none(int);
@@ -244,7 +245,7 @@ int GV_load_vector(int, const char *);
 int GV_get_vectname(int, char **);
 int GV_get_vectname(int, char **);
 int GV_set_style(int, int, int, int, int);
 int GV_set_style(int, int, int, int, int);
 int GV_get_style(int, int *, int *, int *, int *);
 int GV_get_style(int, int *, int *, int *, int *);
-int GV_set_style_thematic(int, int, const char*, const char*);
+int GV_set_style_thematic(int, int, const char *, const char *, struct Colors *);
 int GV_unset_style_thematic(int);
 int GV_unset_style_thematic(int);
 void GV_set_trans(int, float, float, float);
 void GV_set_trans(int, float, float, float);
 int GV_get_trans(int, float *, float *, float *);
 int GV_get_trans(int, float *, float *, float *);
@@ -317,7 +318,7 @@ int GVL_slice_set_pos(int, int, float, float, float, float, float, float,
 /* Gp3.c */
 /* Gp3.c */
 int Gp_set_color(const char *, geopoint *);
 int Gp_set_color(const char *, geopoint *);
 geopoint *Gp_load_sites(const char *, int *, int *);
 geopoint *Gp_load_sites(const char *, int *, int *);
-int Gp_load_sites_thematic(geosite *);
+int Gp_load_sites_thematic(geosite *, struct Colors *);
 
 
 /* Gs3.c */
 /* Gs3.c */
 double Gs_distance(double *, double *);
 double Gs_distance(double *, double *);
@@ -343,7 +344,7 @@ int Gs_update_attrange(geosurf *, int);
 
 
 /* Gv3.c */
 /* Gv3.c */
 geoline *Gv_load_vect(const char *, int *);
 geoline *Gv_load_vect(const char *, int *);
-int Gv_load_vect_thematic(geovect *);
+int Gv_load_vect_thematic(geovect *, struct Colors *);
 void sub_Vectmem(int);
 void sub_Vectmem(int);
 
 
 /* gk.c */
 /* gk.c */

+ 8 - 6
lib/ogsf/GP2.c

@@ -296,15 +296,17 @@ int GP_set_style(int id, int color, int width, float size, int symbol)
    
    
    \param id point set id
    \param id point set id
    \param layer layer number for thematic mapping
    \param layer layer number for thematic mapping
-   \param color icon color
-   \param width icon line width
-   \param size icon size
-   \param symbol icon symbol
+   \param color icon color column name
+   \param width icon line width column name
+   \param size icon size column name
+   \param symbol icon symbol column name
+   \param colors pointer to Colors structure or NULL
 
 
    \return 1 on success
    \return 1 on success
    \return -1 on error (point set not found)
    \return -1 on error (point set not found)
  */
  */
-int GP_set_style_thematic(int id, int layer, const char* color, const char* width, const char* size, const char* symbol)
+int GP_set_style_thematic(int id, int layer, const char* color, const char* width,
+			  const char* size, const char* symbol, struct Colors *color_rules)
 {
 {
     geosite *gp;
     geosite *gp;
     
     
@@ -330,7 +332,7 @@ int GP_set_style_thematic(int id, int layer, const char* color, const char* widt
     if (width)
     if (width)
 	gp->tstyle->width_column = G_store(width);
 	gp->tstyle->width_column = G_store(width);
 
 
-    Gp_load_sites_thematic(gp);
+    Gp_load_sites_thematic(gp, color_rules);
 
 
     return 1;
     return 1;
 }
 }

+ 13 - 14
lib/ogsf/GV2.c

@@ -1,19 +1,16 @@
 /*!
 /*!
-   \file GV2.c
+   \file lib/ogsf/GV2.c
 
 
    \brief OGSF library - loading and manipulating vector sets (higher level functions)
    \brief OGSF library - loading and manipulating vector sets (higher level functions)
 
 
-   GRASS OpenGL gsurf OGSF Library 
+   (C) 1999-2008, 2011 by the GRASS Development Team
 
 
-   (C) 1999-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
-   for details.
+   This program is free software under the GNU General Public License
+   (>=v2).  Read the file COPYING that comes with GRASS for details.
 
 
    \author Bill Brown USACERL, GMSL/University of Illinois
    \author Bill Brown USACERL, GMSL/University of Illinois
-   \author Doxygenized by Martin Landa <landa.martin gmail.com>
+   \author Updated by Martin landa <landa.martin gmail.com>
+   (doxygenized in May 2008, thematic mapping in June 2011)
  */
  */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
@@ -280,13 +277,15 @@ int GV_get_style(int id, int *mem, int *color, int *width, int *flat)
    
    
    \param id vector set id
    \param id vector set id
    \param layer layer number for thematic mapping
    \param layer layer number for thematic mapping
-   \param color color column
-   \param width width column
-   
+   \param color color column name
+   \param width width column name
+   \param colors pointer to Colors structure or NULL
+
    \return 1 on success
    \return 1 on success
    \return -1 on error (point set not found)
    \return -1 on error (point set not found)
  */
  */
-int GV_set_style_thematic(int id, int layer, const char* color, const char* width)
+int GV_set_style_thematic(int id, int layer, const char* color, const char* width,
+			  struct Colors *color_rules)
 {
 {
     geovect *gv;
     geovect *gv;
 
 
@@ -305,7 +304,7 @@ int GV_set_style_thematic(int id, int layer, const char* color, const char* widt
     if (width)
     if (width)
 	gv->tstyle->width_column = G_store(width);
 	gv->tstyle->width_column = G_store(width);
 
 
-    Gv_load_vect_thematic(gv);
+    Gv_load_vect_thematic(gv, color_rules);
 
 
     return 1;
     return 1;
 }
 }

+ 12 - 3
lib/ogsf/Gp3.c

@@ -159,11 +159,12 @@ geopoint *Gp_load_sites(const char *name, int *nsites, int *has_z)
   \brief Load styles for geopoints based on thematic mapping
   \brief Load styles for geopoints based on thematic mapping
 
 
   \param gp pointer to geosite structure
   \param gp pointer to geosite structure
-
+  \param colors pointer to Colors structure or NULL
+  
   \return number of points defined by thematic mapping
   \return number of points defined by thematic mapping
   \return -1 on error
   \return -1 on error
 */
 */
-int Gp_load_sites_thematic(geosite *gp)
+int Gp_load_sites_thematic(geosite *gp, struct Colors *colors)
 {
 {
     geopoint *gpt;
     geopoint *gpt;
 
 
@@ -220,6 +221,14 @@ int Gp_load_sites_thematic(geosite *gp)
 	    continue;
 	    continue;
 
 
 	/* color */
 	/* color */
+	if (colors) {
+	    if (!Rast_get_c_color((const CELL *) &cat, &red, &grn, &blu, colors)) {
+		G_warning(_("No color rule defined for category %d"), cat);
+		gpt->style->color = gp->style->color;
+	    }
+	    gpt->style->color = (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
+		((int)((blu) << 16) & BLU_MASK);
+	}
 	if (gp->tstyle->color_column) {
 	if (gp->tstyle->color_column) {
 	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->color_column, &value);
 	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->color_column, &value);
 	    if (nvals < 1)
 	    if (nvals < 1)
@@ -235,7 +244,7 @@ int Gp_load_sites_thematic(geosite *gp)
 		    ((int)((blu) << 16) & BLU_MASK);
 		    ((int)((blu) << 16) & BLU_MASK);
 	    }
 	    }
 	}
 	}
-
+	
 	/* size */
 	/* size */
 	if (gp->tstyle->size_column) {
 	if (gp->tstyle->size_column) {
 	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->size_column, &value);
 	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->size_column, &value);

+ 12 - 1
lib/ogsf/Gv3.c

@@ -19,6 +19,7 @@
 
 
 #include <grass/gis.h>
 #include <grass/gis.h>
 #include <grass/colors.h>
 #include <grass/colors.h>
+#include <grass/raster.h>
 #include <grass/vector.h>
 #include <grass/vector.h>
 #include <grass/dbmi.h>
 #include <grass/dbmi.h>
 #include <grass/glocale.h>
 #include <grass/glocale.h>
@@ -296,11 +297,12 @@ void sub_Vectmem(int minus)
   \brief Load styles for geolines based on thematic mapping
   \brief Load styles for geolines based on thematic mapping
 
 
   \param gv pointer to geovect structure
   \param gv pointer to geovect structure
+  \param colors pointer to Colors structure or NULL
 
 
   \return number of features defined by thematic mapping
   \return number of features defined by thematic mapping
   \return -1 on error
   \return -1 on error
 */
 */
-int Gv_load_vect_thematic(geovect *gv)
+int Gv_load_vect_thematic(geovect *gv, struct Colors *colors)
 {
 {
     geoline *gvt;
     geoline *gvt;
 
 
@@ -357,6 +359,15 @@ int Gv_load_vect_thematic(geovect *gv)
 	    continue;
 	    continue;
 
 
 	/* color */
 	/* color */
+	if (colors) {
+	    if (!Rast_get_c_color((const CELL *) &cat, &red, &grn, &blu, colors)) {
+		G_warning(_("No color rule defined for category %d"), cat);
+		gvt->style->color = gv->style->color;
+	    }
+	    gvt->style->color = (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
+		((int)((blu) << 16) & BLU_MASK);
+	}
+	
 	if (gv->tstyle->color_column) {
 	if (gv->tstyle->color_column) {
 	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gv->tstyle->color_column, &value);
 	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gv->tstyle->color_column, &value);
 	    if (nvals < 1)
 	    if (nvals < 1)