=================================================================== RCS file: /home/cvs/OpenXM_contrib2/asir2000/plot/plotp.c,v retrieving revision 1.12 retrieving revision 1.21 diff -u -p -r1.12 -r1.21 --- OpenXM_contrib2/asir2000/plot/plotp.c 2005/05/18 03:27:00 1.12 +++ OpenXM_contrib2/asir2000/plot/plotp.c 2014/08/20 16:51:34 1.21 @@ -45,7 +45,7 @@ * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE, * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE. * - * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.11 2002/07/10 09:13:53 noro Exp $ + * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.20 2014/07/05 03:55:42 saito Exp $ */ #include "ca.h" #include "parse.h" @@ -63,13 +63,183 @@ static POINT oldpos; #endif -void if_print(DISPLAY *display,double **tab,struct canvas *can) +#if !defined(VISUAL) +extern Pixel BackPixel; +unsigned long GetColor(Display *, char *); + +unsigned long GetColor(Display *dis, char *color_name) { + Colormap cmap; + XColor near_color, true_color; + + cmap = DefaultColormap( dis, 0 ); + XAllocNamedColor( dis, cmap, color_name, &near_color, &true_color ); + return( near_color.pixel ); +} + +void area_print(DISPLAY *display,double **tab,struct canvas *can,int GXcode){ + int ix,iy,width,height,wc,**mask; + XImage *image; + DRAWABLE pix; + unsigned int color,black,white,c2; + //unsigned long color,black,white,c2; + double *px,*px1,*px2; + //GXcode 0:new 1:cp 2:and 3:or 4:xor + width=can->width; + height=can->height; + pix=can->pix; + mask=(int **)ALLOCA((width)*sizeof(int *)); + for(ix=0;ix0)&&(tab[ix+1][iy]>0)&&(tab[ix][iy+1]>0)&& + (tab[ix+1][iy+1]>0)) mask[ix][iy]=1;//all postive + else if((tab[ix][iy]<0)&&(tab[ix+1][iy]<0)&&(tab[ix][iy+1]<0)&& + (tab[ix+1][iy+1]<0)) mask[ix][iy]=-1;//all negativ + else mask[ix][iy]=0;//boundary + flush(); + black=GetColor(display,"black"); + white=GetColor(display,"white"); + set_drawcolor(can->color); + color=can->color; + image=XGetImage(display,pix,0,0,width,height,-1,ZPixmap); + for(ix=0;ixpix; width=can->width; height=can->height; + for(ix=0;ix=0.0)DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1); + } + count_and_flush(); + } + flush(); +} + +void if_printNG(DISPLAY *display,double **tab,struct canvas *can,int cond){ + int ix,iy,width,height; + double zst,zed,zsp; + DRAWABLE pix; + width=can->width; height=can->height; pix=can->pix; + if(cond==0){ + //IFPLOTB + for(iy=0;iy0){ + if(tab[ix+1][iy+1]<0||tab[ix][iy+1]<0||tab[ix+1][iy]<0) + DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1); + } else if(tab[ix+1][iy+1]>0||tab[ix][iy+1]>0||tab[ix+1][iy]>0) + DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1); + count_and_flush(); + } + } + flush(); +} + +void polar_print(DISPLAY *display,struct canvas *can){ + int len,i,j,x,y; + unsigned int color; + POINT *pa; + +#if defined(VISUAL) + HDC dc; + HPEN pen,oldpen; + len=can->pa[0].length; + color=can->color; + pa=can->pa[0].pos; + for(i=1;ipix,pen); + DRAWLINE(display,can->pix,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i])); + SelectObject(can->pix,oldpen); + + dc = GetDC(can->hwnd); + oldpen = SelectObject(dc,pen); + DRAWLINE(display,dc,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i])); + SelectObject(dc,oldpen); + ReleaseDC(can->hwnd,dc); + + DeleteObject(pen); + } else { + DRAWLINE(display,can->pix,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i])); + dc = GetDC(can->hwnd); + DRAWLINE(display,dc,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i])); + ReleaseDC(can->hwnd,dc); + } + } +#else + len=can->pa[0].length; + color=can->color; + pa=can->pa[0].pos; + for(i=1;ipix,cdrawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i])); + } + XFlush(display); +#endif +} + + +void if_print(DISPLAY *display,double **tab,struct canvas *can){ + int ix,iy,width,height; double *px,*px1,*px2; DRAWABLE pix; - if ( can->mode == MODE_CONPLOT ) { + if ( can->mode == modeNO(CONPLOT) ) { con_print(display,tab,can); return; } flush(); @@ -78,28 +248,81 @@ void if_print(DISPLAY *display,double **tab,struct can for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1; iy= 0) && ((*px1 <= 0) || (*px2 <= 0))) || - ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) { + ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) { + DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1); + count_and_flush(); + } + flush(); +/* + int i,ix,iy,width,height; + double *px,*px1,*px2; + double **vmax,**vmin,*zst,zstep,zv,u,l; + DRAWABLE pix; + POINT *pa,*pa1; + struct pa *parray; + + if(can->mode==modeNO(CONPLOT)){ + width=can->width;height=can->height;pix=can->pix; + //con_print(display,tab,can); + // calc all cell max,min value + vmax=((double **)ALLOCA((width+1)*sizeof(double *))); + vmin=((double **)ALLOCA((width+1)*sizeof(double *))); + for(i=0;izmax==can->zmin)zstep=(can->vmax-can->vmin)/can->nzstep; + else zstep=(can->zmax-can->zmin)/can->nzstep; + zst=(double *)ALLOCA((can->nzstep+1)*sizeof(double)); + zv=can->xmin; + for(i=0,zv=can->xmin;inzstep;zv+=zstep,i++)zst[i]=zv; + for(iy=0;iynzstep;i++){ + if(vmin[ix][iy]<=zst[i] && vmax[ix][iy]>=zst[i]){ + DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1); + break; + } + count_and_flush(); + } + } + } + } else { + width=can->width;height=can->height;pix=can->pix; + for(ix=0;ix=0)&&((*px1<=0)||(*px2<=0)))|| + ((*px<=0)&&((*px1>=0)||(*px2>=0)))){ DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1); count_and_flush(); } + } flush(); +*/ } #define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7))) -void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes) -{ +void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes){ int ix,iy,width,height; double *px,*px1,*px2; unsigned char *array; int scan_len; - - if ( can->mode == MODE_CONPLOT ) { - memory_con_print(tab,can,bytes); return; + if ( can->mode==modeNO(CONPLOT)){ + memory_con_print(tab,can,bytes); + return; } width = can->width; height = can->height; - - /* scan_len = byte length of the scan line */ + // scan_len = byte length of the scan line scan_len = (width+7)/8; MKBYTEARRAY(*bytes,scan_len*height); array = BDY(*bytes); @@ -112,55 +335,49 @@ void memory_if_print(double **tab,struct canvas *can,B } } -void con_print(DISPLAY *display,double **tab,struct canvas *can) -{ - int ix,iy,iz,width,height,pas,pai,len; - double zstep,z; +void con_print(DISPLAY *display,double **tab,struct canvas *can){ + int i,ix,iy,width,height; double *px,*px1,*px2; + double **vmax,**vmin,*zst,zstep,zv,u,l; DRAWABLE pix; POINT *pa,*pa1; struct pa *parray; - - width = can->width; height = can->height; pix = can->pix; - zstep = (can->zmax-can->zmin)/can->nzstep; - can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa)); - pas = width; - pa = (POINT *)ALLOCA(pas*sizeof(POINT)); - initmarker(can,"Drawing..."); - for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) { - marker(can,DIR_Z,iz); - pai = 0; - for( ix=0; ix= z) && ((*px1 <= z) || (*px2 <= z))) || - ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) { - if ( pai == pas ) { - pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT)); - bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1; - pas += pas; - } - XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++; + width=can->width;height=can->height;pix=can->pix; + vmax=((double **)ALLOCA((width+1)*sizeof(double *))); + vmin=((double **)ALLOCA((width+1)*sizeof(double *))); + for(i=0;izmax==can->zmin)zstep=(can->vmax-can->vmin)/can->nzstep; + else zstep=(can->zmax-can->zmin)/can->nzstep; + zst=(double *)ALLOCA((can->nzstep+1)*sizeof(double)); + zv=can->xmin; + for(i=0,zv=can->xmin;inzstep;zv+=zstep,i++)zst[i]=zv; + for(iy=0;iynzstep;i++){ + if(vmin[ix][iy]<=zst[i] && vmax[ix][iy]>=zst[i]){ + DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1); + break; } - can->pa[iz].length = pai; - if ( pai ) { - pa1 = (POINT *)MALLOC(pai*sizeof(POINT)); - bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT)); - can->pa[iz].pos = pa1; + count_and_flush(); + } } } flush(); - for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ ) - for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) { - DRAWPOINT(display,pix,cdrawGC,XC(pa[ix]),YC(pa[ix])); - count_and_flush(); - } - flush(); } -void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes) -{ +void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes){ int ix,iy,iz,width,height,pas,pai,len; double zstep,z; double *px,*px1,*px2; @@ -205,8 +422,24 @@ void memory_con_print(double **tab,struct canvas *can, } } -void qif_print(DISPLAY *display,char **tab,struct canvas *can) -{ +void memory_print(struct canvas *can,BYTEARRAY *bytes){ + int len,scan_len,i; + POINT *pa; + char *array; + + /* scan_len = byte length of the scan line */ + scan_len = (can->width+7)/8; + MKBYTEARRAY(*bytes,scan_len*can->height); + array = (char*)BDY(*bytes); + + len = can->pa[0].length; + pa = can->pa[0].pos; + for ( i = 0; i < len; i++ ) { + MEMORY_DRAWPOINT(array,scan_len,pa[i].x,pa[i].y); + } +} + +void qif_print(DISPLAY *display,char **tab,struct canvas *can){ int ix,iy,width,height; char *px; DRAWABLE pix; @@ -222,8 +455,7 @@ void qif_print(DISPLAY *display,char **tab,struct canv flush(); } -void plot_print(DISPLAY *display,struct canvas *can) -{ +void plot_print(DISPLAY *display,struct canvas *can){ int len; POINT *pa; @@ -242,8 +474,8 @@ void plot_print(DISPLAY *display,struct canvas *can) #endif } -void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color) -{ +void draw_point(DISPLAY *display,struct canvas *can,int x,int y,unsigned int color){ +//void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color){ #if defined(VISUAL) HDC dc; @@ -259,8 +491,9 @@ void draw_point(DISPLAY *display,struct canvas *can,in #endif } -void draw_line(DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color) -{ +void draw_line( + DISPLAY *display,struct canvas *can,int x,int y,int u,int v,unsigned int color){ + //DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color){ #if defined(VISUAL) HDC dc; HPEN pen,oldpen; @@ -292,8 +525,9 @@ void draw_line(DISPLAY *display,struct canvas *can,int #endif } -void draw_character_string(DISPLAY *display,struct canvas *can,int x,int y,char *str,int color) -{ +void draw_character_string( + DISPLAY *display,struct canvas *can,int x,int y,char *str,unsigned int color){ + //DISPLAY *display,struct canvas *can,int x,int y,char *str,int color){ #if defined(VISUAL) HDC dc; COLORREF oldcolor; @@ -324,17 +558,16 @@ void draw_character_string(DISPLAY *display,struct can #define D 5 -void pline(DISPLAY *display,struct canvas *can,DRAWABLE d) -{ +void pline(DISPLAY *display,struct canvas *can,DRAWABLE d){ double w,w1,e,n; int x0,y0,x,y,xadj,yadj; char buf[BUFSIZ]; double adjust_scale(); /* XXX : should be cleaned up */ - if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) ) + if ( can->noaxis || (can->mode==modeNO(PLOT)&& !can->pa) ) return; - if ( can->mode == MODE_INTERACTIVE ) + if ( can->mode==modeNO(INTERACTIVE)) return; xadj = yadj = 0; @@ -386,8 +619,7 @@ void pline(DISPLAY *display,struct canvas *can,DRAWABL } } -double adjust_scale(double e,double w) -{ +double adjust_scale(double e,double w){ switch ( (int)floor(w/e) ) { case 1: return e/4; break; @@ -401,8 +633,7 @@ double adjust_scale(double e,double w) } } -void initmarker(struct canvas *can,char *message) -{ +void initmarker(struct canvas *can,char *message){ #if defined(VISUAL) can->real_can->percentage = 0; can->real_can->prefix = message; @@ -413,8 +644,7 @@ void initmarker(struct canvas *can,char *message) #endif } -void marker(struct canvas *can,int dir,int p) -{ +void marker(struct canvas *can,int dir,int p){ #if defined(VISUAL) if ( dir == DIR_X ) can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->width*100); @@ -436,8 +666,7 @@ void marker(struct canvas *can,int dir,int p) #endif } -void define_cursor(WINDOW w,CURSOR cur) -{ +void define_cursor(WINDOW w,CURSOR cur){ #if !defined(VISUAL) XDefineCursor(display,w,cur); flush(); #endif @@ -450,14 +679,14 @@ static int flush_count; #define MAX_COUNT 32 #endif -void count_and_flush() { +void count_and_flush(){ #if !defined(VISUAL) if ( ++flush_count == MAX_COUNT ) flush(); #endif } -void flush() { +void flush(){ #if !defined(VISUAL) flush_count = 0; XFlush(display);