Annotation of OpenXM_contrib2/asir2000/plot/smoothing.c, Revision 1.8
1.8 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/plot/smoothing.c,v 1.7 2002/07/11 12:35:03 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:
1.8 ! noro 15: static void polyLine_outputProlog(int xmin, int ymin, int xmax, int ymax, int upsidedown);
1.1 takayama 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:
1.8 ! noro 34: static void polyLine_outputProlog(int xmin, int ymin,int xmax, int ymax, int upsidedown) {
1.1 takayama 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.8 ! noro 42: if ( upsidedown )
! 43: fprintf(Fp,"[1 0 0 -1 0 %d] concat \n",2*PRINT_YOFFSET+(ymin+ymax)*MAG);
1.3 takayama 44: fprintf(Fp,"0.1 setlinewidth \n");
45: fprintf(Fp,"2 setlinecap \n");
46: fprintf(Fp,"2 setlinejoin \n");
1.1 takayama 47: fprintf(Fp,"/ifplot_putpixel { \n");
48: fprintf(Fp," /yyy 2 1 roll def /xxx 2 1 roll def \n");
49: fprintf(Fp," gsave newpath xxx yyy .5 0 360 arc \n");
50: fprintf(Fp," fill grestore \n");
51: fprintf(Fp,"} def \n");
52: fflush(Fp);
53: }
54: static void polyLine_outputEpilog(void) {
1.6 takayama 55: fprintf(Fp,"0 0 0 setrgbcolor \n");
1.1 takayama 56: fprintf(Fp,"showpage \n"); fflush(Fp);
57: }
58: static void polyLine_error(char *s) {
59: fprintf(stderr,"Error in smoothing: %s\n",s);
60: exit(-1);
61: }
62:
1.2 takayama 63: static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1) {
64: extern FILE *Fp;
65: fprintf(Fp," gsave [3] 0 setdash newpath \n");
66: fprintf(Fp," %d %d moveto %d %d lineto stroke \n",x0,y0,x1,y1);
67: fprintf(Fp," stroke grestore \n");
68: }
69:
70: #define D 5
71: static int polyLine_pline(can)
72: struct canvas *can;
73: {
74: double w,w1,k,e,n;
75: int x0,y0,x,y,xadj,yadj;
76: char buf[BUFSIZ];
77: double adjust_scale();
78:
79: if ( can->noaxis )
80: return;
81:
82: xadj = yadj = 0;
83: if ( (can->xmin < 0) && (can->xmax > 0) ) {
84: x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin)));
85: polyLine_outputPS_dashed_line(translateX(x0),translateY(0),
86: translateX(x0),translateY(can->height));
87: } else if ( can->xmin >= 0 )
88: x0 = 0;
89: else
90: x0 = can->width-1-D;
91: if ( (can->ymin < 0) && (can->ymax > 0) ) {
92: y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin)));
93: polyLine_outputPS_dashed_line(translateX(0),translateY(y0),
94: translateX(can->width),translateY(y0));
95: } else if ( can->ymin >= 0 )
96: y0 = can->height-1;
97: else
98: y0 = D;
99: /* BUG: not written yet a code for PS.
100: w = can->xmax-can->xmin;
101: w1 = w * DEFAULTWIDTH/can->width;
102: e = adjust_scale(EXP10(floor(log10(w1))),w1);
103: for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
104: x = (int)can->width*(n*e-can->xmin)/w;
105: DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
106: sprintf(buf,"%g",n*e);
107: DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf));
108: }
109: w = can->ymax-can->ymin;
110: w1 = w * DEFAULTHEIGHT/can->height;
111: e = adjust_scale(EXP10(floor(log10(w1))),w1);
112: for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
113: y = (int)can->height*(1-(n*e-can->ymin)/w);
114: DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
115: sprintf(buf,"%g",n*e);
116: if ( can->xmax <= 0 )
117: xadj = TEXTWIDTH(sffs,buf,strlen(buf));
118: DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf));
119: }
120: */
121: }
1.1 takayama 122:
123: generatePS_from_image(FILE *fp,XImage *image,int xsize, int ysize,
1.2 takayama 124: int color[],int colorSize,
1.8 ! noro 125: struct canvas *can,struct xcolorForPS *tableOfxcolorForPS,
! 126: int upsidedown) {
1.1 takayama 127: struct polyLine **pl;
128: int plSize = 0;
129: int *prev;
130: int *curr;
131: int i,x,y,c;
1.4 takayama 132: extern int Strategy_generate_PS;
1.1 takayama 133: Xsize = xsize;
134: Ysize = ysize;
135: Fp = fp;
1.8 ! noro 136: polyLine_outputProlog(0,0,Xsize,Ysize,upsidedown);
1.4 takayama 137: switch(Strategy_generate_PS) {
138: default:
1.7 takayama 139: fprintf(Fp,"%% debug info : colorSize=%d\n",colorSize);
140: for (c=0; c<colorSize; c++) {
141: /* Set color by looking at tableOfxcolorForPS.
1.6 takayama 142: */
1.7 takayama 143: fprintf(Fp,"%f %f %f setrgbcolor \n",(tableOfxcolorForPS[c]).r,(tableOfxcolorForPS[c]).g,(tableOfxcolorForPS[c]).b);
144: for (x=0; x<Xsize; x++) {
145: for (y=0; y<Ysize; y++) {
146: if ((tableOfxcolorForPS[c]).print &&
147: XGetPixel(image,x,y) == (tableOfxcolorForPS[c]).pixel){
148: fprintf(Fp," %d %d ", translateX(x),translateY(y) );
149: fprintf(Fp," ifplot_putpixel\n");
150: }
151: }
152: }
153: }
154: break;
1.1 takayama 155: }
1.8 ! noro 156: /* XXX : reset the color to black */
! 157: fprintf(Fp,"0 0 0 setrgbcolor \n");
1.2 takayama 158: polyLine_pline(can);
1.1 takayama 159: polyLine_outputEpilog();
160: }
1.6 takayama 161:
1.2 takayama 162:
1.1 takayama 163:
164:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>