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