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

Annotation of OpenXM_contrib2/asir2000/plot/plotp.c, Revision 1.20

1.3       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.4       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.20    ! saito      48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.19 2014/06/27 07:58:29 saito Exp $
1.3       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "ox.h"
                     53: #include "ifplot.h"
1.2       noro       54: #include <math.h>
1.1       noro       55:
                     56: #if defined(sun) && !defined(__svr4__)
                     57: #define EXP10(a) exp10(a)
                     58: #else
                     59: #define EXP10(a) pow(10.0,a)
                     60: #endif
                     61:
1.5       noro       62: #if defined(VISUAL)
                     63: static POINT oldpos;
                     64: #endif
                     65:
1.14      saito      66: unsigned long GetColor(Display *, char *);
                     67:
                     68: unsigned long GetColor(Display *dis, char *color_name)
                     69: {
                     70:        Colormap cmap;
                     71:        XColor near_color, true_color;
                     72:
                     73:        cmap = DefaultColormap( dis, 0 );
                     74:        XAllocNamedColor( dis, cmap, color_name, &near_color, &true_color );
                     75:        return( near_color.pixel );
                     76: }
                     77:
1.16      saito      78: void area_print(DISPLAY *display,double **tab,struct canvas *can,int GXcode){
                     79:        int ix,iy,width,height,wc,**mask;
1.14      saito      80:        XImage *image;
1.16      saito      81:        DRAWABLE pix;
1.19      saito      82:        unsigned int color,black,white,c2;
                     83:        //unsigned long color,black,white,c2;
1.16      saito      84:        double *px,*px1,*px2;
                     85:        //GXcode 0:new 1:cp 2:and 3:or 4:xor
                     86:        width=can->width;
                     87:        height=can->height;
                     88:        pix=can->pix;
                     89:        mask=(int **)ALLOCA((width)*sizeof(int *));
                     90:        for(ix=0;ix<width;ix++)mask[ix]=(int *)ALLOCA((height)*sizeof(int));
                     91:        // create mask table values boundary:0 positive:1 negativ:-1
                     92:        for(ix=0;ix<width;ix++)for(iy=0;iy<height;iy++)
                     93:                if((tab[ix][iy]>0)&&(tab[ix+1][iy]>0)&&(tab[ix][iy+1]>0)&&
                     94:                        (tab[ix+1][iy+1]>0)) mask[ix][iy]=1;//all postive
                     95:                else if((tab[ix][iy]<0)&&(tab[ix+1][iy]<0)&&(tab[ix][iy+1]<0)&&
                     96:                        (tab[ix+1][iy+1]<0)) mask[ix][iy]=-1;//all negativ
                     97:                else mask[ix][iy]=0;//boundary
1.14      saito      98:        flush();
1.16      saito      99:        black=GetColor(display,"black");
                    100:        white=GetColor(display,"white");
                    101:        set_drawcolor(can->color);
                    102:        color=can->color;
                    103:        image=XGetImage(display,pix,0,0,width,height,-1,ZPixmap);
                    104:        for(ix=0;ix<width;ix++){
                    105:                for(iy=0;iy<height;iy++){
                    106:                        c2=XGetPixel(image,ix,height-iy-1);
                    107:                        if(c2==white)wc=-1;
                    108:                        else if(c2==black)wc=0;
                    109:                        else wc=1;
                    110:                        if(wc!=0){//XPutPixel(image,ix,iy,black);
                    111:                                if(mask[ix][iy]==0)XPutPixel(image,ix,height-iy-1,black);//boundary
1.14      saito     112:                                else {
1.16      saito     113:                                        switch (GXcode){
                    114:                                        case 0: //new window
                    115:                                        case 1: //cp
                    116:                                                if(mask[ix][iy]==1)XPutPixel(image,ix,height-iy-1,color);
                    117:                                                else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14      saito     118:                                                break;
1.16      saito     119:                                        case 2: //and
                    120:                                                if((mask[ix][iy]==1)&&(wc==1))XPutPixel(image,ix,height-iy-1,color);
                    121:                                                else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14      saito     122:                                                break;
1.16      saito     123:                                        case 3: //or
                    124:                                                if((mask[ix][iy]==1)||(wc==1))XPutPixel(image,ix,height-iy-1,color);
                    125:                                                else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14      saito     126:                                                break;
1.16      saito     127:                                        case 4: //xor
                    128:                                                if((mask[ix][iy]==1)^(wc==1))XPutPixel(image,ix,height-iy-1,color);
                    129:                                                else XPutPixel(image,ix,height-iy-1,BackPixel);
1.14      saito     130:                                                break;
                    131:                                        }
                    132:                                }
                    133:                        }
                    134:                }
                    135:        }
1.16      saito     136:        XPutImage(display,pix,drawGC,image,0,0,0,0,width,height);
1.14      saito     137:        count_and_flush();
                    138:        flush();
                    139: }
1.16      saito     140:
                    141: void over_print(DISPLAY *display,double **tab,struct canvas *can,int GXcode){
                    142:        int ix,iy,width,height;
                    143:        DRAWABLE pix;
                    144:        double vmin,vmax;
                    145:        //GXcode 0:over 1:cp 2:and 3:or 4:xor
                    146:        pix=can->pix; width=can->width; height=can->height;
                    147:        for(ix=0;ix<width;ix++){
                    148:                for(iy=0;iy<height;iy++){
                    149:                        vmax=
                    150:                        MAX(MAX(tab[ix][iy],tab[ix][iy+1]),MAX(tab[ix+1][iy],tab[ix+1][iy+1]));
                    151:                        vmin=
                    152:                        MIN(MIN(tab[ix][iy],tab[ix][iy+1]),MIN(tab[ix+1][iy],tab[ix+1][iy+1]));
                    153:                        if(vmin<=0.0&vmax>=0.0)DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                    154:                }
                    155:                count_and_flush();
                    156:        }
                    157:        flush();
                    158: }
1.14      saito     159:
1.19      saito     160: void if_printNG(DISPLAY *display,double **tab,struct canvas *can,int cond){
1.1       noro      161:        int ix,iy,width,height;
1.16      saito     162:        double zst,zed,zsp;
                    163:        DRAWABLE pix;
                    164:        width=can->width; height=can->height; pix=can->pix;
                    165:        if(cond==0){
1.17      saito     166:                //IFPLOTB
1.16      saito     167:                for(iy=0;iy<height-1;iy++)for(ix=0;ix<width-1;ix++)
                    168:                        if(tab[ix][iy]==0.0) DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.17      saito     169:        } else if(cond==1) {
                    170:                //IFPLOT,IFPLOTD,IFPLOTQ
1.16      saito     171:                for(iy=0;iy<height-1;iy++)for(ix=0;ix<width-1;ix++){
                    172:                        if(tab[ix][iy]==0.0) DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                    173:                        else if(tab[ix][iy]>0){
                    174:                                if(tab[ix+1][iy+1]<0||tab[ix][iy+1]<0||tab[ix+1][iy]<0)
                    175:                                        DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                    176:                        } else if(tab[ix+1][iy+1]>0||tab[ix][iy+1]>0||tab[ix+1][iy]>0)
                    177:                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                    178:                        count_and_flush();
                    179:                }
                    180:        }
                    181:        flush();
                    182: }
                    183:
1.17      saito     184: void polar_print(DISPLAY *display,struct canvas *can){
1.19      saito     185:        int len,i,j,x,y;
                    186:        unsigned int color;
1.17      saito     187:        POINT *pa;
                    188:
1.18      ohara     189: #if defined(VISUAL)
                    190:        HDC dc;
                    191:        HPEN pen,oldpen;
1.17      saito     192:        len=can->pa[0].length;
                    193:        color=can->color;
                    194:        pa=can->pa[0].pos;
                    195:        for(i=1;i<len;i++){
                    196:                j=i-1;
                    197:                if(color){
                    198:                        pen=CreatePen(PS_SOLID,1,color);
                    199:                        oldpen=SelectObject(can->pix,pen);
                    200:                        DRAWLINE(display,can->pix,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i]));
                    201:                        SelectObject(can->pix,oldpen);
                    202:
                    203:                        dc = GetDC(can->hwnd);
                    204:                        oldpen = SelectObject(dc,pen);
                    205:                        DRAWLINE(display,dc,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i]));
                    206:                        SelectObject(dc,oldpen);
                    207:                        ReleaseDC(can->hwnd,dc);
                    208:
                    209:                        DeleteObject(pen);
                    210:                } else {
                    211:                        DRAWLINE(display,can->pix,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i]));
                    212:                        dc = GetDC(can->hwnd);
                    213:                        DRAWLINE(display,dc,drawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i]));
                    214:                        ReleaseDC(can->hwnd,dc);
                    215:                }
                    216:        }
                    217: #else
