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.50 by greg, Fri Jan 5 14:43:03 1996 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines