From nobody Wed Oct  7 15:36:26 1998
x-uunet-gateway: relay2.UU.NET from info-gnuplot to comp.graphics.apps.gnuplot; Wed, 7 Oct 1998 08:38:48 EDT
Message-ID: <199810071236.VAA02430@ds-mail.ds.mei.titech.ac.jp>
Subject: A small modification to draw polygons with gnuplot
Reply-To: koga@mei.titech.ac.jp
X-Mailer: MH 6.8.JP2c
Mime-Version: 1.0 (generated by tm-edit 7.106)
Content-Type: text/plain; charset=US-ASCII
Date: Wed, 07 Oct 1998 21:36:58 +0900
From: koga@ds.mei.titech.ac.jp (Masanobu KOGA/=?ISO-2022-JP?B?GyRCOEUybBsoQg==?=  
	=?ISO-2022-JP?B?GyRCMm0/LRsoQg==?=)
Newsgroups: comp.graphics.apps.gnuplot
Path: eolas.ucc.ie!HEAnet!server5.netnews.ja.net!server6.netnews.ja.net!nntp.news.xara.net!xara.net!news.maxwell.syr.edu!Supernews60!supernews.com!uunet!wendy-fate.uu.net!info-gnuplot
Sender: info-gnuplot-request@dartmouth.edu
Xref: eolas.ucc.ie comp.graphics.apps.gnuplot:14021
Status: RO
X-Status: A
Content-Length: 14954
Lines: 542


Hello, I am a user of gnuplot which I've been using for several years.
I wanted a data style to draw polygons with gnuplot, but there was not
such facility in the latest gnuplot.  I defined a new data style, i.e.,
'polygons' to draw polygons with 'plot' command.  Since this facility
seems to be usefull for other people, I would like to send the paches
from gnuplot-beta347 package.  If you are interested in my modification,
please incorporate the paches to the original files.

In order to incorporate the polygon data style, just define a variable
'HAVE_POLYGONS' by -DHAVE_POLYGONS for compiling.  All modifications
in the files are surrounded by '#ifdef HAVE_POLYGONS' and '#endif'.

Example (1)

  set xrange [0:4*pi]
  plot sin(x) w polyongs
  set term postscript
  set output 'afo.ps'
  replot

Example (2)

  set xrange [0:4*pi]
  set data style polygons
  plot sin(x)
  set term fig
  set output 'afo.fig'
  replot

We can abbreviate 'polygons' as 'po'.

Example (3)

  set xrange [0:4*pi]
  set data style po
  plot sin(x)

--
Masanobu Koga
Phone/Fax: 03-5734-2328
E-mail: koga@mei.titech.ac.jp
http://www.ds.mei.titech.ac.jp/~koga/

-----------------------------------------------------------------------------
diff -c -r gnuplot-beta347/Makefile.in gnuplot-polygons/Makefile.in
*** gnuplot-beta347/Makefile.in	Thu Jun 18 23:55:00 1998
--- gnuplot-polygons/Makefile.in	Wed Oct  7 20:23:03 1998
***************
*** 117,122 ****
--- 117,123 ----
  #    in case the gnuplot routines in time.c misbehave
  #  -Dunix is required to explicitly define "unix" for SCO and IBM
  #          RS/6000 running AIX 3.2
+ #  -DHAVE_POLYGONS if you want to use 'polygons' for data style
  
  #
  # You probably don't need to change anything below here.
Only in gnuplot-polygons: config.cache
Only in gnuplot-polygons: config.h
Only in gnuplot-polygons: config.log
Only in gnuplot-polygons: config.status
Only in gnuplot-polygons/docs: Makefile
Only in gnuplot-polygons/docs/latextut: Makefile
Only in gnuplot-beta347/docs/latextut: makefile
Only in gnuplot-polygons/docs/latextut: makefile.dst
Only in gnuplot-beta347/docs: makefile
Only in gnuplot-polygons/docs: makefile.dst
diff -c -r gnuplot-beta347/gplt_x11.c gnuplot-polygons/gplt_x11.c
*** gnuplot-beta347/gplt_x11.c	Tue Apr 14 09:15:22 1998
--- gnuplot-polygons/gplt_x11.c	Wed Oct  7 20:10:19 1998
***************
*** 753,758 ****
--- 753,762 ----
     int n, x, y, sw, sl, lt=0, width, type, point, px, py;
     int user_width = 1; /* as specified by plot...linewidth */
     char *buf, *str;