1.18      ohara     218:        len=can->pa[0].length;
                    219:        color=can->color;
                    220:        pa=can->pa[0].pos;
1.17      saito     221:        for(i=1;i<len;i++){
                    222:                j=i-1;
                    223:                DRAWLINE(display,can->pix,cdrawGC,XC(pa[j]),YC(pa[j]),XC(pa[i]),YC(pa[i]));
                    224:        }
                    225:        XFlush(display);
                    226: #endif
                    227: }
                    228:
                    229:
1.19      saito     230: void if_print(DISPLAY *display,double **tab,struct canvas *can){
                    231:        int ix,iy,width,height;
                    232:        double *px,*px1,*px2;
                    233:        DRAWABLE pix;
                    234:
                    235:        if ( can->mode == modeNO(CONPLOT) ) {
                    236:                con_print(display,tab,can); return;
                    237:        }
                    238:        flush();
                    239:        width = can->width; height = can->height; pix = can->pix;
                    240:        for( ix=0; ix<width-1; ix++ )
                    241:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    242:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                    243:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                    244:                                ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                    245:                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                    246:                count_and_flush();
                    247:        }
                    248:        flush();
                    249: /*
1.16      saito     250:        int i,ix,iy,width,height;
1.1       noro      251:        double *px,*px1,*px2;
1.16      saito     252:        double **vmax,**vmin,*zst,zstep,zv,u,l;
1.1       noro      253:        DRAWABLE pix;
1.16      saito     254:        POINT *pa,*pa1;
                    255:        struct pa *parray;
1.1       noro      256:
1.17      saito     257:        if(can->mode==modeNO(CONPLOT)){
1.16      saito     258:                width=can->width;height=can->height;pix=can->pix;
                    259:                //con_print(display,tab,can);
                    260:          // calc all cell max,min value
                    261:                vmax=((double **)ALLOCA((width+1)*sizeof(double *)));
                    262:                vmin=((double **)ALLOCA((width+1)*sizeof(double *)));
                    263:                for(i=0;i<width;i++){
                    264:                        vmax[i]=(double *)ALLOCA((height+1)*sizeof(double));
                    265:                        vmin[i]=(double *)ALLOCA((height+1)*sizeof(double));
                    266:                }
                    267:                for(ix=0;ix<width;ix++){
                    268:                        for(iy=0;iy<height;iy++){
                    269:                                vmax[ix][iy]=
                    270:                                MAX(MAX(tab[ix][iy],tab[ix][iy+1]),MAX(tab[ix+1][iy],tab[ix+1][iy+1]));
                    271:                                vmin[ix][iy]=
                    272:                                MIN(MIN(tab[ix][iy],tab[ix][iy+1]),MIN(tab[ix+1][iy],tab[ix+1][iy+1]));
                    273:                        }
                    274:                }
                    275:                if(can->zmax==can->zmin)zstep=(can->vmax-can->vmin)/can->nzstep;
                    276:                else zstep=(can->zmax-can->zmin)/can->nzstep;
                    277:                zst=(double *)ALLOCA((can->nzstep+1)*sizeof(double));
                    278:                zv=can->xmin;
                    279:                for(i=0,zv=can->xmin;i<can->nzstep;zv+=zstep,i++)zst[i]=zv;
                    280:                for(iy=0;iy<height-1;iy++){
                    281:                        for(ix=0;ix<width-1;ix++){
                    282:                                for(i=0;i<can->nzstep;i++){
                    283:                                        if(vmin[ix][iy]<=zst[i] && vmax[ix][iy]>=zst[i]){
                    284:                                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                    285:                                                break;
                    286:                                        }
                    287:                                        count_and_flush();
                    288:                                }
                    289:                        }
                    290:                }
                    291:        } else {
                    292:                width=can->width;height=can->height;pix=can->pix;
                    293:                for(ix=0;ix<width-1;ix++)
                    294:                for(iy=0,px=tab[ix],px1=tab[ix+1],px2=px+1;iy<height-1;
                    295:                        iy++,px++,px1++,px2++)
                    296:                        if(((*px>=0)&&((*px1<=0)||(*px2<=0)))||
                    297:                                ((*px<=0)&&((*px1>=0)||(*px2>=0)))){
1.12      noro      298:                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1       noro      299:                                count_and_flush();
                    300:                        }
1.16      saito     301:        }
1.1       noro      302:        flush();
1.19      saito     303: */
1.1       noro      304: }
                    305:
1.8       noro      306: #define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7)))
                    307:
1.16      saito     308: void memory_if_print(double **tab,struct canvas *can,BYTEARRAY *bytes){
1.8       noro      309:        int ix,iy,width,height;
                    310:        double *px,*px1,*px2;
                    311:        unsigned char *array;
                    312:        int scan_len;
1.17      saito     313:        if ( can->mode==modeNO(CONPLOT)){
1.16      saito     314:                memory_con_print(tab,can,bytes);
                    315:                return;
1.8       noro      316:        }
                    317:        width = can->width; height = can->height;
1.16      saito     318:        // scan_len = byte length of the scan line
1.8       noro      319:        scan_len = (width+7)/8;
                    320:        MKBYTEARRAY(*bytes,scan_len*height);
                    321:        array = BDY(*bytes);
                    322:        for( ix=0; ix<width-1; ix++ )
                    323:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    324:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                    325:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                    326:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                    327:                                MEMORY_DRAWPOINT(array,scan_len,ix,height-iy-1);
                    328:                        }
                    329: }
                    330:
1.16      saito     331: void con_print(DISPLAY *display,double **tab,struct canvas *can){
                    332:        int i,ix,iy,width,height;
1.1       noro      333:        double *px,*px1,*px2;
1.16      saito     334:        double **vmax,**vmin,*zst,zstep,zv,u,l;
1.1       noro      335:        DRAWABLE pix;
                    336:        POINT *pa,*pa1;
                    337:        struct pa *parray;
                    338:
1.16      saito     339:        width=can->width;height=can->height;pix=can->pix;
                    340:        vmax=((double **)ALLOCA((width+1)*sizeof(double *)));
                    341:        vmin=((double **)ALLOCA((width+1)*sizeof(double *)));
                    342:        for(i=0;i<width;i++){
                    343:                vmax[i]=(double *)ALLOCA((height+1)*sizeof(double));
                    344:                vmin[i]=(double *)ALLOCA((height+1)*sizeof(double));
                    345:        }
                    346:        for(ix=0;ix<width;ix++){
                    347:                for(iy=0;iy<height;iy++){
                    348:                        vmax[ix][iy]=
                    349:                        MAX(MAX(tab[ix][iy],tab[ix][iy+1]),MAX(tab[ix+1][iy],tab[ix+1][iy+1]));
                    350:                        vmin[ix][iy]=
                    351:                        MIN(MIN(tab[ix][iy],tab[ix][iy+1]),MIN(tab[ix+1][iy],tab[ix+1][iy+1]));
                    352:                }
                    353:        }
                    354:        if(can->zmax==can->zmin)zstep=(can->vmax-can->vmin)/can->nzstep;
                    355:        else zstep=(can->zmax-can->zmin)/can->nzstep;
                    356:        zst=(double *)ALLOCA((can->nzstep+1)*sizeof(double));
                    357:        zv=can->xmin;
                    358:        for(i=0,zv=can->xmin;i<can->nzstep;zv+=zstep,i++)zst[i]=zv;
                    359:        for(iy=0;iy<height-1;iy++){
                    360:                for(ix=0;ix<width-1;ix++){
                    361:                        for(i=0;i<can->nzstep;i++){
                    362:                                if(vmin[ix][iy]<=zst[i] && vmax[ix][iy]>=zst[i]){
                    363:                                        DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
                    364:                                        break;
1.1       noro      365:                                }
1.16      saito     366:                                count_and_flush();
                    367:                        }
1.1       noro      368:                }
                    369:        }
                    370:        flush();
1.8       noro      371: }
                    372:
1.16      saito     373: void memory_con_print(double **tab,struct canvas *can,BYTEARRAY *bytes){
1.8       noro      374:        int ix,iy,iz,width,height,pas,pai,len;
                    375:        double zstep,z;
                    376:        double *px,*px1,*px2;
                    377:        POINT *pa,*pa1;
                    378:        struct pa *parray;
                    379:        unsigned char *array;
                    380:        int scan_len;
                    381:
                    382:        width = can->width; height = can->height;
                    383:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    384:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    385:        pas = width;
                    386:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    387:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    388:                pai = 0;
                    389:                for( ix=0; ix<width-1; ix++ )
                    390:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    391:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    392:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    393:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    394:                                        if ( pai == pas ) {
                    395:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    396:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    397:                                                pas += pas;
                    398:                                        }
                    399:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    400:                                }
                    401:                can->pa[iz].length = pai;
                    402:                if ( pai ) {
                    403:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    404:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    405:                        can->pa[iz].pos = pa1;
                    406:                }
                    407:        }
                    408:        /* scan_len = byte length of the scan line */
                    409:        scan_len = (width+7)/8;
                    410:        MKBYTEARRAY(*bytes,scan_len*height);
                    411:        array = BDY(*bytes);
                    412:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    413:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                    414:                        MEMORY_DRAWPOINT(array,scan_len,XC(pa[ix]),YC(pa[ix]));
                    415:                }
1.13      noro      416: }
                    417:
1.16      saito     418: void memory_print(struct canvas *can,BYTEARRAY *bytes){
1.13      noro      419:        int len,scan_len,i;
                    420:        POINT *pa;
                    421:        char *array;
                    422:
                    423:        /* scan_len = byte length of the scan line */
                    424:        scan_len = (can->width+7)/8;
                    425:        MKBYTEARRAY(*bytes,scan_len*can->height);
1.17      saito     426:        array = (char*)BDY(*bytes);
1.13      noro      427:
                    428:        len = can->pa[0].length;
                    429:        pa = can->pa[0].pos;
                    430:        for ( i = 0; i < len; i++ ) {
                    431:                MEMORY_DRAWPOINT(array,scan_len,pa[i].x,pa[i].y);
                    432:        }
1.1       noro      433: }
                    434:
1.16      saito     435: void qif_print(DISPLAY *display,char **tab,struct canvas *can){
1.1       noro      436:        int ix,iy,width,height;
                    437:        char *px;
                    438:        DRAWABLE pix;
                    439:
                    440:        flush();
                    441:        width = can->width; height = can->height; pix = can->pix;
                    442:        for( ix = 0; ix < width; ix++ )
                    443:                for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                    444:                        if ( *px ) {
1.12      noro      445:                                DRAWPOINT(display,pix,cdrawGC,ix,height-iy-1);
1.1       noro      446:                                count_and_flush();
                    447:                        }
                    448:        flush();
                    449: }
                    450:
1.16      saito     451: void plot_print(DISPLAY *display,struct canvas *can){
1.9       noro      452:        int len;
1.1       noro      453:        POINT *pa;
1.5       noro      454:
                    455: #if defined(VISUAL)
                    456:        len = can->pa[0].length;
                    457:        pa = can->pa[0].pos;
1.6       noro      458:
                    459:        Polyline(can->pix,pa,len);
                    460: //     for ( i = 0; i < len-1; i++ ) {
                    461: //             DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
                    462: //     }
1.5       noro      463: #else
1.1       noro      464:        XDrawLines(display,can->pix,drawGC,
                    465:                can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
                    466:        XFlush(display);
1.5       noro      467: #endif
                    468: }
                    469:
1.19      saito     470: void draw_point(DISPLAY *display,struct canvas *can,int x,int y,unsigned int color){
                    471: //void draw_point(DISPLAY *display,struct canvas *can,int x,int y,int color){
1.5       noro      472: #if defined(VISUAL)
                    473:        HDC dc;
                    474:
1.6       noro      475:        SetPixel(can->pix,x,y,(COLORREF)color);
1.5       noro      476:        dc = GetDC(can->hwnd);
1.6       noro      477:        SetPixel(dc,x,y,(COLORREF)color);
1.5       noro      478:        ReleaseDC(can->hwnd,dc);
                    479: #else
1.12      noro      480:        set_drawcolor(color);
                    481:        DRAWPOINT(display,can->pix,cdrawGC,x,y);
                    482:        DRAWPOINT(display,can->window,cdrawGC,x,y);
1.5       noro      483:        XFlush(display);
                    484: #endif
                    485: }
                    486:
1.16      saito     487: void draw_line(
1.19      saito     488:        DISPLAY *display,struct canvas *can,int x,int y,int u,int v,unsigned int color){
                    489:        //DISPLAY *display,struct canvas *can,int x,int y,int u,int v,int color){
1.5       noro      490: #if defined(VISUAL)
                    491:        HDC dc;
1.6       noro      492:        HPEN pen,oldpen;
1.5       noro      493:
1.6       noro      494:        if ( color ) {
                    495:                pen = CreatePen(PS_SOLID,1,color);
                    496:                oldpen = SelectObject(can->pix,pen);
                    497:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                    498:                SelectObject(can->pix,oldpen);
                    499:
                    500:                dc = GetDC(can->hwnd);
                    501:                oldpen = SelectObject(dc,pen);
                    502:                DRAWLINE(display,dc,drawGC,x,y,u,v);
                    503:                SelectObject(dc,oldpen);
                    504:                ReleaseDC(can->hwnd,dc);
                    505:
                    506:                DeleteObject(pen);
                    507:        } else {
                    508:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                    509:                dc = GetDC(can->hwnd);
                    510:                DRAWLINE(display,dc,drawGC,x,y,u,v);
                    511:                ReleaseDC(can->hwnd,dc);
                    512:        }
1.5       noro      513: #else
1.12      noro      514:        set_drawcolor(color);
                    515:        DRAWLINE(display,can->pix,cdrawGC,x,y,u,v);
                    516:        DRAWLINE(display,can->window,cdrawGC,x,y,u,v);
1.10      noro      517:        XFlush(display);
                    518: #endif
                    519: }
                    520:
1.16      saito     521: void draw_character_string(
1.19      saito     522:        DISPLAY *display,struct canvas *can,int x,int y,char *str,unsigned int color){
                    523:        //DISPLAY *display,struct canvas *can,int x,int y,char *str,int color){
1.10      noro      524: #if defined(VISUAL)
                    525:        HDC dc;
1.11      noro      526:        COLORREF oldcolor;
1.10      noro      527:
                    528:        if ( color ) {
1.11      noro      529:                oldcolor = SetTextColor(can->pix,color);
1.10      noro      530:                DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
1.11      noro      531:                SetTextColor(can->pix,oldcolor);
1.10      noro      532:
                    533:                dc = GetDC(can->hwnd);
1.11      noro      534:                oldcolor = SetTextColor(dc,color);
1.10      noro      535:                DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
1.11      noro      536:                SetTextColor(dc,oldcolor);
1.10      noro      537:                ReleaseDC(can->hwnd,dc);
                    538:        } else {
                    539:                DRAWSTRING(display,can->pix,drawGC,x,y,str,strlen(str));
                    540:                dc = GetDC(can->hwnd);
                    541:                DRAWSTRING(display,dc,drawGC,x,y,str,strlen(str));
                    542:                ReleaseDC(can->hwnd,dc);
                    543:        }
                    544: #else
1.12      noro      545:        set_drawcolor(color);
                    546:        DRAWSTRING(display,can->pix,cdrawGC,x,y,str,strlen(str));
                    547:        DRAWSTRING(display,can->window,cdrawGC,x,y,str,strlen(str));
1.5       noro      548:        XFlush(display);
                    549: #endif
1.1       noro      550: }
                    551:
                    552: #define D 5
                    553:
1.16      saito     554: void pline(DISPLAY *display,struct canvas *can,DRAWABLE d){
1.9       noro      555:        double w,w1,e,n;
1.1       noro      556:        int x0,y0,x,y,xadj,yadj;
                    557:        char buf[BUFSIZ];
                    558:        double adjust_scale();
                    559:
1.5       noro      560:        /* XXX : should be cleaned up */
1.17      saito     561:        if ( can->noaxis || (can->mode==modeNO(PLOT)&& !can->pa) )
1.5       noro      562:                return;
1.17      saito     563:        if ( can->mode==modeNO(INTERACTIVE))
1.1       noro      564:                return;
                    565:
                    566:        xadj = yadj = 0;
                    567:        if ( (can->xmin < 0) && (can->xmax > 0) ) {
1.6       noro      568:                x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
1.1       noro      569:                DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
                    570:        } else if ( can->xmin >= 0 )
                    571:                x0 = 0;
                    572:        else
1.6       noro      573:                x0 = can->width-D;
1.1       noro      574:        if ( (can->ymin < 0) && (can->ymax > 0) ) {
1.6       noro      575:                y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
1.1       noro      576:                DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
                    577:        } else if ( can->ymin >= 0 )
1.6       noro      578:                y0 = can->height;
1.1       noro      579:        else
                    580:                y0 = D;
1.6       noro      581:
                    582:        /* scale on x-axis */
1.1       noro      583:        w = can->xmax-can->xmin;
                    584:        w1 = w * DEFAULTWIDTH/can->width;
                    585:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    586:        for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
1.9       noro      587:                x = (int)(can->width*(n*e-can->xmin)/w);
1.1       noro      588:                DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                    589:                sprintf(buf,"%g",n*e);
1.6       noro      590:                DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
1.1       noro      591:        }
1.6       noro      592:
                    593:        /* scale on y-axis */
1.1       noro      594:        w = can->ymax-can->ymin;
                    595:        w1 = w * DEFAULTHEIGHT/can->height;
                    596:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    597:        for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
1.9       noro      598:                y = (int)(can->height*(1-(n*e-can->ymin)/w));
1.1       noro      599:                DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                    600:                sprintf(buf,"%g",n*e);
1.6       noro      601:                if ( can->xmax <= 0 ) {
                    602: #if !defined(VISUAL)
1.1       noro      603:                        xadj = TEXTWIDTH(sffs,buf,strlen(buf));
1.6       noro      604: #else
                    605:                        SIZE size;
                    606:
                    607:                        GetTextExtentPoint32(d,buf,strlen(buf),&size);
                    608:                        xadj = size.cx;
                    609: #endif
                    610:                }
                    611:                DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
1.1       noro      612:        }
                    613: }
                    614:
1.16      saito     615: double adjust_scale(double e,double w){
1.1       noro      616:        switch ( (int)floor(w/e) ) {
                    617:                case 1:
                    618:                        return e/4; break;
                    619:                case 2: case 3:
                    620:                        return e/2; break;
                    621:                case 4: case 5: case 6: case 7:
                    622:                        return e; break;
                    623:                        break;
                    624:                case 8: case 9: case 10: default:
                    625:                        return 2*e; break;
                    626:        }
                    627: }
                    628:
1.16      saito     629: void initmarker(struct canvas *can,char *message){
1.5       noro      630: #if defined(VISUAL)
                    631:        can->real_can->percentage = 0;
                    632:        can->real_can->prefix = message;
                    633: #else
1.1       noro      634:        XawScrollbarSetThumb(can->xdone,0.0,0.0);
                    635:        XawScrollbarSetThumb(can->ydone,1.0,0.0);
                    636:        XFlush(display);
1.5       noro      637: #endif
1.1       noro      638: }
                    639:
1.16      saito     640: void marker(struct canvas *can,int dir,int p){
1.5       noro      641: #if defined(VISUAL)
                    642:        if ( dir == DIR_X )
1.9       noro      643:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->width*100);
1.5       noro      644:        else if ( dir == DIR_Y )
1.9       noro      645:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->height*100);
1.5       noro      646:        else
1.9       noro      647:                can->real_can->percentage = (int)ceil((float)p/(float)can->real_can->nzstep*100);
1.5       noro      648: #else
1.1       noro      649:        if ( dir == DIR_X ) {
                    650:                XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
                    651:                count_and_flush();
                    652:        } else if ( dir == DIR_Y ) {
                    653:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
                    654:                count_and_flush();
                    655:        } else {
                    656:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
                    657:                flush();
                    658:        }
1.5       noro      659: #endif
1.1       noro      660: }
                    661:
1.16      saito     662: void define_cursor(WINDOW w,CURSOR cur){
1.5       noro      663: #if !defined(VISUAL)
1.1       noro      664:        XDefineCursor(display,w,cur); flush();
1.5       noro      665: #endif
1.1       noro      666: }
                    667:
                    668: static int flush_count;
                    669: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
                    670: #define MAX_COUNT 64
                    671: #else
                    672: #define MAX_COUNT 32
                    673: #endif
                    674:
1.16      saito     675: void count_and_flush(){
1.5       noro      676: #if !defined(VISUAL)
1.1       noro      677:        if ( ++flush_count == MAX_COUNT )
                    678:                flush();
1.5       noro      679: #endif
1.1       noro      680: }
                    681:
1.16      saito     682: void flush(){
1.5       noro      683: #if !defined(VISUAL)
1.1       noro      684:        flush_count = 0;
                    685:        XFlush(display);
1.5       noro      686: #endif
1.1       noro      687: }

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