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.1 by greg, Thu Mar 11 09:11:00 1993 UTC vs.
Revision 2.66 by greg, Thu Jul 3 15:00:19 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 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 < #include "paths.h"
9 >
10   #include <ctype.h>
11  
12 + #include "platform.h"
13 + #include "view.h"
14 + #include "paths.h"
15 + #include "vars.h"
16  
17 < typedef struct {
18 <        char    *name;          /* variable name */
19 <        short   nick;           /* # characters required for nickname */
20 <        short   nass;           /* # assignments made */
21 <        char    *value;         /* assigned value(s) */
22 <        int     (*fixval)();    /* assignment checking function */
23 < } VARIABLE;
24 <
25 < int     onevalue(), catvalues();
26 <
27 <                                /* variables */
28 < #define OBJECT          0               /* object files */
29 < #define SCENE           1               /* scene files */
30 < #define MATERIAL        2               /* material files */
31 < #define RENDER          3               /* rendering options */
32 < #define OCONV           4               /* oconv options */
33 < #define PFILT           5               /* pfilt options */
34 < #define VIEW            6               /* view(s) for picture(s) */
35 < #define ZONE            7               /* simulation zone */
36 < #define QUALITY         8               /* desired rendering quality */
37 < #define OCTREE          9               /* octree file name */
38 < #define PICTURE         10              /* picture file name */
39 < #define AMBFILE         11              /* ambient file name */
40 < #define OPTFILE         12              /* rendering options file */
41 < #define EXPOSURE        13              /* picture exposure setting */
42 < #define RESOLUTION      14              /* maximum picture resolution */
43 < #define UP              15              /* view up (X, Y or Z) */
43 < #define INDIRECT        16              /* indirection in lighting */
44 < #define DETAIL          17              /* level of scene detail */
45 < #define PENUMBRAS       18              /* shadow penumbras are desired */
46 < #define VARIABILITY     19              /* level of light variability */
47 < #define REPORT          20              /* report frequency and errfile */
17 >                                /* variables (alphabetical by name) */
18 > #define AMBFILE         0               /* ambient file name */
19 > #define DETAIL          1               /* level of scene detail */
20 > #define EXPOSURE        2               /* picture exposure setting */
21 > #define EYESEP          3               /* interocular distance */
22 > #define ILLUM           4               /* mkillum input files */
23 > #define INDIRECT        5               /* indirection in lighting */
24 > #define MATERIAL        6               /* material files */
25 > #define MKILLUM         7               /* mkillum options */
26 > #define OBJECT          8               /* object files */
27 > #define OCONV           9               /* oconv options */
28 > #define OCTREE          10              /* octree file name */
29 > #define OPTFILE         11              /* rendering options file */
30 > #define PENUMBRAS       12              /* shadow penumbras are desired */
31 > #define PFILT           13              /* pfilt options */
32 > #define PICTURE         14              /* picture file root name */
33 > #define QUALITY         15              /* desired rendering quality */
34 > #define RAWFILE         16              /* raw picture file root name */
35 > #define RENDER          17              /* rendering options */
36 > #define REPORT          18              /* report frequency and errfile */
37 > #define RESOLUTION      19              /* maximum picture resolution */
38 > #define SCENE           20              /* scene files */
39 > #define UP              21              /* view up (X, Y or Z) */
40 > #define VARIABILITY     22              /* level of light variability */
41 > #define VIEWS           23              /* view(s) for picture(s) */
42 > #define ZFILE           24              /* distance file root name */
43 > #define ZONE            25              /* simulation zone */
44                                  /* total number of variables */
45 < #define NVARS           21
45 > int NVARS = 26;
46  
47 < VARIABLE        vv[NVARS] = {           /* variable-value pairs */
48 <        {"objects",     3,      0,      NULL,   catvalues},
49 <        {"scene",       3,      0,      NULL,   catvalues},
47 > VARIABLE        vv[] = {                /* variable-value pairs */
48 >        {"AMBFILE",     3,      0,      NULL,   onevalue},
49 >        {"DETAIL",      3,      0,      NULL,   qualvalue},
50 >        {"EXPOSURE",    3,      0,      NULL,   fltvalue},
51 >        {"EYESEP",      3,      0,      NULL,   fltvalue},
52 >        {"illum",       3,      0,      NULL,   catvalues},
53 >        {"INDIRECT",    3,      0,      NULL,   intvalue},
54          {"materials",   3,      0,      NULL,   catvalues},
55 <        {"render",      3,      0,      NULL,   catvalues},
55 >        {"mkillum",     3,      0,      NULL,   catvalues},
56 >        {"objects",     3,      0,      NULL,   catvalues},
57          {"oconv",       3,      0,      NULL,   catvalues},
57        {"pfilt",       2,      0,      NULL,   catvalues},
58        {"view",        2,      0,      NULL,   NULL},
59        {"ZONE",        2,      0,      NULL,   onevalue},
60        {"QUALITY",     3,      0,      NULL,   onevalue},
58          {"OCTREE",      3,      0,      NULL,   onevalue},
62        {"PICTURE",     3,      0,      NULL,   onevalue},
63        {"AMBFILE",     3,      0,      NULL,   onevalue},
59          {"OPTFILE",     3,      0,      NULL,   onevalue},
60 <        {"EXPOSURE",    3,      0,      NULL,   onevalue},
60 >        {"PENUMBRAS",   3,      0,      NULL,   boolvalue},
61 >        {"pfilt",       2,      0,      NULL,   catvalues},
62 >        {"PICTURE",     3,      0,      NULL,   onevalue},
63 >        {"QUALITY",     3,      0,      NULL,   qualvalue},
64 >        {"RAWFILE",     3,      0,      NULL,   onevalue},
65 >        {"render",      3,      0,      NULL,   catvalues},
66 >        {"REPORT",      3,      0,      NULL,   onevalue},
67          {"RESOLUTION",  3,      0,      NULL,   onevalue},
68 +        {"scene",       3,      0,      NULL,   catvalues},
69          {"UP",          2,      0,      NULL,   onevalue},
70 <        {"INDIRECT",    3,      0,      NULL,   onevalue},
71 <        {"DETAIL",      3,      0,      NULL,   onevalue},
72 <        {"PENUMBRAS",   3,      0,      NULL,   onevalue},
73 <        {"VARIABILITY", 3,      0,      NULL,   onevalue},
72 <        {"REPORT",      3,      0,      NULL,   onevalue},
70 >        {"VARIABILITY", 3,      0,      NULL,   qualvalue},
71 >        {"view",        2,      0,      NULL,   NULL},
72 >        {"ZFILE",       2,      0,      NULL,   onevalue},
73 >        {"ZONE",        2,      0,      NULL,   onevalue},
74   };
75  
76 < VARIABLE        *matchvar();
77 < char    *nvalue();
78 < int     vscale();
76 >                                /* overture calculation file */
77 > #ifdef NULL_DEVICE
78 > char    overfile[] = NULL_DEVICE;
79 > #else
80 > char    overfile[] = "overture.unf";
81 > #endif
82  
83 < #define vnam(vc)        (vv[vc].name)
80 < #define vdef(vc)        (vv[vc].nass)
81 < #define vval(vc)        (vv[vc].value)
82 < #define vint(vc)        atoi(vval(vc))
83 < #define vlet(vc)        (vval(vc)[0]&~0x20)
84 < #define vbool(vc)       (vlet(vc)=='T')
83 > extern time_t   time();
84  
85 < #define HIGH            2
86 < #define MEDIUM          1
87 < #define LOW             0
85 > time_t  scenedate;              /* date of latest scene or object file */
86 > time_t  octreedate;             /* date of octree */
87 > time_t  matdate;                /* date of latest material file */
88 > time_t  illumdate;              /* date of last illum file */
89  
90 < int     lowqopts(), medqopts(), hiqopts();
91 < int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
90 > char    *oct0name;              /* name of pre-mkillum octree */
91 > time_t  oct0date;               /* date of pre-mkillum octree */
92 > char    *oct1name;              /* name of post-mkillum octree */
93 > time_t  oct1date;               /* date of post-mkillum octree (>= matdate) */
94  
95 < #define renderopts      (*setqopts[vscale(QUALITY)])
94 <
95 < extern long     fdate();
96 <
97 < long    scenedate;              /* date of latest scene or object file */
98 < long    octreedate;             /* date of octree */
99 <
95 > int     nowarn = 0;             /* no warnings */
96   int     explicate = 0;          /* explicate variables */
97   int     silent = 0;             /* do work silently */
98 < int     noaction = 0;           /* don't do anything */
98 > int     touchonly = 0;          /* touch files only */
99 > int     nprocs = 1;             /* maximum executing processes */
100 > int     sayview = 0;            /* print view out */
101   char    *rvdevice = NULL;       /* rview output device */
102   char    *viewselect = NULL;     /* specific view only */
103  
104   int     overture = 0;           /* overture calculation needed */
105  
106 + int     children_running = 0;   /* set negative in children */
107 +
108   char    *progname;              /* global argv[0] */
109 + char    *rifname;               /* global rad input file name */
110  
111 < char    radname[MAXPATH];       /* root Radiance file name */
111 > char    radname[PATH_MAX];      /* root Radiance file name */
112  
113  
114   main(argc, argv)
# Line 115 | Line 116 | int    argc;
116   char    *argv[];
117   {
118          char    ropts[512];
119 +        char    popts[64];
120          int     i;
121  
122          progname = argv[0];
# Line 125 | Line 127 | char   *argv[];
127                          silent++;
128                          break;
129                  case 'n':
130 <                        noaction++;
130 >                        nprocs = 0;
131                          break;
132 +                case 'N':
133 +                        nprocs = atoi(argv[++i]);
134 +                        if (nprocs < 0)
135 +                                nprocs = 0;
136 +                        break;
137 +                case 't':
138 +                        touchonly++;
139 +                        break;
140                  case 'e':
141                          explicate++;
142                          break;
143                  case 'o':
144                          rvdevice = argv[++i];
145                          break;
146 +                case 'V':
147 +                        sayview++;
148 +                        break;
149                  case 'v':
150                          viewselect = argv[++i];
151                          break;
152 +                case 'w':
153 +                        nowarn++;
154 +                        break;
155                  default:
156                          goto userr;
157                  }
158          if (i >= argc)
159                  goto userr;
160 +        rifname = argv[i];
161                                  /* assign Radiance root file name */
162 <        rootname(radname, argv[i]);
162 >        rootname(radname, rifname);
163                                  /* load variable values */
164 <        load(argv[i]);
164 >        loadvars(rifname);
165                                  /* get any additional assignments */
166          for (i++; i < argc; i++)
167 <                setvariable(argv[i]);
167 >                if (setvariable(argv[i], matchvar) < 0) {
168 >                        fprintf(stderr, "%s: unknown variable: %s\n",
169 >                                        progname, argv[i]);
170 >                        quit(1);
171 >                }
172                                  /* check assignments */
173          checkvalues();
174                                  /* check files and dates */
# Line 156 | Line 177 | char   *argv[];
177          setdefaults();
178                                  /* print all values if requested */
179          if (explicate)
180 <                printvals();
181 <                                /* run simulation */
180 >                printvars(stdout);
181 >                                /* build octree (and run mkillum) */
182          oconv();
183 <        renderopts(ropts);
183 >                                /* check date on ambient file */
184 >        checkambfile();
185 >                                /* run simulation */
186 >        renderopts(ropts, popts);
187          xferopts(ropts);
188          if (rvdevice != NULL)
189 <                rview(ropts);
189 >                rview(ropts, popts);
190          else
191 <                rpict(ropts);
192 <        exit(0);
191 >                rpict(ropts, popts);
192 >        quit(0);
193   userr:
194          fprintf(stderr,
195 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
195 > "Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n",
196                          progname);
197 <        exit(1);
197 >        quit(1);
198   }
199  
200  
# Line 189 | Line 213 | register char  *rn, *fn;
213   }
214  
215  
216 < load(rfname)                    /* load Radiance simulation file */
217 < char    *rfname;
216 > time_t
217 > checklast(fnames)                       /* check files and find most recent */
218 > register char   *fnames;
219   {
220 <        FILE    *fp;
221 <        char    buf[256];
197 <        register char   *cp;
220 >        char    thisfile[PATH_MAX];
221 >        time_t  thisdate, lastdate = 0;
222  
223 <        if (rfname == NULL)
224 <                fp = stdin;
225 <        else if ((fp = fopen(rfname, "r")) == NULL) {
226 <                perror(rfname);
227 <                exit(1);
223 >        if (fnames == NULL)
224 >                return(0);
225 >        while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) {
226 >                if (thisfile[0] == '!' ||
227 >                                (thisfile[0] == '\\' && thisfile[1] == '!'))
228 >                        continue;
229 >                if (!(thisdate = fdate(thisfile)))
230 >                        syserr(thisfile);
231 >                if (thisdate > lastdate)
232 >                        lastdate = thisdate;
233          }
234 <        while (fgetline(buf, sizeof(buf), fp) != NULL) {
206 <                for (cp = buf; *cp; cp++) {
207 <                        switch (*cp) {
208 <                        case '\\':
209 <                        case '\n':
210 <                                *cp = ' ';
211 <                                continue;
212 <                        case '#':
213 <                                *cp = '\0';
214 <                                break;
215 <                        }
216 <                        break;
217 <                }
218 <                setvariable(buf);
219 <        }
220 <        fclose(fp);
234 >        return(lastdate);
235   }
236  
237  
224 setvariable(ass)                /* assign variable according to string */
225 register char   *ass;
226 {
227        char    varname[32];
228        register char   *cp;
229        register VARIABLE       *vp;
230        register int    i;
231        int     n;
232
233        while (isspace(*ass))           /* skip leading space */
234                ass++;
235        cp = varname;                   /* extract name */
236        while (cp < varname+sizeof(varname)-1
237                        && *ass && !isspace(*ass) && *ass != '=')
238                *cp++ = *ass++;
239        *cp = '\0';
240        if (!varname[0])
241                return;         /* no variable name! */
242                                        /* trim value */
243        while (isspace(*ass) || *ass == '=')
244                ass++;
245        cp = ass + strlen(ass);
246        do
247                *cp-- = '\0';
248        while (cp >= ass && isspace(*cp));
249        n = cp - ass + 1;
250        if (!n) {
251                fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
252                                progname, varname);
253                return;
254        }
255                                        /* match variable from list */
256        vp = matchvar(varname);
257        if (vp == NULL) {
258                fprintf(stderr, "%s: unknown variable '%s'\n",
259                                progname, varname);
260                exit(1);
261        }
262                                        /* assign new value */
263        cp = vp->value; i = vp->nass;
264        while (i--)
265                while (*cp++)
266                        ;
267        i = cp - vp->value;
268        vp->value = realloc(vp->value, i+n+1);
269        if (vp->value == NULL) {
270                perror(progname);
271                exit(1);
272        }
273        strcpy(vp->value+i, ass);
274        vp->nass++;
275 }
276
277
278 VARIABLE *
279 matchvar(nam)                   /* match a variable by its name */
280 char    *nam;
281 {
282        int     n = strlen(nam);
283        register int    i;
284
285        for (i = 0; i < NVARS; i++)
286                if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
287                        return(vv+i);
288        return(NULL);
289 }
290
291
238   char *
239 < nvalue(vp, n)                   /* return nth variable value */
240 < VARIABLE        *vp;
241 < register int    n;
239 > newfname(orig, pred)            /* create modified file name */
240 > char    *orig;
241 > int     pred;
242   {
243          register char   *cp;
244 +        register int    n;
245 +        int     suffix;
246  
247 <        if (vp == NULL || n < 0 || n >= vp->nass)
248 <                return(NULL);
249 <        cp = vp->value;
250 <        while (n--)
251 <                while (*cp++)
252 <                        ;
247 >        n = 0; cp = orig; suffix = -1;          /* suffix position, length */
248 >        while (*cp) {
249 >                if (*cp == '.') suffix = n;
250 >                else if (ISDIRSEP(*cp)) suffix = -1;
251 >                cp++; n++;
252 >        }
253 >        if (suffix == -1) suffix = n;
254 >        if ((cp = bmalloc(n+2)) == NULL)
255 >                syserr(progname);
256 >        strncpy(cp, orig, suffix);
257 >        cp[suffix] = pred;                      /* root name + pred + suffix */
258 >        strcpy(cp+suffix+1, orig+suffix);
259          return(cp);
260   }
261  
262  
309 int
310 vscale(vc)                      /* return scale for variable vc */
311 int     vc;
312 {
313        switch(vlet(vc)) {
314        case 'H':
315                return(HIGH);
316        case 'M':
317                return(MEDIUM);
318        case 'L':
319                return(LOW);
320        }
321        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322                        progname, vnam(vc), vval(vc));
323        exit(1);
324 }
325
326
327 checkvalues()                   /* check assignments */
328 {
329        register int    i;
330
331        for (i = 0; i < NVARS; i++)
332                if (vv[i].fixval != NULL)
333                        (*vv[i].fixval)(vv+i);
334 }
335
336
337 onevalue(vp)                    /* only one assignment for this variable */
338 register VARIABLE       *vp;
339 {
340        if (vp->nass < 2)
341                return;
342        fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
343                        progname, vp->name);
344        while (vp->nass-- > 1)
345                vp->value += strlen(vp->value)+1;
346 }
347
348
349 catvalues(vp)                   /* concatenate variable values */
350 register VARIABLE       *vp;
351 {
352        register char   *cp;
353
354        if (vp->nass < 2)
355                return;
356        for (cp = vp->value; vp->nass > 1; vp->nass--) {
357                while (*cp)
358                        cp++;
359                *cp++ = ' ';
360        }
361 }
362
363
364 long
365 checklast(fnames)                       /* check files and find most recent */
366 register char   *fnames;
367 {
368        char    thisfile[MAXPATH];
369        long    thisdate, lastdate = -1;
370        register char   *cp;
371
372        while (*fnames) {
373                while (isspace(*fnames)) fnames++;
374                cp = thisfile;
375                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
376                *cp = '\0';
377                if ((thisdate = fdate(thisfile)) < 0) {
378                        perror(thisfile);
379                        exit(1);
380                }
381                if (thisdate > lastdate)
382                        lastdate = thisdate;
383        }
384        return(lastdate);
385 }
386
387
263   checkfiles()                    /* check for existence and modified times */
264   {
265 <        long    objdate;
265 >        time_t  objdate;
266  
267 <        octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1;
268 <        scenedate = -1;
269 <        if (vdef(SCENE)) {
270 <                scenedate = checklast(vval(SCENE));
271 <                if (vdef(OBJECT)) {
272 <                        objdate = checklast(vval(OBJECT));
273 <                        if (objdate > scenedate)
274 <                                scenedate = objdate;
275 <                }
267 >        if (!vdef(OCTREE)) {
268 >                if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL)
269 >                        syserr(progname);
270 >                sprintf(vval(OCTREE), "%s.oct", radname);
271 >                vdef(OCTREE)++;
272 >        } else if (vval(OCTREE)[0] == '!') {
273 >                fprintf(stderr, "%s: illegal '%s' specification\n",
274 >                                progname, vnam(OCTREE));
275 >                quit(1);
276          }
277 <        if (octreedate < 0 & scenedate < 0) {
278 <                fprintf(stderr, "%s: need scene or octree\n", progname);
279 <                exit(1);
277 >        octreedate = fdate(vval(OCTREE));
278 >        if (vdef(ILLUM)) {              /* illum requires secondary octrees */
279 >                oct0name = newfname(vval(OCTREE), '0');
280 >                oct1name = newfname(vval(OCTREE), '1');
281 >                oct0date = fdate(oct0name);
282 >                oct1date = fdate(oct1name);
283 >        } else
284 >                oct0name = oct1name = vval(OCTREE);
285 >        if ((scenedate = checklast(vval(SCENE))) &&
286 >                        (objdate = checklast(vval(OBJECT))) > scenedate)
287 >                scenedate = objdate;
288 >        illumdate = checklast(vval(ILLUM));
289 >        if (!octreedate & !scenedate & !illumdate) {
290 >                fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname,
291 >                                vnam(OCTREE), vnam(SCENE), vnam(ILLUM));
292 >                quit(1);
293          }
294 +        matdate = checklast(vval(MATERIAL));
295   }      
296  
297  
298 < setdefaults()                   /* set default values for unassigned var's */
298 > getoctcube(org, sizp)           /* get octree bounding cube */
299 > double  org[3], *sizp;
300   {
301 +        extern FILE     *popen();
302 +        static double   oorg[3], osiz = 0.;
303 +        double  min[3], max[3];
304 +        char    buf[1024];
305          FILE    *fp;
306 <        double  xmin, ymin, zmin, size;
413 <        char    buf[512];
414 <        char    *cp;
306 >        register int    i;
307  
308 <        if (!vdef(OCTREE)) {
309 <                sprintf(buf, "%s.oct", radname);
310 <                vval(OCTREE) = savqstr(buf);
311 <                vdef(OCTREE)++;
312 <        }
313 <        if (!vdef(ZONE)) {
314 <                if (scenedate > octreedate) {
315 <                        sprintf(buf, "getbbox -w -h %s", vval(SCENE));
316 <                        if (!silent) {
317 <                                printf("\t%s\n", buf);
318 <                                fflush(stdout);
308 >        if (osiz <= FTINY)
309 >                if (!nprocs && fdate(oct1name) <
310 >                                (scenedate>illumdate?scenedate:illumdate)) {
311 >                                                        /* run getbbox */
312 >                        sprintf(buf, "getbbox -w -h %s",
313 >                                vdef(SCENE) ? vval(SCENE) : vval(ILLUM));
314 >                        if ((fp = popen(buf, "r")) == NULL)
315 >                                syserr("getbbox");
316 >                        if (fscanf(fp, "%lf %lf %lf %lf %lf %lf",
317 >                                        &min[0], &max[0], &min[1], &max[1],
318 >                                        &min[2], &max[2]) != 6) {
319 >                                fprintf(stderr,
320 >                        "%s: error reading bounding box from getbbox\n",
321 >                                                progname);
322 >                                quit(1);
323                          }
324 <                        if ((fp = popen(buf, "r")) == NULL) {
325 <                                perror("getbbox");
326 <                                exit(1);
327 <                        }
328 <                        buf[0] = 'E'; buf[1] = ' ';
433 <                        fgetline(buf+2, sizeof(buf)-2, fp);
324 >                        for (i = 0; i < 3; i++)
325 >                                if (max[i] - min[i] > osiz)
326 >                                        osiz = max[i] - min[i];
327 >                        for (i = 0; i < 3; i++)
328 >                                oorg[i] = (max[i]+min[i]-osiz)*.5;
329                          pclose(fp);
330 <                } else {
331 <                        sprintf(buf, "getinfo -d < %s", vval(OCTREE));
332 <                        if ((fp = popen(buf, "r")) == NULL) {
333 <                                perror("getinfo");
334 <                                exit(1);
330 >                } else {                                /* from octree */
331 >                        oconv();        /* does nothing if done already */
332 >                        sprintf(buf, "getinfo -d < %s", oct1name);
333 >                        if ((fp = popen(buf, "r")) == NULL)
334 >                                syserr("getinfo");
335 >                        if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
336 >                                        &oorg[2], &osiz) != 4) {
337 >                                fprintf(stderr,
338 >                        "%s: error reading bounding cube from getinfo\n",
339 >                                                progname);
340 >                                quit(1);
341                          }
441                        fscanf(fp, "%lf %lf %lf %lf",
442                                        &xmin, &ymin, &zmin, &size);
443                        sprintf(buf, "E %g %g %g %g %g %g", xmin, xmin+size,
444                                        ymin, ymin+size, zmin, zmin+size);
342                          pclose(fp);
343                  }
344 +        org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
345 + }
346 +
347 +
348 + setdefaults()                   /* set default values for unassigned var's */
349 + {
350 +        double  org[3], lim[3], size;
351 +        char    buf[128];
352 +
353 +        if (!vdef(ZONE)) {
354 +                getoctcube(org, &size);
355 +                sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
356 +                                org[1], org[1]+size, org[2], org[2]+size);
357                  vval(ZONE) = savqstr(buf);
358                  vdef(ZONE)++;
359          }
360 <        if (!vdef(UP)) {
361 <                vval(UP) = "Z";
362 <                vdef(UP)++;
360 >        if (!vdef(EYESEP)) {
361 >                if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
362 >                                &org[0], &lim[0], &org[1], &lim[1],
363 >                                &org[2], &lim[2]) != 6)
364 >                        badvalue(ZONE);
365 >                sprintf(buf, "%f",
366 >                        0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2]));
367 >                vval(EYESEP) = savqstr(buf);
368 >                vdef(EYESEP)++;
369          }
370          if (!vdef(INDIRECT)) {
371                  vval(INDIRECT) = "0";
# Line 467 | Line 383 | setdefaults()                  /* set default values for unassigned v
383                  vval(PICTURE) = radname;
384                  vdef(PICTURE)++;
385          }
386 <        if (!vdef(AMBFILE)) {
387 <                sprintf(buf, "%s.amb", radname);
388 <                vval(AMBFILE) = savqstr(buf);
473 <                vdef(AMBFILE)++;
386 >        if (!vdef(VIEWS)) {
387 >                vval(VIEWS) = "X";
388 >                vdef(VIEWS)++;
389          }
475        if (!vdef(VIEW)) {
476                vval(VIEW) = "X";
477                vdef(VIEW)++;
478        }
390          if (!vdef(DETAIL)) {
391                  vval(DETAIL) = "M";
392                  vdef(DETAIL)++;
# Line 491 | Line 402 | setdefaults()                  /* set default values for unassigned v
402   }
403  
404  
405 < printvals()                     /* print variable values */
405 > oconv()                         /* run oconv and mkillum if necessary */
406   {
407 <        register int    i, j;
407 >        static char     illumtmp[] = "ilXXXXXX";
408 >        char    combuf[PATH_MAX], ocopts[64], mkopts[64];
409  
410 <        for (i = 0; i < NVARS; i++)
411 <                for (j = 0; j < vv[i].nass; j++)
412 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
413 <        fflush(stdout);
414 < }
415 <
416 <
417 < oconv()                         /* run oconv if necessary */
418 < {
419 <        char    combuf[512], ocopts[64];
420 <
421 <        if (octreedate > scenedate)     /* check dates */
422 <                return;
423 <                                        /* build command */
424 <        oconvopts(ocopts);
425 <        sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE));
426 <        if (!silent) {                  /* echo it */
427 <                printf("\t%s\n", combuf);
428 <                fflush(stdout);
410 >        oconvopts(ocopts);              /* get options */
411 >        if (octreedate < scenedate) {   /* check date on original octree */
412 >                if (touchonly && octreedate)
413 >                        touch(vval(OCTREE));
414 >                else {                          /* build command */
415 >                        if (vdef(MATERIAL))
416 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
417 >                                                vval(MATERIAL), vval(SCENE),
418 >                                                vval(OCTREE));
419 >                        else
420 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
421 >                                                vval(SCENE), vval(OCTREE));
422 >                        
423 >                        if (runcom(combuf)) {           /* run it */
424 >                                fprintf(stderr,
425 >                                "%s: error generating octree\n\t%s removed\n",
426 >                                                progname, vval(OCTREE));
427 >                                unlink(vval(OCTREE));
428 >                                quit(1);
429 >                        }
430 >                }
431 >                octreedate = time((time_t *)NULL);
432 >                if (octreedate < scenedate)     /* in case clock is off */
433 >                        octreedate = scenedate;
434          }
435 <        if (noaction)
435 >        if (oct1name == vval(OCTREE))           /* no mkillum? */
436 >                oct1date = octreedate > matdate ? octreedate : matdate;
437 >        if (oct1date >= octreedate & oct1date >= matdate
438 >                        & oct1date >= illumdate)        /* all done */
439                  return;
440 <        if (system(combuf)) {           /* run it */
441 <                fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
442 <                                progname, vval(OCTREE));
443 <                unlink(vval(OCTREE));
444 <                exit(1);
440 >                                                /* make octree0 */
441 >        if (oct0date < scenedate | oct0date < illumdate) {
442 >                if (touchonly && oct0date)
443 >                        touch(oct0name);
444 >                else {                          /* build command */
445 >                        if (octreedate)
446 >                                sprintf(combuf, "oconv%s -i %s %s > %s", ocopts,
447 >                                        vval(OCTREE), vval(ILLUM), oct0name);
448 >                        else if (vdef(MATERIAL))
449 >                                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
450 >                                        vval(MATERIAL), vval(ILLUM), oct0name);
451 >                        else
452 >                                sprintf(combuf, "oconv%s %s > %s", ocopts,
453 >                                        vval(ILLUM), oct0name);
454 >                        if (runcom(combuf)) {           /* run it */
455 >                                fprintf(stderr,
456 >                                "%s: error generating octree\n\t%s removed\n",
457 >                                                progname, oct0name);
458 >                                unlink(oct0name);
459 >                                quit(1);
460 >                        }
461 >                }
462 >                oct0date = time((time_t *)NULL);
463 >                if (oct0date < octreedate)      /* in case clock is off */
464 >                        oct0date = octreedate;
465 >                if (oct0date < illumdate)       /* ditto */
466 >                        oct0date = illumdate;
467 >                }
468 >        if (touchonly && oct1date)
469 >                touch(oct1name);
470 >        else {
471 >                mkillumopts(mkopts);            /* build mkillum command */
472 >                mktemp(illumtmp);
473 >                sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts,
474 >                                oct0name, vval(ILLUM), illumtmp);
475 >                if (runcom(combuf)) {                   /* run it */
476 >                        fprintf(stderr, "%s: error running mkillum\n",
477 >                                        progname);
478 >                        unlink(illumtmp);
479 >                        quit(1);
480 >                }
481 >                                                /* make octree1 (frozen) */
482 >                if (octreedate)
483 >                        sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts,
484 >                                vval(OCTREE), illumtmp, oct1name);
485 >                else if (vdef(MATERIAL))
486 >                        sprintf(combuf, "oconv%s -f %s %s > %s", ocopts,
487 >                                vval(MATERIAL), illumtmp, oct1name);
488 >                else
489 >                        sprintf(combuf, "oconv%s -f %s > %s", ocopts,
490 >                                illumtmp, oct1name);
491 >                if (runcom(combuf)) {           /* run it */
492 >                        fprintf(stderr,
493 >                                "%s: error generating octree\n\t%s removed\n",
494 >                                        progname, oct1name);
495 >                        unlink(oct1name);
496 >                        unlink(illumtmp);
497 >                        quit(1);
498 >                }
499 >                rmfile(illumtmp);
500          }
501 +        oct1date = time((time_t *)NULL);
502 +        if (oct1date < oct0date)        /* in case clock is off */
503 +                oct1date = oct0date;
504   }
505  
506  
# Line 538 | Line 516 | register char  *op, *arg;
516  
517  
518   oconvopts(oo)                           /* get oconv options */
519 < char    *oo;
519 > register char   *oo;
520   {
521 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
522 +
523          *oo = '\0';
524          if (vdef(OCONV))
525                  addarg(oo, vval(OCONV));
526   }
527  
528  
529 < lowqopts(ro)                            /* low quality rendering options */
530 < char    *ro;
529 > mkillumopts(mo)                         /* get mkillum options */
530 > register char   *mo;
531   {
532 <        register char   *op = ro;
532 >        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
533  
534 +        *mo = '\0';
535 +        if (vdef(MKILLUM))
536 +                addarg(mo, vval(MKILLUM));
537 + }
538 +
539 +
540 + checkambfile()                  /* check date on ambient file */
541 + {
542 +        time_t  afdate;
543 +
544 +        if (!vdef(AMBFILE))
545 +                return;
546 +        if (!(afdate = fdate(vval(AMBFILE))))
547 +                return;
548 +        if (oct1date > afdate)
549 +                if (touchonly)
550 +                        touch(vval(AMBFILE));
551 +                else
552 +                        rmfile(vval(AMBFILE));
553 + }
554 +
555 +
556 + double
557 + ambval()                                /* compute ambient value */
558 + {
559 +        if (vdef(EXPOSURE)) {
560 +                if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
561 +                        return(.5/pow(2.,vflt(EXPOSURE)));
562 +                return(.5/vflt(EXPOSURE));
563 +        }
564 +        if (vlet(ZONE) == 'E')
565 +                return(10.);
566 +        if (vlet(ZONE) == 'I')
567 +                return(.01);
568 +        badvalue(ZONE);
569 + }
570 +
571 +
572 + renderopts(op, po)                      /* set rendering options */
573 + char    *op, *po;
574 + {
575 +        switch(vscale(QUALITY)) {
576 +        case LOW:
577 +                lowqopts(op, po);
578 +                break;
579 +        case MEDIUM:
580 +                medqopts(op, po);
581 +                break;
582 +        case HIGH:
583 +                hiqopts(op, po);
584 +                break;
585 +        }
586 + }
587 +
588 +
589 + lowqopts(op, po)                        /* low quality rendering options */
590 + register char   *op;
591 + char    *po;
592 + {
593 +        double  d, org[3], siz[3];
594 +
595          *op = '\0';
596 +        *po = '\0';
597 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
598 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
599 +                badvalue(ZONE);
600 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
601 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
602 +                badvalue(ZONE);
603 +        getoctcube(org, &d);
604 +        d *= 3./(siz[0]+siz[1]+siz[2]);
605 +        switch (vscale(DETAIL)) {
606 +        case LOW:
607 +                po = addarg(po, "-ps 16");
608 +                op = addarg(op, "-dp 64");
609 +                sprintf(op, " -ar %d", (int)(4*d));
610 +                op += strlen(op);
611 +                break;
612 +        case MEDIUM:
613 +                po = addarg(po, "-ps 8");
614 +                op = addarg(op, "-dp 128");
615 +                sprintf(op, " -ar %d", (int)(8*d));
616 +                op += strlen(op);
617 +                break;
618 +        case HIGH:
619 +                po = addarg(po, "-ps 4");
620 +                op = addarg(op, "-dp 256");
621 +                sprintf(op, " -ar %d", (int)(16*d));
622 +                op += strlen(op);
623 +                break;
624 +        }
625 +        po = addarg(po, "-pt .16");
626 +        if (vbool(PENUMBRAS))
627 +                op = addarg(op, "-ds .4");
628 +        else
629 +                op = addarg(op, "-ds 0");
630 +        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
631 +        if (vdef(AMBFILE)) {
632 +                sprintf(op, " -af %s", vval(AMBFILE));
633 +                op += strlen(op);
634 +        } else
635 +                overture = 0;
636 +        switch (vscale(VARIABILITY)) {
637 +        case LOW:
638 +                op = addarg(op, "-aa .4 -ad 64");
639 +                break;
640 +        case MEDIUM:
641 +                op = addarg(op, "-aa .3 -ad 128");
642 +                break;
643 +        case HIGH:
644 +                op = addarg(op, "-aa .25 -ad 256");
645 +                break;
646 +        }
647 +        op = addarg(op, "-as 0");
648 +        d = ambval();
649 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
650 +        op += strlen(op);
651 +        op = addarg(op, "-lr 3 -lw .02");
652          if (vdef(RENDER))
653                  op = addarg(op, vval(RENDER));
654   }
655  
656  
657 < medqopts(ro)                            /* medium quality rendering options */
658 < char    *ro;
657 > medqopts(op, po)                        /* medium quality rendering options */
658 > register char   *op;
659 > char    *po;
660   {
661 <        register char   *op = ro;
661 >        double  d, org[3], siz[3], asz;
662  
663          *op = '\0';
664 +        *po = '\0';
665 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
666 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
667 +                badvalue(ZONE);
668 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
669 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
670 +                badvalue(ZONE);
671 +        getoctcube(org, &d);
672 +        asz = (siz[0]+siz[1]+siz[2])/3.;
673 +        d /= asz;
674 +        switch (vscale(DETAIL)) {
675 +        case LOW:
676 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
677 +                op = addarg(op, "-dp 256");
678 +                sprintf(op, " -ar %d", (int)(8*d));
679 +                op += strlen(op);
680 +                sprintf(op, " -ms %.2g", asz/20.);
681 +                op += strlen(op);
682 +                break;
683 +        case MEDIUM:
684 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
685 +                op = addarg(op, "-dp 512");
686 +                sprintf(op, " -ar %d", (int)(16*d));
687 +                op += strlen(op);
688 +                sprintf(op, " -ms %.2g", asz/40.);
689 +                op += strlen(op);
690 +                break;
691 +        case HIGH:
692 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
693 +                op = addarg(op, "-dp 1024");
694 +                sprintf(op, " -ar %d", (int)(32*d));
695 +                op += strlen(op);
696 +                sprintf(op, " -ms %.2g", asz/80.);
697 +                op += strlen(op);
698 +                break;
699 +        }
700 +        po = addarg(po, "-pt .08");
701 +        if (vbool(PENUMBRAS))
702 +                op = addarg(op, "-ds .2 -dj .5");
703 +        else
704 +                op = addarg(op, "-ds .3");
705 +        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
706 +        if (overture = vint(INDIRECT)) {
707 +                sprintf(op, " -ab %d", overture);
708 +                op += strlen(op);
709 +        }
710 +        if (vdef(AMBFILE)) {
711 +                sprintf(op, " -af %s", vval(AMBFILE));
712 +                op += strlen(op);
713 +        } else
714 +                overture = 0;
715 +        switch (vscale(VARIABILITY)) {
716 +        case LOW:
717 +                op = addarg(op, "-aa .25 -ad 196 -as 0");
718 +                break;
719 +        case MEDIUM:
720 +                op = addarg(op, "-aa .2 -ad 400 -as 64");
721 +                break;
722 +        case HIGH:
723 +                op = addarg(op, "-aa .15 -ad 768 -as 196");
724 +                break;
725 +        }
726 +        d = ambval();
727 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
728 +        op += strlen(op);
729 +        op = addarg(op, "-lr 6 -lw .002");
730          if (vdef(RENDER))
731                  op = addarg(op, vval(RENDER));
732   }
733  
734  
735 < hiqopts(ro)                             /* high quality rendering options */
736 < char    *ro;
735 > hiqopts(op, po)                         /* high quality rendering options */
736 > register char   *op;
737 > char    *po;
738   {
739 <        register char   *op = ro;
739 >        double  d, org[3], siz[3], asz;
740  
741          *op = '\0';
742 +        *po = '\0';
743 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
744 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
745 +                badvalue(ZONE);
746 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
747 +        if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY)
748 +                badvalue(ZONE);
749 +        getoctcube(org, &d);
750 +        asz = (siz[0]+siz[1]+siz[2])/3.;
751 +        d /= asz;
752 +        switch (vscale(DETAIL)) {
753 +        case LOW:
754 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
755 +                op = addarg(op, "-dp 1024");
756 +                sprintf(op, " -ar %d", (int)(16*d));
757 +                op += strlen(op);
758 +                sprintf(op, " -ms %.2g", asz/40.);
759 +                op += strlen(op);
760 +                break;
761 +        case MEDIUM:
762 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
763 +                op = addarg(op, "-dp 2048");
764 +                sprintf(op, " -ar %d", (int)(32*d));
765 +                op += strlen(op);
766 +                sprintf(op, " -ms %.2g", asz/80.);
767 +                op += strlen(op);
768 +                break;
769 +        case HIGH:
770 +                po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
771 +                op = addarg(op, "-dp 4096");
772 +                sprintf(op, " -ar %d", (int)(64*d));
773 +                op += strlen(op);
774 +                sprintf(op, " -ms %.2g", asz/160.);
775 +                op += strlen(op);
776 +                break;
777 +        }
778 +        po = addarg(po, "-pt .04");
779 +        if (vbool(PENUMBRAS))
780 +                op = addarg(op, "-ds .1 -dj .65");
781 +        else
782 +                op = addarg(op, "-ds .2");
783 +        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
784 +        sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
785 +        op += strlen(op);
786 +        if (vdef(AMBFILE)) {
787 +                sprintf(op, " -af %s", vval(AMBFILE));
788 +                op += strlen(op);
789 +        } else
790 +                overture = 0;
791 +        switch (vscale(VARIABILITY)) {
792 +        case LOW:
793 +                op = addarg(op, "-aa .15 -ad 256 -as 0");
794 +                break;
795 +        case MEDIUM:
796 +                op = addarg(op, "-aa .125 -ad 512 -as 256");
797 +                break;
798 +        case HIGH:
799 +                op = addarg(op, "-aa .08 -ad 1024 -as 512");
800 +                break;
801 +        }
802 +        d = ambval();
803 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
804 +        op += strlen(op);
805 +        op = addarg(op, "-lr 12 -lw .0005");
806          if (vdef(RENDER))
807                  op = addarg(op, vval(RENDER));
808   }
# Line 583 | Line 812 | xferopts(ro)                           /* transfer options if indicated */
812   char    *ro;
813   {
814          int     fd, n;
815 +        register char   *cp;
816          
817          n = strlen(ro);
818          if (n < 2)
819                  return;
820          if (vdef(OPTFILE)) {
821 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
822 <                        perror(vval(OPTFILE));
823 <                        exit(1);
824 <                }
825 <                if (write(fd, ro+1, n-1) != n-1) {
826 <                        perror(vval(OPTFILE));
827 <                        exit(1);
828 <                }
829 <                write(fd, "\n", 1);
830 <                close(fd);
831 <                ro[0] = ' ';
602 <                ro[1] = '^';
603 <                strcpy(ro+2, vval(OPTFILE));
821 >                for (cp = ro; cp[1]; cp++)
822 >                        if (isspace(cp[1]) && (cp[2] == '@' ||
823 >                                        (cp[2] == '-' && isalpha(cp[3]))))
824 >                                *cp = '\n';
825 >                        else
826 >                                *cp = cp[1];
827 >                *cp = '\n';
828 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
829 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
830 >                        syserr(vval(OPTFILE));
831 >                sprintf(ro, " @%s", vval(OPTFILE));
832          }
833 < #ifdef MSDOS
833 > #ifdef _WIN32
834          else if (n > 50) {
835 <                register char   *evp = bmalloc(n+6);
608 <                if (evp == NULL) {
609 <                        perror(progname);
610 <                        exit(1);
611 <                }
612 <                strcpy(evp, "ROPT=");
613 <                strcat(evp, ro);
614 <                putenv(evp);
835 >                setenv("ROPT", ro+1);
836                  strcpy(ro, " $ROPT");
837          }
838   #endif
# Line 626 | Line 847 | register char  *po;
847                  po = addarg(po, "-1 -e");
848                  po = addarg(po, vval(EXPOSURE));
849          }
850 <        if (vscale(QUALITY) == HIGH)
851 <                po = addarg(po, "-r .65");
850 >        switch (vscale(QUALITY)) {
851 >        case MEDIUM:
852 >                po = addarg(po, "-r .6");
853 >                break;
854 >        case HIGH:
855 >                po = addarg(po, "-m .25");
856 >                break;
857 >        }
858          if (vdef(PFILT))
859                  po = addarg(po, vval(PFILT));
860   }
# Line 649 | Line 876 | char *
876   specview(vs)                            /* get proper view spec from vs */
877   register char   *vs;
878   {
879 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
880 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
881          static char     viewopts[128];
882          register char   *cp;
883 <        int     xpos, ypos, zpos, viewtype;
884 <        int     exterior;
883 >        int     xpos, ypos, zpos, viewtype, upax;
884 >        register int    i;
885          double  cent[3], dim[3], mult, d;
886  
887          if (vs == NULL || *vs == '-')
888                  return(vs);
889 +        upax = 0;                       /* get the up vector */
890 +        if (vdef(UP)) {
891 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
892 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
893 +                else
894 +                        upax = 1-'X'+vlet(UP);
895 +                if (upax < 1 | upax > 3)
896 +                        badvalue(UP);
897 +                if (vval(UP)[0] == '-')
898 +                        upax = -upax;
899 +        }
900                                          /* check standard view names */
901          xpos = ypos = zpos = 0;
662        viewtype = 0;
902          if (*vs == 'X') {
903                  xpos = 1; vs++;
904          } else if (*vs == 'x') {
# Line 675 | Line 914 | register char  *vs;
914          } else if (*vs == 'z') {
915                  zpos = -1; vs++;
916          }
917 <        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
917 >        viewtype = 'v';
918 >        if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c')
919                  viewtype = *vs++;
680        else if (!*vs || isspace(*vs))
681                viewtype = 'v';
920          cp = viewopts;
921 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
921 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
922                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
923                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
924                                  &cent[0], &dim[0], &cent[1], &dim[1],
925 <                                &cent[2], &dim[2]) != 6) {
926 <                        fprintf(stderr, "%s: bad zone specification\n",
927 <                                        progname);
928 <                        exit(1);
925 >                                &cent[2], &dim[2]) != 6)
926 >                        badvalue(ZONE);
927 >                for (i = 0; i < 3; i++) {
928 >                        dim[i] -= cent[i];
929 >                        if (dim[i] <= FTINY)
930 >                                badvalue(ZONE);
931 >                        cent[i] += .5*dim[i];
932                  }
933 <                dim[0] -= cent[0];
693 <                dim[1] -= cent[1];
694 <                dim[2] -= cent[2];
695 <                exterior = vlet(ZONE) == 'E';
696 <                mult = exterior ? 2. : .45 ;
933 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
934                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
935                                  cent[0]+xpos*mult*dim[0],
936                                  cent[1]+ypos*mult*dim[1],
937                                  cent[2]+zpos*mult*dim[2],
938                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
939                  cp += strlen(cp);
940 <                switch (vlet(UP)) {
941 <                case 'Z':
942 <                        if (xpos|ypos) {
943 <                                cp = addarg(cp, "-vu 0 0 1");
944 <                                break;
945 <                        }
946 <                /* fall through */
710 <                case 'Y':
711 <                        if (xpos|zpos) {
712 <                                cp = addarg(cp, "-vu 0 1 0");
713 <                                break;
714 <                        }
715 <                /* fall through */
716 <                case 'X':
717 <                        if (ypos|zpos)
718 <                                cp = addarg(cp, "-vu 1 0 0");
719 <                        else
720 <                                cp = addarg(cp, "-vu 0 0 1");
940 >                                        /* redirect up axis if necessary */
941 >                switch (upax) {
942 >                case 3:                 /* plus or minus Z axis */
943 >                case -3:
944 >                case 0:
945 >                        if (!(xpos|ypos))
946 >                                upax = 2;
947                          break;
948 <                default:
949 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
950 <                                        progname, vnam(UP));
951 <                        exit(1);
948 >                case 2:                 /* plus or minus Y axis */
949 >                case -2:
950 >                        if (!(xpos|zpos))
951 >                                upax = 1;
952 >                        break;
953 >                case 1:                 /* plus or minus X axis */
954 >                case -1:
955 >                        if (!(ypos|zpos))
956 >                                upax = 3;
957 >                        break;
958                  }
959 +                cp = addarg(cp, vup[upax+3]);
960                  switch (viewtype) {
961                  case 'v':
962                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 737 | Line 970 | register char  *vs;
970                  case 'h':
971                          cp = addarg(cp, "-vh 180 -vv 180");
972                          break;
973 +                case 'c':
974 +                        cp = addarg(cp, "-vh 180 -vv 90");
975 +                        break;
976                  }
977 <        } else
978 <                while (*vs && !isspace(*vs))    /* else skip id */
979 <                        vs++;
980 <                                        /* append any additional options */
981 <        while (isspace(*vs)) vs++;
977 >        } else {
978 >                while (!isspace(*vs))           /* else skip id */
979 >                        if (!*vs++)
980 >                                return(NULL);
981 >                if (upax) {                     /* specify up vector */
982 >                        strcpy(cp, vup[upax+3]);
983 >                        cp += strlen(cp);
984 >                }
985 >        }
986 >        if (cp == viewopts)             /* append any additional options */
987 >                vs++;           /* skip prefixed space if unneeded */
988          strcpy(cp, vs);
989 + #ifdef _WIN32
990 +        if (strlen(viewopts) > 40) {
991 +                setenv("VIEW", viewopts);
992 +                return("$VIEW");
993 +        }
994 + #endif
995          return(viewopts);
996   }
997  
# Line 751 | Line 999 | register char  *vs;
999   char *
1000   getview(n, vn)                          /* get view n, or NULL if none */
1001   int     n;
1002 < char    *vn;
1002 > char    *vn;            /* returned view name */
1003   {
1004          register char   *mv;
1005  
1006 <        if (viewselect != NULL) {
1006 >        if (viewselect != NULL) {               /* command-line selected */
1007                  if (n)                          /* only do one */
1008                          return(NULL);
1009                  if (viewselect[0] == '-') {     /* already specified */
# Line 768 | Line 1016 | char   *vn;
1016                                  ;
1017                          *vn = '\0';
1018                  }
1019 +                                                /* view number? */
1020 +                if (isint(viewselect))
1021 +                        return(specview(nvalue(VIEWS, atoi(viewselect)-1)));
1022                                                  /* check list */
1023 <                while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1023 >                while ((mv = nvalue(VIEWS, n++)) != NULL)
1024                          if (matchword(viewselect, mv))
1025                                  return(specview(mv));
1026                  return(specview(viewselect));   /* standard view? */
1027          }
1028 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1029 <                if (*mv != '-')
1030 <                        while (*mv && !isspace(*mv))
1031 <                                *vn++ = *mv++;
1028 >        mv = nvalue(VIEWS, n);          /* use view n */
1029 >        if (vn != NULL & mv != NULL) {
1030 >                register char   *mv2 = mv;
1031 >                if (*mv2 != '-')
1032 >                        while (*mv2 && !isspace(*mv2))
1033 >                                *vn++ = *mv2++;
1034                  *vn = '\0';
1035          }
1036 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1036 >        return(specview(mv));
1037   }
1038  
1039  
1040 < rview(opts)                             /* run rview with first view */
1041 < char    *opts;
1040 > printview(vopts)                        /* print out selected view */
1041 > register char   *vopts;
1042   {
1043 <        char    combuf[512];
1043 >        VIEW    vwr;
1044 >        char    buf[128];
1045 >        register char   *cp;
1046 > again:
1047 >        if (vopts == NULL)
1048 >                return(-1);
1049 > #ifdef _WIN32
1050 >        if (vopts[0] == '$') {
1051 >                vopts = getenv(vopts+1);
1052 >                goto again;
1053 >        }
1054 > #endif
1055 >        copystruct(&vwr, &stdview);
1056 >        sscanview(&vwr, cp=vopts);              /* set initial options */
1057 >        while ((cp = strstr(cp, "-vf ")) != NULL &&
1058 >                        *atos(buf, sizeof(buf), cp += 4)) {
1059 >                viewfile(buf, &vwr, NULL);      /* load -vf file */
1060 >                sscanview(&vwr, cp);            /* reset tail */
1061 >        }
1062 >        fputs(VIEWSTR, stdout);
1063 >        fprintview(&vwr, stdout);               /* print full spec. */
1064 >        fputc('\n', stdout);
1065 >        return(0);
1066 > }
1067 >
1068 >
1069 > rview(opts, po)                         /* run rview with first view */
1070 > char    *opts, *po;
1071 > {
1072 >        char    *vw;
1073 >        char    combuf[PATH_MAX];
1074                                          /* build command */
1075 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1075 >        if (touchonly || (vw = getview(0, NULL)) == NULL)
1076 >                return;
1077 >        if (sayview)
1078 >                printview(vw);
1079 >        sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname);
1080          if (rvdevice != NULL)
1081                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1082 <        strcat(combuf, vval(OCTREE));
1083 <        if (!silent) {                  /* echo it */
1084 <                printf("\t%s\n", combuf);
1085 <                fflush(stdout);
799 <        }
800 <        if (noaction)
801 <                return;
802 <        if (system(combuf)) {           /* run it */
1082 >        if (vdef(EXPOSURE))
1083 >                sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE));
1084 >        strcat(combuf, oct1name);
1085 >        if (runcom(combuf)) {           /* run it */
1086                  fprintf(stderr, "%s: error running rview\n", progname);
1087 <                exit(1);
1087 >                quit(1);
1088          }
1089   }
1090  
1091  
1092 < rpict(opts)                             /* run rpict and pfilt for each view */
1093 < char    *opts;
1092 > rpict(opts, po)                         /* run rpict and pfilt for each view */
1093 > char    *opts, *po;
1094   {
1095 <        char    combuf[512];
1096 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1097 <        char    pfopts[64];
1095 >        char    combuf[PATH_MAX];
1096 >        char    rawfile[PATH_MAX], picfile[PATH_MAX];
1097 >        char    zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32];
1098 >        char    pfopts[128];
1099          char    vs[32], *vw;
1100          int     vn, mult;
1101 +        time_t  rfdt, pfdt;
1102                                          /* get pfilt options */
1103          pfiltopts(pfopts);
1104                                          /* get resolution, reporting */
1105 <        mult = vscale(QUALITY)+1;
1105 >        switch (vscale(QUALITY)) {
1106 >        case LOW:
1107 >                mult = 1;
1108 >                break;
1109 >        case MEDIUM:
1110 >                mult = 2;
1111 >                break;
1112 >        case HIGH:
1113 >                mult = 3;
1114 >                break;
1115 >        }
1116          {
1117                  int     xres, yres;
1118                  double  aspect;
# Line 829 | Line 1124 | char   *opts;
1124                  else if (n) {
1125                          if (n == 1) yres = xres;
1126                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1127 <                } else {
1128 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
834 <                                        progname, vnam(RESOLUTION));
835 <                        exit(1);
836 <                }
1127 >                } else
1128 >                        badvalue(RESOLUTION);
1129          }
1130          rep[0] = '\0';
1131          if (vdef(REPORT)) {
# Line 844 | Line 1136 | char   *opts;
1136                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1137                  else if (n == 1)
1138                          sprintf(rep, " -t %d", (int)(minutes*60));
1139 <                else {
1140 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
849 <                                        progname, vnam(REPORT));
850 <                        exit(1);
851 <                }
1139 >                else
1140 >                        badvalue(REPORT);
1141          }
1142 <                                        /* do each view */
854 <        vn = 0;
1142 >        vn = 0;                                 /* do each view */
1143          while ((vw = getview(vn++, vs)) != NULL) {
1144 +                if (sayview)
1145 +                        printview(vw);
1146                  if (!vs[0])
1147                          sprintf(vs, "%d", vn);
1148                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1149 +                if (vdef(ZFILE))
1150 +                        sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs);
1151 +                else
1152 +                        zopt[0] = '\0';
1153                                                  /* check date on picture */
1154 <                if (fdate(picfile) > octreedate)
1154 >                pfdt = fdate(picfile);
1155 >                if (pfdt >= oct1date)
1156                          continue;
1157 +                                                /* get raw file name */
1158 +                sprintf(rawfile, "%s_%s.unf",
1159 +                        vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs);
1160 +                rfdt = fdate(rawfile);
1161 +                if (touchonly) {                /* update times only */
1162 +                        if (rfdt) {
1163 +                                if (rfdt < oct1date)
1164 +                                        touch(rawfile);
1165 +                        } else if (pfdt && pfdt < oct1date)
1166 +                                touch(picfile);
1167 +                        continue;
1168 +                }
1169 +                if (next_process())             /* parallel running? */
1170 +                        continue;
1171 +                /* XXX Remember to call finish_process() */
1172                                                  /* build rpict command */
1173 <                sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1174 <                if (fdate(rawfile) > octreedate)        /* recover */
1175 <                        sprintf(combuf, "rpict%s%s -ro %s %s",
866 <                                        rep, opts, rawfile, vval(OCTREE));
1173 >                if (rfdt >= oct1date)           /* recover */
1174 >                        sprintf(combuf, "rpict%s%s%s%s -ro %s %s",
1175 >                                rep, po, opts, zopt, rawfile, oct1name);
1176                  else {
1177                          if (overture) {         /* run overture calculation */
1178                                  sprintf(combuf,
1179                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1180                                                  rep, vw, opts,
1181 <                                                vval(OCTREE), rawfile);
1182 <                                if (!silent) {
874 <                                        printf("\t%s\n", combuf);
875 <                                        fflush(stdout);
876 <                                }
877 <                                if (!noaction && system(combuf)) {
1181 >                                                oct1name, overfile);
1182 >                                if (runcom(combuf)) {
1183                                          fprintf(stderr,
1184 <                        "%s: error in overture for view %s\n\t%s removed\n",
1185 <                                                progname, vs, rawfile);
1186 <                                        unlink(rawfile);
882 <                                        exit(1);
1184 >                                        "%s: error in overture for view %s\n",
1185 >                                                progname, vs);
1186 >                                        quit(1);
1187                                  }
1188 + #ifndef NULL_DEVICE
1189 +                                rmfile(overfile);
1190 + #endif
1191                          }
1192 <                        sprintf(combuf, "rpict%s %s %s%s %s > %s",
1193 <                                        rep, vw, res, opts,
1194 <                                        vval(OCTREE), rawfile);
1192 >                        sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s",
1193 >                                        rep, vw, res, po, opts, zopt,
1194 >                                        oct1name, rawfile);
1195                  }
1196 <                if (!silent) {                  /* echo rpict command */
890 <                        printf("\t%s\n", combuf);
891 <                        fflush(stdout);
892 <                }
893 <                if (!noaction && system(combuf)) {      /* run rpict */
1196 >                if (runcom(combuf)) {           /* run rpict */
1197                          fprintf(stderr, "%s: error rendering view %s\n",
1198                                          progname, vs);
1199 <                        exit(1);
1199 >                        quit(1);
1200                  }
1201 +                if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) {
1202                                                  /* build pfilt command */
1203 <                if (mult > 1)
1204 <                        sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1203 >                        if (mult > 1)
1204 >                                sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1205                                          pfopts, mult, mult, rawfile, picfile);
1206 <                else
1207 <                        sprintf(combuf, "pfilt%s %s > %s", pfopts,
1208 <                                        rawfile, picfile);
1209 <                if (!silent) {                  /* echo pfilt command */
1210 <                        printf("\t%s\n", combuf);
1211 <                        fflush(stdout);
1206 >                        else
1207 >                                sprintf(combuf, "pfilt%s %s > %s", pfopts,
1208 >                                                rawfile, picfile);
1209 >                        if (runcom(combuf)) {           /* run pfilt */
1210 >                                fprintf(stderr,
1211 >                                "%s: error filtering view %s\n\t%s removed\n",
1212 >                                                progname, vs, picfile);
1213 >                                unlink(picfile);
1214 >                                quit(1);
1215 >                        }
1216                  }
1217 <                if (!noaction && system(combuf)) {      /* run pfilt */
1218 <                        fprintf(stderr,
1219 <                        "%s: error filtering view %s\n\t%s removed\n",
1220 <                                        progname, vs, picfile);
1221 <                        unlink(picfile);
1222 <                        exit(1);
1223 <                }
1224 <                                                /* remove raw file */
1225 <                if (!silent)
1226 < #ifdef MSDOS
1227 <                        printf("\tdel %s\n", rawfile);
1217 >                                                /* remove/rename raw file */
1218 >                if (vdef(RAWFILE)) {
1219 >                        sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs);
1220 >                        mvfile(rawfile, combuf);
1221 >                } else
1222 >                        rmfile(rawfile);
1223 >                finish_process();               /* leave if child */
1224 >        }
1225 >        wait_process(1);                /* wait for children to finish */
1226 > }
1227 >
1228 >
1229 > touch(fn)                       /* update a file */
1230 > char    *fn;
1231 > {
1232 >        if (!silent)
1233 >                printf("\ttouch %s\n", fn);
1234 >        if (!nprocs)
1235 >                return(0);
1236 > #ifdef notused
1237 >        if (access(fn, F_OK) == -1)             /* create it */
1238 >                if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1)
1239 >                        return(-1);
1240 > #endif
1241 >        return(setfdate(fn, time((time_t *)NULL)));
1242 > }
1243 >
1244 >
1245 > runcom(cs)                      /* run command */
1246 > char    *cs;
1247 > {
1248 >        if (!silent)            /* echo it */
1249 >                printf("\t%s\n", cs);
1250 >        if (!nprocs)
1251 >                return(0);
1252 >        fflush(stdout);         /* flush output and pass to shell */
1253 >        return(system(cs));
1254 > }
1255 >
1256 >
1257 > rmfile(fn)                      /* remove a file */
1258 > char    *fn;
1259 > {
1260 >        if (!silent)
1261 > #ifdef _WIN32
1262 >                printf("\tdel %s\n", fn);
1263   #else
1264 <                        printf("\trm %s\n", rawfile);
1264 >                printf("\trm -f %s\n", fn);
1265   #endif
1266 <                if (!noaction)
1267 <                        unlink(rawfile);
1266 >        if (!nprocs)
1267 >                return(0);
1268 >        return(unlink(fn));
1269 > }
1270 >
1271 >
1272 > mvfile(fold, fnew)              /* move a file */
1273 > char    *fold, *fnew;
1274 > {
1275 >        if (!silent)
1276 > #ifdef _WIN32
1277 >                printf("\trename %s %s\n", fold, fnew);
1278 > #else
1279 >                printf("\tmv %s %s\n", fold, fnew);
1280 > #endif
1281 >        if (!nprocs)
1282 >                return(0);
1283 >        return(rename(fold, fnew));
1284 > }
1285 >
1286 >
1287 > #ifdef RHAS_FORK_EXEC
1288 > int
1289 > next_process()                  /* fork the next process (max. nprocs) */
1290 > {
1291 >        int     child_pid;
1292 >
1293 >        if (nprocs <= 1)
1294 >                return(0);              /* it's us or no one */
1295 >        if (children_running < 0) {
1296 >                fprintf(stderr, "%s: internal error 1 in spawn_process()\n",
1297 >                                progname);
1298 >                quit(1);
1299          }
1300 +        if (children_running >= nprocs)
1301 +                wait_process(0);        /* wait for someone to finish */
1302 +        fflush(stdout);
1303 +        child_pid = fork();             /* split process */
1304 +        if (child_pid == 0) {           /* we're the child */
1305 +                children_running = -1;
1306 +                return(0);
1307 +        }
1308 +        if (child_pid > 0) {            /* we're the parent */
1309 +                ++children_running;
1310 +                return(1);
1311 +        }
1312 +        fprintf(stderr, "%s: warning -- fork() failed\n", progname);
1313 +        return(0);
1314 + }
1315 +
1316 + wait_process(all)                       /* wait for process(es) to finish */
1317 + int     all;
1318 + {
1319 +        int     ourstatus = 0;
1320 +        int     pid, status;
1321 +
1322 +        if (all)
1323 +                all = children_running;
1324 +        else if (children_running > 0)
1325 +                all = 1;
1326 +        while (all-- > 0) {
1327 +                pid = wait(&status);
1328 +                if (pid < 0)
1329 +                        syserr(progname);
1330 +                status = status>>8 & 0xff;
1331 +                --children_running;
1332 +                if (status != 0) {      /* child's problem is our problem */
1333 +                        if (ourstatus == 0 & children_running > 0)
1334 +                                fprintf(stderr, "%s: waiting for remaining processes\n",
1335 +                                                progname);
1336 +                        ourstatus = status;
1337 +                        all = children_running;
1338 +                }
1339 +        }
1340 +        if (ourstatus != 0)
1341 +                quit(ourstatus);        /* bad status from child */
1342 + }
1343 + #else   /* ! RHAS_FORK_EXEC */
1344 + int
1345 + next_process()
1346 + {
1347 +        return(0);                      /* cannot start new process */
1348 + }
1349 + wait_process(all)
1350 + int     all;
1351 + {
1352 +        (void)all;                      /* no one to wait for */
1353 + }
1354 + #endif  /* ! RHAS_FORK_EXEC */
1355 +
1356 + finish_process()                        /* exit a child process */
1357 + {
1358 +        if (children_running >= 0)
1359 +                return;                 /* in parent -- noop */
1360 +        exit(0);
1361 + }
1362 +
1363 + #ifdef _WIN32
1364 + setenv(vname, value)            /* set an environment variable */
1365 + char    *vname, *value;
1366 + {
1367 +        register char   *evp;
1368 +
1369 +        evp = bmalloc(strlen(vname)+strlen(value)+2);
1370 +        if (evp == NULL)
1371 +                syserr(progname);
1372 +        sprintf(evp, "%s=%s", vname, value);
1373 +        if (putenv(evp) != 0) {
1374 +                fprintf(stderr, "%s: out of environment space\n", progname);
1375 +                quit(1);
1376 +        }
1377 +        if (!silent)
1378 +                printf("set %s\n", evp);
1379 + }
1380 + #endif
1381 +
1382 +
1383 + badvalue(vc)                    /* report bad variable value and exit */
1384 + int     vc;
1385 + {
1386 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1387 +                        progname, vnam(vc));
1388 +        quit(1);
1389 + }
1390 +
1391 +
1392 + syserr(s)                       /* report a system error and exit */
1393 + char    *s;
1394 + {
1395 +        perror(s);
1396 +        quit(1);
1397 + }
1398 +
1399 +
1400 + void
1401 + quit(ec)                        /* exit program */
1402 + int     ec;
1403 + {
1404 +        exit(ec);
1405   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines