Annotation of OpenXM_contrib2/asir2000/plot/smoothing.c, Revision 1.5
1.5 ! takayama 1: /* $OpenXM: OpenXM_contrib2/asir2000/plot/smoothing.c,v 1.4 2000/11/08 05:49:35 takayama Exp $ */
1.1 takayama 2: #include "ca.h"
3: #include "parse.h"
4: #include "ox.h"
5: #include "ifplot.h"
6: #include "cursor.h"
7:
8: #define MAG 1
9: #define PRINT_XOFFSET 100
10: #define PRINT_YOFFSET 100
11:
12:
13: static FILE *Fp = NULL;
14:
15: static void polyLine_outputProlog(int xmin, int ymin, int xmax, int ymax);
16: static void polyLine_outputEpilog(void);
17: static void polyLine_error(char *s);
18: #define translateX(x) (x*MAG+PRINT_XOFFSET)
19: #define translateY(y) (y*MAG+PRINT_YOFFSET)
20: /* #define translateY(y) ((Ysize-y)*MAG+PRINT_YOFFSET) */
21: #define IS_DOT != 0
22: #define IS_POLYLINE > -1
23: #define YES 1
24: #define NO 0
25:
26: static int Xsize = 0;
27: static int Ysize = 0;
28:
1.2 takayama 29: static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1);
30: static int polyLine_pline(struct canvas *can);
1.4 takayama 31: static int Strategy_generate_PS = 0;
1.2 takayama 32:
1.1 takayama 33:
34: static void polyLine_outputProlog(int xmin, int ymin,int xmax, int ymax) {
35: fprintf(Fp,"%%!PS-Adobe-1.0\n");
36: fprintf(Fp,"%%%%BoundingBox: %d %d %d %d \n",
37: PRINT_XOFFSET+xmin*MAG,PRINT_YOFFSET+ymin*MAG,
38: PRINT_XOFFSET+xmax*MAG, PRINT_YOFFSET+ymax*MAG);
39: fprintf(Fp,"%%%%Creator: This is generated by ifplot\n");
40: fprintf(Fp,"%%%%Title: ifplot\n");
41: fprintf(Fp,"%%%%EndComments: \n");
1.3 takayama 42: fprintf(Fp,"0.1 setlinewidth \n");
43: fprintf(Fp,"2 setlinecap \n");
44: fprintf(Fp,"2 setlinejoin \n");
1.1 takayama 45: fprintf(Fp,"/ifplot_putpixel { \n");
46: fprintf(Fp," /yyy 2 1 roll def /xxx 2 1 roll def \n");
47: fprintf(Fp," gsave newpath xxx yyy .5 0 360 arc \n");
48: fprintf(Fp," fill grestore \n");
49: fprintf(Fp,"} def \n");
50: fflush(Fp);
51: }
52: static void polyLine_outputEpilog(void) {
53: fprintf(Fp,"showpage \n"); fflush(Fp);
54: }
55: static void polyLine_error(char *s) {
56: fprintf(stderr,"Error in smoothing: %s\n",s);
57: exit(-1);
58: }
59:
1.2 takayama 60: static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1) {
61: extern FILE *Fp;
62: fprintf(Fp," gsave [3] 0 setdash newpath \n");
63: fprintf(Fp," %d %d moveto %d %d lineto stroke \n",x0,y0,x1,y1);
64: fprintf(Fp," stroke grestore \n");
65: }
66:
67: #define D 5
68: static int polyLine_pline(can)
69: struct canvas *can;
70: {
71: double w,w1,k,e,n;
72: int x0,y0,x,y,xadj,yadj;
73: char buf[BUFSIZ];
74: double adjust_scale();
75:
76: if ( can->noaxis )
77: return;
78:
79: xadj = yadj = 0;
80: if ( (can->xmin < 0) && (can->xmax > 0) ) {
81: x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin)));
82: polyLine_outputPS_dashed_line(translateX(x0),translateY(0),
83: translateX(x0),translateY(can->height));
84: } else if ( can->xmin >= 0 )
85: x0 = 0;
86: else
87: x0 = can->width-1-D;
88: if ( (can->ymin < 0) && (can->ymax > 0) ) {
89: y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin)));
90: polyLine_outputPS_dashed_line(translateX(0),translateY(y0),
91: translateX(can->width),translateY(y0));
92: } else if ( can->ymin >= 0 )
93: y0 = can->height-1;
94: else
95: y0 = D;
96: /* BUG: not written yet a code for PS.
97: w = can->xmax-can->xmin;
98: w1 = w * DEFAULTWIDTH/can->width;
99: e = adjust_scale(EXP10(floor(log10(w1))),w1);
100: for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
101: x = (int)can->width*(n*e-can->xmin)/w;
102: DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
103: sprintf(buf,"%g",n*e);
104: DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf));
105: }
106: w = can->ymax-can->ymin;
107: w1 = w * DEFAULTHEIGHT/can->height;
108: e = adjust_scale(EXP10(floor(log10(w1))),w1);
109: for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
110: y = (int)can->height*(1-(n*e-can->ymin)/w);
111: DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
112: sprintf(buf,"%g",n*e);
113: if ( can->xmax <= 0 )
114: xadj = TEXTWIDTH(sffs,buf,strlen(buf));
115: DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf));
116: }
117: */
118: }
1.1 takayama 119:
120: generatePS_from_image(FILE *fp,XImage *image,int xsize, int ysize,
1.2 takayama 121: int color[],int colorSize,
122: struct canvas *can) {
1.1 takayama 123: struct polyLine **pl;
124: int plSize = 0;
125: int *prev;
126: int *curr;
127: int i,x,y,c;
1.4 takayama 128: extern int Strategy_generate_PS;
1.1 takayama 129:
130: Xsize = xsize;
131: Ysize = ysize;
132: Fp = fp;
133: polyLine_outputProlog(0,0,Xsize,Ysize);
1.4 takayama 134: switch(Strategy_generate_PS) {
135: default:
136: for (c=0; c<colorSize; c++) {
137: /* Set color if necessary */
138: for (x=0; x<Xsize; x++) {
139: for (y=0; y<Ysize; y++) {
140: if ((int) XGetPixel(image,x,y) == color[c]){
141: fprintf(Fp," %d %d ", translateX(x),translateY(y) );
142: fprintf(Fp," ifplot_putpixel\n");
143: }
144: }
145: }
1.1 takayama 146: }
1.4 takayama 147: break;
1.1 takayama 148: }
1.2 takayama 149: polyLine_pline(can);
1.1 takayama 150: polyLine_outputEpilog();
151: }
1.2 takayama 152:
1.1 takayama 153:
154:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>