[GRASS-dev] discussion: replacing ps.map

Sören Gebbert soerengebbert at gmx.de
Sat Apr 7 06:26:38 EDT 2007


Hi,

Glynn Clements schrieb:
> S-Bören Gebbert wrote:-A
> 
>> 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.

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 10:22:21 -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 10:22:21 -0000
@@ -11,5 +11,6 @@
 int attr(struct Map_info *, int, char *, struct cat_list *, LATTR *, int);
 int zcoor(struct Map_info *, int, LATTR *);
 int test_bg_color (const char*);
-void plot_polygon(double *, double *, int);
+inline void plot_polygon(double *, double *, int);
+inline 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 10:22:22 -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,15 @@
 	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"
+				   "\n               g - use the gislib render functions"
+				   "\n                   features: clipping support"
+				   "\n               r - use the raster graphics library functions"
+				   "\n                   features: smoothed polylines (PS driver)"
+				   "\n               d - use the display library render functions"
+				   "\n                   features: smoothed polyline (PS driver)"
+				   "\n               c - use the display library render functions" 
+				   "\n                   features: clipping support");
 
 	/* 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 10:22:22 -0000
@@ -11,9 +11,19 @@
 #include <grass/glocale.h>
 #include <grass/dbmi.h>
 
+#define RENDER_POLYLINE 0
+#define RENDER_POLYGON  1
+
+/*local functions*/
+static inline 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,52 @@
 		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[0], yf[0], xf[1], yf[1]);
+                 	xf++;
+                 	yf++;
+		}
+		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[0], yf[0], xf[1], yf[1]);
+                	xf++;
+                	yf++;
+		}
+		break;
+	}
+return;
+}
+
+/* *************************************************************** */
+/* function to use different render methods for polygons  ******** */
+/* *************************************************************** */
 void plot_polygon(double *xf, double *yf, int n)
 {
 	switch (render)
@@ -49,14 +102,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 +248,7 @@
 	    }
 	}
 
+
 	if ( !(type & ltype) ) continue;
 
 	if ( chcat ) {
@@ -452,14 +510,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