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