version 1.7, 2002/07/11 12:35:03 |
version 1.10, 2013/11/05 02:55:03 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/plot/smoothing.c,v 1.6 2002/07/11 03:34:34 takayama Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/plot/smoothing.c,v 1.9 2007/01/25 16:19:41 saito Exp $ */ |
|
#include <stdio.h> |
|
#include <time.h> |
|
#include <math.h> |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#include "ox.h" |
#include "ox.h" |
|
|
#define MAG 1 |
#define MAG 1 |
#define PRINT_XOFFSET 100 |
#define PRINT_XOFFSET 100 |
#define PRINT_YOFFSET 100 |
#define PRINT_YOFFSET 100 |
|
#define DPI 300 |
|
|
|
|
static FILE *Fp = NULL; |
static FILE *Fp = NULL; |
|
static void PSProlog(int, int, int, int); |
|
static void PSDashedLine(int, int, int, int); |
|
static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1); |
|
void PSFromImage(FILE *fp,XImage *image,struct canvas *can); |
|
|
static void polyLine_outputProlog(int xmin, int ymin, int xmax, int ymax); |
static int Strategy_generate_PS = 0; |
static void polyLine_outputEpilog(void); |
|
static void polyLine_error(char *s); |
|
#define translateX(x) (x*MAG+PRINT_XOFFSET) |
|
#define translateY(y) (y*MAG+PRINT_YOFFSET) |
|
/* #define translateY(y) ((Ysize-y)*MAG+PRINT_YOFFSET) */ |
|
#define IS_DOT != 0 |
|
#define IS_POLYLINE > -1 |
|
#define YES 1 |
|
#define NO 0 |
|
|
|
static int Xsize = 0; |
void PSFromImage(FILE *fp,XImage *image,struct canvas *can) { |
static int Ysize = 0; |
int x, y, ir, ig, ib; |
|
float r, g, b; |
|
int srcc, trg,grux, gruy, ix, iy; |
|
float xwd, ywd, t; |
|
|
static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1); |
Fp = fp; |
static int polyLine_pline(struct canvas *can); |
srcc = 0xffffff; |
static int Strategy_generate_PS = 0; |
PSProlog(0,0,can->width,can->height); |
|
for(y=0;y< can->height;y++) |
|
for(x=0;x < can->width; x++){ |
|
trg = XGetPixel(image,x,y) & 0xffffff; |
|
if ( trg != 0xffffff ){ |
|
if ( trg != srcc ){ |
|
srcc = trg; |
|
r = ir = (srcc >>16) & 0xff; |
|
r = r/256; |
|
g = ig = (srcc >> 8) & 0xff; |
|
g = g/256; |
|
b = ib = (srcc) & 0xff; |
|
b = b/256; |
|
if(ir == 0 && ig ==0 && ib == 0) |
|
fprintf(Fp,"0 0 0 C\n"); |
|
else |
|
fprintf(Fp,"%f %f %f C\n",r,g,b); |
|
} |
|
fprintf(Fp,"%d %d R\n", x,can->height - y); |
|
} |
|
} |
|
fprintf(Fp,"0 0 0 C\n"); |
|
if ( can->noaxis == 0 ){ |
|
grux = ceil(can->xmax); |
|
xwd = can->width/(can->xmax - can->xmin); |
|
for(ix=ceil(can->xmin); ix < grux; ix++){ |
|
t = ix; |
|
x = (t - can->xmin) * xwd; |
|
PSDashedLine(x, 0, x, can->height); |
|
} |
|
gruy = ceil(can->ymax); |
|
ywd = can->height/(can->ymax - can->ymin); |
|
for(iy=can->ymin; iy < gruy; iy++){ |
|
t = iy; |
|
y = (t - can->ymin ) * ywd; |
|
PSDashedLine(0, y, can->width, y); |
|
} |
|
} |
|
fprintf(Fp,"[] 0 setdash 0 0 moveto "); |
|
fprintf(Fp,"%d 0 lineto %d %d lineto 0 %d lineto closepath stroke\n", |
|
can->width, can->width, can->height, can->height); |
|
fprintf(Fp,"showpage grestore\n"); |
|
fflush(Fp); |
|
} |
|
|
|
static void PSProlog(int xmin, int ymin,int xmax, int ymax) { |
|
int width, height; |
|
struct tm *systime; |
|
time_t t; |
|
|
static void polyLine_outputProlog(int xmin, int ymin,int xmax, int ymax) { |
t = time(NULL); |
fprintf(Fp,"%%!PS-Adobe-1.0\n"); |
systime = localtime(&t); |
fprintf(Fp,"%%%%BoundingBox: %d %d %d %d \n", |
width = 72*(xmax - xmin-1)/300; |
PRINT_XOFFSET+xmin*MAG,PRINT_YOFFSET+ymin*MAG, |
height = 72*(ymax - ymin-1)/300; |
PRINT_XOFFSET+xmax*MAG, PRINT_YOFFSET+ymax*MAG); |
fprintf(Fp,"%%!PS-Adobe-2.0 EPSF-2.0\n"); |
|
fprintf(Fp,"%%%%BoundingBox: -3 -2 %d %d \n", width*MAG+3, height*MAG+3); |
fprintf(Fp,"%%%%Creator: This is generated by ifplot\n"); |
fprintf(Fp,"%%%%Creator: This is generated by ifplot\n"); |
fprintf(Fp,"%%%%Title: ifplot\n"); |
fprintf(Fp,"%%%%Title: ifplot\n"); |
|
fprintf(Fp,"%%%%CreationDate: %.4d-%.2d-%.2d\n", |
|
systime->tm_year+1900,systime->tm_mon+1,systime->tm_mday); |
|
fprintf(Fp,"%%%%Pages: 0\n"); |
fprintf(Fp,"%%%%EndComments: \n"); |
fprintf(Fp,"%%%%EndComments: \n"); |
fprintf(Fp,"0.1 setlinewidth \n"); |
fprintf(Fp,"%%%%EndProlog\n%%%%Page: one 1\n%%!\n"); |
fprintf(Fp,"2 setlinecap \n"); |
fprintf(Fp,"/dpi %d def\n", DPI); |
fprintf(Fp,"2 setlinejoin \n"); |
fprintf(Fp,"/SCALE 72 dpi div def\n"); |
fprintf(Fp,"/ifplot_putpixel { \n"); |
fprintf(Fp,"/R {moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto closepath"); |
fprintf(Fp," /yyy 2 1 roll def /xxx 2 1 roll def \n"); |
fprintf(Fp," fill} bind def\n"); |
fprintf(Fp," gsave newpath xxx yyy .5 0 360 arc \n"); |
fprintf(Fp,"/C {setrgbcolor} bind def\n"); |
fprintf(Fp," fill grestore \n"); |
fprintf(Fp,"gsave newpath\n"); |
fprintf(Fp,"} def \n"); |
fprintf(Fp,"0 0 moveto SCALE SCALE scale 1 setlinewidth\n"); |
fflush(Fp); |
fflush(Fp); |
} |
} |
static void polyLine_outputEpilog(void) { |
|
fprintf(Fp,"0 0 0 setrgbcolor \n"); |
|
fprintf(Fp,"showpage \n"); fflush(Fp); |
|
} |
|
static void polyLine_error(char *s) { |
|
fprintf(stderr,"Error in smoothing: %s\n",s); |
|
exit(-1); |
|
} |
|
|
|
static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1) { |
static void PSDashedLine(int x0,int y0,int x1,int y1) { |
extern FILE *Fp; |
extern FILE *Fp; |
fprintf(Fp," gsave [3] 0 setdash newpath \n"); |
fprintf(Fp,"0.1 setlinewidth [3 3] 0 setdash\n"); |
fprintf(Fp," %d %d moveto %d %d lineto stroke \n",x0,y0,x1,y1); |
fprintf(Fp," %d %d moveto %d %d lineto stroke \n",x0,y0,x1,y1); |
fprintf(Fp," stroke grestore \n"); |
|
} |
} |
|
|
#define D 5 |
|
static int polyLine_pline(can) |
|
struct canvas *can; |
|
{ |
|
double w,w1,k,e,n; |
|
int x0,y0,x,y,xadj,yadj; |
|
char buf[BUFSIZ]; |
|
double adjust_scale(); |
|
|
|
if ( can->noaxis ) |
|
return; |
|
|
|
xadj = yadj = 0; |
|
if ( (can->xmin < 0) && (can->xmax > 0) ) { |
|
x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin))); |
|
polyLine_outputPS_dashed_line(translateX(x0),translateY(0), |
|
translateX(x0),translateY(can->height)); |
|
} else if ( can->xmin >= 0 ) |
|
x0 = 0; |
|
else |
|
x0 = can->width-1-D; |
|
if ( (can->ymin < 0) && (can->ymax > 0) ) { |
|
y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin))); |
|
polyLine_outputPS_dashed_line(translateX(0),translateY(y0), |
|
translateX(can->width),translateY(y0)); |
|
} else if ( can->ymin >= 0 ) |
|
y0 = can->height-1; |
|
else |
|
y0 = D; |
|
/* BUG: not written yet a code for PS. |
|
w = can->xmax-can->xmin; |
|
w1 = w * DEFAULTWIDTH/can->width; |
|
e = adjust_scale(EXP10(floor(log10(w1))),w1); |
|
for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) { |
|
x = (int)can->width*(n*e-can->xmin)/w; |
|
DRAWLINE(display,d,drawGC,x,y0,x,y0-D); |
|
sprintf(buf,"%g",n*e); |
|
DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf)); |
|
} |
|
w = can->ymax-can->ymin; |
|
w1 = w * DEFAULTHEIGHT/can->height; |
|
e = adjust_scale(EXP10(floor(log10(w1))),w1); |
|
for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) { |
|
y = (int)can->height*(1-(n*e-can->ymin)/w); |
|
DRAWLINE(display,d,drawGC,x0,y,x0+D,y); |
|
sprintf(buf,"%g",n*e); |
|
if ( can->xmax <= 0 ) |
|
xadj = TEXTWIDTH(sffs,buf,strlen(buf)); |
|
DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf)); |
|
} |
|
*/ |
|
} |
|
|
|
generatePS_from_image(FILE *fp,XImage *image,int xsize, int ysize, |
|
int color[],int colorSize, |
|
struct canvas *can,struct xcolorForPS *tableOfxcolorForPS) { |
|
struct polyLine **pl; |
|
int plSize = 0; |
|
int *prev; |
|
int *curr; |
|
int i,x,y,c; |
|
extern int Strategy_generate_PS; |
|
|
|
Xsize = xsize; |
|
Ysize = ysize; |
|
Fp = fp; |
|
polyLine_outputProlog(0,0,Xsize,Ysize); |
|
switch(Strategy_generate_PS) { |
|
default: |
|
fprintf(Fp,"%% debug info : colorSize=%d\n",colorSize); |
|
for (c=0; c<colorSize; c++) { |
|
/* Set color by looking at tableOfxcolorForPS. |
|
*/ |
|
fprintf(Fp,"%f %f %f setrgbcolor \n",(tableOfxcolorForPS[c]).r,(tableOfxcolorForPS[c]).g,(tableOfxcolorForPS[c]).b); |
|
for (x=0; x<Xsize; x++) { |
|
for (y=0; y<Ysize; y++) { |
|
if ((tableOfxcolorForPS[c]).print && |
|
XGetPixel(image,x,y) == (tableOfxcolorForPS[c]).pixel){ |
|
fprintf(Fp," %d %d ", translateX(x),translateY(y) ); |
|
fprintf(Fp," ifplot_putpixel\n"); |
|
} |
|
} |
|
} |
|
} |
|
break; |
|
} |
|
polyLine_pline(can); |
|
polyLine_outputEpilog(); |
|
} |
|
|
|
|
|
|
|
|
|