Annotation of OpenXM_contrib2/asir2000/plot/plotp.c, Revision 1.8
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.8 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/plot/plotp.c,v 1.7 2000/11/09 02:30:45 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:
1.8 ! noro 91: #define MEMORY_DRAWPOINT(a,len,x,y) (((a)[(len)*(y)+((x)>>3)]) |= (1<<((x)&7)))
! 92:
! 93: memory_if_print(tab,can,bytes)
! 94: double **tab;
! 95: struct canvas *can;
! 96: BYTEARRAY *bytes;
! 97: {
! 98: int ix,iy,width,height;
! 99: double *px,*px1,*px2;
! 100: unsigned char *array;
! 101: int scan_len;
! 102:
! 103: if ( can->mode == MODE_CONPLOT ) {
! 104: memory_con_print(tab,can,bytes); return;
! 105: }
! 106: width = can->width; height = can->height;
! 107:
! 108: /* scan_len = byte length of the scan line */
! 109: scan_len = (width+7)/8;
! 110: MKBYTEARRAY(*bytes,scan_len*height);
! 111: array = BDY(*bytes);
! 112: for( ix=0; ix<width-1; ix++ )
! 113: for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
! 114: iy<height-1 ;iy++, px++, px1++, px2++ )
! 115: if ( ((*px >= 0) && ((*px1 <= 0) || (*px2 <= 0))) ||
! 116: ((*px <= 0) && ((*px1 >= 0) || (*px2 >= 0))) ) {
! 117: MEMORY_DRAWPOINT(array,scan_len,ix,height-iy-1);
! 118: }
! 119: }
! 120:
1.1 noro 121: con_print(display,tab,can)
122: DISPLAY *display;
123: double **tab;
124: struct canvas *can;
125: {
126: int ix,iy,iz,width,height,pas,pai,len;
127: double zstep,z;
128: double *px,*px1,*px2;
129: DRAWABLE pix;
130: POINT *pa,*pa1;
131: struct pa *parray;
132:
133:
134: width = can->width; height = can->height; pix = can->pix;
135: zstep = (can->zmax-can->zmin)/can->nzstep;
136: can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
137: pas = width;
138: pa = (POINT *)ALLOCA(pas*sizeof(POINT));
139: initmarker(can,"Drawing...");
140: for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
141: marker(can,DIR_Z,iz);
142: pai = 0;
143: for( ix=0; ix<width-1; ix++ )
144: for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
145: iy<height-1 ;iy++, px++, px1++, px2++ )
146: if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
147: ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
148: if ( pai == pas ) {
149: pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
150: bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
151: pas += pas;
152: }
153: XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
154: }
155: can->pa[iz].length = pai;
156: if ( pai ) {
157: pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
158: bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
159: can->pa[iz].pos = pa1;
160: }
161: }
162: flush();
163: for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
164: for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
165: DRAWPOINT(display,pix,drawGC,XC(pa[ix]),YC(pa[ix]));
166: count_and_flush();
167: }
168: flush();
1.8 ! noro 169: }
! 170:
! 171: memory_con_print(tab,can,bytes)
! 172: double **tab;
! 173: struct canvas *can;
! 174: BYTEARRAY *bytes;
! 175: {
! 176: int ix,iy,iz,width,height,pas,pai,len;
! 177: double zstep,z;
! 178: double *px,*px1,*px2;
! 179: POINT *pa,*pa1;
! 180: struct pa *parray;
! 181: unsigned char *array;
! 182: int scan_len;
! 183:
! 184: width = can->width; height = can->height;
! 185: zstep = (can->zmax-can->zmin)/can->nzstep;
! 186: can->pa = (struct pa *)MALLOC((can->nzstep+1)*sizeof(struct pa));
! 187: pas = width;
! 188: pa = (POINT *)ALLOCA(pas*sizeof(POINT));
! 189: for ( z = can->zmin, iz = 0; z <= can->zmax; z += zstep, iz++ ) {
! 190: pai = 0;
! 191: for( ix=0; ix<width-1; ix++ )
! 192: for(iy=0, px=tab[ix], px1 = tab[ix+1], px2 = px+1;
! 193: iy<height-1 ;iy++, px++, px1++, px2++ )
! 194: if ( ((*px >= z) && ((*px1 <= z) || (*px2 <= z))) ||
! 195: ((*px <= z) && ((*px1 >= z) || (*px2 >= z))) ) {
! 196: if ( pai == pas ) {
! 197: pa1 = (POINT *)ALLOCA(2*pas*sizeof(POINT));
! 198: bcopy((char *)pa,(char *)pa1,pas*sizeof(POINT)); pa = pa1;
! 199: pas += pas;
! 200: }
! 201: XC(pa[pai]) = ix; YC(pa[pai]) = height-iy-1; pai++;
! 202: }
! 203: can->pa[iz].length = pai;
! 204: if ( pai ) {
! 205: pa1 = (POINT *)MALLOC(pai*sizeof(POINT));
! 206: bcopy((char *)pa,(char *)pa1,pai*sizeof(POINT));
! 207: can->pa[iz].pos = pa1;
! 208: }
! 209: }
! 210: /* scan_len = byte length of the scan line */
! 211: scan_len = (width+7)/8;
! 212: MKBYTEARRAY(*bytes,scan_len*height);
! 213: array = BDY(*bytes);
! 214: for ( parray = can->pa, iz = 0; iz <= can->nzstep; iz++, parray++ )
! 215: for ( pa = parray->pos, len = parray->length, ix = 0; ix < len; ix++ ) {
! 216: MEMORY_DRAWPOINT(array,scan_len,XC(pa[ix]),YC(pa[ix]));
! 217: }
1.1 noro 218: }
219:
220: qif_print(display,tab,can)
221: DISPLAY *display;
222: char **tab;
223: struct canvas *can;
224: {
225: int ix,iy,width,height;
226: char *px;
227: DRAWABLE pix;
228:
229: flush();
230: width = can->width; height = can->height; pix = can->pix;
231: for( ix = 0; ix < width; ix++ )
232: for(iy = 0, px = tab[ix]; iy < height ;iy++, px++ )
233: if ( *px ) {
234: DRAWPOINT(display,pix,drawGC,ix,height-iy-1);
235: count_and_flush();
236: }
237: flush();
238: }
239:
240: plot_print(display,can)
241: DISPLAY *display;
242: struct canvas *can;
243: {
244: int len,i;
245: POINT *pa;
1.5 noro 246:
247: #if defined(VISUAL)
248: len = can->pa[0].length;
249: pa = can->pa[0].pos;
1.6 noro 250:
251: Polyline(can->pix,pa,len);
252: // for ( i = 0; i < len-1; i++ ) {
253: // DRAWLINE(display,can->pix,drawGC,pa[i].x,pa[i].y,pa[i+1].x,pa[i+1].y);
254: // }
1.5 noro 255: #else
1.1 noro 256: XDrawLines(display,can->pix,drawGC,
257: can->pa[0].pos,can->pa[0].length,CoordModeOrigin);
258: XFlush(display);
1.5 noro 259: #endif
260: }
261:
1.6 noro 262: draw_point(display,can,x,y,color)
1.5 noro 263: DISPLAY *display;
264: struct canvas *can;
265: int x,y;
1.6 noro 266: int color;
1.5 noro 267: {
268: #if defined(VISUAL)
269: HDC dc;
270:
1.6 noro 271: SetPixel(can->pix,x,y,(COLORREF)color);
1.5 noro 272: dc = GetDC(can->hwnd);
1.6 noro 273: SetPixel(dc,x,y,(COLORREF)color);
1.5 noro 274: ReleaseDC(can->hwnd,dc);
275: #else
1.7 noro 276: if ( color ) {
277: set_drawcolor(color);
278: DRAWPOINT(display,can->pix,cdrawGC,x,y);
279: DRAWPOINT(display,can->window,cdrawGC,x,y);
280: } else {
281: DRAWPOINT(display,can->pix,drawGC,x,y);
282: DRAWPOINT(display,can->window,drawGC,x,y);
283: }
1.5 noro 284: XFlush(display);
285: #endif
286: }
287:
1.6 noro 288: draw_line(display,can,x,y,u,v,color)
1.5 noro 289: DISPLAY *display;
290: struct canvas *can;
291: int x,y,u,v;
1.6 noro 292: int color;
1.5 noro 293: {
294: #if defined(VISUAL)
295: HDC dc;
1.6 noro 296: HPEN pen,oldpen;
1.5 noro 297:
1.6 noro 298: if ( color ) {
299: pen = CreatePen(PS_SOLID,1,color);
300: oldpen = SelectObject(can->pix,pen);
301: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
302: SelectObject(can->pix,oldpen);
303:
304: dc = GetDC(can->hwnd);
305: oldpen = SelectObject(dc,pen);
306: DRAWLINE(display,dc,drawGC,x,y,u,v);
307: SelectObject(dc,oldpen);
308: ReleaseDC(can->hwnd,dc);
309:
310: DeleteObject(pen);
311: } else {
312: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
313: dc = GetDC(can->hwnd);
314: DRAWLINE(display,dc,drawGC,x,y,u,v);
315: ReleaseDC(can->hwnd,dc);
316: }
1.5 noro 317: #else
1.7 noro 318: if ( color ) {
319: set_drawcolor(color);
320: DRAWLINE(display,can->pix,cdrawGC,x,y,u,v);
321: DRAWLINE(display,can->window,cdrawGC,x,y,u,v);
322: } else {
323: DRAWLINE(display,can->pix,drawGC,x,y,u,v);
324: DRAWLINE(display,can->window,drawGC,x,y,u,v);
325: }
1.5 noro 326: XFlush(display);
327: #endif
1.1 noro 328: }
329:
330: #define D 5
331:
332: pline(display,can,d)
333: DISPLAY *display;
334: struct canvas *can;
335: DRAWABLE d;
336: {
337: double w,w1,k,e,n;
338: int x0,y0,x,y,xadj,yadj;
339: char buf[BUFSIZ];
340: double adjust_scale();
341:
1.5 noro 342: /* XXX : should be cleaned up */
343: if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
344: return;
345: if ( can->mode == MODE_INTERACTIVE )
1.1 noro 346: return;
347:
348: xadj = yadj = 0;
349: if ( (can->xmin < 0) && (can->xmax > 0) ) {
1.6 noro 350: x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
1.1 noro 351: DRAWLINE(display,d,dashGC,x0,0,x0,can->height);
352: } else if ( can->xmin >= 0 )
353: x0 = 0;
354: else
1.6 noro 355: x0 = can->width-D;
1.1 noro 356: if ( (can->ymin < 0) && (can->ymax > 0) ) {
1.6 noro 357: y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
1.1 noro 358: DRAWLINE(display,d,dashGC,0,y0,can->width,y0);
359: } else if ( can->ymin >= 0 )
1.6 noro 360: y0 = can->height;
1.1 noro 361: else
362: y0 = D;
1.6 noro 363:
364: /* scale on x-axis */
1.1 noro 365: w = can->xmax-can->xmin;
366: w1 = w * DEFAULTWIDTH/can->width;
367: e = adjust_scale(EXP10(floor(log10(w1))),w1);
368: for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
369: x = (int)can->width*(n*e-can->xmin)/w;
370: DRAWLINE(display,d,drawGC,x,y0,x,y0-D);
371: sprintf(buf,"%g",n*e);
1.6 noro 372: DRAWSTRING(display,d,scaleGC,x+2,y0+2,buf,strlen(buf));
1.1 noro 373: }
1.6 noro 374:
375: /* scale on y-axis */
1.1 noro 376: w = can->ymax-can->ymin;
377: w1 = w * DEFAULTHEIGHT/can->height;
378: e = adjust_scale(EXP10(floor(log10(w1))),w1);
379: for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
380: y = (int)can->height*(1-(n*e-can->ymin)/w);
381: DRAWLINE(display,d,drawGC,x0,y,x0+D,y);
382: sprintf(buf,"%g",n*e);
1.6 noro 383: if ( can->xmax <= 0 ) {
384: #if !defined(VISUAL)
1.1 noro 385: xadj = TEXTWIDTH(sffs,buf,strlen(buf));
1.6 noro 386: #else
387: SIZE size;
388:
389: GetTextExtentPoint32(d,buf,strlen(buf),&size);
390: xadj = size.cx;
391: #endif
392: }
393: DRAWSTRING(display,d,scaleGC,x0+2-xadj,y+2,buf,strlen(buf));
1.1 noro 394: }
395: }
396:
397: double adjust_scale(e,w)
398: double e,w;
399: {
400: switch ( (int)floor(w/e) ) {
401: case 1:
402: return e/4; break;
403: case 2: case 3:
404: return e/2; break;
405: case 4: case 5: case 6: case 7:
406: return e; break;
407: break;
408: case 8: case 9: case 10: default:
409: return 2*e; break;
410: }
411: }
412:
413: initmarker(can,message)
414: struct canvas *can;
415: char *message;
416: {
1.5 noro 417: #if defined(VISUAL)
418: can->real_can->percentage = 0;
419: can->real_can->prefix = message;
420: #else
1.1 noro 421: XawScrollbarSetThumb(can->xdone,0.0,0.0);
422: XawScrollbarSetThumb(can->ydone,1.0,0.0);
423: XFlush(display);
1.5 noro 424: #endif
1.1 noro 425: }
426:
427: marker(can,dir,p)
428: struct canvas *can;
429: int dir,p;
430: {
1.5 noro 431: #if defined(VISUAL)
432: if ( dir == DIR_X )
433: can->real_can->percentage = ceil((float)p/(float)can->real_can->width*100);
434: else if ( dir == DIR_Y )
435: can->real_can->percentage = ceil((float)p/(float)can->real_can->height*100);
436: else
437: can->real_can->percentage = ceil((float)p/(float)can->real_can->nzstep*100);
438: #else
1.1 noro 439: if ( dir == DIR_X ) {
440: XawScrollbarSetThumb(can->xdone,(float)p/(float)can->width,0.05);
441: count_and_flush();
442: } else if ( dir == DIR_Y ) {
443: XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->height,0.05);
444: count_and_flush();
445: } else {
446: XawScrollbarSetThumb(can->ydone,1.0-(float)p/(float)can->nzstep,0.05);
447: flush();
448: }
1.5 noro 449: #endif
1.1 noro 450: }
451:
452: define_cursor(w,cur)
453: WINDOW w;
454: CURSOR cur;
455: {
1.5 noro 456: #if !defined(VISUAL)
1.1 noro 457: XDefineCursor(display,w,cur); flush();
1.5 noro 458: #endif
1.1 noro 459: }
460:
461: static int flush_count;
462: #if defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)
463: #define MAX_COUNT 64
464: #else
465: #define MAX_COUNT 32
466: #endif
467:
468: count_and_flush() {
1.5 noro 469: #if !defined(VISUAL)
1.1 noro 470: if ( ++flush_count == MAX_COUNT )
471: flush();
1.5 noro 472: #endif
1.1 noro 473: }
474:
475: flush() {
1.5 noro 476: #if !defined(VISUAL)
1.1 noro 477: flush_count = 0;
478: XFlush(display);
1.5 noro 479: #endif
1.1 noro 480: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>