+ #ifdef HAVE_POLYGONS
+ 	int polygon_flag = 0, polygon_n;
+ 	XPoint *polygon_p = 0;
+ #endif
  
     FPRINTF((stderr,"Display %d ; %d commands\n", plot - plot_array, plot->ncommands));
     
***************
*** 806,812 ****
        /*   X11_vector(x,y) - draw vector  */
        if (*buf == 'V') { 
  	 sscanf(buf, "V%4d%4d", &x, &y);  
! 	 XDrawLine(dpy, plot->pixmap, gc, X(cx), Y(cy), X(x), Y(y));
  	 cx = x; cy = y;
  	 }
  
--- 810,841 ----
        /*   X11_vector(x,y) - draw vector  */
        if (*buf == 'V') { 
  	 sscanf(buf, "V%4d%4d", &x, &y);  
! #ifdef HAVE_POLYGONS
! 			if (polygon_flag == 0) {
! 				if (x == 9999 && y == 9999) {
! 					polygon_flag = 1;
! 
! 					if (polygon_p) free((void *)polygon_p);
! 					polygon_p = (XPoint *)
! 						malloc(sizeof(XPoint)*plot->ncommands);
! 					polygon_n = 0;
! 				} else {
! 					XDrawLine(dpy, plot->pixmap, gc, X(cx), Y(cy), X(x), Y(y));
! 				}
! 			} else {
! 				if (x == 9999 && y == 9999) {
! 					polygon_flag = 0;
! 					XFillPolygon(dpy, plot->pixmap, gc, polygon_p,
! 								 polygon_n, Complex, CoordModeOrigin);
! 				} else {
! 					(polygon_p + polygon_n)->x = X(x);
! 					(polygon_p + polygon_n)->y = Y(y);
! 					polygon_n++;
! 				}
! 			}
! #else
! 			XDrawLine(dpy, plot->pixmap, gc, X(cx), Y(cy), X(x), Y(y));
! #endif
  	 cx = x; cy = y;
  	 }
  
diff -c -r gnuplot-beta347/graph3d.c gnuplot-polygons/graph3d.c
*** gnuplot-beta347/graph3d.c	Thu Jun 18 23:55:07 1998
--- gnuplot-polygons/graph3d.c	Wed Oct  7 20:12:57 1998
***************
*** 802,807 ****
--- 802,810 ----
  		  case STEPS: /* HBB: I think these should be here */
  		  case FSTEPS:
  		  case HISTEPS:
