[GRASS-dev] discussion: replacing ps.map
Sören Gebbert
soerengebbert at gmx.de
Sat Apr 7 08:28:18 EDT 2007
Glynn Clements schrieb:
> Sören Gebbert wrote:
>
>>>> I have patched d.vect to use R_polyline_abs. Now lines of widths greater then 1 are
>>>> are smoothed by the PS driver.
>>>>
>>>> I have tested the code with the XDRIVER, pngdriver and psdriver. The code seems to work,
>>>> but i needed to add some memory allocation stuff, so the memory usage is a bit higher
>>>> and it should be a bit slower than the G_plot_line approach (with move and cont functions).
>>>>
>>>> Everyone is welcome to test it. If no problems appear, i will submit these changes to CVS.
>>> Unfortunately, there's a bit more to it than that.
>>>
>>> 1. G_plot_line handles longitude wrap-around (try plotting something
>>> which crosses the 180th meridian).
>>>
>>> 2. G_plot_line is using D_{move,cont}_abs(), which clip against the
>>> frame (try using a square region, so that there are blank bands on the
>>> left and right sides of the monitor).
>>>
>>> I already had to deal with something similar for filled polygons; see
>>> plot_polygon() at the top of plot1.c, and the render= option.
>>>
>>> FWIW, I've already added a D_polyline_clip() function, which should
>>> handle both of the above issues (although it hasn't been extensively
>>> tested).
>>>
>>> I would suggest adding a plot_polyline() function which uses either
>>> the render= setting or a separate option (e.g. lrender=). That allows
>>> people to compare the new implementation against the old one without
>>> having to keep an old version of d.vect around.
>>>
>> Done. The patch is attached.
>
> I intend to apply this, subject to a few changes:
>
> plot_poly{gon,line} aren't declared "inline", as the "inline" keyword
> isn't ANSI C89 (C99 and GCC extension), and there isn't much benefit
> to inlining in this case.
>
> The option descriptions use the ->descriptions field; embedding
> formatting information in the ->description field is unsupported (e.g.
> it may not work with --tcltk, --html-description etc).
>
> The G_plot_line() loop uses array indexing rather than pointer
> arithmetic, as the former tends to be easier to read.
>
I have modified the sources to fulfil hopefully your suggestions.
Feel free to modify the patch in any way you think.
New patch is attached.
Best regards
Soeren
-------------- next part --------------
Index: area.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/display/d.vect/area.c,v
retrieving revision 1.29
diff -u -r1.29 area.c
--- area.c 15 Feb 2007 02:54:53 -0000 1.29
+++ area.c 7 Apr 2007 12:23:46 -0000
@@ -325,7 +325,7 @@
/* boundary */
if ( bcolor ) {
- int i, j;
+ int i;
Vect_get_area_points ( Map, area, Points );
if (rgb) {
R_RGB_color ((unsigned char) red, (unsigned char) grn, (unsigned char) blu);
@@ -333,15 +333,13 @@
else {
R_RGB_color(bcolor->r, bcolor->g, bcolor->b);
}
- for ( i = 0; i < Points->n_points - 1; i++) {
- G_plot_line (Points->x[i], Points->y[i], Points->x[i+1], Points->y[i+1]);
- }
+ /*use different user defined render methods*/
+ plot_polyline ( Points->x, Points->y, Points->n_points);
for ( i = 0; i < n_isles; i++) {
isle = Vect_get_area_isle ( Map, area, i );
Vect_get_isle_points ( Map, isle, Points );
- for ( j = 0; j < Points->n_points - 1; j++) {
- G_plot_line (Points->x[j], Points->y[j], Points->x[j+1], Points->y[j+1]);
- }
+ /*use different user defined render methods*/
+ plot_polyline ( Points->x, Points->y, Points->n_points);
}
}
} /* end for */
Index: local_proto.h
===================================================================
RCS file: /home/grass/grassrepository/grass6/display/d.vect/local_proto.h,v
retrieving revision 1.19
diff -u -r1.19 local_proto.h
--- local_proto.h 15 Feb 2007 02:54:53 -0000 1.19
+++ local_proto.h 7 Apr 2007 12:23:46 -0000
@@ -12,4 +12,5 @@
int zcoor(struct Map_info *, int, LATTR *);
int test_bg_color (const char*);
void plot_polygon(double *, double *, int);
+void plot_polyline(double *, double *, int);
Index: main.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/display/d.vect/main.c,v
retrieving revision 1.86
diff -u -r1.86 main.c
--- main.c 20 Feb 2007 13:15:42 -0000 1.86
+++ main.c 7 Apr 2007 12:23:47 -0000
@@ -85,7 +85,7 @@
int i, stat = 0, type, area, display;
int chcat = 0;
int r, g, b;
- int has_color, has_fcolor;
+ int has_color = 0, has_fcolor = 0;
struct color_rgb color, fcolor;
int size;
int default_width;
@@ -305,7 +305,7 @@
render_opt->multiple = NO;
render_opt->answer = "g" ;
render_opt->options = "g,r,d,c";
- render_opt->description= _("Rendering method for filled polygons");
+ render_opt->description= _("Rendering method for filled polygons and polylines");
/* please remove before GRASS 7 released */
verbose_flag = G_define_flag ();
Index: plot1.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/display/d.vect/plot1.c,v
retrieving revision 1.26
diff -u -r1.26 plot1.c
--- plot1.c 26 Feb 2007 10:50:37 -0000 1.26
+++ plot1.c 7 Apr 2007 12:23:48 -0000
@@ -11,9 +11,19 @@
#include <grass/glocale.h>
#include <grass/dbmi.h>
+#define RENDER_POLYLINE 0
+#define RENDER_POLYGON 1
+
+/*local functions*/
+static void local_plot_poly(double *xf, double *yf, int n, int type);
+
+/*global render switch*/
int render;
-static void local_plot_polygon(double *xf, double *yf, int n)
+/* *************************************************************** */
+/* function to plot polygons and polylines ***************** */
+/* the parameter type switches render mode ***************** */
+static void local_plot_poly(double *xf, double *yf, int n, int type)
{
static int *xi, *yi;
static int nalloc;
@@ -32,9 +42,46 @@
yi[i] = (int) floor(0.5 + D_u_to_d_row(yf[i]));
}
- R_polygon_abs(xi, yi, n);
+ if(type == RENDER_POLYGON)
+ R_polygon_abs(xi, yi, n);
+ else
+ R_polyline_abs(xi, yi, n);
+return;
}
+/* *************************************************************** */
+/* function to use different render methods for polylines ******** */
+/* *************************************************************** */
+void plot_polyline(double *xf, double *yf, int n)
+{
+ int i;
+
+ switch (render)
+ {
+ case RENDER_GPP:
+ for(i=1; i < n; i++)
+ G_plot_line(xf[i - 1], yf[i - 1], xf[i], yf[i]);
+ break;
+ case RENDER_DP:
+ D_polyline(xf, yf, n);
+ break;
+ case RENDER_DPC:
+ D_polyline_clip(xf, yf, n);
+ break;
+ case RENDER_RPA:
+ local_plot_poly(xf, yf, n, RENDER_POLYLINE);
+ break;
+ default:
+ for(i=1; i < n; i++)
+ G_plot_line(xf[i - 1], yf[i - 1], xf[i], yf[i]);
+ break;
+ }
+return;
+}
+
+/* *************************************************************** */
+/* function to use different render methods for polygons ******** */
+/* *************************************************************** */
void plot_polygon(double *xf, double *yf, int n)
{
switch (render)
@@ -49,14 +96,18 @@
D_polygon_clip(xf, yf, n);
break;
case RENDER_RPA:
- local_plot_polygon(xf, yf, n);
+ local_plot_poly(xf, yf, n, RENDER_POLYGON);
break;
default:
G_plot_polygon(xf, yf, n);
break;
}
+return;
}
+/* *************************************************************** */
+/* *************************************************************** */
+/* *************************************************************** */
int plot1 (
struct Map_info *Map, int type, int area, struct cat_list *Clist,
const struct color_rgb *color, const struct color_rgb *fcolor,
@@ -191,6 +242,7 @@
}
}
+
if ( !(type & ltype) ) continue;
if ( chcat ) {
@@ -452,14 +504,12 @@
R_RGB_color(color->r, color->g, color->b);
}
}
+ /* Plot the lines */
if ( Points->n_points == 1 ) { /* line with one coor */
- G_plot_line(x[0], y[0], x[0], y[0]);
+ D_polydots_clip(x, y, Points->n_points);
} else {
- for(i=1; i < Points->n_points; i++) {
- G_plot_line(x[0], y[0], x[1], y[1]);
- x++;
- y++;
- }
+ /*use different user defined render methods*/
+ plot_polyline(x, y, Points->n_points);
}
}
}
More information about the grass-dev
mailing list