[GRASS-dev] nviz colored vectors

Radek Bartoň blackhex at post.cz
Tue May 30 04:13:56 EDT 2006


Here is colored vector patch for nviz. It uses grassrgb attribute to get line 
colors. Displaying of line vectors should work, area vectors aren't 
implemented.

Radek Bartoň
-------------- next part --------------
Index: include/gstypes.h
===================================================================
RCS file: /home/grass/grassrepository/grass6/include/gstypes.h,v
retrieving revision 1.1
diff -r1.1 gstypes.h
161a162
>     int color;
173c174
<     int color, width;
---
>     int color, width; /* Color is deprecated. */
Index: lib/ogsf/Gv3.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/lib/ogsf/Gv3.c,v
retrieving revision 1.9
diff -r1.9 Gv3.c
12a13,15
> #include <grass/dbmi.h>
> #include <grass/display.h>
> #include <grass/glocale.h>
24c27
< geoline *Gv_load_vect(char *grassname, int *nlines)
---
> 	geoline *Gv_load_vect(char *grassname, int *nlines)
27a31
>     struct line_cats *cats;
29c33,34
<     int np, i, n, nareas, nl=0, area, type, is3d;
---
>     int np, i, n, nareas, ncols, nl=0, area, leftarea, rightarea, line, type,
>       cat, is3d;
32a38,54
>     /* Variables for field info. */
>     struct Option *fieldopt;
>     struct cat_list *catlist;
>     struct field_info *fieldinfo;
> 
>     /* Database variables. */
>     dbDriver *driver;
>     dbString *tablestr;
>     dbTable *table;
>     dbColumn *column;
>     dbValue value;
> 
>     /* Color translate variables. */
>     int has_grassrgb;
>     const char * colorstr;
>     int red, green, blue;
> 
48a71
>     cats = Vect_new_cats_struct();
55c78,114
<     
---
> 
>     /* Get field and field info */
>     fieldopt = G_define_standard_option(G_OPT_V_FIELD);
>     catlist = Vect_new_cat_list();
>     catlist->field = atoi(fieldopt->answer);
>     if ((fieldinfo = Vect_get_field(&map, catlist->field)) == NULL)
>     {
>       G_fatal_error(_("Database connection not defined"));
>     }
> 
>     /* Connect database. */
>     if ((driver = db_start_driver_open_database(fieldinfo->driver,
>       fieldinfo->database)) == NULL)
>     {
>       G_fatal_error(_("Can't open driver %s"), fieldinfo->driver);
>     }
> 
>     /* Check if grassrgb attribute is present in table. */
>     db_init_string(tablestr);
>     db_set_string(tablestr, fieldinfo->table);
>     if (db_describe_table(driver, tablestr, &table) != DB_OK)
>     {
>       G_fatal_error(_("Can't get schema of table %s"), fieldinfo->table);
>     }
>     has_grassrgb = 0;
>     ncols = db_get_table_number_of_columns(table);
>     for (n = 0; n < ncols; n++)
>     {
>       column = db_get_table_column(table, n);
>       if (!strcmp(db_get_column_name(column), "grassrgb") ||
>         !strcmp(db_get_column_name(column), "GRASSRGB"))
>       {
>         has_grassrgb = 1;
>         break;
>       }
>     }
> 
128c187,189
<     while (-1 < (type = Vect_read_next_line(&map, points, NULL))) {
---
>     n = Vect_get_num_lines (&map);
>     for ( line = 1; line <= n; line++ ) {
>         type = Vect_read_line (&map, points, cats, line);
184c245,276
< 	
---
> 
>             if (has_grassrgb)
>             {
>               /* Get line or area category. */
>               if ((cat = Vect_get_line_cat(&map, line, catlist->field)) < 0)
>               {
>                 gln->color = 0x00000000;
>                 continue;
>               }
> 
>               /* Get grassrgb attribute value. */
>               if (db_select_value(driver, fieldinfo->table, fieldinfo->key, cat,
>                 "grassrgb", &value) == -1)
>               {
>                 G_fatal_error (_("Can't get grassrgb attribute value for line %d"),
>                   cat);
>               }
>               colorstr = db_get_value_string(&value);
>               if (!colorstr)
>               {
>                 G_fatal_error (_("Color definition column (%s) not a string. "
>                   "Column must be of form RRR:GGG:BBB where RGB values range 0-255."),
>                   "grassrgb");
>               }
>               G_str_to_color(colorstr, &red, &green, &blue);
>               gln->color = red | (green << 8) | (blue << 16) | 0xFF000000;
>             }
>             else
>             {
>               gln->color = 0x00000000;
>             }
> 
209c301,305
<     
---
> 
>     if (driver)
>     {
>       db_close_database_shutdown_driver(driver);
>     }
Index: lib/ogsf/gvd.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/lib/ogsf/gvd.c,v
retrieving revision 1.6
diff -r1.6 gvd.c
141a142,147
>         /* Set line color. */
>         if (gln->color != 0x00000000)
>         {
>           gsd_color_func(gln->color);
>         }
> 


More information about the grass-dev mailing list