+ #ifdef HAVE_POLYGONS
+ 		  case POLYGONS:
+ #endif
  		  case LINES: {
  		    if (lkey) {
  		      key_sample_line(xl,yl);
***************
*** 892,897 ****
--- 895,903 ----
  				switch(this_plot->plot_style) {
  				case IMPULSES:
  				case LINES:
+ #ifdef HAVE_POLYGONS
+ 			    case POLYGONS:
+ #endif
  				case BOXES: /* HBB: I think these should be here... */
  				case STEPS:
  				case FSTEPS:
***************
*** 932,937 ****
--- 938,946 ----
  				switch(this_plot->plot_style) {
  					case IMPULSES:
  					case LINES:
+ #ifdef HAVE_POLYGONS
+ 				    case POLYGONS:
+ #endif
  					case LINESPOINTS:
  					case BOXES: /* HBB: these should be treated as well... */
  					case STEPS:
***************
*** 969,974 ****
--- 978,986 ----
  				  cntr3d_impulses(cntrs, this_plot);
  				  break;
  				case LINES:
+ #ifdef HAVE_POLYGONS
+ 				case POLYGONS:
+ #endif
  				case STEPS:    /* HBB: these should also be handled, I think */
  				case FSTEPS:
  				case HISTEPS:
***************
*** 1120,1125 ****
--- 1132,1144 ----
       enum coord_type prev = UNDEFINED;
       double lx[2], ly[2], lz[2];		/* two edge points */
  
+ #ifdef HAVE_POLYGONS
+     struct termentry *t = term;
+ 	
+ 	if (plot->plot_style == POLYGONS)
+ 		(*t->vector)(9999,9999);
+ #endif
+ 
  #ifndef LITE
  /* These are handled elsewhere.  */
      if (plot->has_grid_topology && hidden3d)
***************
*** 1144,1149 ****
--- 1163,1173 ----
  			  {
  			    /* from outrange to inrange */
  			    if (!clip_lines1) {
+ #ifdef HAVE_POLYGONS
+ 						  if (plot->plot_style == POLYGONS) {
+ 							  clip_vector(x, y);	
+ 						  } else
+ #endif
  			      clip_move(x, y);
  			    }
  			    else {
***************
*** 1154,1165 ****
--- 1178,1200 ----
  			      
  			      map3d_xy(clip_x, clip_y, clip_z, &x0, &y0);
  			      
+ #ifdef HAVE_POLYGONS
+ 						  if (plot->plot_style == POLYGONS) {
+ 							  clip_vector(x0,y0);
+ 						  } else
+ #endif
  			      clip_move(x0,y0);
  			      clip_vector(x,y);
  			    }
  			  }
  			else
  			  {
+ #ifdef HAVE_POLYGONS
+ 					  if (plot->plot_style == POLYGONS) {
+ 						  if (i == 0) clip_vector(x,y);
+ 						  clip_vector(x,y);
+ 					  } else
+ #endif
  			    clip_move(x,y);
  			  }
  		      }
***************
*** 1195,1200 ****
--- 1230,1240 ----
  
  			    map3d_xy(lx[1], ly[1], lz[1], &x0, &y0);
  
+ #ifdef HAVE_POLYGONS
+ 							  if (plot->plot_style == POLYGONS) {
+ 								  clip_vector(x, y);
+ 							  } else
+ #endif
  			    clip_move(x, y);
  			    clip_vector(x0, y0);
  			  }
***************
*** 1214,1219 ****
--- 1254,1263 ----
  
  	icrvs = icrvs->next;
      }
+ #ifdef HAVE_POLYGONS
+ 	if (plot->plot_style == POLYGONS)
+ 		(*t->vector)(9999,9999);
+ #endif
  }
  
  /* plot3d_points:
diff -c -r gnuplot-beta347/graphics.c gnuplot-polygons/graphics.c
*** gnuplot-beta347/graphics.c	Thu Jun 18 23:55:08 1998
--- gnuplot-polygons/graphics.c	Wed Oct  7 20:14:28 1998
***************
*** 1439,1445 ****
--- 1439,1449 ----
  	strcpy(ss, ylabel.text);
  	/* we worked out x-posn in boundary() */
  	if ((*t->text_angle)(1)) {
+ #ifdef HAVE_POLYGONS
+ 		unsigned int x=ylabel_x+t->h_char;
+ #else
  		unsigned int x=ylabel_x;
+ #endif
  		unsigned int y=(ytop+ybot)/2 + ylabel.yoffset*(t->h_char);
  		write_multiline(x,y,ss,CENTRE, JUST_TOP, 1, ylabel.font);
  		(*t->text_angle)(0);
***************
*** 1752,1757 ****
--- 1756,1768 ----
  				plot_c_bars(this_plot);
  				break;
  			/*}}}*/
+ #ifdef HAVE_POLYGONS
+ 			/*{{{  POLYGONS*/
+ 			case POLYGONS:
+ 				plot_lines(this_plot);
+ 				break;
+ 			/*}}}*/
+ #endif
  		}
  
  		
***************
*** 1841,1846 ****
--- 1852,1862 ----
      double ex, ey;			/* an edge point */
      double lx[2], ly[2];		/* two edge points */
  
+ #ifdef HAVE_POLYGONS
+ 	if (plot->plot_style == POLYGONS)
+ 		(*t->vector)(9999,9999); /* Start of polygon */
+ #endif
+ 
      for (i = 0; i < plot->p_count; i++) {
  	   switch (plot->points[i].type) {
  		  case INRANGE: {
***************
*** 1890,1895 ****
--- 1906,1915 ----
  	   }
  	   prev = plot->points[i].type;
      }
+ #ifdef HAVE_POLYGONS
+ 	if (plot->plot_style == POLYGONS)
+ 		(*t->vector)(9999,9999); /* End of polygon */
+ #endif
  }
  
  /* XXX - JG  */
diff -c -r gnuplot-beta347/hidden3d.c gnuplot-polygons/hidden3d.c
*** gnuplot-beta347/hidden3d.c	Thu Jun 18 23:55:10 1998
--- gnuplot-polygons/hidden3d.c	Wed Oct  7 20:15:44 1998
***************
*** 971,976 ****
--- 971,979 ----
  		case FSTEPS:
  		case HISTEPS:
  		case LINES:
+ #ifdef HAVE_POLYGONS
+   	case POLYGONS:
+ #endif
  #if FOUR_TRIANGLES
  			nvert += ncrv * (2 * this_plot->iso_crvs->p_count - 1);
  #else
