[GRASS-dev] discussion: replacing ps.map

Sören Gebbert soerengebbert at gmx.de
Fri Apr 6 19:34:18 EDT 2007


Hi,

Glynn Clements schrieb:
  >> 2.) The d.vect module works fine, the lines are really smooth if the line width is set to 1.
>>      If i choose a larger line width, polylines are broken into pieces
>>      spearfish60 example:
>>      d.mon PS
>>      d.vect roads color=black width=4
>>      d.vect roads color=white width=1
>>      gv map.ps
>>
>>      Is there a way to avoid this? Well, i guess this is not an easy task.
> 
> Modify d.vect to generate polylines (R_polyline_abs()) rather than
> individual line segments (R_{move,cont}_abs()). Unlike the PNG driver,
> the PS driver implements polylines as a single stroked path. If you
> send it a polyline, you'll get joins (rather than caps) between the
> segments.
> 
> This is a good example of what I mean when I say that the main problem
> with implementing a PostScript driver is the way that modules use the
> graphics API.
> 
> Note that being able to change the line width is a relatively recent
> feature (2005/08/09). Back when lines were always single-pixel, there
> wasn't any difference between a polyline and lots of individual
> segments.
> 
> Also note that the PS driver cannot realistically convert move/cont
> operations into polylines, as a polyline has to be "stroke"d in a
> single operation.

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.

Best regards
Soeren

The patch:

cvs server: Diffing .
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     6 Apr 2007 23:29:24 -0000
@@ -191,6 +191,7 @@
             }
         }

+
         if ( !(type & ltype) ) continue;

         if ( chcat ) {
@@ -452,14 +453,22 @@
               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]);
             } else {
-               for(i=1; i < Points->n_points; i++) {
-                   G_plot_line(x[0], y[0], x[1], y[1]);
-                   x++;
-                   y++;
+               G_debug(3, "d.vect::plot1: plot polyline");
+               /*Allocate memory for the window position arrays*/
+               int *x_int = G_calloc(Points->n_points, sizeof(int));
+               int *y_int = G_calloc(Points->n_points, sizeof(int));
+               /*convert map coordinates into window x,y positions*/
+               for(i=0; i < Points->n_points; i++) {
+                   G_plot_where_xy(x[i], y[i], &x_int[i], &y_int[i]);
                   }
+               /*Draw the polyline*/
+               R_polyline_abs(x_int, y_int, Points->n_points);
+               G_free(x_int);
+               G_free(y_int);
             }
         }
      }




More information about the grass-dev mailing list