[BACK]Return to plotp.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / plot

Diff for /OpenXM_contrib2/asir2000/plot/plotp.c between version 1.5 and 1.14

version 1.5, 2000/11/07 06:06:40 version 1.14, 2011/08/10 04:51:58
Line 45 
Line 45 
  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,   * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.   * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
  *   *
  * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.4 2000/08/22 05:04:33 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.13 2005/12/21 23:18:16 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 63 
Line 63 
 static POINT oldpos;  static POINT oldpos;
 #endif  #endif
   
 if_print(display,tab,can)  unsigned long GetColor(Display *, char *);
 DISPLAY *display;  
 double **tab;  unsigned long GetColor(Display *dis, char *color_name)
 struct canvas *can;  
 {  {
           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, int **mask, struct canvas *can, int GXcode)
   {
           int ix, iy;
           XImage *image;
           unsigned long color, black, white;
           int wc;
   
           flush();
           black = GetColor(display, "black");
           white = GetColor(display, "white");
           image = XGetImage(display, can->pix, 0, 0, can->width, can->height,
                   -1, ZPixmap);
           for(iy = 0; iy < can->height; iy++){
                   for(ix = 0; ix < can->width; ix++){
                           color = XGetPixel(image, ix, iy);
                           if (color == white) wc = -1;
                           else if (color == black) wc = 0;
                           else wc = 1;
                           if ( wc != 0 ) {//XPutPixel(image,ix,iy,black);
                                   if ( mask[iy][ix] == 0 ) XPutPixel(image, ix, iy, black);
                                   else {
                                           switch (GXcode) {
                                           case 3: /* copy case */
                                                   if (mask[iy][ix] == 1 ) XPutPixel(image, ix, iy, can->color);
                                                   else XPutPixel(image, ix, iy, BackPixel);
                                                   break;
                                           case 1: /* and case */
                                                   if ((mask[iy][ix] == 1) && (wc == 1))
                                                           XPutPixel(image, ix, iy, can->color);
                                                   else XPutPixel(image, ix, iy, BackPixel);
                                                   break;
                                           case 7: /* or case */
                                                   if ((mask[iy][ix] == 1) || (wc == 1))
                                                           XPutPixel(image, ix, iy, can->color);
                                                   else XPutPixel(image, ix, iy, BackPixel);
                                                   break;
                                           case 6: /* xor case */
                                                   if ((mask[iy][ix] == 1) ^ (wc == 1))
                                                           XPutPixel(image, ix, iy, can->color);
                                                   else XPutPixel(image, ix, iy, BackPixel);
                                                   break;
                                           }
                                   }
                           }
                   }
           }
           XPutImage(display,can->pix,drawGC,image,0,0,0,0,can->width, can->height);
           count_and_flush();
           flush();
   }
   
   void if_print(DISPLAY *display,double **tab,struct canvas *can)
   {
         int ix,iy,width,height;          int ix,iy,width,height;
         double *px,*px1,*px2;          double *px,*px1,*px2;
         DRAWABLE pix;          DRAWABLE pix;
Line 82  struct canvas *can;
Line 142  struct canvas *can;
                         iy<height-1 ;iy++, px++, px1++, px2++ )                          iy<height-1 ;iy++, px++, px1++, px2++ )
                         if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||                          if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                                  ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {                                   ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                                 DRAWPOINT(display,pix,drawGC,ix,height-iy-1);                                  DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                                 count_and_flush();                                  count_and_flush();
                         }                          }
         flush();          flush();
 }  }
   
 con_print(display,tab,can)  #define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7)))
 DISPLAY *display;  
 double **tab;  void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes)
 struct canvas *can;  
 {  {
           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;
           }
           width = can->width; height = can->height;
   
           /* scan_len = byte length of the scan line */
           scan_len = (width+7)/8;
           MKBYTEARRAY(*bytes,scan_len*height);
           array = BDY(*bytes);
           for( ix=0; ix<width-1; ix++ )
                   for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                           iy<height-1 ;iy++, px++, px1++, px2++ )
                           if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                                    ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                                   MEMORY_DRAWPOINT(array,scan_len,ix,height-iy-1);
                           }
   }
   
   void con_print(DISPLAY *display,double **tab,struct canvas *can)
   {
         int ix,iy,iz,width,height,pas,pai,len;          int ix,iy,iz,width,height,pas,pai,len;
         double zstep,z;          double zstep,z;
         double *px,*px1,*px2;          double *px,*px1,*px2;
Line 132  struct canvas *can;
Line 216  struct canvas *can;
         flush();          flush();
         for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )          for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                 for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {                  for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                         DRAWPOINT(display,pix,drawGC,XC(pa[ix]),YC(pa[ix]));                          DRAWPOINT(display,pix,cdrawGC,XC(pa[ix]),YC(pa[ix]));
                         count_and_flush();                          count_and_flush();
                 }                  }
         flush();          flush();
 }  }
   
 qif_print(display,tab,can)  void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes)
 DISPLAY *display;  
 char **tab;  
 struct canvas *can;  
 {  {
           int ix,iy,iz,width,height,pas,pai,len;
           double zstep,z;
           double *px,*px1,*px2;
           POINT *pa,*pa1;
           struct pa *parray;
           unsigned char *array;
           int scan_len;
   
           width = can->width; height = can->height;
           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));
           for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                   pai = 0;
                   for( ix=0; ix<width-1; ix++ )
                           for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                                   iy<height-1 ;iy++, px++, px1++, px2++ )
                                   if ( ((*px >= 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++;
                                   }
                   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;
                   }
           }
           /* scan_len = byte length of the scan line */
           scan_len = (width+7)/8;
           MKBYTEARRAY(*bytes,scan_len*height);
           array = BDY(*bytes);
           for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                   for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                           MEMORY_DRAWPOINT(array,scan_len,XC(pa[ix]),YC(pa[ix]));
                   }
   }
   
   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 = 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;          int ix,iy,width,height;
         char *px;          char *px;
         DRAWABLE pix;          DRAWABLE pix;