***************
*** 1024,1029 ****
--- 1027,1035 ----
  		case FSTEPS:
  		case HISTEPS:
  		case LINES:
+ #ifdef HAVE_POLYGONS
+ 		case POLYGONS:
+ #endif
  		case DOTS:
  		case BOXES:             /* handle as IMPULSES */
  		case IMPULSES:
***************
*** 1058,1067 ****
--- 1064,1080 ----
  				}
  #if FOUR_TRIANGLES
  				/* FIXME: handle other styles as well! */
+ #ifdef HAVE_POLYGONS
+ 				if ((this_plot->plot_style == LINES ||
+ 						 this_plot->plot_style == POLYGONS) && 
+ 						i < icrvs->p_count - 1) 
+ 					vert_free++;    /* keep one entry free for quad-center */
+ #else
  				if (this_plot->plot_style == LINES && 
  						i < icrvs->p_count - 1) 
  					vert_free++;    /* keep one entry free for quad-center */
  #endif
+ #endif
  			}
  		}
  	}
***************
*** 1085,1090 ****
--- 1098,1106 ----
  				case STEPS: /* handle as LINES */
  				case FSTEPS:
  				case HISTEPS:
+ #ifdef HAVE_POLYGONS
+ 				case POLYGONS:
+ #endif
  				case LINES:
  					if (i < icrvs->p_count - 1 && ncrv < ncrv1 - 1) {
  #if FOUR_TRIANGLES
diff -c -r gnuplot-beta347/misc.c gnuplot-polygons/misc.c
*** gnuplot-beta347/misc.c	Tue Apr 14 09:16:02 1998
--- gnuplot-polygons/misc.c	Wed Oct  7 20:16:16 1998
***************
*** 734,739 ****
--- 734,742 ----
  		case VECTOR : fprintf(fp, "vector\n"); break;
  		case FINANCEBARS: fprintf(fp, "financebars\n"); break;
  		case CANDLESTICKS: fprintf(fp, "candlesticks\n"); break;
+ #ifdef HAVE_POLYGONS
+ 		case POLYGONS: fprintf(fp, "polygons\n"); break;
+ #endif
  	}
  	fprintf(fp,"set function style ");
  	switch (func_style) {
***************
*** 754,759 ****
--- 757,765 ----
  		case VECTOR: fprintf(fp,"vector\n"); break;
  		case FINANCEBARS: fprintf(fp, "financebars\n"); break;
  		case CANDLESTICKS: fprintf(fp, "candlesticks\n"); break;
+ #ifdef HAVE_POLYGONS
+ 		case POLYGONS: fprintf(fp, "polygons\n"); break;
+ #endif
  		default:  fprintf(fp, "---error!---\n"); /* HBB: default case demanded by gcc, still needed ?? */
  	}
          fprintf(fp,"set xzeroaxis lt %d lw %.3f\n", xzeroaxis.l_type+1,xzeroaxis.l_width);
diff -c -r gnuplot-beta347/plot.h gnuplot-polygons/plot.h
*** gnuplot-beta347/plot.h	Tue Apr 14 09:16:06 1998
--- gnuplot-polygons/plot.h	Wed Oct  7 20:27:02 1998
***************
*** 478,484 ****
--- 478,489 ----
  	HISTEPS    =13*8 + 1,
  	VECTOR     =14*8 + 1,
  	CANDLESTICKS=15*8 + 4,
+ #ifdef HAVE_POLYGONS
+ 	FINANCEBARS=16*8 + 1,
+     POLYGONS=17*8 + 1
+ #else
  	FINANCEBARS=16*8 + 1
