ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.53 by greg, Thu Mar 20 12:50:07 1997 UTC vs.
Revision 2.74 by schorsch, Mon Oct 27 10:32:06 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Executive program for oconv, rpict and pfilt
6   */
7  
8   #include "standard.h"
9 +
10 + #include <ctype.h>
11 + #include <time.h>
12 +
13 + #include "platform.h"
14 + #include "rtprocess.h"
15 + #include "view.h"
16   #include "paths.h"
17   #include "vars.h"
14 #include <ctype.h>
15 #include <sys/types.h>
18  
19 <                                /* variables */
20 < #define OBJECT          0               /* object files */
21 < #define SCENE           1               /* scene files */
22 < #define MATERIAL        2               /* material files */
23 < #define ILLUM           3               /* mkillum input files */
24 < #define MKILLUM         4               /* mkillum options */
25 < #define RENDER          5               /* rendering options */
26 < #define OCONV           6               /* oconv options */
27 < #define PFILT           7               /* pfilt options */
28 < #define VIEW            8               /* view(s) for picture(s) */
29 < #define ZONE            9               /* simulation zone */
30 < #define QUALITY         10              /* desired rendering quality */
31 < #define OCTREE          11              /* octree file name */
32 < #define PICTURE         12              /* picture file root name */
33 < #define AMBFILE         13              /* ambient file name */
34 < #define OPTFILE         14              /* rendering options file */
35 < #define EXPOSURE        15              /* picture exposure setting */
36 < #define RESOLUTION      16              /* maximum picture resolution */
37 < #define UP              17              /* view up (X, Y or Z) */
38 < #define INDIRECT        18              /* indirection in lighting */
39 < #define DETAIL          19              /* level of scene detail */
40 < #define PENUMBRAS       20              /* shadow penumbras are desired */
41 < #define VARIABILITY     21              /* level of light variability */
42 < #define REPORT          22              /* report frequency and errfile */
43 < #define RAWFILE         23              /* raw picture file root name */
19 > #ifdef _WIN32
20 >  #define DELCMD "del"
21 >  #define RENAMECMD "rename"
22 > #else
23 >  #define DELCMD "rm -f"
24 >  #define RENAMECMD "mv"
25 > #endif
26 >
27 >                                /* variables (alphabetical by name) */
28 > #define AMBFILE         0               /* ambient file name */
29 > #define DETAIL          1               /* level of scene detail */
30 > #define EXPOSURE        2               /* picture exposure setting */
31 > #define EYESEP          3               /* interocular distance */
32 > #define ILLUM           4               /* mkillum input files */
33 > #define INDIRECT        5               /* indirection in lighting */
34 > #define MATERIAL        6               /* material files */
35 > #define MKILLUM         7               /* mkillum options */
36 > #define OBJECT          8               /* object files */
37 > #define OCONV           9               /* oconv options */
38 > #define OCTREE          10              /* octree file name */
39 > #define OPTFILE         11              /* rendering options file */
40 > #define PENUMBRAS       12              /* shadow penumbras are desired */
41 > #define PFILT           13              /* pfilt options */
42 > #define PICTURE         14              /* picture file root name */
43 > #define QUALITY         15              /* desired rendering quality */
44 > #define RAWFILE         16              /* raw picture file root name */
45 > #define RENDER          17              /* rendering options */
46 > #define REPORT          18              /* report frequency and errfile */
47 > #define RESOLUTION      19              /* maximum picture resolution */
48 > #define SCENE           20              /* scene files */
49 > #define UP              21              /* view up (X, Y or Z) */
50 > #define VARIABILITY     22              /* level of light variability */
51 > #define VIEWS           23              /* view(s) for picture(s) */
52   #define ZFILE           24              /* distance file root name */
53 + #define ZONE            25              /* simulation zone */
54                                  /* total number of variables */
55 < int NVARS = 25;
55 > int NVARS = 26;
56  
57   VARIABLE        vv[] = {                /* variable-value pairs */
58 <        {"objects",     3,      0,      NULL,   catvalues},
59 <        {"scene",       3,      0,      NULL,   catvalues},
60 <        {"materials",   3,      0,      NULL,   catvalues},
58 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
59 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
60 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
61 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
62          {"illum",       3,      0,      NULL,   catvalues},
63 +        {"INDIRECT",    3,      0,      NULL,   intvalue},
64 +        {"materials",   3,      0,      NULL,   catvalues},
65          {"mkillum",     3,      0,      NULL,   catvalues},
66 <        {"render",      3,      0,      NULL,   catvalues},
66 >        {"objects",     3,      0,      NULL,   catvalues},
67          {"oconv",       3,      0,      NULL,   catvalues},
54        {"pfilt",       2,      0,      NULL,   catvalues},
55        {"view",        2,      0,      NULL,   NULL},
56        {"ZONE",        2,      0,      NULL,   onevalue},
57        {"QUALITY",     3,      0,      NULL,   qualvalue},
68          {"OCTREE",      3,      0,      NULL,   onevalue},
59        {"PICTURE",     3,      0,      NULL,   onevalue},
60        {"AMBFILE",     3,      0,      NULL,   onevalue},
69          {"OPTFILE",     3,      0,      NULL,   onevalue},
70 <        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
70 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
71 >        {"pfilt",       2,      0,      NULL,   catvalues},
72 >        {"PICTURE",     3,      0,      NULL,   onevalue},
73 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
74 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
75 >        {"render",      3,      0,      NULL,   catvalues},
76 >        {"REPORT",      3,      0,      NULL,   onevalue},
77          {"RESOLUTION",  3,      0,      NULL,   onevalue},
78 +        {"scene",       3,      0,      NULL,   catvalues},
79          {"UP",          2,      0,      NULL,   onevalue},
65        {"INDIRECT",    3,      0,      NULL,   intvalue},
66        {"DETAIL",      3,      0,      NULL,   qualvalue},
67        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
80          {"VARIABILITY", 3,      0,      NULL,   qualvalue},
81 <        {"REPORT",      3,      0,      NULL,   onevalue},
70 <        {"RAWFILE",     3,      0,      NULL,   onevalue},
81 >        {"view",        2,      0,      NULL,   NULL},
82          {"ZFILE",       2,      0,      NULL,   onevalue},
83 +        {"ZONE",        2,      0,      NULL,   onevalue},
84   };
85  
86                                  /* overture calculation file */
87 < #ifdef NIX
88 < char    overfile[] = "overture.unf";
87 > #ifdef NULL_DEVICE
88 > char    overfile[] = NULL_DEVICE;
89   #else
90 < char    overfile[] = "/dev/null";
90 > char    overfile[] = "overture.unf";
91   #endif
92  
81 extern time_t   fdate(), time();
93  
94   time_t  scenedate;              /* date of latest scene or object file */
95   time_t  octreedate;             /* date of octree */
# Line 94 | Line 105 | int    nowarn = 0;             /* no warnings */
105   int     explicate = 0;          /* explicate variables */
106   int     silent = 0;             /* do work silently */
107   int     touchonly = 0;          /* touch files only */
108 < int     noaction = 0;           /* don't do anything */
108 > int     nprocs = 1;             /* maximum executing processes */
109   int     sayview = 0;            /* print view out */
110   char    *rvdevice = NULL;       /* rview output device */
111   char    *viewselect = NULL;     /* specific view only */
112  
113   int     overture = 0;           /* overture calculation needed */
114  
115 + int     children_running = 0;   /* set negative in children */
116 +
117   char    *progname;              /* global argv[0] */
118   char    *rifname;               /* global rad input file name */
119  
120 < char    radname[MAXPATH];       /* root Radiance file name */
120 > char    radname[PATH_MAX];      /* root Radiance file name */
121  
122 + #define inchild()       (children_running < 0)
123  
124 +
125   main(argc, argv)
126   int     argc;
127   char    *argv[];
# Line 123 | Line 138 | char   *argv[];
138                          silent++;
139                          break;
140                  case 'n':
141 <                        noaction++;
141 >                        nprocs = 0;
142                          break;
143 +                case 'N':
144 +                        nprocs = atoi(argv[++i]);
145 +                        if (nprocs < 0)
146 +                                nprocs = 0;
147 +                        break;
148                  case 't':
149                          touchonly++;
150                          break;
# Line 149 | Line 169 | char   *argv[];
169          if (i >= argc)
170                  goto userr;
171          rifname = argv[i];
172 +                                /* check command-line options */
173 +        if ((nprocs > 1) & (viewselect != NULL))
174 +                nprocs = 1;
175                                  /* assign Radiance root file name */
176          rootname(radname, rifname);
177                                  /* load variable values */
# Line 183 | Line 206 | char   *argv[];
206          quit(0);
207   userr:
208          fprintf(stderr,
209 < "Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
209 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
210                          progname);
211          quit(1);
212   }
# Line 194 | Line 217 | register char  *rn, *fn;
217   {
218          char    *tp, *dp;
219  
220 <        for (tp = NULL, dp = rn; *rn = *fn++; rn++)
220 >        for (tp = NULL, dp = rn; (*rn = *fn++); rn++)
221                  if (ISDIRSEP(*rn))
222                          dp = rn;
223                  else if (*rn == '.')
# Line 208 | Line 231 | time_t
231   checklast(fnames)                       /* check files and find most recent */
232   register char   *fnames;
233   {
234 <        char    thisfile[MAXPATH];
234 >        char    thisfile[PATH_MAX];
235          time_t  thisdate, lastdate = 0;
213        register char   *cp;
236  
237          if (fnames == NULL)
238                  return(0);
239 <        while (*fnames) {
240 <                while (isspace(*fnames)) fnames++;
241 <                cp = thisfile;
242 <                while (*fnames && !isspace(*fnames))
221 <                        *cp++ = *fnames++;
222 <                *cp = '\0';
239 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
240 >                if (thisfile[0] == '!' ||
241 >                                (thisfile[0] == '\\' && thisfile[1] == '!'))
242 >                        continue;
243                  if (!(thisdate = fdate(thisfile)))
244                          syserr(thisfile);
245                  if (thisdate > lastdate)
# Line 234 | Line 254 | newfname(orig, pred)           /* create modified file name */
254   char    *orig;
255   int     pred;
256   {
237        extern char     *rindex();
257          register char   *cp;
258          register int    n;
259          int     suffix;
# Line 264 | Line 283 | checkfiles()                   /* check for existence and modified tim
283                          syserr(progname);
284                  sprintf(vval(OCTREE), "%s.oct", radname);
285                  vdef(OCTREE)++;
286 +        } else if (vval(OCTREE)[0] == '!') {
287 +                fprintf(stderr, "%s: illegal '%s' specification\n",
288 +                                progname, vnam(OCTREE));
289 +                quit(1);
290          }
291          octreedate = fdate(vval(OCTREE));
292          if (vdef(ILLUM)) {              /* illum requires secondary octrees */
# Line 289 | Line 312 | checkfiles()                   /* check for existence and modified tim
312   getoctcube(org, sizp)           /* get octree bounding cube */
313   double  org[3], *sizp;
314   {
292        extern FILE     *popen();
315          static double   oorg[3], osiz = 0.;
316          double  min[3], max[3];
317          char    buf[1024];
318          FILE    *fp;
319          register int    i;
320  
321 <        if (osiz <= FTINY)
322 <                if (noaction && fdate(oct1name) <
321 >        if (osiz <= FTINY) {
322 >                if (!nprocs && fdate(oct1name) <
323                                  (scenedate>illumdate?scenedate:illumdate)) {
324                                                          /* run getbbox */
325                          sprintf(buf, "getbbox -w -h %s",
# Line 332 | Line 354 | double org[3], *sizp;
354                          }
355                          pclose(fp);
356                  }
357 +        }
358          org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
359   }
360  
361  
362   setdefaults()                   /* set default values for unassigned var's */
363   {
364 <        double  org[3], size;
364 >        double  org[3], lim[3], size;
365          char    buf[128];
366  
367          if (!vdef(ZONE)) {
# Line 348 | Line 371 | setdefaults()                  /* set default values for unassigned v
371                  vval(ZONE) = savqstr(buf);
372                  vdef(ZONE)++;
373          }
374 +        if (!vdef(EYESEP)) {
375 +                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
376 +                                &org[0], &lim[0], &org[1], &lim[1],
377 +                                &org[2], &lim[2]) != 6)
378 +                        badvalue(ZONE);
379 +                sprintf(buf, "%f",
380 +                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
381 +                vval(EYESEP) = savqstr(buf);
382 +                vdef(EYESEP)++;
383 +        }
384          if (!vdef(INDIRECT)) {
385                  vval(INDIRECT) = "0";
386                  vdef(INDIRECT)++;
# Line 364 | Line 397 | setdefaults()                  /* set default values for unassigned v
397                  vval(PICTURE) = radname;
398                  vdef(PICTURE)++;
399          }
400 <        if (!vdef(VIEW)) {
401 <                vval(VIEW) = "X";
402 <                vdef(VIEW)++;
400 >        if (!vdef(VIEWS)) {
401 >                vval(VIEWS) = "X";
402 >                vdef(VIEWS)++;
403          }
404          if (!vdef(DETAIL)) {
405                  vval(DETAIL) = "M";
# Line 386 | Line 419 | setdefaults()                  /* set default values for unassigned v
419   oconv()                         /* run oconv and mkillum if necessary */
420   {
421          static char     illumtmp[] = "ilXXXXXX";
422 <        char    combuf[1024], ocopts[64], mkopts[64];
422 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
423  
424          oconvopts(ocopts);              /* get options */
425          if (octreedate < scenedate) {   /* check date on original octree */
# Line 415 | Line 448 | oconv()                                /* run oconv and mkillum if necessary */
448          }
449          if (oct1name == vval(OCTREE))           /* no mkillum? */
450                  oct1date = octreedate > matdate ? octreedate : matdate;
451 <        if (oct1date >= octreedate & oct1date >= matdate
452 <                        & oct1date >= illumdate)        /* all done */
451 >        if ((oct1date >= octreedate) & (oct1date >= matdate)
452 >                        & (oct1date >= illumdate))      /* all done */
453                  return;
454                                                  /* make octree0 */
455 <        if (oct0date < scenedate | oct0date < illumdate) {
455 >        if ((oct0date < scenedate) | (oct0date < illumdate)) {
456                  if (touchonly && oct0date)
457                          touch(oct0name);
458                  else {                          /* build command */
# Line 490 | Line 523 | addarg(op, arg)                                /* add argument and advance pointer
523   register char   *op, *arg;
524   {
525          *op = ' ';
526 <        while (*++op = *arg++)
526 >        while ( (*++op = *arg++) )
527                  ;
528          return(op);
529   }
# Line 526 | Line 559 | checkambfile()                 /* check date on ambient file */
559                  return;
560          if (!(afdate = fdate(vval(AMBFILE))))
561                  return;
562 <        if (oct1date > afdate)
562 >        if (oct1date > afdate) {
563                  if (touchonly)
564                          touch(vval(AMBFILE));
565                  else
566                          rmfile(vval(AMBFILE));
567 +        }
568   }
569  
570  
# Line 579 | Line 613 | char   *po;
613                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
614                  badvalue(ZONE);
615          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
616 <        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
616 >        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
617                  badvalue(ZONE);
618          getoctcube(org, &d);
619          d *= 3./(siz[0]+siz[1]+siz[2]);
# Line 587 | Line 621 | char   *po;
621          case LOW:
622                  po = addarg(po, "-ps 16");
623                  op = addarg(op, "-dp 64");
624 <                sprintf(op, " -ar %d", (int)(4*d));
624 >                sprintf(op, " -ar %d", (int)(8*d));
625                  op += strlen(op);
626                  break;
627          case MEDIUM:
628                  po = addarg(po, "-ps 8");
629                  op = addarg(op, "-dp 128");
630 <                sprintf(op, " -ar %d", (int)(8*d));
630 >                sprintf(op, " -ar %d", (int)(16*d));
631                  op += strlen(op);
632                  break;
633          case HIGH:
634                  po = addarg(po, "-ps 4");
635                  op = addarg(op, "-dp 256");
636 <                sprintf(op, " -ar %d", (int)(16*d));
636 >                sprintf(op, " -ar %d", (int)(32*d));
637                  op += strlen(op);
638                  break;
639          }
# Line 616 | Line 650 | char   *po;
650                  overture = 0;
651          switch (vscale(VARIABILITY)) {
652          case LOW:
653 <                op = addarg(op, "-aw 128 -aa .4 -ad 64");
653 >                op = addarg(op, "-aa .3 -ad 256");
654                  break;
655          case MEDIUM:
656 <                op = addarg(op, "-aw 1024 -aa .3 -ad 128");
656 >                op = addarg(op, "-aa .25 -ad 512");
657                  break;
658          case HIGH:
659 <                op = addarg(op, "-aa .25 -ad 256");
659 >                op = addarg(op, "-aa .2 -ad 1024");
660                  break;
661          }
662          op = addarg(op, "-as 0");
663          d = ambval();
664          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
665          op += strlen(op);
666 <        op = addarg(op, "-lr 3 -lw .02");
666 >        op = addarg(op, "-lr 6 -lw .01");
667          if (vdef(RENDER))
668                  op = addarg(op, vval(RENDER));
669   }
# Line 647 | Line 681 | char   *po;
681                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
682                  badvalue(ZONE);
683          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
684 <        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
684 >        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
685                  badvalue(ZONE);
686          getoctcube(org, &d);
687          asz = (siz[0]+siz[1]+siz[2])/3.;
# Line 656 | Line 690 | char   *po;
690          case LOW:
691                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
692                  op = addarg(op, "-dp 256");
693 <                sprintf(op, " -ar %d", (int)(8*d));
693 >                sprintf(op, " -ar %d", (int)(16*d));
694                  op += strlen(op);
695                  sprintf(op, " -ms %.2g", asz/20.);
696                  op += strlen(op);
# Line 664 | Line 698 | char   *po;
698          case MEDIUM:
699                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
700                  op = addarg(op, "-dp 512");
701 <                sprintf(op, " -ar %d", (int)(16*d));
701 >                sprintf(op, " -ar %d", (int)(32*d));
702                  op += strlen(op);
703                  sprintf(op, " -ms %.2g", asz/40.);
704                  op += strlen(op);
# Line 672 | Line 706 | char   *po;
706          case HIGH:
707                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
708                  op = addarg(op, "-dp 1024");
709 <                sprintf(op, " -ar %d", (int)(32*d));
709 >                sprintf(op, " -ar %d", (int)(64*d));
710                  op += strlen(op);
711                  sprintf(op, " -ms %.2g", asz/80.);
712                  op += strlen(op);
# Line 684 | Line 718 | char   *po;
718          else
719                  op = addarg(op, "-ds .3");
720          op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
721 <        if (overture = vint(INDIRECT)) {
721 >        if ( (overture = vint(INDIRECT)) ) {
722                  sprintf(op, " -ab %d", overture);
723                  op += strlen(op);
724          }
# Line 695 | Line 729 | char   *po;
729                  overture = 0;
730          switch (vscale(VARIABILITY)) {
731          case LOW:
732 <                op = addarg(op, "-aw 128 -aa .25 -ad 196 -as 0");
732 >                op = addarg(op, "-aa .2 -ad 329 -as 42");
733                  break;
734          case MEDIUM:
735 <                op = addarg(op, "-aw 1024 -aa .2 -ad 400 -as 64");
735 >                op = addarg(op, "-aa .15 -ad 800 -as 128");
736                  break;
737          case HIGH:
738 <                op = addarg(op, "-aa .15 -ad 768 -as 196");
738 >                op = addarg(op, "-aa .1 -ad 1536 -as 392");
739                  break;
740          }
741          d = ambval();
742          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
743          op += strlen(op);
744 <        op = addarg(op, "-lr 6 -lw .002");
744 >        op = addarg(op, "-lr 8 -lw .002");
745          if (vdef(RENDER))
746                  op = addarg(op, vval(RENDER));
747   }
# Line 725 | Line 759 | char   *po;
759                          &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
760                  badvalue(ZONE);
761          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
762 <        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
762 >        if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY))
763                  badvalue(ZONE);
764          getoctcube(org, &d);
765          asz = (siz[0]+siz[1]+siz[2])/3.;
# Line 734 | Line 768 | char   *po;
768          case LOW:
769                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
770                  op = addarg(op, "-dp 1024");
771 <                sprintf(op, " -ar %d", (int)(16*d));
771 >                sprintf(op, " -ar %d", (int)(32*d));
772                  op += strlen(op);
773                  sprintf(op, " -ms %.2g", asz/40.);
774                  op += strlen(op);
# Line 742 | Line 776 | char   *po;
776          case MEDIUM:
777                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
778                  op = addarg(op, "-dp 2048");
779 <                sprintf(op, " -ar %d", (int)(32*d));
779 >                sprintf(op, " -ar %d", (int)(64*d));
780                  op += strlen(op);
781                  sprintf(op, " -ms %.2g", asz/80.);
782                  op += strlen(op);
# Line 750 | Line 784 | char   *po;
784          case HIGH:
785                  po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
786                  op = addarg(op, "-dp 4096");
787 <                sprintf(op, " -ar %d", (int)(64*d));
787 >                sprintf(op, " -ar %d", (int)(128*d));
788                  op += strlen(op);
789                  sprintf(op, " -ms %.2g", asz/160.);
790                  op += strlen(op);
# Line 771 | Line 805 | char   *po;
805                  overture = 0;
806          switch (vscale(VARIABILITY)) {
807          case LOW:
808 <                op = addarg(op, "-aw 128 -aa .15 -ad 256 -as 0");
808 >                op = addarg(op, "-aa .125 -ad 512 -as 64");
809                  break;
810          case MEDIUM:
811 <                op = addarg(op, "-aw 1024 -aa .125 -ad 512 -as 256");
811 >                op = addarg(op, "-aa .1 -ad 1536 -as 768");
812                  break;
813          case HIGH:
814 <                op = addarg(op, "-aa .08 -ad 1024 -as 512");
814 >                op = addarg(op, "-aa .075 -ad 4096 -as 2048");
815                  break;
816          }
817          d = ambval();
# Line 811 | Line 845 | char   *ro;
845                          syserr(vval(OPTFILE));
846                  sprintf(ro, " @%s", vval(OPTFILE));
847          }
848 < #ifdef MSDOS
848 > #ifdef _WIN32
849          else if (n > 50) {
850                  setenv("ROPT", ro+1);
851                  strcpy(ro, " $ROPT");
# Line 830 | Line 864 | register char  *po;
864          }
865          switch (vscale(QUALITY)) {
866          case MEDIUM:
867 <                po = addarg(po, "-r 1");
867 >                po = addarg(po, "-r .6");
868                  break;
869          case HIGH:
870                  po = addarg(po, "-m .25");
# Line 873 | Line 907 | register char  *vs;
907                          upax = 1-'X'+UPPER(vval(UP)[1]);
908                  else
909                          upax = 1-'X'+vlet(UP);
910 <                if (upax < 1 | upax > 3)
910 >                if ((upax < 1) | (upax > 3))
911                          badvalue(UP);
912                  if (vval(UP)[0] == '-')
913                          upax = -upax;
# Line 896 | Line 930 | register char  *vs;
930                  zpos = -1; vs++;
931          }
932          viewtype = 'v';
933 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
933 >        if((*vs == 'v') | (*vs == 'l') | (*vs == 'a') | (*vs == 'h') | (*vs == 'c'))
934                  viewtype = *vs++;
935          cp = viewopts;
936          if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
# Line 967 | Line 1001 | register char  *vs;
1001          if (cp == viewopts)             /* append any additional options */
1002                  vs++;           /* skip prefixed space if unneeded */
1003          strcpy(cp, vs);
1004 < #ifdef MSDOS
1004 > #ifdef _WIN32
1005          if (strlen(viewopts) > 40) {
1006                  setenv("VIEW", viewopts);
1007                  return("$VIEW");
# Line 999 | Line 1033 | char   *vn;            /* returned view name */
1033                  }
1034                                                  /* view number? */
1035                  if (isint(viewselect))
1036 <                        return(specview(nvalue(VIEW, atoi(viewselect)-1)));
1036 >                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1037                                                  /* check list */
1038 <                while ((mv = nvalue(VIEW, n++)) != NULL)
1038 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1039                          if (matchword(viewselect, mv))
1040                                  return(specview(mv));
1041                  return(specview(viewselect));   /* standard view? */
1042          }
1043 <        mv = nvalue(VIEW, n);           /* use view n */
1044 <        if (vn != NULL & mv != NULL) {
1043 >        mv = nvalue(VIEWS, n);          /* use view n */
1044 >        if ((vn != NULL) & (mv != NULL)) {
1045                  register char   *mv2 = mv;
1046                  if (*mv2 != '-')
1047                          while (*mv2 && !isspace(*mv2))
# Line 1018 | Line 1052 | char   *vn;            /* returned view name */
1052   }
1053  
1054  
1055 < printview(vopts)                        /* print out selected view */
1055 > int
1056 > myprintview(vopts, fp)                  /* print out selected view */
1057   register char   *vopts;
1058 + FILE    *fp;
1059   {
1060 <        extern char     *atos(), *getenv();
1061 <        char    buf[256];
1026 <        FILE    *fp;
1060 >        VIEW    vwr;
1061 >        char    buf[128];
1062          register char   *cp;
1063 <
1063 > again:
1064          if (vopts == NULL)
1065                  return(-1);
1066 <        fputs("VIEW=", stdout);
1067 <        do {
1068 <                if (matchword(vopts, "-vf")) {          /* expand view file */
1069 <                        vopts = sskip(vopts);
1070 <                        if (!*atos(buf, sizeof(buf), vopts))
1036 <                                return(-1);
1037 <                        if ((fp = fopen(buf, "r")) == NULL)
1038 <                                return(-1);
1039 <                        for (buf[sizeof(buf)-2] = '\n';
1040 <                                        fgets(buf, sizeof(buf), fp) != NULL &&
1041 <                                                buf[0] != '\n';
1042 <                                        buf[sizeof(buf)-2] = '\n') {
1043 <                                if (buf[sizeof(buf)-2] != '\n') {
1044 <                                        ungetc(buf[sizeof(buf)-2], fp);
1045 <                                        buf[sizeof(buf)-2] = '\0';
1046 <                                }
1047 <                                if (matchword(buf, "VIEW=") ||
1048 <                                                matchword(buf, "rview")) {
1049 <                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1050 <                                                putchar(*cp);
1051 <                                }
1052 <                        }
1053 <                        fclose(fp);
1054 <                        vopts = sskip(vopts);
1055 <                } else {
1056 <                        while (isspace(*vopts))
1057 <                                vopts++;
1058 <                        putchar(' ');
1059 < #ifdef MSDOS
1060 <                        if (*vopts == '$') {            /* expand env. var. */
1061 <                                if (!*atos(buf, sizeof(buf), vopts+1))
1062 <                                        return(-1);
1063 <                                if ((cp = getenv(buf)) == NULL)
1064 <                                        return(-1);
1065 <                                fputs(cp, stdout);
1066 <                                vopts = sskip(vopts);
1067 <                        } else
1066 > #ifdef _WIN32
1067 >        if (vopts[0] == '$') {
1068 >                vopts = getenv(vopts+1);
1069 >                goto again;
1070 >        }
1071   #endif
1072 <                                while (*vopts && !isspace(*vopts))
1073 <                                        putchar(*vopts++);
1074 <                }
1075 <        } while (*vopts++);
1076 <        putchar('\n');
1072 >        vwr = stdview;
1073 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1074 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1075 >                        *atos(buf, sizeof(buf), cp += 4)) {
1076 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1077 >                sscanview(&vwr, cp);            /* reset tail */
1078 >        }
1079 >        fputs(VIEWSTR, fp);
1080 >        fprintview(&vwr, fp);                   /* print full spec. */
1081 >        fputc('\n', fp);
1082          return(0);
1083   }
1084  
# Line 1079 | Line 1087 | rview(opts, po)                                /* run rview with first view */
1087   char    *opts, *po;
1088   {
1089          char    *vw;
1090 <        char    combuf[512];
1090 >        char    combuf[PATH_MAX];
1091                                          /* build command */
1092          if (touchonly || (vw = getview(0, NULL)) == NULL)
1093                  return;
1094          if (sayview)
1095 <                printview(vw);
1095 >                myprintview(vw, stdout);
1096          sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1097          if (rvdevice != NULL)
1098                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
# Line 1101 | Line 1109 | char   *opts, *po;
1109   rpict(opts, po)                         /* run rpict and pfilt for each view */
1110   char    *opts, *po;
1111   {
1112 <        char    combuf[1024];
1113 <        char    rawfile[MAXPATH], picfile[MAXPATH];
1114 <        char    zopt[MAXPATH+4], rep[MAXPATH+16], res[32];
1112 >        char    combuf[PATH_MAX];
1113 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1114 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1115 >        char    rppopt[128], *pfile = NULL;
1116          char    pfopts[128];
1117          char    vs[32], *vw;
1118          int     vn, mult;
1119 +        FILE    *fp;
1120          time_t  rfdt, pfdt;
1121                                          /* get pfilt options */
1122          pfiltopts(pfopts);
# Line 1148 | Line 1158 | char   *opts, *po;
1158                  else
1159                          badvalue(REPORT);
1160          }
1161 <                                        /* do each view */
1162 <        vn = 0;
1161 >                                        /* set up parallel rendering */
1162 >        if ((nprocs > 1) & (!vdef(ZFILE))) {
1163 >                strcpy(rppopt, "-S 1 -PP pfXXXXXX");
1164 >                pfile = rppopt+9;
1165 >                if (mktemp(pfile) == NULL)
1166 >                        pfile = NULL;
1167 >        }
1168 >        vn = 0;                                 /* do each view */
1169          while ((vw = getview(vn++, vs)) != NULL) {
1170                  if (sayview)
1171 <                        printview(vw);
1171 >                        myprintview(vw, stdout);
1172                  if (!vs[0])
1173                          sprintf(vs, "%d", vn);
1174                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
# Line 1176 | Line 1192 | char   *opts, *po;
1192                                  touch(picfile);
1193                          continue;
1194                  }
1195 +                if (next_process()) {           /* parallel running? */
1196 +                        if (pfile != NULL)
1197 +                                sleep(20);
1198 +                        continue;
1199 +                }
1200 +                /* XXX Remember to call finish_process() */
1201                                                  /* build rpict command */
1202 <                if (rfdt >= oct1date)           /* recover */
1202 >                if (rfdt >= oct1date) {         /* recover */
1203                          sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1204                                  rep, po, opts, zopt, rawfile, oct1name);
1205 <                else {
1205 >                        if (runcom(combuf))     /* run rpict */
1206 >                                goto rperror;
1207 >                } else {
1208                          if (overture) {         /* run overture calculation */
1209                                  sprintf(combuf,
1210                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
# Line 1192 | Line 1216 | char   *opts, *po;
1216                                                  progname, vs);
1217                                          quit(1);
1218                                  }
1219 < #ifdef NIX
1219 > #ifndef NULL_DEVICE
1220                                  rmfile(overfile);
1221   #endif
1222                          }
1223                          sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1224 <                                        rep, vw, res, po, opts, zopt,
1225 <                                        oct1name, rawfile);
1224 >                                        rep, vw, res, po, opts,
1225 >                                        zopt, oct1name, rawfile);
1226 >                        if (pfile != NULL && inchild()) {
1227 >                                                /* rpict persistent mode */
1228 >                                if (!silent)
1229 >                                        printf("\t%s\n", combuf);
1230 >                                sprintf(combuf, "rpict%s %s %s%s%s %s > %s",
1231 >                                                rep, rppopt, res, po, opts,
1232 >                                                oct1name, rawfile);
1233 >                                fflush(stdout);
1234 >                                fp = popen(combuf, "w");
1235 >                                if (fp == NULL)
1236 >                                        goto rperror;
1237 >                                myprintview(vw, fp);
1238 >                                if (pclose(fp))
1239 >                                        goto rperror;
1240 >                        } else {                /* rpict normal mode */
1241 >                                if (runcom(combuf))
1242 >                                        goto rperror;
1243 >                        }
1244                  }
1203                if (runcom(combuf)) {           /* run rpict */
1204                        fprintf(stderr, "%s: error rendering view %s\n",
1205                                        progname, vs);
1206                        quit(1);
1207                }
1245                  if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1246                                                  /* build pfilt command */
1247                          if (mult > 1)
# Line 1213 | Line 1250 | char   *opts, *po;
1250                          else
1251                                  sprintf(combuf, "pfilt%s %s > %s", pfopts,
1252                                                  rawfile, picfile);
1253 <                        if (runcom(combuf)) {           /* run pfilt */
1253 >                        if (runcom(combuf)) {   /* run pfilt */
1254                                  fprintf(stderr,
1255                                  "%s: error filtering view %s\n\t%s removed\n",
1256                                                  progname, vs, picfile);
# Line 1227 | Line 1264 | char   *opts, *po;
1264                          mvfile(rawfile, combuf);
1265                  } else
1266                          rmfile(rawfile);
1267 +                finish_process();               /* exit if child */
1268          }
1269 +        wait_process(1);                /* wait for children to finish */
1270 +        if (pfile != NULL) {            /* clean up rpict persistent mode */
1271 +                int     pid;
1272 +                fp = fopen(pfile, "r");
1273 +                if (fp != NULL) {
1274 +                        if (fscanf(fp, "%*s %d", &pid) != 1 ||
1275 +                                        kill(pid, 1) < 0)
1276 +                                unlink(pfile);
1277 +                        fclose(fp);
1278 +                }
1279 +        }
1280 +        return;
1281 + rperror:
1282 +        fprintf(stderr, "%s: error rendering view %s\n", progname, vs);
1283 +        quit(1);
1284   }
1285  
1286  
# Line 1236 | Line 1289 | char   *fn;
1289   {
1290          if (!silent)
1291                  printf("\ttouch %s\n", fn);
1292 <        if (noaction)
1292 >        if (!nprocs)
1293                  return(0);
1294   #ifdef notused
1295          if (access(fn, F_OK) == -1)             /* create it */
# Line 1252 | Line 1305 | char   *cs;
1305   {
1306          if (!silent)            /* echo it */
1307                  printf("\t%s\n", cs);
1308 <        if (noaction)
1308 >        if (!nprocs)
1309                  return(0);
1310          fflush(stdout);         /* flush output and pass to shell */
1311          return(system(cs));
# Line 1263 | Line 1316 | rmfile(fn)                     /* remove a file */
1316   char    *fn;
1317   {
1318          if (!silent)
1319 < #ifdef MSDOS
1320 <                printf("\tdel %s\n", fn);
1268 < #else
1269 <                printf("\trm -f %s\n", fn);
1270 < #endif
1271 <        if (noaction)
1319 >                printf("\t%s %s\n", DELCMD, fn);
1320 >        if (!nprocs)
1321                  return(0);
1322          return(unlink(fn));
1323   }
# Line 1278 | Line 1327 | mvfile(fold, fnew)             /* move a file */
1327   char    *fold, *fnew;
1328   {
1329          if (!silent)
1330 < #ifdef MSDOS
1331 <                printf("\trename %s %s\n", fold, fnew);
1283 < #else
1284 <                printf("\tmv %s %s\n", fold, fnew);
1285 < #endif
1286 <        if (noaction)
1330 >                printf("\t%s %s %s\n", RENAMECMD, fold, fnew);
1331 >        if (!nprocs)
1332                  return(0);
1333          return(rename(fold, fnew));
1334   }
1335  
1336  
1337 < #ifdef MSDOS
1337 > #ifdef RHAS_FORK_EXEC
1338 > int
1339 > next_process()                  /* fork the next process (max. nprocs) */
1340 > {
1341 >        int     child_pid;
1342 >
1343 >        if (nprocs <= 1)
1344 >                return(0);              /* it's us or no one */
1345 >        if (inchild()) {
1346 >                fprintf(stderr, "%s: internal error 1 in next_process()\n",
1347 >                                progname);
1348 >                quit(1);
1349 >        }
1350 >        if (children_running >= nprocs)
1351 >                wait_process(0);        /* wait for someone to finish */
1352 >        fflush(stdout);
1353 >        child_pid = fork();             /* split process */
1354 >        if (child_pid == 0) {           /* we're the child */
1355 >                children_running = -1;
1356 >                return(0);
1357 >        }
1358 >        if (child_pid > 0) {            /* we're the parent */
1359 >                ++children_running;
1360 >                return(1);
1361 >        }
1362 >        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1363 >        return(0);
1364 > }
1365 >
1366 > wait_process(all)                       /* wait for process(es) to finish */
1367 > int     all;
1368 > {
1369 >        int     ourstatus = 0;
1370 >        int     pid, status;
1371 >
1372 >        if (all)
1373 >                all = children_running;
1374 >        else if (children_running > 0)
1375 >                all = 1;
1376 >        while (all-- > 0) {
1377 >                pid = wait(&status);
1378 >                if (pid < 0)
1379 >                        syserr(progname);
1380 >                status = status>>8 & 0xff;
1381 >                --children_running;
1382 >                if (status != 0) {      /* child's problem is our problem */
1383 >                        if ((ourstatus == 0) & (children_running > 0))
1384 >                                fprintf(stderr, "%s: waiting for remaining processes\n",
1385 >                                                progname);
1386 >                        ourstatus = status;
1387 >                        all = children_running;
1388 >                }
1389 >        }
1390 >        if (ourstatus != 0)
1391 >                quit(ourstatus);        /* bad status from child */
1392 > }
1393 > #else   /* ! RHAS_FORK_EXEC */
1394 > int
1395 > next_process()
1396 > {
1397 >        return(0);                      /* cannot start new process */
1398 > }
1399 > wait_process(all)
1400 > int     all;
1401 > {
1402 >        (void)all;                      /* no one to wait for */
1403 > }
1404 > int
1405 > kill(pid, sig) /* win|unix_process.c should also wait and kill */
1406 > int pid, sig;
1407 > {
1408 >        return 0;
1409 > }
1410 > #endif  /* ! RHAS_FORK_EXEC */
1411 >
1412 > finish_process()                        /* exit a child process */
1413 > {
1414 >        if (!inchild())
1415 >                return;                 /* in parent -- noop */
1416 >        exit(0);
1417 > }
1418 >
1419 > #ifdef _WIN32
1420   setenv(vname, value)            /* set an environment variable */
1421   char    *vname, *value;
1422   {
# Line 1326 | Line 1453 | char   *s;
1453   }
1454  
1455  
1456 + void
1457   quit(ec)                        /* exit program */
1458   int     ec;
1459   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines