[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.6

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.6     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.5 2000/11/07 06:06:40 noro 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.1       noro       66: if_print(display,tab,can)
                     67: DISPLAY *display;
                     68: double **tab;
                     69: struct canvas *can;
                     70: {
                     71:        int ix,iy,width,height;
                     72:        double *px,*px1,*px2;
                     73:        DRAWABLE pix;
                     74:
                     75:        if ( can->mode == MODE_CONPLOT ) {
                     76:                con_print(display,tab,can); return;
                     77:        }
                     78:        flush();
                     79:        width = can->width; height = can->height; pix = can->pix;
                     80:        for( ix=0; ix<width-1; ix++ )
                     81:                for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                     82:                        iy<height-1 ;iy++, px++, px1++, px2++ )
                     83:                        if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
                     84:                                 ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
                     85:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                     86:                                count_and_flush();
                     87:                        }
                     88:        flush();
                     89: }
                     90:
                     91: con_print(display,tab,can)
                     92: DISPLAY *display;
                     93: double **tab;
                     94: struct canvas *can;
                     95: {
                     96:        int ix,iy,iz,width,height,pas,pai,len;
                     97:        double zstep,z;
                     98:        double *px,*px1,*px2;
                     99:        DRAWABLE pix;
                    100:        POINT *pa,*pa1;
                    101:        struct pa *parray;
                    102:
                    103:
                    104:        width = can->width; height = can->height; pix = can->pix;
                    105:        zstep = (can->zmax-can->zmin)/can->nzstep;
                    106:        can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
                    107:        pas = width;
                    108:        pa = (POINT *)ALLOCA(pas*sizeof(POINT));
                    109:        initmarker(can,"Drawing...");
                    110:        for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
                    111:                marker(can,DIR_Z,iz);
                    112:                pai = 0;
                    113:                for( ix=0; ix<width-1; ix++ )
                    114:                        for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
                    115:                                iy<height-1 ;iy++, px++, px1++, px2++ )
                    116:                                if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
                    117:                                         ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
                    118:                                        if ( pai == pas ) {
                    119:                                                pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
                    120:                                                bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
                    121:                                                pas += pas;
                    122:                                        }
                    123:                                        XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
                    124:                                }
                    125:                can->pa[iz].length = pai;
                    126:                if ( pai ) {
                    127:                        pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
                    128:                        bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
                    129:                        can->pa[iz].pos = pa1;
                    130:                }
                    131:        }
                    132:        flush();
                    133:        for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
                    134:                for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
                    135:                        DRAWPOINT(display,pix,drawGC,XC(pa[ix]),YC(pa[ix]));
                    136:                        count_and_flush();
                    137:                }
                    138:        flush();
                    139: }
                    140:
                    141: qif_print(display,tab,can)
                    142: DISPLAY *display;
                    143: char **tab;
                    144: struct canvas *can;
                    145: {
                    146:        int ix,iy,width,height;
                    147:        char *px;
                    148:        DRAWABLE pix;
                    149:
                    150:        flush();
                    151:        width = can->width; height = can->height; pix = can->pix;
                    152:        for( ix = 0; ix < width; ix++ )
                    153:                for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
                    154:                        if ( *px ) {
                    155:                                DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
                    156:                                count_and_flush();
                    157:                        }
                    158:        flush();
                    159: }
                    160:
                    161: plot_print(display,can)
                    162: DISPLAY *display;
                    163: struct canvas *can;
                    164: {
                    165:        int len,i;
                    166:        POINT *pa;
1.5       noro      167:
                    168: #if defined(VISUAL)
                    169:        len = can->pa[0].length;
                    170:        pa = can->pa[0].pos;
1.6     ! noro      171:
        !           172:        Polyline(can->pix,pa,len);
        !           173: //     for ( i = 0; i < len-1; i++ ) {
        !           174: //             DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
        !           175: //     }
1.5       noro      176: #else
1.1       noro      177:        XDrawLines(display,can->pix,drawGC,
                    178:                can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
                    179:        XFlush(display);
1.5       noro      180: #endif
                    181: }
                    182:
1.6     ! noro      183: draw_point(display,can,x,y,color)
1.5       noro      184: DISPLAY *display;
                    185: struct canvas *can;
                    186: int x,y;
1.6     ! noro      187: int color;
1.5       noro      188: {
                    189: #if defined(VISUAL)
                    190:        HDC dc;
                    191:
1.6     ! noro      192:        SetPixel(can->pix,x,y,(COLORREF)color);
1.5       noro      193:        dc = GetDC(can->hwnd);
1.6     ! noro      194:        SetPixel(dc,x,y,(COLORREF)color);
1.5       noro      195:        ReleaseDC(can->hwnd,dc);
                    196: #else
                    197:        DRAWPOINT(display,can->pix,drawGC,x,y);
                    198:        DRAWPOINT(display,can->window,drawGC,x,y);
                    199:        XFlush(display);
                    200: #endif
                    201: }
                    202:
1.6     ! noro      203: draw_line(display,can,x,y,u,v,color)
1.5       noro      204: DISPLAY *display;
                    205: struct canvas *can;
                    206: int x,y,u,v;
1.6     ! noro      207: int color;
1.5       noro      208: {
                    209: #if defined(VISUAL)
                    210:        HDC dc;
1.6     ! noro      211:        HPEN pen,oldpen;
1.5       noro      212:
1.6     ! noro      213:        if ( color ) {
        !           214:                pen = CreatePen(PS_SOLID,1,color);
        !           215:                oldpen = SelectObject(can->pix,pen);
        !           216:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
        !           217:                SelectObject(can->pix,oldpen);
        !           218:
        !           219:                dc = GetDC(can->hwnd);
        !           220:                oldpen = SelectObject(dc,pen);
        !           221:                DRAWLINE(display,dc,drawGC,x,y,u,v);
        !           222:                SelectObject(dc,oldpen);
        !           223:                ReleaseDC(can->hwnd,dc);
        !           224:
        !           225:                DeleteObject(pen);
        !           226:        } else {
        !           227:                DRAWLINE(display,can->pix,drawGC,x,y,u,v);
        !           228:                dc = GetDC(can->hwnd);
        !           229:                DRAWLINE(display,dc,drawGC,x,y,u,v);
        !           230:                ReleaseDC(can->hwnd,dc);
        !           231:        }
1.5       noro      232: #else
                    233:        DRAWLINE(display,can->pix,drawGC,x,y,u,v);
                    234:        DRAWLINE(display,can->window,drawGC,x,y,u,v);
                    235:        XFlush(display);
                    236: #endif
1.1       noro      237: }
                    238:
                    239: #define D 5
                    240:
                    241: pline(display,can,d)
                    242: DISPLAY *display;
                    243: struct canvas *can;
                    244: DRAWABLE d;
                    245: {
                    246:        double w,w1,k,e,n;
                    247:        int x0,y0,x,y,xadj,yadj;
                    248:        char buf[BUFSIZ];
                    249:        double adjust_scale();
                    250:
1.5       noro      251:        /* XXX : should be cleaned up */
                    252:        if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
                    253:                return;
                    254:        if ( can->mode == MODE_INTERACTIVE )
1.1       noro      255:                return;
                    256:
                    257:        xadj = yadj = 0;
                    258:        if ( (can->xmin < 0) && (can->xmax > 0) ) {
1.6     ! noro      259:                x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
1.1       noro      260:                DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
                    261:        } else if ( can->xmin >= 0 )
                    262:                x0 = 0;
                    263:        else
1.6     ! noro      264:                x0 = can->width-D;
1.1       noro      265:        if ( (can->ymin < 0) && (can->ymax > 0) ) {
1.6     ! noro      266:                y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
1.1       noro      267:                DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
                    268:        } else if ( can->ymin >= 0 )
1.6     ! noro      269:                y0 = can->height;
1.1       noro      270:        else
                    271:                y0 = D;
1.6     ! noro      272:
        !           273:        /* scale on x-axis */
1.1       noro      274:        w = can->xmax-can->xmin;
                    275:        w1 = w * DEFAULTWIDTH/can->width;
                    276:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    277:        for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
                    278:                x = (int)can->width*(n*e-can->xmin)/w;
                    279:                DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
                    280:                sprintf(buf,"%g",n*e);
1.6     ! noro      281:                DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
1.1       noro      282:        }
1.6     ! noro      283:
        !           284:        /* scale on y-axis */
1.1       noro      285:        w = can->ymax-can->ymin;
                    286:        w1 = w * DEFAULTHEIGHT/can->height;
                    287:        e = adjust_scale(EXP10(floor(log10(w1))),w1);
                    288:        for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
                    289:                y = (int)can->height*(1-(n*e-can->ymin)/w);
                    290:                DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
                    291:                sprintf(buf,"%g",n*e);
1.6     ! noro      292:                if ( can->xmax <= 0 ) {
        !           293: #if !defined(VISUAL)
1.1       noro      294:                        xadj = TEXTWIDTH(sffs,buf,strlen(buf));
1.6     ! noro      295: #else
        !           296:                        SIZE size;
        !           297:
        !           298:                        GetTextExtentPoint32(d,buf,strlen(buf),&size);
        !           299:                        xadj = size.cx;
        !           300: #endif
        !           301:                }
        !           302:                DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
1.1       noro      303:        }
                    304: }
                    305:
                    306: double adjust_scale(e,w)
                    307: double e,w;
                    308: {
                    309:        switch ( (int)floor(w/e) ) {
                    310:                case 1:
                    311:                        return e/4; break;
                    312:                case 2: case 3:
                    313:                        return e/2; break;
                    314:                case 4: case 5: case 6: case 7:
                    315:                        return e; break;
                    316:                        break;
                    317:                case 8: case 9: case 10: default:
                    318:                        return 2*e; break;
                    319:        }
                    320: }
                    321:
                    322: initmarker(can,message)
                    323: struct canvas *can;
                    324: char *message;
                    325: {
1.5       noro      326: #if defined(VISUAL)
                    327:        can->real_can->percentage = 0;
                    328:        can->real_can->prefix = message;
                    329: #else
1.1       noro      330:        XawScrollbarSetThumb(can->xdone,0.0,0.0);
                    331:        XawScrollbarSetThumb(can->ydone,1.0,0.0);
                    332:        XFlush(display);
1.5       noro      333: #endif
1.1       noro      334: }
                    335:
                    336: marker(can,dir,p)
                    337: struct canvas *can;
                    338: int dir,p;
                    339: {
1.5       noro      340: #if defined(VISUAL)
                    341:        if ( dir == DIR_X )
                    342:                can->real_can->percentage = ceil((float)p/(float)can->real_can->width*100);
                    343:        else if ( dir == DIR_Y )
                    344:                can->real_can->percentage = ceil((float)p/(float)can->real_can->height*100);
                    345:        else
                    346:                can->real_can->percentage = ceil((float)p/(float)can->real_can->nzstep*100);
                    347: #else
1.1       noro      348:        if ( dir == DIR_X ) {
                    349:                XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
                    350:                count_and_flush();
                    351:        } else if ( dir == DIR_Y ) {
                    352:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
                    353:                count_and_flush();
                    354:        } else {
                    355:                XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
                    356:                flush();
                    357:        }
1.5       noro      358: #endif
1.1       noro      359: }
                    360:
                    361: define_cursor(w,cur)
                    362: WINDOW w;
                    363: CURSOR cur;
                    364: {
1.5       noro      365: #if !defined(VISUAL)
1.1       noro      366:        XDefineCursor(display,w,cur); flush();
1.5       noro      367: #endif
1.1       noro      368: }
                    369:
                    370: static int flush_count;
                    371: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
                    372: #define MAX_COUNT 64
                    373: #else
                    374: #define MAX_COUNT 32
                    375: #endif
                    376:
                    377: count_and_flush() {
1.5       noro      378: #if !defined(VISUAL)
1.1       noro      379:        if ( ++flush_count == MAX_COUNT )
                    380:                flush();
1.5       noro      381: #endif
1.1       noro      382: }
                    383:
                    384: flush() {
1.5       noro      385: #if !defined(VISUAL)
1.1       noro      386:        flush_count = 0;
                    387:        XFlush(display);
1.5       noro      388: #endif
1.1       noro      389: }

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