version 1.1, 2000/10/15 06:56:53 |
version 1.4, 2000/11/08 05:49:35 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/plot/smoothing.c,v 1.3 2000/10/24 01:53:53 takayama Exp $ */ |
#include "ca.h" |
#include "ca.h" |
#include "parse.h" |
#include "parse.h" |
#include "ox.h" |
#include "ox.h" |
Line 24 static struct polyLine *polyLine_addNewSegment(struct |
|
Line 24 static struct polyLine *polyLine_addNewSegment(struct |
|
int x,int y); |
int x,int y); |
static int polyLine_lastY(struct polyLine *pl); |
static int polyLine_lastY(struct polyLine *pl); |
static void polyLine_outputPS(struct polyLine *pl); |
static void polyLine_outputPS(struct polyLine *pl); |
|
static void polyLine_output_bezier_PS(struct polyLine *pl); |
static void polyLine_outputProlog(int xmin, int ymin, int xmax, int ymax); |
static void polyLine_outputProlog(int xmin, int ymin, int xmax, int ymax); |
static void polyLine_outputEpilog(void); |
static void polyLine_outputEpilog(void); |
static void polyLine_error(char *s); |
static void polyLine_error(char *s); |
Line 41 static int Ysize = 0; |
|
Line 42 static int Ysize = 0; |
|
static int updatePolyLine(struct polyLine *pl[], int plSize, |
static int updatePolyLine(struct polyLine *pl[], int plSize, |
int prev[], int Curr[], int x); |
int prev[], int Curr[], int x); |
|
|
|
static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1); |
|
static int polyLine_pline(struct canvas *can); |
|
static int Strategy_generate_PS = 0; |
|
|
static void *gcmalloc(a) { |
static void *gcmalloc(a) { |
void *m; |
void *m; |
/* BUG: interruption must be locked. */ |
/* BUG: interruption must be locked. */ |
Line 111 static void polyLine_outputPS(struct polyLine *pl) { |
|
Line 116 static void polyLine_outputPS(struct polyLine *pl) { |
|
} |
} |
fflush(Fp); |
fflush(Fp); |
} |
} |
|
static void polyLine_output_bezier_PS(struct polyLine *pl) { |
|
int n,i,m; |
|
n = pl->numberOfSegments; |
|
if (n == 1) { |
|
fprintf(Fp," %d %d ifplot_putpixel\n",translateX(pl->x[0]),translateY(pl->y[0])); |
|
}else if (n > 1) { |
|
fprintf(Fp," newpath "); |
|
i=0; |
|
m = n-1-((n-1)/3)*3; |
|
fprintf(Fp," %d %d ",translateX(pl->x[i]),translateY(pl->y[i])); |
|
fprintf(Fp," moveto \n "); |
|
for (i=1; i<= ((n-1)/3)*3; i++) { |
|
fprintf(Fp," %d %d ",translateX(pl->x[i]),translateY(pl->y[i])); |
|
if ( i%3 == 0) fprintf(Fp," curveto "); |
|
} |
|
for (i=n-m; i<n; i++) { |
|
fprintf(Fp," %d %d lineto ",translateX(pl->x[i]),translateY(pl->y[i])); |
|
} |
|
fprintf(Fp," stroke\n"); |
|
} |
|
fflush(Fp); |
|
} |
static void polyLine_outputProlog(int xmin, int ymin,int xmax, int ymax) { |
static void polyLine_outputProlog(int xmin, int ymin,int xmax, int ymax) { |
fprintf(Fp,"%%!PS-Adobe-1.0\n"); |
fprintf(Fp,"%%!PS-Adobe-1.0\n"); |
fprintf(Fp,"%%%%BoundingBox: %d %d %d %d \n", |
fprintf(Fp,"%%%%BoundingBox: %d %d %d %d \n", |
Line 119 static void polyLine_outputProlog(int xmin, int ymin,i |
|
Line 146 static void polyLine_outputProlog(int xmin, int ymin,i |
|
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,"%%%%EndComments: \n"); |
fprintf(Fp,"%%%%EndComments: \n"); |
|
fprintf(Fp,"0.1 setlinewidth \n"); |
|
fprintf(Fp,"2 setlinecap \n"); |
|
fprintf(Fp,"2 setlinejoin \n"); |
fprintf(Fp,"/ifplot_putpixel { \n"); |
fprintf(Fp,"/ifplot_putpixel { \n"); |
fprintf(Fp," /yyy 2 1 roll def /xxx 2 1 roll def \n"); |
fprintf(Fp," /yyy 2 1 roll def /xxx 2 1 roll def \n"); |
fprintf(Fp," gsave newpath xxx yyy .5 0 360 arc \n"); |
fprintf(Fp," gsave newpath xxx yyy .5 0 360 arc \n"); |
Line 179 static int updatePolyLine(struct polyLine *pl[], int p |
|
Line 209 static int updatePolyLine(struct polyLine *pl[], int p |
|
} |
} |
for (i=1; i<=Ysize; i++) { |
for (i=1; i<=Ysize; i++) { |
if (prevHasNext[i] == NO && prev[i] IS_POLYLINE) { |
if (prevHasNext[i] == NO && prev[i] IS_POLYLINE) { |
polyLine_outputPS(pl[prev[i]]); |
/* polyLine_outputPS(pl[prev[i]]); */ |
|
polyLine_output_bezier_PS(pl[prev[i]]); |
} |
} |
} |
} |
|
|
|
|
} |
} |
|
|
*/ |
*/ |
|
static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1) { |
|
extern FILE *Fp; |
|
fprintf(Fp," gsave [3] 0 setdash newpath \n"); |
|
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, |
generatePS_from_image(FILE *fp,XImage *image,int xsize, int ysize, |
int color[],int colorSize) { |
int color[],int colorSize, |
|
struct canvas *can) { |
struct polyLine **pl; |
struct polyLine **pl; |
int plSize = 0; |
int plSize = 0; |
int *prev; |
int *prev; |
int *curr; |
int *curr; |
int i,x,y,c; |
int i,x,y,c; |
|
extern int Strategy_generate_PS; |
|
|
Xsize = xsize; |
Xsize = xsize; |
Ysize = ysize; |
Ysize = ysize; |
Line 269 generatePS_from_image(FILE *fp,XImage *image,int xsize |
|
Line 361 generatePS_from_image(FILE *fp,XImage *image,int xsize |
|
curr = (int *)gcmalloc(sizeof(int)*(Ysize+2)); |
curr = (int *)gcmalloc(sizeof(int)*(Ysize+2)); |
Fp = fp; |
Fp = fp; |
polyLine_outputProlog(0,0,Xsize,Ysize); |
polyLine_outputProlog(0,0,Xsize,Ysize); |
for (c=0; c<colorSize; c++) { |
switch(Strategy_generate_PS) { |
/* Set color if necessary */ |
case 1: |
for (i=0; i<= Ysize+1; i++) { |
for (c=0; c<colorSize; c++) { |
prev[i] = -1; |
/* Set color if necessary */ |
|
for (i=0; i<= Ysize+1; i++) { |
|
prev[i] = -1; |
|
} |
|
for (x=0; x<Xsize; x++) { |
|
curr[0] = curr[Ysize+1] = 0; |
|
for (y=0; y<Ysize; y++) { |
|
if ((int) XGetPixel(image,x,y) == color[c]) curr[y+1]=1; |
|
else curr[y+1] = 0; |
|
} |
|
plSize = updatePolyLine(pl,plSize,prev,curr,x); |
|
} |
|
for (y=0; y<Ysize+2; y++) { |
|
curr[y] = 0; |
|
} |
|
plSize = updatePolyLine(pl,plSize,prev,curr,Xsize); |
} |
} |
for (x=0; x<Xsize; x++) { |
break; |
curr[0] = curr[Ysize+1] = 0; |
default: |
for (y=0; y<Ysize; y++) { |
for (c=0; c<colorSize; c++) { |
if ((int) XGetPixel(image,x,y) == color[c]) curr[y+1]=1; |
/* Set color if necessary */ |
else curr[y+1] = 0; |
for (x=0; x<Xsize; x++) { |
|
for (y=0; y<Ysize; y++) { |
|
if ((int) XGetPixel(image,x,y) == color[c]){ |
|
fprintf(Fp," %d %d ", translateX(x),translateY(y) ); |
|
fprintf(Fp," ifplot_putpixel\n"); |
|
} |
|
} |
} |
} |
plSize = updatePolyLine(pl,plSize,prev,curr,x); |
|
} |
} |
for (y=0; y<Ysize+2; y++) { |
break; |
curr[y] = 0; |
|
} |
|
plSize = updatePolyLine(pl,plSize,prev,curr,Xsize); |
|
} |
} |
|
polyLine_pline(can); |
polyLine_outputEpilog(); |
polyLine_outputEpilog(); |
} |
} |
|
|
|
|
|
|