+ #endif
  };
  
  enum PLOT_SMOOTH { 
diff -c -r gnuplot-beta347/set.c gnuplot-polygons/set.c
*** gnuplot-beta347/set.c	Mon Jun 22 21:24:54 1998
--- gnuplot-polygons/set.c	Wed Oct  7 20:17:17 1998
***************
*** 2726,2731 ****
--- 2726,2735 ----
  		ps = LINES;
  	else if (almost_equals(c_token,"i$mpulses"))
  		ps = IMPULSES;
+ #ifdef HAVE_POLYGONS
+ 	else if (almost_equals(c_token,"po$lygons"))
+ 		ps = POLYGONS;
+ #endif
  	else if (almost_equals(c_token,"p$oints"))
  		ps = POINTSTYLE;
  	else if (almost_equals(c_token,"linesp$oints") || equals(c_token, "lp"))
***************
*** 2759,2768 ****
--- 2763,2778 ----
  	else if (almost_equals(c_token, "can$dlesticks"))
  		ps = CANDLESTICKS;	
  	else {
+ #ifdef HAVE_POLYGONS
+ 		int_error("expecting 'lines', 'points', 'linespoints', 'dots', 'impulses',\n\
+         'yerrorbars', 'xerrorbars', 'xyerrorbars', 'steps', 'fsteps', 'histeps',\n\
+         'boxes', 'boxerrorbars', 'boxxyerrorbars', 'vector', 'financebars', 'candlesticks', 'polygons'",c_token);
+ #else
  		int_error("expecting 'lines', 'points', 'linespoints', 'dots', 'impulses',\n\
          'yerrorbars', 'xerrorbars', 'xyerrorbars', 'steps', 'fsteps', 'histeps',\n\
          'boxes', 'boxerrorbars', 'boxxyerrorbars', 'vector', 'financebars', 'candlesticks'",c_token);
        return LINES; /* keep gcc -Wuninitialised happy */
+ #endif
     }
  	c_token++;
  	return(ps);
diff -c -r gnuplot-beta347/show.c gnuplot-polygons/show.c
*** gnuplot-beta347/show.c	Thu Jun 18 23:55:18 1998
--- gnuplot-polygons/show.c	Wed Oct  7 20:18:04 1998
***************
*** 727,732 ****
--- 727,735 ----
  		case VECTOR: fprintf(stderr,"vector\n"); break;
  		case FINANCEBARS: fprintf(stderr, "financebars\n"); break;
  		case CANDLESTICKS: fprintf(stderr, "candlesticsks\n"); break;
+ #ifdef HAVE_POLYGONS
+ 		case POLYGONS: fprintf(stderr,"polygons\n"); break;
+ #endif
  	}
  }
  
Only in gnuplot-polygons: stamp-h
diff -c -r gnuplot-beta347/term/fig.trm gnuplot-polygons/term/fig.trm
*** gnuplot-beta347/term/fig.trm	Thu Jun 18 23:59:20 1998
--- gnuplot-polygons/term/fig.trm	Wed Oct  7 20:19:41 1998
***************
*** 556,561 ****
--- 556,585 ----
       unsigned int ux,uy;
  {
    int x=ux, y=uy;
+ #ifdef HAVE_POLYGONS
+ 	static int polygon_flag = 0;
+ #endif
+ 
+ #ifdef HAVE_POLYGONS
+ 	if (ux == 9999 && uy == 9999) {
+ 		if (polygon_flag == 0) {
+ 			polygon_flag = 1;
+ 		} else {
+ 			polygon_flag = 0;
+ 
+ 			FIG_line.type = T_POLYGON;
+ 			FIG_line.depth = 100;
+ 			FIG_line.fill_style = 20;
+ 
+ 			FIG_poly_clean(FIG_polyvec_stat);
+ 
+ 			FIG_line.type = T_POLYLINE;
+ 			FIG_line.depth = FIG_linedepth;
+ 			FIG_line.fill_style = -1;
+ 		}
+ 		return;
+ 	}
+ #endif
   
    if (FIG_polyvec_stat != FIG_poly_part) {
  	FIG_line.pen_color = FIG_color;
diff -c -r gnuplot-beta347/term/post.trm gnuplot-polygons/term/post.trm
*** gnuplot-beta347/term/post.trm	Thu Jun 18 23:59:23 1998
--- gnuplot-polygons/term/post.trm	Wed Oct  7 20:20:28 1998
***************
*** 1092,1097 ****
--- 1092,1114 ----
  {
  	int dx, dy;
  	char abso[20],rel[20];
+ #ifdef HAVE_POLYGONS
+ 	static int polygon_flag = 0;
+ #endif
+ 
+ #ifdef HAVE_POLYGONS
+ 	if (x == 9999 && y == 9999) {
+ 		if (polygon_flag == 0) {
+ 			polygon_flag = 1;
+ 			fputs("newpath\n", outfile);
+ 		} else {
+ 			polygon_flag = 0;
+ 			fputs("closepath\n", outfile);
+ 			fputs("fill\n", outfile);
+ 		}
+ 		return;
+ 	}
+ #endif
  	dx = x - PS_pen_x;
  	dy = y - PS_pen_y;
  	if (dx==0 && dy==0) return;
-----------------------------------------------------------------------------

