[GRASS-SVN] r47875 - grass/trunk/display/d.vect
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 25 06:32:41 EDT 2011
Author: martinl
Date: 2011-08-25 03:32:41 -0700 (Thu, 25 Aug 2011)
New Revision: 47875
Modified:
grass/trunk/display/d.vect/area.c
grass/trunk/display/d.vect/lines.c
grass/trunk/display/d.vect/local_proto.h
grass/trunk/display/d.vect/shape.c
Log:
d.vect: optimalize rendering also for linked OGR layers
Modified: grass/trunk/display/d.vect/area.c
===================================================================
--- grass/trunk/display/d.vect/area.c 2011-08-24 21:11:28 UTC (rev 47874)
+++ grass/trunk/display/d.vect/area.c 2011-08-25 10:32:41 UTC (rev 47875)
@@ -29,7 +29,7 @@
int cat, centroid;
int red, grn, blu;
- int i, custom_rgb, found, nerror_rgb;
+ int i, custom_rgb, found;
int width;
struct bound_box box;
@@ -42,7 +42,6 @@
G_debug(1, "display areas:");
- nerror_rgb = 0;
centroid = 0;
Points = Vect_new_line_struct();
APoints = Vect_new_line_struct();
@@ -171,7 +170,7 @@
/* custom colors */
if (colors || cvarr_rgb) {
custom_rgb = get_table_color(cat, area, colors, cvarr_rgb,
- &red, &grn, &blu, &nerror_rgb);
+ &red, &grn, &blu);
}
/* random colors */
Modified: grass/trunk/display/d.vect/lines.c
===================================================================
--- grass/trunk/display/d.vect/lines.c 2011-08-24 21:11:28 UTC (rev 47874)
+++ grass/trunk/display/d.vect/lines.c 2011-08-25 10:32:41 UTC (rev 47875)
@@ -36,6 +36,22 @@
{0, 139, 139} /* 16: dark cyan */
};
+static int draw_line(int, int, int,
+ const struct line_pnts *, const struct line_cats *,
+ const struct color_rgb *, const struct color_rgb *, int,
+ const char *, int, int,
+ int, int,
+ int, double,
+ struct Colors *,
+ dbCatValArray *, struct Colors *,
+ dbCatValArray *, int,
+ dbCatValArray *, int,
+ dbCatValArray *, int,
+ const struct cat_list *, SYMBOL *,
+ RGBA_Color *, RGBA_Color *,
+ RGBA_Color *,
+ int *, int *, int *, int *, int *);
+
int display_lines(struct Map_info *Map, int type, struct cat_list *Clist,
const struct color_rgb *color, const struct color_rgb *fcolor, int chcat,
const char *symbol_name, double size, int sqrt_flag,
@@ -48,25 +64,16 @@
dbCatValArray *cvarr_rot, int nrec_rot)
{
- int i, ltype, nlines, line, cat, found;
- double *x, *y;
+ int ltype, line;
struct line_pnts *Points;
struct line_cats *Cats;
- double x0, y0;
- int nerror_rgb;
int n_points, n_lines, n_centroids, n_boundaries, n_faces;
- int custom_rgb;
- int red, grn, blu;
RGBA_Color *line_color, *fill_color, *primary_color;
- int width;
SYMBOL *Symb;
- double var_size, rotation;
Symb = NULL;
- cat = -1;
- nlines = 0;
if (id_flag && Vect_level(Map) < 2) {
G_warning(_("Unable to display lines by id, topology not available. "
@@ -74,10 +81,6 @@
"v.build or v.build.all."));
}
- var_size = size;
- rotation = 0.0;
- nerror_rgb = 0;
-
line_color = G_malloc(sizeof(RGBA_Color));
fill_color = G_malloc(sizeof(RGBA_Color));
primary_color = G_malloc(sizeof(RGBA_Color));
@@ -119,213 +122,84 @@
if (color && !cvarr_rgb && !cats_color_flag)
D_RGB_color(color->r, color->g, color->b);
-
- if (Vect_level(Map) >= 2)
- nlines = Vect_get_num_lines(Map);
-
+
line = 0;
n_points = n_lines = 0;
n_centroids = n_boundaries = 0;
n_faces = 0;
while (TRUE) {
line++;
- custom_rgb = FALSE;
- if (Vect_level(Map) >= 2) {
- if (line > nlines)
- break;
- if (!Vect_line_alive(Map, line))
- continue;
- ltype = Vect_read_line(Map, Points, Cats, line);
- }
- else {
- ltype = Vect_read_next_line(Map, Points, Cats);
- if (ltype == -1) {
- G_fatal_error(_("Unable to read vector map"));
- }
- else if (ltype == -2) { /* EOF */
- break;
- }
- }
+ ltype = Vect_read_next_line(Map, Points, Cats);
- if (!(type & ltype))
- continue;
-
- if (Points->n_points == 0)
- continue;
-
- found = FALSE;
- if (chcat) {
- if (id_flag) { /* use line id */
- if (!(Vect_cat_in_cat_list(line, Clist)))
- continue;
- }
- else {
- for (i = 0; i < Cats->n_cats; i++) {
- if (Cats->field[i] == Clist->field &&
- Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
- found = TRUE;
- break;
- }
- }
- if (!found)
- continue;
- }
+ if (ltype == -1) {
+ G_fatal_error(_("Unable to read vector map"));
}
- else if (Clist->field > 0) {
- for (i = 0; i < Cats->n_cats; i++) {
- if (Cats->field[i] == Clist->field) {
- found = TRUE;
- break;
- }
- }
- /* lines with no category will be displayed */
- if (Cats->n_cats > 0 && !found)
- continue;
+ else if (ltype == -2) { /* EOF */
+ break;
}
- G_debug(3, "\tdisplay feature %d, cat %d", line, cat);
-
- /* z height colors */
- if (zcolors) {
- if (Rast_get_d_color(&Points->z[0], &red, &grn, &blu, zcolors) == 1)
- custom_rgb = TRUE;
- else
- custom_rgb = FALSE;
- }
+ draw_line(type, ltype, line,
+ Points, Cats,
+ color, fcolor, chcat,
+ symbol_name, size, sqrt_flag,
+ id_flag, cats_color_flag,
+ default_width, width_scale,
+ zcolors,
+ cvarr_rgb, colors,
+ cvarr_width, nrec_width,
+ cvarr_size, nrec_size,
+ cvarr_rot, nrec_rot,
+ Clist, Symb,
+ line_color, fill_color,
+ primary_color,
+ &n_points, &n_lines, &n_centroids, &n_boundaries,
+ &n_faces);
+ }
+
+ if (Vect_maptype(Map) == GV_FORMAT_OGR) {
+ /* centroids are stored in topology for OGR layers */
+ if (Vect_level(Map) >= 2) {
+ if (Vect_get_num_primitives(Map, GV_CENTROID) > 0) {
+ int nlines;
+ struct bound_box box;
+ struct boxlist *list;
- if (colors || cvarr_rgb ||
- nrec_width > 0 || nrec_size > 0 || nrec_rot > 0)
- /* only first category */
- Vect_cat_get(Cats,
- (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1)),
- &cat);
-
- /* custom colors */
- if (colors || cvarr_rgb) {
- custom_rgb = get_table_color(cat, line, colors, cvarr_rgb,
- &red, &grn, &blu, &nerror_rgb);
- }
-
- /* random colors */
- if (cats_color_flag) {
- custom_rgb = get_cat_color(line, Cats, Clist,
- &red, &grn, &blu);
- }
+ list = Vect_new_boxlist(FALSE); /* bboxes not needed */
+ Vect_get_map_box(Map, &box);
+ nlines = Vect_select_lines_by_box(Map, &box, GV_CENTROID, list);
+ G_debug(0, "%d", nlines);
+
+ for (line = 0; line < nlines; line++) {
+ ltype = Vect_read_line(Map, Points, Cats, list->id[line]);
- /* line width */
- if (nrec_width) {
- width = (int) get_property(cat, line, cvarr_width,
- (double) width_scale,
- (double) default_width);
-
- D_line_width(width);
- }
-
- /* enough of the prep work, lets start plotting stuff */
- x = Points->x;
- y = Points->y;
-
- if ((ltype & GV_POINTS) && (Symb != NULL || (nrec_size || nrec_rot)) ) {
- if (!(color || fcolor || custom_rgb))
- continue;
-
- x0 = x[0];
- y0 = y[0];
-
- /* skip if the point is outside of the display window */
- /* xy < 0 tests make it go ever-so-slightly faster */
- if (x0 > D_get_u_east() || x0 < D_get_u_west() ||
- y0 < D_get_u_south() || y0 > D_get_u_north())
- continue;
-
- /* dynamic symbol size */
- if (nrec_size)
- var_size = get_property(cat, line, cvarr_size, size, size);
-
- if (sqrt_flag)
- var_size = sqrt(var_size);
-
- /* dynamic symbol rotation */
- if (nrec_rot)
- rotation = get_property(cat, line, cvarr_rot, 1.0, 0.0);
-
- if(nrec_size || nrec_rot) {
- G_debug(3, "\tdynamic symbol: cat=%d size=%.2f rotation=%.2f",
- cat, var_size, rotation);
-
- /* symbol stroking is cumulative, so we need to reread it each time */
- if(Symb) /* unclean free() on first iteration if variables are not init'd to NULL? */
- G_free(Symb);
- Symb = S_read(symbol_name);
- if (Symb == NULL)
- G_warning(_("Unable to read symbol <%s>, unable to display points"),
- symbol_name);
- else
- S_stroke(Symb, var_size, rotation, 0);
+ draw_line(type, ltype, line,
+ Points, Cats,
+ color, fcolor, chcat,
+ symbol_name, size, sqrt_flag,
+ id_flag, cats_color_flag,
+ default_width, width_scale,
+ zcolors,
+ cvarr_rgb, colors,
+ cvarr_width, nrec_width,
+ cvarr_size, nrec_size,
+ cvarr_rot, nrec_rot,
+ Clist, Symb,
+ line_color, fill_color,
+ primary_color,
+ &n_points, &n_lines, &n_centroids, &n_boundaries,
+ &n_faces);
+ }
+ Vect_destroy_boxlist(list);
}
-
- /* use random or RGB column color if given, otherwise reset */
- /* centroids always use default color to stand out from underlying area */
- if (custom_rgb && (ltype != GV_CENTROID)) {
- primary_color->r = (unsigned char)red;
- primary_color->g = (unsigned char)grn;
- primary_color->b = (unsigned char)blu;
- D_symbol2(Symb, x0, y0, primary_color, line_color);
- }
- else
- D_symbol(Symb, x0, y0, line_color, fill_color);
-
- /* reset to defaults */
- var_size = size;
- rotation = 0.0;
}
- else if (color || custom_rgb || zcolors) {
- if (!cvarr_rgb && !cats_color_flag && !zcolors && !colors)
- D_RGB_color(color->r, color->g, color->b);
- else {
- if (custom_rgb)
- D_RGB_color((unsigned char)red, (unsigned char)grn,
- (unsigned char)blu);
- else
- D_RGB_color(color->r, color->g, color->b);
- }
-
- /* Plot the lines */
- if (Points->n_points == 1) /* line with one coor */
- D_polydots_abs(x, y, Points->n_points);
- else /* use different user defined render methods */
- D_polyline_abs(x, y, Points->n_points);
+ else {
+ G_warning(_("Topology level required for drawing centroids "
+ "for OGR layers"));
}
+ }
- switch (ltype) {
- case GV_POINT:
- n_points++;
- break;
- case GV_LINE:
- n_lines++;
- break;
- case GV_CENTROID:
- n_centroids++;
- break;
- case GV_BOUNDARY:
- n_boundaries++;
- break;
- case GV_FACE:
- n_faces++;
- break;
- default:
- break;
- }
- }
- /*
- if (nerror_rgb > 0) {
- G_warning(_("Error in color definition column '%s': %d features affected"),
- rgb_column, nerror_rgb);
- }
- */
-
if (n_points > 0)
G_verbose_message(_("%d points plotted"), n_points);
if (n_lines > 0)
@@ -345,3 +219,206 @@
return 0;
}
+
+int draw_line(int type, int ltype, int line,
+ const struct line_pnts *Points, const struct line_cats *Cats,
+ const struct color_rgb *color, const struct color_rgb *fcolor, int chcat,
+ const char *symbol_name, int size, int sqrt_flag,
+ int id_flag, int cats_color_flag,
+ int default_width, double width_scale,
+ struct Colors *zcolors,
+ dbCatValArray *cvarr_rgb, struct Colors *colors,
+ dbCatValArray *cvarr_width, int nrec_width,
+ dbCatValArray *cvarr_size, int nrec_size,
+ dbCatValArray *cvarr_rot, int nrec_rot,
+ const struct cat_list *Clist, SYMBOL *Symb,
+ RGBA_Color *line_color, RGBA_Color *fill_color,
+ RGBA_Color *primary_color,
+ int *n_points, int *n_lines, int *n_centroids, int *n_boundaries,
+ int *n_faces)
+{
+ double var_size, rotation;
+ int i, width;
+ int red, grn, blu;
+ int custom_rgb;
+ double x0, y0;
+ double *x, *y;
+ int found, cat;
+
+ rotation = 0.0;
+ var_size = size;
+ custom_rgb = FALSE;
+ cat = -1;
+
+ if (!(type & ltype))
+ return 0;
+
+ if (Points->n_points == 0)
+ return 0;
+
+ found = FALSE;
+ if (chcat) {
+ if (id_flag) { /* use line id */
+ if (!(Vect_cat_in_cat_list(line, Clist)))
+ return 0;
+ }
+ else {
+ for (i = 0; i < Cats->n_cats; i++) {
+ if (Cats->field[i] == Clist->field &&
+ Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+ }
+ }
+ else if (Clist->field > 0) {
+ for (i = 0; i < Cats->n_cats; i++) {
+ if (Cats->field[i] == Clist->field) {
+ found = TRUE;
+ break;
+ }
+ }
+ /* lines with no category will be displayed */
+ if (Cats->n_cats > 0 && !found)
+ return 0;
+ }
+
+ G_debug(3, "\tdisplay feature %d, cat %d", line, cat);
+
+ /* z height colors */
+ if (zcolors) {
+ if (Rast_get_d_color(&Points->z[0], &red, &grn, &blu, zcolors) == 1)
+ custom_rgb = TRUE;
+ else
+ custom_rgb = FALSE;
+ }
+
+ if (colors || cvarr_rgb ||
+ nrec_width > 0 || nrec_size > 0 || nrec_rot > 0)
+ /* only first category */
+ Vect_cat_get(Cats,
+ (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1)),
+ &cat);
+
+ /* custom colors */
+ if (colors || cvarr_rgb) {
+ custom_rgb = get_table_color(cat, line, colors, cvarr_rgb,
+ &red, &grn, &blu);
+ }
+
+ /* random colors */
+ if (cats_color_flag) {
+ custom_rgb = get_cat_color(line, Cats, Clist,
+ &red, &grn, &blu);
+ }
+
+ /* line width */
+ if (nrec_width) {
+ width = (int) get_property(cat, line, cvarr_width,
+ (double) width_scale,
+ (double) default_width);
+
+ D_line_width(width);
+ }
+
+ /* enough of the prep work, lets start plotting stuff */
+ x = Points->x;
+ y = Points->y;
+
+ if ((ltype & GV_POINTS) && (Symb != NULL || (nrec_size || nrec_rot)) ) {
+ if (!(color || fcolor || custom_rgb))
+ return 0;
+
+ x0 = x[0];
+ y0 = y[0];
+
+ /* skip if the point is outside of the display window */
+ /* xy < 0 tests make it go ever-so-slightly faster */
+ if (x0 > D_get_u_east() || x0 < D_get_u_west() ||
+ y0 < D_get_u_south() || y0 > D_get_u_north())
+ return 0;
+
+ /* dynamic symbol size */
+ if (nrec_size)
+ var_size = get_property(cat, line, cvarr_size, size, size);
+
+ if (sqrt_flag)
+ var_size = sqrt(var_size);
+
+ /* dynamic symbol rotation */
+ if (nrec_rot)
+ rotation = get_property(cat, line, cvarr_rot, 1.0, 0.0);
+
+ if(nrec_size || nrec_rot) {
+ G_debug(3, "\tdynamic symbol: cat=%d size=%.2f rotation=%.2f",
+ cat, var_size, rotation);
+
+ /* symbol stroking is cumulative, so we need to reread it each time */
+ if(Symb) /* unclean free() on first iteration if variables are not init'd to NULL? */
+ G_free(Symb);
+ Symb = S_read(symbol_name);
+ if (Symb == NULL)
+ G_warning(_("Unable to read symbol <%s>, unable to display points"),
+ symbol_name);
+ else
+ S_stroke(Symb, var_size, rotation, 0);
+ }
+
+ /* use random or RGB column color if given, otherwise reset */
+ /* centroids always use default color to stand out from underlying area */
+ if (custom_rgb && (ltype != GV_CENTROID)) {
+ primary_color->r = (unsigned char)red;
+ primary_color->g = (unsigned char)grn;
+ primary_color->b = (unsigned char)blu;
+ D_symbol2(Symb, x0, y0, primary_color, line_color);
+ }
+ else
+ D_symbol(Symb, x0, y0, line_color, fill_color);
+
+ /* reset to defaults */
+ var_size = size;
+ rotation = 0.0;
+ }
+ else if (color || custom_rgb || zcolors) {
+ if (!cvarr_rgb && !cats_color_flag && !zcolors && !colors)
+ D_RGB_color(color->r, color->g, color->b);
+ else {
+ if (custom_rgb)
+ D_RGB_color((unsigned char)red, (unsigned char)grn,
+ (unsigned char)blu);
+ else
+ D_RGB_color(color->r, color->g, color->b);
+ }
+
+ /* Plot the lines */
+ if (Points->n_points == 1) /* line with one coor */
+ D_polydots_abs(x, y, Points->n_points);
+ else /* use different user defined render methods */
+ D_polyline_abs(x, y, Points->n_points);
+ }
+
+ switch (ltype) {
+ case GV_POINT:
+ (*n_points)++;
+ break;
+ case GV_LINE:
+ (*n_lines)++;
+ break;
+ case GV_CENTROID:
+ (*n_centroids)++;
+ break;
+ case GV_BOUNDARY:
+ (*n_boundaries)++;
+ break;
+ case GV_FACE:
+ (*n_faces)++;
+ break;
+ default:
+ break;
+ }
+
+ return 1;
+}
Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h 2011-08-24 21:11:28 UTC (rev 47874)
+++ grass/trunk/display/d.vect/local_proto.h 2011-08-25 10:32:41 UTC (rev 47875)
@@ -42,7 +42,7 @@
int, char *, double,
int, char *);
int get_table_color(int, int, struct Colors *, dbCatValArray *,
- int *, int *, int *, int *);
+ int *, int *, int *);
int get_cat_color(int, const struct line_cats *, const struct cat_list *,
int *, int *, int *);
double get_property(int, int, dbCatValArray *, double, double);
Modified: grass/trunk/display/d.vect/shape.c
===================================================================
--- grass/trunk/display/d.vect/shape.c 2011-08-24 21:11:28 UTC (rev 47874)
+++ grass/trunk/display/d.vect/shape.c 2011-08-25 10:32:41 UTC (rev 47875)
@@ -189,7 +189,6 @@
table_colors_flag ? &cvarr_rgb : NULL,
have_colors ? &colors : NULL,
&cvarr_width, nrec_width);
-
stat += display_lines(Map, type, Clist,
bcolor, fcolor, chcat,
@@ -208,14 +207,13 @@
int get_table_color(int cat, int line,
struct Colors *colors, dbCatValArray *cvarr,
- int *red, int *grn, int *blu, int *nerror)
+ int *red, int *grn, int *blu)
{
- int custom_rgb, nerror_rgb;
+ int custom_rgb;
char colorstring[12]; /* RRR:GGG:BBB */
dbCatVal *cv;
- *nerror = nerror_rgb = 0;
custom_rgb = FALSE;
cv = NULL;
@@ -245,18 +243,14 @@
else {
G_important_message(_("Error in color definition (%s) - feature %d with category %d"),
colorstring, line, cat);
- nerror_rgb++;
}
}
else {
G_important_message(_("Error in color definition (%s) - feature %d with category %d"),
colorstring, line, cat);
- nerror_rgb++;
}
}
- *nerror = nerror_rgb;
-
return custom_rgb;
}
More information about the grass-commit
mailing list