Line 152  struct canvas *can;
Line 297  struct canvas *can;
         for( ix = 0; ix < width; ix++ )          for( ix = 0; ix < width; ix++ )
                 for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )                  for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                         if ( *px ) {                          if ( *px ) {
                                 DRAWPOINT(display,pix,drawGC,ix,height-iy-1);                                  DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                                 count_and_flush();                                  count_and_flush();
                         }                          }
         flush();          flush();
 }  }
   
 plot_print(display,can)  void plot_print(DISPLAY *display,struct canvas *can)
 DISPLAY *display;  
 struct canvas *can;  
 {  {
         int len,i;          int len;
         POINT *pa;          POINT *pa;
   
 #if defined(VISUAL)  #if defined(VISUAL)
         len = can->pa[0].length;          len = can->pa[0].length;
         pa = can->pa[0].pos;          pa = can->pa[0].pos;
         for ( i = 0; i < len-1; i++ ) {  
                 DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);          Polyline(can->pix,pa,len);
         }  //      for ( i = 0; i < len-1; i++ ) {
   //              DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
   //      }
 #else  #else
         XDrawLines(display,can->pix,drawGC,          XDrawLines(display,can->pix,drawGC,
                 can->pa[0].pos,can->pa[0].length,CoordModeOrigin);                  can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
Line 178  struct canvas *can;
Line 323  struct canvas *can;
 #endif  #endif
 }  }
   
 draw_point(display,can,x,y)  void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color)
 DISPLAY *display;  
 struct canvas *can;  
 int x,y;  
 {  {
 #if defined(VISUAL)  #if defined(VISUAL)
         HDC dc;          HDC dc;
   
         y = can->height-y;          SetPixel(can->pix,x,y,(COLORREF)color);
         DRAWPOINT(display,can->pix,drawGC,x,y);  
         dc = GetDC(can->hwnd);          dc = GetDC(can->hwnd);
         DRAWPOINT(display,dc,drawGC,x,y);          SetPixel(dc,x,y,(COLORREF)color);
         ReleaseDC(can->hwnd,dc);          ReleaseDC(can->hwnd,dc);
 #else  #else
         y = can->height-y;          set_drawcolor(color);
         DRAWPOINT(display,can->pix,drawGC,x,y);          DRAWPOINT(display,can->pix,cdrawGC,x,y);
         DRAWPOINT(display,can->window,drawGC,x,y);          DRAWPOINT(display,can->window,cdrawGC,x,y);
         XFlush(display);          XFlush(display);
 #endif  #endif
 }  }
   
 draw_line(display,can,x,y,u,v)  void draw_line(DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color)
 DISPLAY *display;  
 struct canvas *can;  
 int x,y,u,v;  
 {  {
 #if defined(VISUAL)  #if defined(VISUAL)
         HDC dc;          HDC dc;
           HPEN pen,oldpen;
   
         y = can->height-y;          if ( color ) {
         v = can->height-v;                  pen = CreatePen(PS_SOLID,1,color);
         DRAWLINE(display,can->pix,drawGC,x,y,u,v);                  oldpen = SelectObject(can->pix,pen);
         dc = GetDC(can->hwnd);                  DRAWLINE(display,can->pix,drawGC,x,y,u,v);
         DRAWLINE(display,dc,drawGC,x,y,u,v);                  SelectObject(can->pix,oldpen);
         ReleaseDC(can->hwnd,dc);  
                   dc = GetDC(can->hwnd);
                   oldpen = SelectObject(dc,pen);
                   DRAWLINE(display,dc,drawGC,x,y,u,v);
                   SelectObject(dc,oldpen);
                   ReleaseDC(can->hwnd,dc);
   
                   DeleteObject(pen);
           } else {
                   DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                   dc = GetDC(can->hwnd);
                   DRAWLINE(display,dc,drawGC,x,y,u,v);
                   ReleaseDC(can->hwnd,dc);
           }
 #else  #else
         y = can->height-y;          set_drawcolor(color);
         v = can->height-v;          DRAWLINE(display,can->pix,cdrawGC,x,y,u,v);
         DRAWLINE(display,can->pix,drawGC,x,y,u,v);          DRAWLINE(display,can->window,cdrawGC,x,y,u,v);
         DRAWLINE(display,can->window,drawGC,x,y,u,v);  
         XFlush(display);          XFlush(display);
 #endif  #endif
 }  }
   
   void draw_character_string(DISPLAY *display,struct canvas *can,int x,int y,char *str,int color)
   {
   #if defined(VISUAL)
           HDC dc;
           COLORREF oldcolor;
   
           if ( color ) {
                   oldcolor = SetTextColor(can->pix,color);
                   DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
                   SetTextColor(can->pix,oldcolor);
   
                   dc = GetDC(can->hwnd);
                   oldcolor = SetTextColor(dc,color);
                   DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
                   SetTextColor(dc,oldcolor);
                   ReleaseDC(can->hwnd,dc);
           } else {
                   DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
                   dc = GetDC(can->hwnd);
                   DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
                   ReleaseDC(can->hwnd,dc);
           }
   #else
           set_drawcolor(color);
           DRAWSTRING(display,can->pix,cdrawGC,x,y,str,strlen(str));
           DRAWSTRING(display,can->window,cdrawGC,x,y,str,strlen(str));
           XFlush(display);
   #endif
   }
   
 #define D 5  #define D 5
   
 pline(display,can,d)  void pline(DISPLAY *display,struct canvas *can,DRAWABLE d)
 DISPLAY *display;  
 struct canvas *can;  
 DRAWABLE d;  
 {  {
         double w,w1,k,e,n;          double w,w1,e,n;
         int x0,y0,x,y,xadj,yadj;          int x0,y0,x,y,xadj,yadj;
         char buf[BUFSIZ];          char buf[BUFSIZ];
         double adjust_scale();          double adjust_scale();
Line 242  DRAWABLE d;
Line 420  DRAWABLE d;
   
         xadj = yadj = 0;          xadj = yadj = 0;
         if ( (can->xmin < 0) && (can->xmax > 0) ) {          if ( (can->xmin < 0) && (can->xmax > 0) ) {
                 x0 = (int)((can->width-1)*(-can->xmin/(can->xmax-can->xmin)));                  x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
                 DRAWLINE(display,d,dashGC,x0,0,x0,can->height);                  DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
         } else if ( can->xmin >= 0 )          } else if ( can->xmin >= 0 )
                 x0 = 0;                  x0 = 0;
         else          else
                 x0 = can->width-1-D;                  x0 = can->width-D;
         if ( (can->ymin < 0) && (can->ymax > 0) ) {          if ( (can->ymin < 0) && (can->ymax > 0) ) {
                 y0 = (int)((can->height-1)*(can->ymax/(can->ymax-can->ymin)));                  y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
                 DRAWLINE(display,d,dashGC,0,y0,can->width,y0);                  DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
         } else if ( can->ymin >= 0 )          } else if ( can->ymin >= 0 )
                 y0 = can->height-1;                  y0 = can->height;
         else          else
                 y0 = D;                  y0 = D;
   
           /* scale on x-axis */
         w = can->xmax-can->xmin;          w = can->xmax-can->xmin;
         w1 = w * DEFAULTWIDTH/can->width;          w1 = w * DEFAULTWIDTH/can->width;
         e = adjust_scale(EXP10(floor(log10(w1))),w1);          e = adjust_scale(EXP10(floor(log10(w1))),w1);
         for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {          for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
                 x = (int)can->width*(n*e-can->xmin)/w;                  x = (int)(can->width*(n*e-can->xmin)/w);
                 DRAWLINE(display,d,drawGC,x,y0,x,y0-D);                  DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                 sprintf(buf,"%g",n*e);                  sprintf(buf,"%g",n*e);
                 DRAWSTRING(display,d,scaleGC,x+2,y0,buf,strlen(buf));                  DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
         }          }
   
           /* scale on y-axis */
         w = can->ymax-can->ymin;          w = can->ymax-can->ymin;
         w1 = w * DEFAULTHEIGHT/can->height;          w1 = w * DEFAULTHEIGHT/can->height;
         e = adjust_scale(EXP10(floor(log10(w1))),w1);          e = adjust_scale(EXP10(floor(log10(w1))),w1);
         if ( w == 0 )  
                 printf("afo");  
         for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {          for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
                 y = (int)can->height*(1-(n*e-can->ymin)/w);                  y = (int)(can->height*(1-(n*e-can->ymin)/w));
                 DRAWLINE(display,d,drawGC,x0,y,x0+D,y);                  DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                 sprintf(buf,"%g",n*e);                  sprintf(buf,"%g",n*e);
                 if ( can->xmax <= 0 )                  if ( can->xmax <= 0 ) {
   #if !defined(VISUAL)
                         xadj = TEXTWIDTH(sffs,buf,strlen(buf));                          xadj = TEXTWIDTH(sffs,buf,strlen(buf));
                 DRAWSTRING(display,d,scaleGC,x0-xadj,y,buf,strlen(buf));  #else
                           SIZE size;
   
                           GetTextExtentPoint32(d,buf,strlen(buf),&size);
                           xadj = size.cx;
   #endif
                   }
                   DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
         }          }
 }  }
   
 double adjust_scale(e,w)  double adjust_scale(double e,double w)
 double e,w;  
 {  {
         switch ( (int)floor(w/e) ) {          switch ( (int)floor(w/e) ) {
                 case 1:                  case 1:
Line 295  double e,w;
Line 482  double e,w;
         }          }
 }  }
   
 initmarker(can,message)  void initmarker(struct canvas *can,char *message)
 struct canvas *can;  
 char *message;  
 {  {
 #if defined(VISUAL)  #if defined(VISUAL)
         can->real_can->percentage = 0;          can->real_can->percentage = 0;
Line 309  char *message;
Line 494  char *message;
 #endif  #endif
 }  }
   
 marker(can,dir,p)  void marker(struct canvas *can,int dir,int p)
 struct canvas *can;  
 int dir,p;  
 {  {
 #if defined(VISUAL)  #if defined(VISUAL)
         if ( dir == DIR_X )          if ( dir == DIR_X )
                 can->real_can->percentage = ceil((float)p/(float)can->real_can->width*100);                  can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->width*100);
         else if ( dir == DIR_Y )          else if ( dir == DIR_Y )
                 can->real_can->percentage = ceil((float)p/(float)can->real_can->height*100);                  can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->height*100);
         else          else
                 can->real_can->percentage = ceil((float)p/(float)can->real_can->nzstep*100);                  can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->nzstep*100);
 #else  #else
         if ( dir == DIR_X ) {          if ( dir == DIR_X ) {
                 XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);                  XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
Line 334  int dir,p;
Line 517  int dir,p;
 #endif  #endif
 }  }
   
 define_cursor(w,cur)  void define_cursor(WINDOW w,CURSOR cur)
 WINDOW w;  
 CURSOR cur;  
 {  {
 #if !defined(VISUAL)  #if !defined(VISUAL)
         XDefineCursor(display,w,cur); flush();          XDefineCursor(display,w,cur); flush();
Line 350  static int flush_count;
Line 531  static int flush_count;
 #define MAX_COUNT 32  #define MAX_COUNT 32
 #endif  #endif
   
 count_and_flush() {  void count_and_flush() {
 #if !defined(VISUAL)  #if !defined(VISUAL)
         if ( ++flush_count == MAX_COUNT )          if ( ++flush_count == MAX_COUNT )
                 flush();                  flush();
 #endif  #endif
 }  }
   
 flush() {  void flush() {
 #if !defined(VISUAL)  #if !defined(VISUAL)
         flush_count = 0;          flush_count = 0;
         XFlush(display);          XFlush(display);

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.14

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>