source: branches/properties/GDE/PHYLIP/draw2.c

Last change on this file was 19480, checked in by westram, 21 months ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 54.4 KB
Line 
1
2#include <stdio.h> /* Metrowerks for windows defines WIN32 here */
3#define swap_m(x,y) temp = y,y=x,x=temp;
4
5extern long winheight;
6extern long winwidth;
7
8#ifdef WIN32
9#include <windows.h>
10HDC hdc;
11
12/******* Menu Defines *******/
13
14#define IDM_ABOUT      1000
15#define IDM_PLOT       1001
16#define IDM_CHANGE     1002
17#define IDM_QUIT       1003
18
19#define XWINPERCENT    0.66
20#define YWINPERCENT    0.66
21#endif
22
23
24#ifdef QUICKC
25extern struct videoconfig myscreen;
26#endif
27
28#include "draw.h"
29
30static long eb[]={
31  0 , 1 ,2 ,3 ,55,45,46,47,22,5,37,11,12,13,14,15,16,17,18,19,60,61,50,38,
32  24, 25,63,39,28,29,30,31,64,90,127,123,91,108,80,125,77,93,92,78,107,96,
33  75,97,240,241,242,243,244,245,246,247,248,249,122,94,76,126,110,111, 124,
34  193,194,195,196,197,198,199,200,201,209,210,211, 212,213,214,215,216,217,
35  226,227,228,229,230,231,232,233,173,224,189, 95,109,121,129,130,131,132,
36  133,134,135,136,137,145,146,147,148,149,150, 151, 152,153,162,163,164,165,
37  166,167,168,169,192,79,208,161,7};
38
39double oldxreal, oldyreal;
40boolean didenter, didexit, curvetrue;
41extern long vrmlplotcolor;
42
43extern double oldx, oldy ;
44/*xx only here for debugging */ extern node *root;
45extern long    nmoves, oldpictint ;
46extern long    rootmatrix[51][51];
47extern long    strpbottom,strptop,strpwide,strpdeep;
48extern boolean dotmatrix, empty, previewing;
49extern double  ynow, ysize, xsize, yunitspercm;
50extern FILE          *plotfile;
51extern plottertype   plotter;
52extern striptype     stripe;
53
54extern long vrmltreecolor, vrmlnamecolor, vrmlskycolorfar, vrmlskycolornear,
55  vrmlgroundcolorfar, vrmlgroundcolornear;
56extern colortype colors[7];
57extern vrmllighttype vrmllights[3];
58extern double pie;
59double pie = 3.141592654;
60
61
62/* Added by Dan F. for the new previewing paradigm */
63extern double labelline,linewidth,oldxhigh,oldxlow,oldyhigh,oldylow,
64  vrmllinewidth, raylinewidth,treeline,oldxsize,oldysize,oldxunitspercm,
65  oldyunitspercm,oldxcorner,oldycorner,clipx0,clipx1,clipy0,clipy1;
66
67/* func. protocol added for vrml - danieyek 981111 */
68
69extern long          strpdiv,hpresolution;
70extern boolean       preview,pictbold,pictitalic,
71  pictshadow,pictoutline;
72extern double        expand,xcorner,xnow,xscale,xunitspercm,
73  ycorner,yscale,labelrotation,
74  labelheight,ymargin,pagex,pagey,paperx,papery,hpmargin,vpmargin;
75
76extern long          filesize;
77extern growth        grows;
78extern enum {yes,no} penchange,oldpenchange;
79extern plottertype   oldplotter,previewer;
80extern char             resopts;
81extern winactiontype winaction;
82
83#ifndef OLDC
84/* function prototypes */
85void   plotdot(long, long);
86void   circlepoints(int, int, int, int);
87void   drawpen(long, long, long);
88void   drawfatline(long, long, long, long, long);
89void   idellipse(double, double); 
90void   splyne(double,double,double,double,boolean,long,boolean,boolean);
91static void   putshort(FILE *, int);
92
93static void   putint(FILE *, int);
94void   reverse_bits (byte *, int); 
95void   void_func(void);
96/* function prototypes */
97#endif
98
99
100void plotdot(long ix, long iy)
101{
102  /* plot one dot at ix, iy */
103  long ix0, iy0, iy1 = 0, iy2 = 0;
104
105  iy0 = strptop - iy;
106  if ((unsigned)iy0 > strpdeep || ix <= 0 || ix > strpwide)
107    return;
108  empty = false;
109  ix0 = ix;
110  switch (plotter) {
111
112  case citoh:
113    iy1 = 1;
114    iy2 = iy0;
115    break;
116
117  case epson:
118    iy1 = 1;
119    iy2 = 7 - iy0;
120    break;
121
122  case oki:
123    iy1 = 1;
124    iy2 = 7 - iy0;
125    break;
126
127  case toshiba:
128    iy1 = iy0 / 6 + 1;
129    iy2 = 5 - iy0 % 6;
130    break;
131
132  case pcx:
133    iy1 = iy0 + 1;
134    ix0 = (ix - 1) / 8 + 1;
135    iy2 = 7 - ((ix - 1) & 7);
136    break;
137
138  case pcl:
139    iy1 = iy0 + 1;
140    ix0 = (ix - 1) / 8 + 1;
141    iy2 = 7 - ((ix - 1) & 7);
142    break;
143
144  case bmp: 
145    iy1 = iy0 + 1;
146    ix0 = (ix - 1) / 8 + 1;
147    iy2 = 7 - ((ix - 1) & 7);
148    __attribute__ ((fallthrough)); // implicit fallthrough
149  case xbm:
150  case gif:
151    iy1 = iy0 + 1;
152    ix0 = (ix - 1) / 8 + 1;
153    iy2 = (ix - 1) & 7;
154    break;
155
156  case lw:
157  case hp:
158  case tek:
159  case mac:
160  case houston:
161  case decregis:
162  case fig:
163  case pict:
164  case ray:
165  case pov:
166  case idraw:
167  case ibm:
168  case other:
169    break;
170  default:        /* cases xpreview and vrml not handled        */
171    break;
172    /* code for making dot array for a new printer
173      goes here */
174  }
175  stripe[iy1 - 1][ix0 - 1] |= (unsigned char)1<<iy2;
176}  /* plotdot */
177
178
179void circlepoints(int x, int y, int x0, int y0)
180{
181  /* circlepoints is consecutively passed a circle center and x,y coordinates *
182   * for 1 octant of a circle. Since the circle is symmetrical, we can use    *
183   * this to plot a complete circle with adjacent pixels (to avoid holes      *
184   * often associated with diagonal stairstepping.                            */
185 
186  plotdot(x0+x,y0+y);
187  plotdot(x0+x,y0+y-1);
188  plotdot(x0+y,y0+x);
189  plotdot(x0+y-1,y0+x);
190 
191  plotdot(x0-x,y0+y);
192  plotdot(x0-x,y0+y-1);
193  plotdot(x0-y,y0+x);
194  plotdot(x0-y+1,y0+x);
195 
196  plotdot(x0+x,y0-y);
197  plotdot(x0+x,y0-y+1);
198  plotdot(x0+y,y0-x);
199  plotdot(x0+y-1,y0-x);
200 
201  plotdot(x0-x,y0-y);
202  plotdot(x0-x,y0-y+1);
203  plotdot(x0-y,y0-x);
204  plotdot(x0-y+1,y0-x);
205}  /* circlepoints */
206
207
208void drawpen(long x0, long y0, long radius)
209{
210 int x,y,d,deltaE,deltaSE;
211
212  x = 0;
213  y = radius;
214  d = 1-radius;
215  deltaE = 3;
216  deltaSE = -2 * radius + 5;
217  circlepoints(x,y,x0,y0);
218
219  while (y > x){
220    if (d < 0) {
221      d = d + deltaE;
222      deltaE += 2;
223      deltaSE += 2;
224      x++;
225    }
226    else {
227      d+=deltaSE;
228      deltaE += 2;
229      deltaSE += 4;
230      x++;
231      y--;
232    }
233    circlepoints(x,y,x0,y0);
234  }
235} /* drawpen */
236
237
238void drawfatline(long ixabs, long iyabs, long ixnow, long iynow,
239                        long penwide)
240{
241  long temp, xdiff, ydiff, err, x1, y1;
242
243  didenter = false;
244  didexit = false;
245
246  if (ixabs < ixnow) {
247    temp = ixnow;
248    ixnow = ixabs;
249    ixabs = temp;
250    temp = iynow;
251    iynow = iyabs;
252    iyabs = temp;
253  }
254  xdiff = ixabs - ixnow;
255  ydiff = iyabs - iynow;
256  if (ydiff >= 0) {
257    if (xdiff >= ydiff) {
258      err = -(xdiff / 2);
259      x1 = ixnow;
260      while (x1 <= ixabs && !(didenter && didexit)) {
261        drawpen(x1, iynow, penwide);
262        err += ydiff;
263        if (err > 0) {
264          iynow++;
265          err -= xdiff;
266        }
267        x1++;
268      }
269      return;
270    }
271    err = -(ydiff / 2);
272    y1 = iynow;
273    while (y1 < iyabs && !(didenter && didexit)) {
274      drawpen(ixnow, y1, penwide);
275      err += xdiff;
276      if (err > 0) {
277        ixnow++;
278        err -= ydiff;
279      }
280      y1++;
281    }
282    return;
283  }
284  if (xdiff < -ydiff) {
285    err = ydiff / 2;
286    y1 = iynow;
287    while (y1 >= iyabs && !(didenter && didexit)) {
288      drawpen(ixnow, y1, penwide);
289      err += xdiff;
290      if (err > 0) {
291        ixnow++;
292        err += ydiff;
293      }
294      y1--;
295    }
296    return;
297  }
298  err = -(xdiff / 2);
299  x1 = ixnow;
300  while (x1 <= ixabs && !(didenter && didexit)) {
301    drawpen(x1, iynow, penwide);
302    err -= ydiff;
303    if (err > 0) {
304      iynow--;
305      err -= xdiff;
306    }
307    x1++;
308  }
309}  /* drawfatline */
310
311
312void plot(pensttstype pen, double xabs, double yabs)
313{
314  long xhigh, yhigh, xlow, ylow, ixnow, iynow, ixabs, iyabs,
315       cdx, temp, i;
316  long pictint;
317  double newx, newy, lscale, dxreal, dyreal;
318  Char picthi, pictlo;
319
320  /* added to give every line a name in vrml! - danieyek 981110 */
321  static long lineCount = 0;
322  /* Record the first node as the coordinate for viewpoint! */
323  static int firstNodeP=1;
324  double distance, angle;
325  double episilon = 1.0e-10;
326
327  /* For povray, added by Dan F. */
328  char texture_string[7];
329
330/* remember to respect & translate for clipping region, clip{x,y}{0,1} */
331
332  if (!dotmatrix || previewing) {
333    switch (plotter) {
334
335    case xpreview:
336      if (pen == pendown) {
337#ifdef X
338        XDrawLine(display,mainwin,gc1,(long)oldx,(long)(height-oldy),
339                                      (long)xabs,(long)(height-yabs));
340#endif
341      }
342      oldx = xabs;
343      oldy = yabs;
344      break;
345
346    case winpreview:
347#ifdef WIN32
348      if (pen == pendown) {
349        LineTo(hdc, (int) xabs, (int)(winheight-yabs)); 
350      }
351      else {
352        MoveToEx(hdc, (int) xabs, (int) (winheight-yabs), (LPPOINT) NULL); 
353      }
354#endif
355      break;
356
357    case tek:
358      if (pen == penup) {
359        if (previewing)
360          putchar('\035');
361        else
362          putc('\035', plotfile);
363      }
364      ixnow = (long)floor(xabs + 0.5);
365      iynow = (long)floor(yabs + 0.5);
366      xhigh = ixnow / 32;
367      yhigh = iynow / 32;
368      xlow = ixnow & 31;
369      ylow = iynow & 31;
370      if (!ebcdic) {
371        if (yhigh != oldyhigh) {
372          if (previewing)
373            putchar(yhigh + 32);
374          else
375            putc(yhigh + 32, plotfile);
376        }
377        if (ylow != oldylow || xhigh != oldxhigh) {
378          if (previewing)
379            putchar(ylow + 96);
380          else
381            putc(ylow + 96, plotfile);
382        }
383        if (xhigh != oldxhigh) {
384          if (previewing)
385            putchar(xhigh + 32);
386          else
387            putc(xhigh + 32, plotfile);
388        }
389        if (previewing)
390          putchar(xlow + 64);
391        else
392          putc(xlow + 64, plotfile);
393      } else {  /* DLS/JMH -- for systems that use EBCDIC coding */
394        if (yhigh != oldyhigh) {
395          if (previewing)
396            putchar(eb[yhigh + 32]);
397          else
398            putc(eb[yhigh + 32], plotfile);
399        }
400        if (ylow != oldylow || xhigh != oldxhigh) {
401          if (previewing)
402            putchar(eb[ylow + 96]);
403          else
404            putc(eb[ylow + 96], plotfile);
405        }
406        if (xhigh != oldxhigh) {
407          if (previewing)
408            putchar(eb[xhigh + 32]);
409          else
410            putc(eb[xhigh + 32], plotfile);
411        }
412        if (previewing)
413          putchar(eb[xlow + 64]);
414        else
415          putc(eb[xlow + 64], plotfile);
416      }
417
418      oldxhigh = xhigh;
419      oldxlow = xlow;
420      oldyhigh = yhigh;
421      oldylow = ylow;
422      break;
423
424    case hp:
425      if (pen == pendown)
426        fprintf(plotfile, "PD");
427      else
428        fprintf(plotfile, "PU");
429      pout((long)floor(xabs + 0.5));
430      putc(',', plotfile);
431      pout((long)floor(yabs + 0.5));
432      fprintf(plotfile, ";\n");
433      break;
434
435    case pict:
436      newx = floor(xabs + 0.5);
437      newy = floor(ysize * yunitspercm - yabs + 0.5);
438      if (pen == pendown) {
439        if (linewidth > 5) {
440          dxreal = xabs - oldxreal;
441          dyreal = yabs - oldyreal;
442          lscale = sqrt(dxreal * dxreal + dyreal * dyreal) /
443            (fabs(dxreal) + fabs(dyreal));
444          pictint = (long)(lscale * linewidth + 0.5);
445
446          if (pictint == 0)
447            pictint = 1;
448          if (pictint != oldpictint) {
449            picthi = (Char)(pictint / 256);
450            pictlo = (Char)(pictint & 255);
451            fprintf(plotfile, "\007%c%c%c%c", picthi, pictlo, picthi, pictlo);
452          }
453          oldpictint = pictint;
454        }
455        fprintf(plotfile, " %c%c%c%c",
456                (Char)((long) oldy / 256), (Char)((long) oldy & 255), (Char)((long) oldx / 256),
457                (Char)((long) oldx & 255));
458        fprintf(plotfile, "%c%c%c%c",
459                (Char)((long)newy / 256), (Char)((long)newy & 255), (Char)((long)newx / 256),
460                (Char)((long)newx & 255));
461        }
462      oldxreal = xabs;
463      oldyreal = yabs;
464      oldx = newx;
465      oldy = newy;
466      break;
467
468    case ray:
469      if (pen == pendown) {
470        if (linewidth != treeline) {
471          if (raylinewidth > labelline) {
472            raylinewidth = labelline;
473            fprintf(plotfile, "end\n\n");
474            fprintf(plotfile, "name species_names\n");
475            fprintf(plotfile, "grid 22 22 22\n");
476          }
477        }
478
479        if (oldxreal != xabs || oldyreal != yabs) {
480          raylinewidth *= 0.99999;
481          fprintf(plotfile, "cylinder %8.7f %6.3f 0 %6.3f %6.3f 0 %6.3f\n",
482                  raylinewidth, oldxreal, oldyreal, xabs, yabs);
483          fprintf(plotfile, "sphere %8.7f %6.3f 0 %6.3f\n",
484                  raylinewidth, xabs, yabs);
485        }
486      }
487      oldxreal = xabs;
488      oldyreal = yabs;
489      break;
490
491    case pov:
492      /* Default to writing out tree texture... */
493      strcpy (texture_string, TREE_TEXTURE);
494
495      if (pen == pendown) {
496        if (linewidth != treeline) {
497          /* Change the texture to name texture */
498          strcpy (texture_string, NAME_TEXTURE);
499
500          if (raylinewidth > labelline) {
501            raylinewidth = labelline;
502            fprintf(plotfile, "\n// Now, the species names:\n\n");
503          }
504        }
505
506        if (oldxreal != xabs || oldyreal != yabs) {
507          raylinewidth *= 0.99999;
508          fprintf(plotfile,
509                  "cylinder { <%6.3f, 0, %6.3f,>, <%6.3f, 0, %6.3f>, %8.7f \n",
510                  oldxreal, oldyreal, xabs, yabs, raylinewidth);
511          fprintf(plotfile, "\ttexture { %s } }\n", texture_string);
512
513          fprintf(plotfile, "sphere { <%6.3f, 0, %6.3f>, %8.7f \n",
514                  xabs, yabs, raylinewidth);
515          fprintf(plotfile, "\ttexture { %s } }\n", texture_string);
516
517        }
518      }
519      oldxreal = xabs;
520      oldyreal = yabs;
521      break;
522
523    case lw:
524      if (pen == pendown){
525        /* If there's NO possibility that the line interesects the page,
526         * leave it out. Otherwise, let postscript clip it to the page. */
527          if (!((xabs > clipx1*xunitspercm &&  oldx > clipx1*xunitspercm) ||
528              (xabs < clipx0*xunitspercm &&  oldx < clipx0*xunitspercm) ||
529              (yabs > clipy1*yunitspercm &&  oldy > clipy1*yunitspercm) ||
530              (yabs < clipy0*yunitspercm &&  oldy < clipy0*yunitspercm)))
531            fprintf(plotfile, "%8.2f %8.2f %8.2f %8.2f l\n",
532                    oldx-(clipx0*xunitspercm), oldy-(clipy0*yunitspercm),
533                    xabs-(clipx0*xunitspercm), yabs-(clipy0*yunitspercm));
534        }
535        oldx     = xabs,
536        oldy     = yabs;
537      break;
538
539    case idraw:
540      if (pen == pendown) {
541        fprintf(plotfile, "Begin %%I Line\n");
542        fprintf(plotfile, "%%I b 65535\n");
543        fprintf(plotfile, "%d 0 0 [] 0 SetB\n",
544                ((linewidth>=1.0) ? (int)linewidth : 1));
545        fprintf(plotfile, "%%I cfg Black\n");
546        fprintf(plotfile, "0 0 0 SetCFg\n");
547        fprintf(plotfile, "%%I cbg White\n");
548        fprintf(plotfile, "1 1 1 SetCBg\n");
549        fprintf(plotfile, "%%I p\n");
550        fprintf(plotfile, "0 SetP\n");
551        fprintf(plotfile, "%%I t\n");
552        fprintf(plotfile, "[ 0.01 0 0 0.01 216 285 ] concat\n");
553        fprintf(plotfile, "%%I\n");
554        fprintf(plotfile, "%ld %ld %ld %ld Line\n",
555                (long)(100.0 * (oldxreal+0.5)),
556                (long)(100.0 * (oldyreal+0.5)),
557                (long)(100.0 * (xabs+0.5)),
558                (long)(100.0 * (yabs+0.5)));
559        fprintf(plotfile, "End\n\n");
560
561        if (linewidth >= 4.0) {
562            fprintf(plotfile, "Begin %%I Elli\n");
563            fprintf(plotfile, "%%I b 65535\n");
564            fprintf(plotfile, "1 0 0 [] 0 SetB\n");
565            fprintf(plotfile, "%%I cfg Black\n");
566            fprintf(plotfile, "0 0 0 SetCFg\n");
567            fprintf(plotfile, "%%I cbg White\n");
568            fprintf(plotfile, "1 1 1 SetCBg\n");
569            fprintf(plotfile, "%%I p\n");
570            fprintf(plotfile, "0 SetP\n");
571            fprintf(plotfile, "%%I t\n");
572            fprintf(plotfile, "[ 0.01 0 0 0.01 216 285 ] concat\n");
573            fprintf(plotfile, "%%I\n");
574            fprintf(plotfile, "%ld %ld %ld %ld Elli\n",
575                    (long)(100.0 * (oldxreal+0.5)),
576                    (long)(100.0 * (oldyreal+0.5)),
577                    (long)(100.0 * (linewidth/2)) - 100,
578                    (long)(100.0 * (linewidth/2)) - 100);
579            fprintf(plotfile, "End\n");
580           
581            fprintf(plotfile, "Begin %%I Elli\n");
582            fprintf(plotfile, "%%I b 65535\n");
583            fprintf(plotfile, "1 0 0 [] 0 SetB\n");
584            fprintf(plotfile, "%%I cfg Black\n");
585            fprintf(plotfile, "0 0 0 SetCFg\n");
586            fprintf(plotfile, "%%I cbg White\n");
587            fprintf(plotfile, "1 1 1 SetCBg\n");
588            fprintf(plotfile, "%%I p\n");
589            fprintf(plotfile, "0 SetP\n");
590            fprintf(plotfile, "%%I t\n");
591            fprintf(plotfile, "[ 0.01 0 0 0.01 216 285 ] concat\n");
592            fprintf(plotfile, "%%I\n");
593            fprintf(plotfile, "%ld %ld %ld %ld Elli\n",
594                    (long)(100.0 * (xabs+0.5)),
595                    (long)(100.0 * (yabs+0.5)),
596                    (long)(100.0 * (linewidth/2)) - 100,
597                    (long)(100.0 * (linewidth/2)) - 100);
598            fprintf(plotfile, "End\n");
599        }
600      }
601      oldxreal = xabs;
602      oldyreal = yabs;
603      break;
604
605    case ibm:
606#ifdef TURBOC
607    newx = floor(xabs + 0.5);
608    newy = fabs(floor(yabs) - getmaxy());
609    if (pen == pendown)
610      line((long)oldx,(long)oldy,(long)newx,(long)newy);
611    oldx = newx;
612    oldy = newy;
613#endif
614#ifdef QUICKC
615    newx = floor(xabs + 0.5);
616    newy = fabs(floor(yabs) - myscreen.numypixels);
617
618    if (pen == pendown)
619        _lineto((long)newx,(long)newy);
620    else
621        _moveto((long)newx,(long)newy);
622    oldx = newx;
623    oldy = newy;
624
625#endif
626    break;
627     case mac:
628#ifdef MAC
629      if (pen == pendown){
630        LineTo((int)floor((double)xabs + 0.5),
631               winheight - (long)floor((double)yabs + 0.5)+MAC_OFFSET);}
632      else{
633        MoveTo((int)floor((double)xabs + 0.5),
634               winheight - (long)floor((double)yabs + 0.5)+MAC_OFFSET);}
635#endif
636
637      break;
638
639    case houston:
640      if (pen == pendown)
641        fprintf(plotfile, "D ");
642      else
643        fprintf(plotfile, "U ");
644      pout((long)((long)floor(xabs + 0.5)));
645      putc(',', plotfile);
646      pout((long)((long)floor(yabs + 0.5)));
647      putc('\n', plotfile);
648      break;
649
650    case decregis:
651      newx = floor(xabs + 0.5);
652      newy = fabs(floor(yabs + 0.5) - 479);
653      if (pen == pendown) {
654        if (previewing) {
655          printf("P[");
656          pout((long)oldx);
657          putchar(',');
658          pout((long)oldy);
659          printf("]V[");
660          pout((long)newx);
661          putchar(',');
662          pout((long)newy);
663          putchar(']');
664        } else {
665          fprintf(plotfile, "P[");
666          pout((long)oldx);
667          putc(',', plotfile);
668          pout((long)oldy);
669          fprintf(plotfile, "]V[");
670          pout((long)newx);
671          putc(',', plotfile);
672          pout((long)newy);
673          putc(']', plotfile);
674        }
675        nmoves++;
676        if (nmoves == 3) {
677          nmoves = 0;
678          if (previewing)
679            putchar('\n');
680          else
681            putc('\n', plotfile);
682        }
683      }
684      oldx = newx;
685      oldy = newy;
686      break;
687
688    case fig:
689      newx = floor(xabs + 0.5);
690      newy = floor(yabs + 0.5);
691      if (pen == pendown) {
692        fprintf(plotfile, "2 1 0 %5ld 0 0 0 0 0.000 0 0\n",
693                (long)floor(linewidth + 0.5) + 1);
694        fprintf(plotfile, "%5ld%5ld%5ld%5ld 9999 9999\n",
695                (long)oldx, 606 - (long) oldy, (long)newx, 606 - (long)newy);
696        fprintf(plotfile,
697          "1 3 0  1 0 0 0 21 0.00 1 0.0 %5ld%5ld%5ld %5ld %5ld%5ld%5ld 349\n",
698                (long)oldx, 
699                606 - (long) oldy, 
700                (long)floor(linewidth / 2 + 0.5),
701                (long)floor(linewidth / 2 + 0.5), 
702                (long)oldx, 606 - (long)oldy, 
703                606 - (long)oldy);
704        fprintf(plotfile,
705          "1 3 0  1 0 0 0 21 0.00 1 0.0 %5ld%5ld%5ld %5ld %5ld%5ld%5ld 349\n",
706                (long)newx, 
707                606 - (long)newy, 
708                (long)floor(linewidth / 2 + 0.5),
709                (long)floor(linewidth / 2 + 0.5), 
710                (long)newx, 
711                606 - (long)newy, 
712                606 - (long)newy);
713      }
714      oldx = newx;
715      oldy = newy;
716      break;
717
718    case vrml:
719
720      newx = xabs;
721      newy = yabs;
722      /* if this is the root node,
723         use the coordinates to define the view point */
724      if (firstNodeP-- == 1)
725      {
726        fprintf(plotfile, "#VRML V2.0 utf8\n");
727        fprintf(plotfile, "    NavigationInfo {\n");
728        fprintf(plotfile, "      headlight FALSE\n");
729        fprintf(plotfile, "    }\n");
730        fprintf(plotfile, "    Viewpoint\n");
731        fprintf(plotfile, "    {\n");
732        fprintf(plotfile, "      position %f %f %f\n", xsize/2, ysize/2, ysize*1.2);
733        fprintf(plotfile, "      description \"Entry View\"\n");
734        fprintf(plotfile, "    }\n");
735
736        for (i=0; i<3; i++) {
737          fprintf(plotfile, "    PointLight {\n");
738          fprintf(plotfile, "      on TRUE\n");
739          fprintf(plotfile, "      intensity %f\n",
740               vrmllights[i].intensity);
741          fprintf(plotfile, "      ambientIntensity 0.0\n");
742          fprintf(plotfile, "      color 1.0 1.0 1.0\n");
743          fprintf(plotfile, "      location %f %f %f\n",
744               vrmllights[i].x,
745               vrmllights[i].y,
746               vrmllights[i].z);
747          fprintf(plotfile, "      attenuation 0.0 0.0 0.0\n");
748          fprintf(plotfile, "      radius 200.0\n");
749          fprintf(plotfile, "    }\n");
750        }
751
752        fprintf(plotfile, "    Background\n");
753        fprintf(plotfile, "    {\n");
754        fprintf(plotfile, "      skyAngle [1.75]\n");
755        fprintf(plotfile, "      skyColor [%f %f %f, %f %f %f]\n",
756                  colors[vrmlskycolornear-1].red, 
757                  colors[vrmlskycolornear-1].green, 
758                  colors[vrmlskycolornear-1].blue,
759                  colors[vrmlskycolorfar-1].red, 
760                  colors[vrmlskycolorfar-1].green, 
761                  colors[vrmlskycolorfar-1].blue);
762        fprintf(plotfile, "      groundAngle[0 1.57 3.14]\n");
763        fprintf(plotfile,
764            "      groundColor [0.9 0.9 0.9, 0.7 0.7 0.7, %f %f %f]\n",
765                  colors[vrmlgroundcolorfar-1].red,
766                  colors[vrmlgroundcolorfar-1].green, 
767                  colors[vrmlgroundcolorfar-1].blue);
768        fprintf(plotfile, "    }\n");
769      }
770
771      if (pen == penup)
772      {/* pen down = beginning of a new path */
773      }
774      else if (pen == pendown)
775      {/* pen up = continue, line may not end yet. */
776
777        if (linewidth != treeline) {
778          if (vrmllinewidth > labelline) {
779            vrmllinewidth = labelline;
780            vrmlplotcolor = vrmlnamecolor;
781          }
782        }
783
784        distance = sqrt((newy - oldy)*(newy - oldy) + (newx - oldx)*(newx - oldx));
785        angle = computeAngle(oldx, oldy, newx, newy);
786
787        if (distance >= episilon)
788        {
789          fprintf(plotfile, "    DEF Line%ld Transform\n", lineCount++);
790          fprintf(plotfile, "    {\n");
791          fprintf(plotfile, "      rotation 0 0 1 %f\n", angle);
792          fprintf(plotfile, "      translation %f %f 0\n", oldx, oldy);
793          fprintf(plotfile, "      children\n");
794          fprintf(plotfile, "      [\n");
795          fprintf(plotfile, "        Shape\n");
796          fprintf(plotfile, "        {\n");
797          fprintf(plotfile, "          appearance Appearance\n");
798          fprintf(plotfile, "          {\n");
799          fprintf(plotfile, "            material Material { diffuseColor %f %f %f}\n",
800                  colors[vrmlplotcolor-1].red, 
801                  colors[vrmlplotcolor-1].green, 
802                  colors[vrmlplotcolor-1].blue);
803          fprintf(plotfile, "          }\n");
804          fprintf(plotfile, "          geometry Sphere\n");
805          fprintf(plotfile, "          {\n");
806/*          vrmllinewidth *= 0.99999; */
807          fprintf(plotfile, "            radius %f\n", vrmllinewidth);
808          fprintf(plotfile, "          }\n");
809          fprintf(plotfile, "        }\n");
810          fprintf(plotfile, "        Transform\n");
811          fprintf(plotfile, "        {\n");
812          fprintf(plotfile, "          rotation 0 0 1 -1.570796327\n" );
813          fprintf(plotfile, "          translation %f 0 0\n", distance/2);
814          fprintf(plotfile, "          children\n");
815          fprintf(plotfile, "          [\n");
816          fprintf(plotfile, "            Shape\n");
817          fprintf(plotfile, "            {\n");
818          fprintf(plotfile, "              appearance Appearance\n");
819          fprintf(plotfile, "              {\n");
820          fprintf(plotfile, "                material Material { diffuseColor %f %f %f}\n",
821                  colors[vrmlplotcolor-1].red, 
822                  colors[vrmlplotcolor-1].green, 
823                  colors[vrmlplotcolor-1].blue );
824          fprintf(plotfile, "              }\n");
825          fprintf(plotfile, "              geometry Cylinder\n");
826          fprintf(plotfile, "              {\n");
827          /* line radius affects end sphere's size */
828/*          vrmllinewidth *= 0.99999; */
829          fprintf(plotfile, "                radius %f\n", vrmllinewidth);
830          fprintf(plotfile, "                height %f\n", distance);
831          fprintf(plotfile, "              }\n");
832          fprintf(plotfile, "            }\n");
833          fprintf(plotfile, "          ]\n");
834          fprintf(plotfile, "        }\n");
835          fprintf(plotfile, "        Transform\n");
836          fprintf(plotfile, "        {\n");
837          fprintf(plotfile, "          translation %f 0 0\n", distance);
838          fprintf(plotfile, "          children\n");
839          fprintf(plotfile, "          [\n");
840          fprintf(plotfile, "            Shape\n");
841          fprintf(plotfile, "            {\n");
842          fprintf(plotfile, "              appearance Appearance\n");
843          fprintf(plotfile, "              {\n");
844          fprintf(plotfile, "                material Material { diffuseColor %f %f %f}\n",
845                  colors[vrmlplotcolor-1].red, 
846                  colors[vrmlplotcolor-1].green, 
847                  colors[vrmlplotcolor-1].blue );
848          fprintf(plotfile, "              }\n");
849          fprintf(plotfile, "              geometry Sphere\n");
850          fprintf(plotfile, "              {\n");
851          /* radius affects line size */
852/*          vrmllinewidth *= 0.99999; */
853          fprintf(plotfile, "                radius %f\n", vrmllinewidth);
854          fprintf(plotfile, "              }\n");
855          fprintf(plotfile, "            }\n");
856          fprintf(plotfile, "          ]\n");
857          fprintf(plotfile, "        }\n");
858          fprintf(plotfile, "      ]\n");
859          fprintf(plotfile, "    }\n");
860        }
861      }
862      else
863      {
864        fprintf(stderr, "ERROR: Programming error in plot().");
865      }
866
867      oldx = newx;
868      oldy = newy;
869      break;
870
871    case epson:
872    case oki:
873    case citoh:
874    case toshiba:
875    case pcx:
876    case pcl:
877    case bmp:
878    case xbm:
879    case gif:
880    case other:
881      break;
882      /* code for a pen move on a new plotter goes here */
883    }
884    return;
885  }
886  if (pen == pendown) {
887    ixabs = (long)floor(xabs + 0.5);
888    iyabs = (long)floor(yabs + 0.5);
889    ixnow = (long)floor(xnow + 0.5);
890    iynow = (long)floor(ynow + 0.5);
891    if (ixnow > ixabs) {
892      temp = ixnow;
893      ixnow = ixabs;
894      ixabs = temp;
895      temp = iynow;
896      iynow = iyabs;
897      iyabs = temp;
898    }
899    cdx = (long)floor(linewidth + 0.5);
900    if ((iyabs + cdx >= strpbottom || iynow + cdx >= strpbottom) &&
901        (iyabs - cdx <= strptop || iynow - cdx <= strptop)) {
902      drawfatline(ixnow,iynow,ixabs,iyabs,(long)floor(linewidth+0.5));
903    }
904  }
905
906  xnow = xabs;
907  ynow = yabs;
908
909  /* Bitmap Code to plot (xnow,ynow) to (xabs,yabs)                 */
910} /* plot                                                           */
911
912
913void idellipse(double x, double y) 
914{
915  fprintf(plotfile, "Begin %%I Elli\n");
916  fprintf(plotfile, "%%I b 65535\n");
917  fprintf(plotfile, "1 0 0 [] 0 SetB\n");
918  fprintf(plotfile, "%%I cfg Black\n");
919  fprintf(plotfile, "0 0 0 SetCFg\n");
920  fprintf(plotfile, "%%I cbg White\n");
921  fprintf(plotfile, "1 1 1 SetCBg\n");
922  fprintf(plotfile, "%%I p\n");
923  fprintf(plotfile, "0 SetP\n");
924  fprintf(plotfile, "%%I t\n");
925  fprintf(plotfile, "[ 0.01 0 0 0.01 216 285 ] concat\n");
926  fprintf(plotfile, "%%I\n");
927  fprintf(plotfile, "%ld %ld %ld %ld Elli\n",
928          (long)(100.0 * (x+0.5)),(long)(100.0 * (y+0.5)),
929          (long)(100.0 * (linewidth/2)) - 100,
930          (long)(100.0 * (linewidth/2)) - 100);
931  fprintf(plotfile, "End\n");
932}  /* idellipse */
933
934
935void splyne(double x1, double y1, double x2, double y2, boolean sense,
936                        long segs, boolean head, boolean tail)
937{
938/* sense is true if line departing from x1,y1 is tangential to x,
939   false if tangential to y */
940
941   
942  long i,fromx,fromy,tox,toy;
943  double f, g, h, x3, y3;
944  long ptop, pleft, pbottom, pright, startangle, arcangle;
945  double dtheta;
946  double sintheta,costheta,sindtheta,cosdtheta,newsintheta,newcostheta;
947  double rx,ry; /* axes of ellipse   */
948  double ox,oy; /* center of ellipse */
949  double prevx,prevy;
950 
951  x1 = x1 - (clipx0 * xunitspercm);
952  x2 = x2 - (clipx0 * xunitspercm);
953  y1 = y1 - (clipy0 * yunitspercm);
954  y2 = y2 - (clipy0 * yunitspercm); /* adjust by clipping region */
955
956  switch (plotter) {
957
958  case lw:
959    fprintf(plotfile,"stroke %8.2f %8.2f moveto\n",x1,y1);
960    if (sense)
961      fprintf(plotfile,"%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f curveto\n",
962              (x1+(0.55*(x2-x1))), y1, x2, (y1+(0.45*(y2-y1))),
963              x2, y2);
964    else
965      fprintf(plotfile,"%8.2f %8.2f %8.2f %8.2f %8.2f %8.2f curveto\n",
966              x1, (y1+(0.55*(y2-y1))), (x1+(0.45*(x2-x1))), y2,
967              x2, y2);
968    break;
969
970  case pict:
971    {
972      double dtop, dleft, dbottom, dright,temp;
973      if (x1 == x2 || y1 == y2) {
974        plot(penup, x1, y1);
975        plot(pendown, x2, y2);
976      } else {
977    if (x2 > x1 && y2 < y1){ swap_m(x2,x1); swap_m(y2,y1); sense = !sense; } 
978       
979        y1 = (ysize * yunitspercm) - y1;
980        y2 = (ysize * yunitspercm) - y2; 
981
982        if (sense) {
983          if (x2 > x1) {
984            dtop = y2 - y1 + y2;
985            dleft = x1 - x2 + x1;
986            dbottom = y1;
987            dright = x2;
988            startangle = 90;
989          } else {
990
991            dtop = y2 - y1 + y2;
992            dleft = x2;
993            dbottom = y1;
994            dright = x1 + (x1 - x2);
995            startangle = 180;
996          }
997        }
998         else {
999          if (x2 > x1) {
1000            dtop = y1 + (y1 - y2);
1001            dleft = x1;
1002            dbottom = y2;
1003            dright = x2 + (x2 - x1);
1004            startangle = 270;
1005          } else {
1006            dtop = y2;
1007            dleft = x1;
1008            dbottom = y1 + y1 - y2;;
1009                dright = x2 + (x2 - x1);
1010            startangle = 0;
1011          }
1012        }
1013        arcangle = 90;
1014         if (dbottom < dtop) {swap_m(dbottom,dtop);}
1015    if (dleft> dright) {swap_m(dleft,dright);}
1016 
1017        ptop    = (long)floor((dtop - 0) + 0.5);
1018        pleft   = (long)floor(dleft  + 0.5);
1019        pbottom = (long)floor(dbottom + 0.5) + (long)floor(linewidth + 0.5);
1020        pright  = (long)floor(dright  + 0.5) + (long)floor(linewidth + 0.5);
1021
1022    if (!sense)
1023        pbottom++;
1024     else
1025        if (x2 < x1)
1026            pright++;
1027         else
1028            pleft--;
1029
1030        fprintf(plotfile,"\140%c%c%c%c%c%c%c%c%c%c%c%c",
1031                (Char)(ptop / 256), (Char)(ptop % 256),
1032                (Char)(pleft / 256), (Char)(pleft % 256),
1033                (Char)(pbottom / 256), (Char)(pbottom % 256),
1034                (Char)(pright / 256), (Char)(pright % 256),
1035                (Char)(startangle / 256), (Char)(startangle % 256),
1036                (Char)(arcangle / 256), (Char)(arcangle % 256));
1037      }
1038    }
1039    break;
1040
1041  case fig:
1042   fromx = (long)floor(x1 + 0.5);
1043   fromy = (long)floor(y1 + 0.5);
1044   tox = (long)floor(x2 + 0.5);
1045   toy = (long)floor(y2 + 0.5);
1046   
1047    fprintf(plotfile, "3 0 0 %5ld 0 0 0 0 0.000 0 0\n",
1048            (long)floor(linewidth + 0.5) + 1);
1049    if (sense)
1050      fprintf(plotfile, "%5ld%5ld%5ld%5ld%5ld%5ld%5ld%5ld 9999 9999\n",
1051              fromx, 606 - fromy,
1052              (long)floor((x1+(0.55*(x2-x1))) + 0.5), 606 - fromy,
1053              tox, 606 - (long)floor((y1+(0.45*(y2-y1))) + 0.5),
1054              tox, 606 - toy);
1055    else
1056      fprintf(plotfile, "%5ld%5ld%5ld%5ld%5ld%5ld%5ld%5ld 9999 9999\n",
1057              fromx, 606 - fromy,
1058              fromx, 606 - (long)floor((y1+(0.55*(y2-y1))) + 0.5),
1059              (long)floor((x1+(0.45*(x2-x1))) + 0.5), 606 - toy,
1060              tox, 606 - toy);
1061    fprintf(plotfile, "1 3 0  1 0 0 0 21 0.00 1 0.0 ");
1062    fprintf(plotfile, "%5ld%5ld%5ld %5ld %5ld%5ld%5ld 349\n",
1063            fromx, 606 - fromy, (long)floor(linewidth / 2 + 0.5),
1064            (long)floor(linewidth / 2 + 0.5), fromx,
1065            606 - fromy, 606 - fromy);
1066    fprintf(plotfile, "1 3 0  1 0 0 0 21 0.00 1 0.0 ");
1067    fprintf(plotfile, "%5ld%5ld%5ld %5ld %5ld%5ld%5ld 349\n",
1068            tox, 606 - toy, (long)floor(linewidth / 2 + 0.5),
1069            (long)floor(linewidth / 2 + 0.5), tox,
1070            606 - toy, 606 - toy);
1071    break;
1072
1073  case idraw:
1074   
1075    if (head){
1076      fprintf(plotfile,"Begin %%I Pict\n%%I b u\n%%I cfg u\n%%I cbg u\n");
1077      fprintf(plotfile,"%%I f u\n%%I p u \n%%I t u\n\n");
1078      idellipse(x1,y1);
1079      fprintf(plotfile, "Begin %%I BSpl\n");
1080      fprintf(plotfile, "%%I b 65535\n");
1081      fprintf(plotfile, "%ld 0 0 [] 0 SetB\n",
1082              ((linewidth>=1.0) ? (long)linewidth : 1));
1083      fprintf(plotfile, "%%I cfg Black\n");
1084      fprintf(plotfile, "0 0 0 SetCFg\n");
1085      fprintf(plotfile, "%%I cbg White\n");
1086      fprintf(plotfile, "1 1 1 SetCBg\n");
1087      fprintf(plotfile, "none SetP %%I p n\n");
1088      fprintf(plotfile, "%%I t\n");
1089      fprintf(plotfile, "[ 0.01 0 0 0.01 216 285 ] concat\n");
1090      if (tail)
1091        fprintf(plotfile,"%%I %ld\n",segs+1);
1092      else
1093        fprintf(plotfile,"%%I %ld\n",(segs*2)+1);
1094      fprintf(plotfile, "%ld %ld\n", (long)(100.0 * (x1+0.5)), 
1095              (long)(100.0 * (y1+0.5))); 
1096    }
1097    rx = (fabs(x2 - x1));
1098    ry = (fabs(y2 - y1));
1099
1100    if (!sense){
1101      if (x2 < x1)
1102        sintheta  = 0.0,
1103        costheta  = 1.0,
1104        dtheta = 90.0 / ((double)segs),
1105        ox = x2,
1106        oy = y1;
1107      else
1108        sintheta  = 0.0,
1109        costheta  = -1.0,
1110        dtheta = -90.0 / ((double)segs),
1111        ox = x2,
1112        oy = y1;
1113    }
1114    else{
1115      if (x2 < x1)
1116        sintheta  = -1.0,
1117        costheta  = 0.0,
1118        dtheta = -90.0 / ((double)segs),
1119        ox = x1,
1120        oy = y2;
1121      else
1122        sintheta  = -1.0,
1123        costheta  = 0.0,
1124        dtheta = 90.0 / ((double)segs),
1125        ox = x1,
1126        oy = y2;
1127        }
1128    x3        = x1;
1129    y3        = y1;
1130    sindtheta = sin(dtheta * (3.1415926535897932384626433 / 180.0));
1131    cosdtheta = cos(dtheta * (3.1415926535897932384626433 / 180.0));
1132   
1133    for (i = 1; i <= segs; i++) {
1134      prevx = x3;
1135      prevy = y3;
1136      newsintheta = (sintheta * cosdtheta) + (costheta * sindtheta);
1137      newcostheta = (costheta * cosdtheta) - (sintheta * sindtheta);
1138      sintheta = newsintheta;
1139      costheta = newcostheta;
1140      x3 = ox + (costheta * rx);
1141      y3 = oy + (sintheta * ry);
1142
1143      /* adjust spline for better aesthetics: */
1144      if (i == 1){
1145        if (sense)
1146          y3 = (y3 + prevy)  / 2.0;
1147        else
1148          x3 = (x3 + prevx) / 2.0;}
1149      else if (i == segs - 1){
1150        if (sense)
1151          x3 = (x3 + x2) / 2.0;
1152        else
1153          y3 = (y2 + y3) / 2.0;
1154      }
1155      fprintf(plotfile, "%ld %ld\n", (long)(100.0 * (x3+0.5)), 
1156              (long)(100.0 * (y3+0.5))); 
1157  }
1158    if (head && tail) 
1159      fprintf(plotfile," BSpl\nEnd\n\n"); /* changed for gcc */
1160      /*fprintf(plotfile,"%ld BSpl\nEnd\n\n"); This is the original */
1161    else if (tail) 
1162             fprintf(plotfile," BSpl \nEnd\n\n");  /* changed for gcc */
1163        /*fprintf(plotfile,"%ld BSpl\nEnd\n\n"); This is the original */
1164    if (tail)
1165      idellipse(x2,y2),
1166      fprintf(plotfile,"\nEnd %%I eop\n\n");
1167    break;
1168
1169  case hp:
1170    plot(penup,x1,y1);   
1171    if (sense){
1172      if (x2 > x1)
1173        fprintf(plotfile,"PD;AA%ld,%ld,90,1;\n",(long)x1,(long)y2);
1174      else
1175        fprintf(plotfile,"PD;AA%ld,%ld,-90,1;\n",(long)x1,(long)y2);
1176    }
1177    else {
1178      if (x2 > x1)
1179        fprintf(plotfile,"PD;AA%ld,%ld,-90,1;\n",(long)x2,(long)y1);
1180      else
1181        fprintf(plotfile,"PD;AA%ld,%ld,90,1;\n",(long)x2,(long)y1);
1182    }
1183    plot(penup,x2,y2); fprintf(plotfile,"PD;PU;");
1184
1185/*    else
1186      fprintf(plotfile,"PD;AA%ld,%ld,90,1;\n",(long)x2,(int)y1); */
1187    plot(penup,x2,y2);
1188    break;
1189  default:
1190    for (i = 1; i <= 2*segs; i++) {
1191      f = (double)i / (2*segs);
1192      g = (double)i / (2*segs);
1193      h = 1.0 - sqrt(1.0 - g * g);
1194      if (sense) {
1195        x3 = x1 * (1.0 - f) + x2 * f;
1196        y3 = y1 + (y2 - y1) * h;
1197      } else {
1198        x3 = x1 + (x2 - x1) * h;
1199        y3 = y1 * (1.0 - f) + y2 * f;
1200      }
1201      plot(pendown, x3, y3);
1202    }
1203    break;
1204  }
1205}  /* splyne */
1206
1207
1208void swoopspline(double x1, double y1, double x2, double y2, double x3,
1209                        double y3, boolean sense, long segs)
1210{
1211  splyne(x1,y1,x2,y2,sense,segs/4,true,false); 
1212  splyne(x2,y2,x3,y3,(boolean)(!sense),segs/4,false,true); 
1213}  /* swoopspline */
1214
1215
1216void curvespline(double x1, double y1, double x2, double y2,
1217                        boolean sense, long segs)
1218{
1219  splyne(x1,y1,x2,y2,sense,segs/2,true,true); 
1220}  /* curvespline */
1221
1222
1223/*******************************************/
1224static void putshort(FILE *fp, int i)
1225{
1226  int c, c1;
1227
1228  c = ((unsigned int ) i) & 0xff;  c1 = (((unsigned int) i)>>8) & 0xff;
1229  putc(c, fp);   putc(c1,fp);
1230}  /* putshort */
1231/*******************************************/
1232
1233
1234static void putint(FILE *fp, int i)
1235{
1236  int c, c1, c2, c3;
1237  c  = ((unsigned int ) i)      & 0xff; 
1238  c1 = (((unsigned int) i)>>8)  & 0xff;
1239  c2 = (((unsigned int) i)>>16) & 0xff;
1240  c3 = (((unsigned int) i)>>24) & 0xff;
1241
1242  putc(c, fp);   putc(c1,fp);  putc(c2,fp);  putc(c3,fp);
1243}  /* ptint */
1244
1245
1246void write_bmp_header (FILE *fp_plotfile,int width,int height)
1247{
1248  /*
1249   *  write a 1-bit image header
1250   *
1251   */
1252
1253  byte r1[2],g1[2],b1[2] ;
1254
1255  int i, bperlin;
1256
1257  r1[0] = (long) 255;   /* Black */
1258  g1[0] = (long) 255;
1259  b1[0] = (long) 255;
1260
1261  r1[1] = 0;
1262  g1[1] = 0;
1263  b1[1] = 0;
1264
1265  bperlin = ((width + 31) / 32) * 4;   /* # bytes written per line */
1266
1267  putc('B', fp_plotfile);
1268  putc('M', fp_plotfile);     /* BMP file magic number */
1269
1270  /* compute filesize and write it */
1271  i = 14 +                    /* size of bitmap file header */
1272      40 +                    /* size of bitmap info header */
1273      8 +                     /* size of colormap */
1274      bperlin * height;       /* size of image data */
1275
1276  putint(fp_plotfile, i);
1277  putshort(fp_plotfile, 0);       /* reserved1 */
1278  putshort(fp_plotfile, 0);       /* reserved2 */
1279  putint(fp_plotfile,
1280         14 + 40 + 8);            /* offset from BOfile to BObitmap */
1281  putint(fp_plotfile, 40);        /* biSize: size of bitmap info header */
1282  putint(fp_plotfile, width);     /* Width */
1283  putint(fp_plotfile, height);    /* Height */
1284  putshort(fp_plotfile, 1);       /* Planes:  must be '1' */
1285  putshort(fp_plotfile, 1);       /* BitCount: 1 */
1286  putint(fp_plotfile, 0);         /* Compression:  BI_RGB = 0 */
1287  putint(fp_plotfile, bperlin*height);/* SizeImage: size of raw image data */
1288  putint(fp_plotfile, 75 * 39);   /* XPelsPerMeter: (75dpi * 39 in. per meter) */
1289  putint(fp_plotfile, 75 * 39);   /* YPelsPerMeter: (75dpi * 39 in. per meter) */
1290  putint(fp_plotfile, 2);         /* ClrUsed: # of colors used in cmap */
1291  putint(fp_plotfile, 2);         /* ClrImportant: same as above */
1292
1293  /* write out the colormap */
1294  for (i = 0 ; i < 2 ; i++) {
1295    putc(b1[i],fp_plotfile);
1296    putc(g1[i],fp_plotfile);
1297    putc(r1[i],fp_plotfile);
1298    putc(0,    fp_plotfile);
1299  }
1300}  /* write_bmp_header */
1301
1302
1303void reverse_bits (byte *full_pic, int location) 
1304{
1305  /* Reverse all the bits at location */
1306  int i, loop_end ; 
1307  byte orig, reversed;
1308
1309  /* initialize...*/
1310  orig = full_pic[location] ;
1311  reversed = (byte) '\0'; 
1312  loop_end = sizeof (byte) * 8 ;
1313
1314  if (orig == (byte) '\0') {
1315    /* No need to do anything for 0 bytes, */
1316    return ;
1317  } else {
1318    for (i = 0 ; i < loop_end ; i++) {
1319      reversed = (reversed << 1) | (orig & 1) ;
1320      orig   >>= 1 ;
1321    }
1322    full_pic[location] = reversed ;
1323  }
1324}  /* reverse_bits */
1325
1326
1327void turn_rows (byte *full_pic, int padded_width, int height)
1328{
1329  int i, j;
1330  int midpoint = padded_width / 2 ;
1331  byte temp ; /* For the swap call */
1332
1333  for (j = 0 ; j < height ; j++) {
1334    for (i = 0 ; i < midpoint ; i++) {
1335
1336      reverse_bits (full_pic, (j * padded_width) + i);
1337      reverse_bits (full_pic, (j * padded_width) + (padded_width - i));
1338      swap_m (full_pic[(j * padded_width) + i],
1339            full_pic[(j * padded_width) + (padded_width - i)]) ;
1340    }
1341    /* Then do the midpoint */
1342    reverse_bits (full_pic, (j * padded_width) + midpoint);
1343  }
1344}  /* turn_rows */
1345
1346
1347void translate_stripe_to_bmp(striptype *local_stripe, byte *full_pic,
1348                        int increment, int width, int div, int *total_bytes) 
1349{
1350  int padded_width, i, j, offset, pad_size,
1351    total_stripes, last_stripe_offset, truncated_stripe_height ;
1352  if (div == 0)
1353    /* For some reason this is called once without valid data */
1354    return ;
1355  else if (div == DEFAULT_STRIPE_HEIGHT) {
1356    /* For a non-last-stripe, figure out if the last stripe is going
1357       to be shorter than the others, to know how far from the bottom
1358       things should be offset. */
1359
1360    truncated_stripe_height = (int) ysize % DEFAULT_STRIPE_HEIGHT;
1361   
1362    if (truncated_stripe_height != 0)
1363      /* The last stripe isn't default height */
1364      last_stripe_offset = DEFAULT_STRIPE_HEIGHT - ((int) ysize %
1365                                                    DEFAULT_STRIPE_HEIGHT) ;
1366    else
1367      /* Stripes are all default height */
1368      last_stripe_offset = 0 ;
1369
1370  } else {
1371    /* For the last stripe, */
1372    last_stripe_offset = 0 ; 
1373  }
1374
1375  /* just for debugging... */
1376 
1377  total_stripes        = (int) ceil (ysize / (double) DEFAULT_STRIPE_HEIGHT);
1378
1379  /* width, padded to be a multiple of 32 bits, or 4 bytes */
1380  padded_width = ((width + 3)/4) * 4; 
1381  pad_size     = padded_width - width;
1382
1383  /* Include pad_size here, as it'll be turned horizontally later */
1384  offset       = ((total_stripes - increment) *
1385                  (padded_width * DEFAULT_STRIPE_HEIGHT))
1386    - (padded_width * last_stripe_offset)
1387    + pad_size ;
1388
1389  for (j = div; j >= 0; j--) {
1390    for (i = 0; i < width; i++) {
1391      full_pic[offset +       
1392              (((div-j) * padded_width) 
1393               + (width-i))] = (byte) (*local_stripe)[j][i];
1394      (*total_bytes)++ ;
1395    }
1396
1397    /* Take into account the padding */
1398    (*total_bytes) += pad_size ;
1399  }
1400}  /* translate_stripe_to_bmp */
1401
1402
1403void write_full_pic(byte *full_pic, int total_bytes)
1404{
1405  int i ;
1406  for (i = 0; i < total_bytes; i++) {
1407    putc (full_pic[i], plotfile);
1408  }
1409}  /* write_full_pic */
1410
1411
1412void makebox_no_interaction(double *xo, double *yo, double *scale, long ntips)
1413/*         xo,yo--x and y offsets */
1414{
1415  /* draw the box on screen which represents plotting area.        */
1416
1417  long xpag,ypag,i,j;
1418
1419  oldpenchange   = penchange;
1420  oldxsize       = xsize;
1421  oldysize       = ysize;
1422  oldxunitspercm = xunitspercm;
1423  oldyunitspercm = yunitspercm;
1424  oldxcorner     = xcorner;
1425  oldycorner     = ycorner;
1426  oldplotter     = plotter;
1427
1428  plotrparms(ntips);
1429  xcorner += 0.05 * xsize;
1430  ycorner += 0.05 * ysize;
1431  xsize *= 0.9;
1432  ysize *= 0.9;
1433  (*scale) = ysize / oldysize;
1434  if (xsize / oldxsize < (*scale))
1435    (*scale) = xsize / oldxsize;
1436  (*xo) = (xcorner + (xsize - oldxsize * (*scale)) / 2.0) / (*scale);
1437  (*yo) = (ycorner   + (ysize - oldysize * (*scale)) / 2.0) / (*scale);
1438
1439  xscale = (*scale) * xunitspercm;
1440  yscale = (*scale) * yunitspercm;
1441  initplotter(ntips);
1442  plot(penup, xscale * (*xo), yscale * (*yo));
1443  plot(pendown, xscale * (*xo), yscale * ((*yo) + oldysize));
1444  plot(pendown, xscale * ((*xo) + oldxsize), yscale * ((*yo) + oldysize));
1445  plot(pendown, xscale * ((*xo) + oldxsize), yscale * (*yo));
1446  plot(pendown, xscale * (*xo), yscale * (*yo));
1447  /* we've done the extent, now draw the dividing lines: */
1448  xpag = (int)((pagex-hpmargin-0.01)/(paperx - hpmargin))+1;
1449  ypag = (int)((pagey-vpmargin-0.01)/(papery - vpmargin))+1;
1450  for (i=0;i<xpag;++i){
1451    plot(penup,(xscale * (*xo))+xscale*i*(paperx - hpmargin),((*yo)*yscale)+0);
1452    plot(pendown,(xscale * (*xo))+xscale*i*(paperx - hpmargin),((*yo)*yscale)+yscale*pagey);
1453    }
1454  for (j=0;j<ypag;++j){
1455    plot(penup,(xscale * (*xo)),((*yo)*yscale)+yscale*j*(papery-vpmargin));
1456    plot(pendown,(xscale * (*xo))+xscale*pagex,((*yo)*yscale)+yscale*j*(papery-hpmargin));
1457    }
1458}  /* makebox_no_interaction */
1459
1460
1461boolean plot_without_preview(double *xo, double *yo, double *scale, long nt)
1462{
1463
1464  previewing = false;
1465  makebox_no_interaction(xo,yo,scale,nt);
1466  penchange = oldpenchange;
1467  xsize = oldxsize;
1468  ysize = oldysize;
1469  xunitspercm = oldxunitspercm;
1470  yunitspercm = oldyunitspercm;
1471  xscale = xunitspercm;
1472  yscale = yunitspercm;
1473  plotter = oldplotter;
1474  xcorner = oldxcorner;
1475  ycorner = oldycorner;
1476  return 1;
1477}  /* plot_without_preview */
1478
1479
1480void void_func()
1481{
1482    fprintf(plotfile, "// Declare the colors\n\n");
1483    fprintf(plotfile, "#declare C_White       = color rgb<1, 1, 1>\n");
1484
1485    fprintf(plotfile, "#declare C_White_trans = color rgbt<1, 1, 1, 0.7>\n");
1486
1487    fprintf(plotfile, "#declare C_Red         = color rgb<1, 0, 0>\n");
1488   
1489    fprintf(plotfile, "#declare C_Yellow      = color rgb<1, 1, 0>\n");
1490   
1491    fprintf(plotfile, "#declare C_Green       = color rgb<0, 1, 0>\n");
1492   
1493    fprintf(plotfile, "#declare C_Black       = color rgb<0, 0, 0>\n");
1494   
1495    fprintf(plotfile, "#declare C_Blue        = color rgb<0, 0, 1>\n");
1496   
1497    fprintf(plotfile, "\n// Declare the textures\n\n");
1498    fprintf(plotfile, "#declare T_White = texture { pigment { C_White }}\n");
1499    fprintf(plotfile, "#declare T_White_trans = texture { pigment { C_White_trans }}\n");
1500    fprintf(plotfile, "#declare T_Red = texture { pigment { C_Red }\n");
1501    fprintf(plotfile, "\tfinish { phong 1 phong_size 100 }}\n");
1502    fprintf(plotfile, "#declare T_Red_trans = texture { pigment { C_Red filter 0.7 }\n");
1503    fprintf(plotfile, "\tfinish { phong 1 phong_size 100 }}\n");
1504    fprintf(plotfile, "#declare T_Green = texture { pigment { C_Green }\n");
1505    fprintf(plotfile, "\tfinish { phong 1 phong_size 100 }}\n");
1506
1507    fprintf(plotfile, "#declare T_Green_trans = texture { \n");
1508    fprintf(plotfile, "\tpigment { C_Green filter 0.7 }\n");
1509    fprintf(plotfile, "\tfinish { phong 1 phong_size 100 }}\n");
1510
1511    fprintf(plotfile, "#declare T_Blue = texture { pigment { C_Blue }\n");
1512    fprintf(plotfile, "\tfinish { phong 1 phong_size 100 }}\n");
1513
1514    fprintf(plotfile, "#background { color rgb<1, 1, 1> }\n");
1515}  /* void_func */
1516
1517
1518/* added for vrml - danieyek 981111 */
1519/* Returned angle in radian */
1520/* A related function is "double angleBetVectors(Xu, Yu, Xv, Yv)"
1521   in drawtree.c */
1522double computeAngle(double local_oldx, double local_oldy, double newx, double newy)
1523{
1524  double angle;
1525
1526  if ((newx-local_oldx) == 0 )
1527  {
1528    /* pi/2 or -pi/2! */
1529    if (newy > local_oldy) angle = pie/2;
1530    else if (newy < local_oldy) angle = -pie/2;
1531    else 
1532    {
1533      /* added - danieyek 990130 */
1534      /* newx = local_oldx; newy = local_oldy; one point on top of the other!
1535         If new and old correspond to 2 points, changes are that the 2 coordinates
1536         are not identical under double precision value. */
1537      fprintf(stderr, 
1538      "ERROR: Angle can't be computed, 2 points on top of each other in computeAngle()!\n");
1539      angle = 0;
1540    }
1541  }
1542  else
1543  {
1544    angle = atan( (newy-local_oldy)/(newx-local_oldx) );
1545
1546    if (newy >= local_oldy && newx >= local_oldx)
1547    {
1548      /* First quardrant - no adjustment */
1549    }
1550    else if (newx <= local_oldx)
1551    {
1552      /* Second (angle = negative) and
1553         third (angle = positive) quardrant */
1554      angle = pie + angle;
1555    }
1556    else if (newy <= local_oldy && newx >= local_oldx)
1557    {
1558      /* Fourth quardrant; "angle" is negative! */
1559      angle = 2*pie + angle;
1560    }
1561    else
1562    {
1563      /* Should never get here. */
1564      fprintf(stderr, "ERROR: Programming error in computeAngle()!\n");
1565    }
1566  }
1567  return angle;
1568}  /* computeAngle */
1569
1570#ifdef WIN32
1571#include <windows.h>
1572
1573/*********************  Prototypes  ***********************/
1574
1575LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
1576LRESULT WINAPI AboutDlgProc( HWND, UINT, WPARAM, LPARAM );
1577
1578/*******************  Global Variables ********************/
1579extern void winplotpreviewcore();
1580HANDLE ghInstance;
1581HPEN hPenTree, hPenLabel, hPenBackground, hPenOld; 
1582
1583/********************************************************************\
1584*  Comments: Register window class, create and display the main      *
1585*            window, and enter message loop.                         *
1586\********************************************************************/
1587
1588winplotpreview()
1589{
1590   WNDCLASS wc;
1591   MSG msg;
1592   HWND hWnd;
1593   int screenXres, screenYres, winXres, winYres;
1594
1595   winaction = quitnow;
1596
1597   wc.lpszClassName = "GenericAppClass";
1598   wc.lpfnWndProc = MainWndProc;
1599   wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
1600   wc.hInstance = NULL;
1601   wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
1602   wc.hCursor = LoadCursor( NULL, IDC_ARROW );
1603   wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
1604   wc.lpszMenuName = "GenericAppMenu";
1605   wc.cbClsExtra = 0;
1606   wc.cbWndExtra = 0;
1607
1608   RegisterClass( &wc );
1609
1610   ghInstance = NULL;
1611
1612   screenXres = GetSystemMetrics(SM_CXSCREEN);
1613   winXres = (int)((float)(screenXres)*XWINPERCENT);
1614   screenYres = GetSystemMetrics(SM_CYSCREEN);
1615   winYres = (int)((float)(screenYres)*YWINPERCENT);
1616
1617   hWnd = CreateWindow( "GenericAppClass",
1618      "Tree Preview",
1619      WS_OVERLAPPEDWINDOW,
1620      0,
1621      0,
1622      winXres,
1623      winYres,
1624      NULL,
1625      NULL,
1626      NULL,
1627      NULL
1628   );
1629
1630   ShowWindow( hWnd, SW_SHOWNORMAL );
1631
1632   while( GetMessage( &msg, NULL, 0, 0 ) ) {
1633      TranslateMessage( &msg );
1634      DispatchMessage( &msg );
1635   }
1636
1637   return msg.wParam;
1638}
1639
1640/*********************     *
1641*                                                                    *
1642* Comments: The following messages are processed                     *
1643*                                                                    *
1644*           WM_PAINT                                                 *
1645*           WM_COMMAND                                               *
1646*           WM_DESTROY                                               *
1647*                                                                    *
1648*                                                                    *
1649\********************************************************************/
1650
1651LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
1652   LPARAM lParam )
1653{
1654   PAINTSTRUCT ps;
1655   LOGBRUSH lb;
1656   HBRUSH bgbrush; 
1657   RECT lpRect;
1658   int windowwidth, windowheight;
1659
1660   switch( msg ) {
1661/**************************************************************\
1662*     WM_ACTIVATE:                                             *
1663\**************************************************************/
1664
1665      case WM_ACTIVATE:
1666         if (wParam != WA_INACTIVE)
1667            BringWindowToTop(hWnd);
1668      break;
1669
1670/**************************************************************\
1671*     WM_PAINT:                                                *
1672\**************************************************************/
1673
1674      case WM_PAINT:
1675         hdc = BeginPaint( hWnd, &ps );
1676         /* Initialize the pen's brush. */
1677         lb.lbStyle = BS_SOLID; 
1678         lb.lbColor = RGB(0,0,0); 
1679         lb.lbHatch = 0;
1680         /* 2 pixel pen for the tree */
1681         hPenTree = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND,
1682                            (DWORD)2, &lb, 0, NULL); 
1683         /* 1 pixel pen for labels */
1684         hPenLabel = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_ROUND,
1685                            (DWORD)1, &lb, 0, NULL); 
1686         /* light blue pen for outline of background rectangle */
1687         lb.lbColor = RGB(204,255,255);
1688         hPenBackground = ExtCreatePen(PS_GEOMETRIC | PS_SOLID,
1689                            (DWORD)1, &lb, 0, NULL); 
1690         /* light blue brush for interior of background rectangle */
1691         bgbrush = CreateSolidBrush(RGB(204,255,255));
1692         /* GetClientRect returns the size of that part of the window
1693            that is actually ours to draw in.
1694          */
1695         GetClientRect(hWnd, &lpRect);
1696         windowwidth = lpRect.right;
1697         windowheight = lpRect.bottom;
1698         /* select background pen and brush */ 
1699         SelectObject(hdc, hPenBackground);
1700         SelectObject(hdc, bgbrush);
1701         /* fill background */
1702         Rectangle(hdc, 0, 0, windowwidth, windowheight);
1703         /* select tree pen */
1704         hPenOld = SelectObject(hdc, hPenTree); 
1705         /* winplotpreviewcore calls makebox, plottree, plotlabels and
1706            finishplotter
1707          */
1708         winplotpreviewcore(windowwidth, windowheight);
1709         /* delete pens to recover memory */
1710         DeleteObject(hPenTree); 
1711         DeleteObject(hPenLabel);
1712         DeleteObject(hPenBackground);
1713         DeleteObject(bgbrush);
1714         EndPaint( hWnd, &ps );
1715         break;
1716
1717/**************************************************************\
1718*     WM_COMMAND:                                              *
1719\**************************************************************/
1720
1721      case WM_COMMAND:
1722         switch( wParam ) {
1723            case IDM_ABOUT:
1724               DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
1725                          AboutDlgProc );
1726            break;
1727            case IDM_PLOT: // "Plot" menu item
1728               winaction = plotnow;
1729               DestroyWindow(hWnd);
1730            break;
1731            case IDM_CHANGE: // "Change Parameters" menu item
1732               winaction = changeparms;
1733               DestroyWindow(hWnd);
1734            break;
1735            case IDM_QUIT: // "Quit" menu item
1736               winaction = quitnow;
1737               DestroyWindow(hWnd);
1738            break;
1739         }
1740      break;
1741
1742/**************************************************************\
1743*     WM_DESTROY: PostQuitMessage() is called                  *
1744\**************************************************************/
1745
1746      case WM_DESTROY:
1747         PostQuitMessage( 0 );
1748         break;
1749
1750/**************************************************************\
1751*     Let the default window proc handle all other messages    *
1752\**************************************************************/
1753
1754      default:
1755         return( DefWindowProc( hWnd, msg, wParam, lParam ));
1756   }
1757
1758   return 0;
1759}
1760
1761/********************************************************************\
1762* Function: LRESULT CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM)*
1763*                                                                    *
1764*  Purpose: Processes "About" Dialog Box Messages                    *
1765*                                                                    *
1766* Comments: The About dialog box is displayed when the user clicks   *
1767*           About from the Help menu.                                *
1768*                                                                    *
1769\********************************************************************/
1770
1771LRESULT CALLBACK AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
1772{
1773   switch( uMsg ) {
1774      case WM_INITDIALOG:
1775         return TRUE;
1776      case WM_COMMAND:
1777         switch( wParam ) {
1778            case IDOK:
1779               EndDialog( hDlg, TRUE );
1780               return TRUE;
1781         }
1782      break;
1783   }
1784
1785   return FALSE;
1786}
1787
1788
1789#endif
Note: See TracBrowser for help on using the repository browser.