| 1 | greg | 2.1 | /* Copyright (c) 1993 Regents of the University of California */ | 
| 2 |  |  |  | 
| 3 |  |  | #ifndef lint | 
| 4 |  |  | static char SCCSid[] = "$SunId$ LBL"; | 
| 5 |  |  | #endif | 
| 6 |  |  |  | 
| 7 |  |  | /* | 
| 8 |  |  | * Executive program for oconv, rpict and pfilt | 
| 9 |  |  | */ | 
| 10 |  |  |  | 
| 11 |  |  | #include "standard.h" | 
| 12 |  |  | #include "paths.h" | 
| 13 |  |  | #include <ctype.h> | 
| 14 |  |  |  | 
| 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 |  |  |  | 
| 26 |  |  | /* variables */ | 
| 27 |  |  | #define OBJECT          0               /* object files */ | 
| 28 |  |  | #define SCENE           1               /* scene files */ | 
| 29 |  |  | #define MATERIAL        2               /* material files */ | 
| 30 |  |  | #define RENDER          3               /* rendering options */ | 
| 31 |  |  | #define OCONV           4               /* oconv options */ | 
| 32 |  |  | #define PFILT           5               /* pfilt options */ | 
| 33 |  |  | #define VIEW            6               /* view(s) for picture(s) */ | 
| 34 |  |  | #define ZONE            7               /* simulation zone */ | 
| 35 |  |  | #define QUALITY         8               /* desired rendering quality */ | 
| 36 |  |  | #define OCTREE          9               /* octree file name */ | 
| 37 |  |  | #define PICTURE         10              /* picture file name */ | 
| 38 |  |  | #define AMBFILE         11              /* ambient file name */ | 
| 39 |  |  | #define OPTFILE         12              /* rendering options file */ | 
| 40 |  |  | #define EXPOSURE        13              /* picture exposure setting */ | 
| 41 |  |  | #define RESOLUTION      14              /* maximum picture resolution */ | 
| 42 |  |  | #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 */ | 
| 48 |  |  | /* total number of variables */ | 
| 49 |  |  | #define NVARS           21 | 
| 50 |  |  |  | 
| 51 |  |  | VARIABLE        vv[NVARS] = {           /* variable-value pairs */ | 
| 52 |  |  | {"objects",     3,      0,      NULL,   catvalues}, | 
| 53 |  |  | {"scene",       3,      0,      NULL,   catvalues}, | 
| 54 |  |  | {"materials",   3,      0,      NULL,   catvalues}, | 
| 55 |  |  | {"render",      3,      0,      NULL,   catvalues}, | 
| 56 |  |  | {"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}, | 
| 61 |  |  | {"OCTREE",      3,      0,      NULL,   onevalue}, | 
| 62 |  |  | {"PICTURE",     3,      0,      NULL,   onevalue}, | 
| 63 |  |  | {"AMBFILE",     3,      0,      NULL,   onevalue}, | 
| 64 |  |  | {"OPTFILE",     3,      0,      NULL,   onevalue}, | 
| 65 |  |  | {"EXPOSURE",    3,      0,      NULL,   onevalue}, | 
| 66 |  |  | {"RESOLUTION",  3,      0,      NULL,   onevalue}, | 
| 67 |  |  | {"UP",          2,      0,      NULL,   onevalue}, | 
| 68 |  |  | {"INDIRECT",    3,      0,      NULL,   onevalue}, | 
| 69 |  |  | {"DETAIL",      3,      0,      NULL,   onevalue}, | 
| 70 |  |  | {"PENUMBRAS",   3,      0,      NULL,   onevalue}, | 
| 71 |  |  | {"VARIABILITY", 3,      0,      NULL,   onevalue}, | 
| 72 |  |  | {"REPORT",      3,      0,      NULL,   onevalue}, | 
| 73 |  |  | }; | 
| 74 |  |  |  | 
| 75 |  |  | VARIABLE        *matchvar(); | 
| 76 |  |  | char    *nvalue(); | 
| 77 |  |  | int     vscale(); | 
| 78 |  |  |  | 
| 79 | greg | 2.3 | #define UPPER(c)        ((c)&~0x20)     /* ASCII trick */ | 
| 80 |  |  |  | 
| 81 | greg | 2.1 | #define vnam(vc)        (vv[vc].name) | 
| 82 |  |  | #define vdef(vc)        (vv[vc].nass) | 
| 83 |  |  | #define vval(vc)        (vv[vc].value) | 
| 84 |  |  | #define vint(vc)        atoi(vval(vc)) | 
| 85 | greg | 2.3 | #define vlet(vc)        UPPER(vval(vc)[0]) | 
| 86 | greg | 2.1 | #define vbool(vc)       (vlet(vc)=='T') | 
| 87 |  |  |  | 
| 88 |  |  | #define HIGH            2 | 
| 89 |  |  | #define MEDIUM          1 | 
| 90 |  |  | #define LOW             0 | 
| 91 |  |  |  | 
| 92 |  |  | int     lowqopts(), medqopts(), hiqopts(); | 
| 93 |  |  | int     (*setqopts[3])() = {lowqopts, medqopts, hiqopts}; | 
| 94 |  |  |  | 
| 95 |  |  | #define renderopts      (*setqopts[vscale(QUALITY)]) | 
| 96 |  |  |  | 
| 97 | greg | 2.2 | extern long     fdate(), time(); | 
| 98 | greg | 2.1 |  | 
| 99 |  |  | long    scenedate;              /* date of latest scene or object file */ | 
| 100 |  |  | long    octreedate;             /* date of octree */ | 
| 101 |  |  |  | 
| 102 |  |  | int     explicate = 0;          /* explicate variables */ | 
| 103 |  |  | int     silent = 0;             /* do work silently */ | 
| 104 |  |  | int     noaction = 0;           /* don't do anything */ | 
| 105 |  |  | char    *rvdevice = NULL;       /* rview output device */ | 
| 106 |  |  | char    *viewselect = NULL;     /* specific view only */ | 
| 107 |  |  |  | 
| 108 |  |  | int     overture = 0;           /* overture calculation needed */ | 
| 109 |  |  |  | 
| 110 |  |  | char    *progname;              /* global argv[0] */ | 
| 111 |  |  |  | 
| 112 |  |  | char    radname[MAXPATH];       /* root Radiance file name */ | 
| 113 |  |  |  | 
| 114 |  |  |  | 
| 115 |  |  | main(argc, argv) | 
| 116 |  |  | int     argc; | 
| 117 |  |  | char    *argv[]; | 
| 118 |  |  | { | 
| 119 |  |  | char    ropts[512]; | 
| 120 |  |  | int     i; | 
| 121 |  |  |  | 
| 122 |  |  | progname = argv[0]; | 
| 123 |  |  | /* get options */ | 
| 124 |  |  | for (i = 1; i < argc && argv[i][0] == '-'; i++) | 
| 125 |  |  | switch (argv[i][1]) { | 
| 126 |  |  | case 's': | 
| 127 |  |  | silent++; | 
| 128 |  |  | break; | 
| 129 |  |  | case 'n': | 
| 130 |  |  | noaction++; | 
| 131 |  |  | break; | 
| 132 |  |  | case 'e': | 
| 133 |  |  | explicate++; | 
| 134 |  |  | break; | 
| 135 |  |  | case 'o': | 
| 136 |  |  | rvdevice = argv[++i]; | 
| 137 |  |  | break; | 
| 138 |  |  | case 'v': | 
| 139 |  |  | viewselect = argv[++i]; | 
| 140 |  |  | break; | 
| 141 |  |  | default: | 
| 142 |  |  | goto userr; | 
| 143 |  |  | } | 
| 144 |  |  | if (i >= argc) | 
| 145 |  |  | goto userr; | 
| 146 |  |  | /* assign Radiance root file name */ | 
| 147 |  |  | rootname(radname, argv[i]); | 
| 148 |  |  | /* load variable values */ | 
| 149 |  |  | load(argv[i]); | 
| 150 |  |  | /* get any additional assignments */ | 
| 151 |  |  | for (i++; i < argc; i++) | 
| 152 |  |  | setvariable(argv[i]); | 
| 153 |  |  | /* check assignments */ | 
| 154 |  |  | checkvalues(); | 
| 155 |  |  | /* check files and dates */ | 
| 156 |  |  | checkfiles(); | 
| 157 |  |  | /* set default values as necessary */ | 
| 158 |  |  | setdefaults(); | 
| 159 |  |  | /* print all values if requested */ | 
| 160 |  |  | if (explicate) | 
| 161 |  |  | printvals(); | 
| 162 |  |  | /* run simulation */ | 
| 163 |  |  | oconv(); | 
| 164 |  |  | renderopts(ropts); | 
| 165 |  |  | xferopts(ropts); | 
| 166 |  |  | if (rvdevice != NULL) | 
| 167 |  |  | rview(ropts); | 
| 168 |  |  | else | 
| 169 |  |  | rpict(ropts); | 
| 170 |  |  | exit(0); | 
| 171 |  |  | userr: | 
| 172 |  |  | fprintf(stderr, | 
| 173 | greg | 2.3 | "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n", | 
| 174 | greg | 2.1 | progname); | 
| 175 |  |  | exit(1); | 
| 176 |  |  | } | 
| 177 |  |  |  | 
| 178 |  |  |  | 
| 179 |  |  | rootname(rn, fn)                /* remove tail from end of fn */ | 
| 180 |  |  | register char   *rn, *fn; | 
| 181 |  |  | { | 
| 182 |  |  | char    *tp, *dp; | 
| 183 |  |  |  | 
| 184 |  |  | for (tp = NULL, dp = rn; *rn = *fn++; rn++) | 
| 185 |  |  | if (ISDIRSEP(*rn)) | 
| 186 |  |  | dp = rn; | 
| 187 |  |  | else if (*rn == '.') | 
| 188 |  |  | tp = rn; | 
| 189 |  |  | if (tp != NULL && tp > dp) | 
| 190 |  |  | *tp = '\0'; | 
| 191 |  |  | } | 
| 192 |  |  |  | 
| 193 |  |  |  | 
| 194 |  |  | load(rfname)                    /* load Radiance simulation file */ | 
| 195 |  |  | char    *rfname; | 
| 196 |  |  | { | 
| 197 |  |  | FILE    *fp; | 
| 198 | greg | 2.4 | char    buf[512]; | 
| 199 | greg | 2.1 | register char   *cp; | 
| 200 |  |  |  | 
| 201 |  |  | if (rfname == NULL) | 
| 202 |  |  | fp = stdin; | 
| 203 | greg | 2.3 | else if ((fp = fopen(rfname, "r")) == NULL) | 
| 204 |  |  | syserr(rfname); | 
| 205 | greg | 2.1 | 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 | greg | 2.4 | default: | 
| 216 |  |  | continue; | 
| 217 | greg | 2.1 | } | 
| 218 |  |  | break; | 
| 219 |  |  | } | 
| 220 |  |  | setvariable(buf); | 
| 221 |  |  | } | 
| 222 |  |  | fclose(fp); | 
| 223 |  |  | } | 
| 224 |  |  |  | 
| 225 |  |  |  | 
| 226 |  |  | setvariable(ass)                /* assign variable according to string */ | 
| 227 |  |  | register char   *ass; | 
| 228 |  |  | { | 
| 229 |  |  | char    varname[32]; | 
| 230 |  |  | register char   *cp; | 
| 231 |  |  | register VARIABLE       *vp; | 
| 232 |  |  | register int    i; | 
| 233 |  |  | int     n; | 
| 234 |  |  |  | 
| 235 |  |  | while (isspace(*ass))           /* skip leading space */ | 
| 236 |  |  | ass++; | 
| 237 |  |  | cp = varname;                   /* extract name */ | 
| 238 |  |  | while (cp < varname+sizeof(varname)-1 | 
| 239 |  |  | && *ass && !isspace(*ass) && *ass != '=') | 
| 240 |  |  | *cp++ = *ass++; | 
| 241 |  |  | *cp = '\0'; | 
| 242 |  |  | if (!varname[0]) | 
| 243 |  |  | return;         /* no variable name! */ | 
| 244 |  |  | /* trim value */ | 
| 245 |  |  | while (isspace(*ass) || *ass == '=') | 
| 246 |  |  | ass++; | 
| 247 |  |  | cp = ass + strlen(ass); | 
| 248 |  |  | do | 
| 249 |  |  | *cp-- = '\0'; | 
| 250 |  |  | while (cp >= ass && isspace(*cp)); | 
| 251 |  |  | n = cp - ass + 1; | 
| 252 |  |  | if (!n) { | 
| 253 |  |  | fprintf(stderr, "%s: warning - missing value for variable '%s'\n", | 
| 254 |  |  | progname, varname); | 
| 255 |  |  | return; | 
| 256 |  |  | } | 
| 257 |  |  | /* match variable from list */ | 
| 258 |  |  | vp = matchvar(varname); | 
| 259 |  |  | if (vp == NULL) { | 
| 260 |  |  | fprintf(stderr, "%s: unknown variable '%s'\n", | 
| 261 |  |  | progname, varname); | 
| 262 |  |  | exit(1); | 
| 263 |  |  | } | 
| 264 |  |  | /* assign new value */ | 
| 265 | greg | 2.4 | if (i = vp->nass) { | 
| 266 |  |  | cp = vp->value; | 
| 267 |  |  | while (i--) | 
| 268 |  |  | while (*cp++) | 
| 269 |  |  | ; | 
| 270 |  |  | i = cp - vp->value; | 
| 271 |  |  | vp->value = realloc(vp->value, i+n+1); | 
| 272 |  |  | } else | 
| 273 |  |  | vp->value = malloc(n+1); | 
| 274 | greg | 2.3 | if (vp->value == NULL) | 
| 275 |  |  | syserr(progname); | 
| 276 | greg | 2.1 | strcpy(vp->value+i, ass); | 
| 277 |  |  | vp->nass++; | 
| 278 |  |  | } | 
| 279 |  |  |  | 
| 280 |  |  |  | 
| 281 |  |  | VARIABLE * | 
| 282 |  |  | matchvar(nam)                   /* match a variable by its name */ | 
| 283 |  |  | char    *nam; | 
| 284 |  |  | { | 
| 285 |  |  | int     n = strlen(nam); | 
| 286 |  |  | register int    i; | 
| 287 |  |  |  | 
| 288 |  |  | for (i = 0; i < NVARS; i++) | 
| 289 |  |  | if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) | 
| 290 |  |  | return(vv+i); | 
| 291 |  |  | return(NULL); | 
| 292 |  |  | } | 
| 293 |  |  |  | 
| 294 |  |  |  | 
| 295 |  |  | char * | 
| 296 |  |  | nvalue(vp, n)                   /* return nth variable value */ | 
| 297 |  |  | VARIABLE        *vp; | 
| 298 |  |  | register int    n; | 
| 299 |  |  | { | 
| 300 |  |  | register char   *cp; | 
| 301 |  |  |  | 
| 302 |  |  | if (vp == NULL || n < 0 || n >= vp->nass) | 
| 303 |  |  | return(NULL); | 
| 304 |  |  | cp = vp->value; | 
| 305 |  |  | while (n--) | 
| 306 |  |  | while (*cp++) | 
| 307 |  |  | ; | 
| 308 |  |  | return(cp); | 
| 309 |  |  | } | 
| 310 |  |  |  | 
| 311 |  |  |  | 
| 312 |  |  | int | 
| 313 |  |  | vscale(vc)                      /* return scale for variable vc */ | 
| 314 |  |  | int     vc; | 
| 315 |  |  | { | 
| 316 |  |  | switch(vlet(vc)) { | 
| 317 |  |  | case 'H': | 
| 318 |  |  | return(HIGH); | 
| 319 |  |  | case 'M': | 
| 320 |  |  | return(MEDIUM); | 
| 321 |  |  | case 'L': | 
| 322 |  |  | return(LOW); | 
| 323 |  |  | } | 
| 324 | greg | 2.3 | badvalue(vc); | 
| 325 | greg | 2.1 | } | 
| 326 |  |  |  | 
| 327 |  |  |  | 
| 328 |  |  | checkvalues()                   /* check assignments */ | 
| 329 |  |  | { | 
| 330 |  |  | register int    i; | 
| 331 |  |  |  | 
| 332 |  |  | for (i = 0; i < NVARS; i++) | 
| 333 |  |  | if (vv[i].fixval != NULL) | 
| 334 |  |  | (*vv[i].fixval)(vv+i); | 
| 335 |  |  | } | 
| 336 |  |  |  | 
| 337 |  |  |  | 
| 338 |  |  | onevalue(vp)                    /* only one assignment for this variable */ | 
| 339 |  |  | register VARIABLE       *vp; | 
| 340 |  |  | { | 
| 341 |  |  | if (vp->nass < 2) | 
| 342 |  |  | return; | 
| 343 |  |  | fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n", | 
| 344 |  |  | progname, vp->name); | 
| 345 | greg | 2.2 | do | 
| 346 | greg | 2.1 | vp->value += strlen(vp->value)+1; | 
| 347 | greg | 2.2 | while (--vp->nass > 1); | 
| 348 | greg | 2.1 | } | 
| 349 |  |  |  | 
| 350 |  |  |  | 
| 351 |  |  | catvalues(vp)                   /* concatenate variable values */ | 
| 352 |  |  | register VARIABLE       *vp; | 
| 353 |  |  | { | 
| 354 |  |  | register char   *cp; | 
| 355 |  |  |  | 
| 356 |  |  | if (vp->nass < 2) | 
| 357 |  |  | return; | 
| 358 |  |  | for (cp = vp->value; vp->nass > 1; vp->nass--) { | 
| 359 |  |  | while (*cp) | 
| 360 |  |  | cp++; | 
| 361 |  |  | *cp++ = ' '; | 
| 362 |  |  | } | 
| 363 |  |  | } | 
| 364 |  |  |  | 
| 365 |  |  |  | 
| 366 |  |  | long | 
| 367 |  |  | checklast(fnames)                       /* check files and find most recent */ | 
| 368 |  |  | register char   *fnames; | 
| 369 |  |  | { | 
| 370 |  |  | char    thisfile[MAXPATH]; | 
| 371 |  |  | long    thisdate, lastdate = -1; | 
| 372 |  |  | register char   *cp; | 
| 373 |  |  |  | 
| 374 |  |  | while (*fnames) { | 
| 375 |  |  | while (isspace(*fnames)) fnames++; | 
| 376 |  |  | cp = thisfile; | 
| 377 | greg | 2.4 | while (*fnames && !isspace(*fnames)) | 
| 378 |  |  | *cp++ = *fnames++; | 
| 379 | greg | 2.1 | *cp = '\0'; | 
| 380 | greg | 2.3 | if ((thisdate = fdate(thisfile)) < 0) | 
| 381 |  |  | syserr(thisfile); | 
| 382 | greg | 2.1 | if (thisdate > lastdate) | 
| 383 |  |  | lastdate = thisdate; | 
| 384 |  |  | } | 
| 385 |  |  | return(lastdate); | 
| 386 |  |  | } | 
| 387 |  |  |  | 
| 388 |  |  |  | 
| 389 |  |  | checkfiles()                    /* check for existence and modified times */ | 
| 390 |  |  | { | 
| 391 | greg | 2.2 | char    *cp; | 
| 392 | greg | 2.1 | long    objdate; | 
| 393 |  |  |  | 
| 394 | greg | 2.2 | if (!vdef(OCTREE)) { | 
| 395 | greg | 2.3 | if ((cp = bmalloc(strlen(radname)+5)) == NULL) | 
| 396 |  |  | syserr(progname); | 
| 397 | greg | 2.2 | sprintf(cp, "%s.oct", radname); | 
| 398 |  |  | vval(OCTREE) = cp; | 
| 399 |  |  | vdef(OCTREE)++; | 
| 400 |  |  | } | 
| 401 |  |  | octreedate = fdate(vval(OCTREE)); | 
| 402 | greg | 2.1 | scenedate = -1; | 
| 403 |  |  | if (vdef(SCENE)) { | 
| 404 |  |  | scenedate = checklast(vval(SCENE)); | 
| 405 |  |  | if (vdef(OBJECT)) { | 
| 406 |  |  | objdate = checklast(vval(OBJECT)); | 
| 407 |  |  | if (objdate > scenedate) | 
| 408 |  |  | scenedate = objdate; | 
| 409 |  |  | } | 
| 410 |  |  | } | 
| 411 |  |  | if (octreedate < 0 & scenedate < 0) { | 
| 412 | greg | 2.2 | fprintf(stderr, "%s: need '%s' or '%s'\n", progname, | 
| 413 |  |  | vnam(OCTREE), vnam(SCENE)); | 
| 414 | greg | 2.1 | exit(1); | 
| 415 |  |  | } | 
| 416 |  |  | } | 
| 417 |  |  |  | 
| 418 |  |  |  | 
| 419 | greg | 2.2 | getoctcube(org, sizp)           /* get octree bounding cube */ | 
| 420 |  |  | double  org[3], *sizp; | 
| 421 | greg | 2.1 | { | 
| 422 | greg | 2.2 | extern FILE     *popen(); | 
| 423 |  |  | static double   oorg[3], osiz = 0.; | 
| 424 |  |  | char    buf[MAXPATH+16]; | 
| 425 | greg | 2.1 | FILE    *fp; | 
| 426 |  |  |  | 
| 427 | greg | 2.2 | if (osiz <= FTINY) { | 
| 428 |  |  | oconv();                /* does nothing if done already */ | 
| 429 |  |  | sprintf(buf, "getinfo -d < %s", vval(OCTREE)); | 
| 430 | greg | 2.3 | if ((fp = popen(buf, "r")) == NULL) | 
| 431 |  |  | syserr("getinfo"); | 
| 432 | greg | 2.2 | if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], | 
| 433 |  |  | &oorg[2], &osiz) != 4) { | 
| 434 |  |  | fprintf(stderr, | 
| 435 |  |  | "%s: error reading bounding cube from getinfo\n", | 
| 436 |  |  | progname); | 
| 437 |  |  | exit(1); | 
| 438 |  |  | } | 
| 439 |  |  | pclose(fp); | 
| 440 | greg | 2.1 | } | 
| 441 | greg | 2.2 | org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; | 
| 442 |  |  | } | 
| 443 |  |  |  | 
| 444 |  |  |  | 
| 445 |  |  | setdefaults()                   /* set default values for unassigned var's */ | 
| 446 |  |  | { | 
| 447 |  |  | double  org[3], size; | 
| 448 |  |  | char    buf[128]; | 
| 449 |  |  |  | 
| 450 | greg | 2.1 | if (!vdef(ZONE)) { | 
| 451 | greg | 2.2 | getoctcube(org, &size); | 
| 452 |  |  | sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size, | 
| 453 |  |  | org[1], org[1]+size, org[2], org[2]+size); | 
| 454 | greg | 2.1 | vval(ZONE) = savqstr(buf); | 
| 455 |  |  | vdef(ZONE)++; | 
| 456 |  |  | } | 
| 457 |  |  | if (!vdef(INDIRECT)) { | 
| 458 |  |  | vval(INDIRECT) = "0"; | 
| 459 |  |  | vdef(INDIRECT)++; | 
| 460 |  |  | } | 
| 461 |  |  | if (!vdef(QUALITY)) { | 
| 462 |  |  | vval(QUALITY) = "L"; | 
| 463 |  |  | vdef(QUALITY)++; | 
| 464 |  |  | } | 
| 465 |  |  | if (!vdef(RESOLUTION)) { | 
| 466 |  |  | vval(RESOLUTION) = "512"; | 
| 467 |  |  | vdef(RESOLUTION)++; | 
| 468 |  |  | } | 
| 469 |  |  | if (!vdef(PICTURE)) { | 
| 470 |  |  | vval(PICTURE) = radname; | 
| 471 |  |  | vdef(PICTURE)++; | 
| 472 |  |  | } | 
| 473 |  |  | if (!vdef(VIEW)) { | 
| 474 |  |  | vval(VIEW) = "X"; | 
| 475 |  |  | vdef(VIEW)++; | 
| 476 |  |  | } | 
| 477 |  |  | if (!vdef(DETAIL)) { | 
| 478 |  |  | vval(DETAIL) = "M"; | 
| 479 |  |  | vdef(DETAIL)++; | 
| 480 |  |  | } | 
| 481 |  |  | if (!vdef(PENUMBRAS)) { | 
| 482 |  |  | vval(PENUMBRAS) = "F"; | 
| 483 |  |  | vdef(PENUMBRAS)++; | 
| 484 |  |  | } | 
| 485 |  |  | if (!vdef(VARIABILITY)) { | 
| 486 |  |  | vval(VARIABILITY) = "L"; | 
| 487 |  |  | vdef(VARIABILITY)++; | 
| 488 |  |  | } | 
| 489 |  |  | } | 
| 490 |  |  |  | 
| 491 |  |  |  | 
| 492 |  |  | printvals()                     /* print variable values */ | 
| 493 |  |  | { | 
| 494 |  |  | register int    i, j; | 
| 495 |  |  |  | 
| 496 |  |  | for (i = 0; i < NVARS; i++) | 
| 497 | greg | 2.4 | for (j = 0; j < vdef(i); j++) | 
| 498 |  |  | printf("%s= %s\n", vnam(i), nvalue(vv+i, j)); | 
| 499 | greg | 2.1 | fflush(stdout); | 
| 500 |  |  | } | 
| 501 |  |  |  | 
| 502 |  |  |  | 
| 503 |  |  | oconv()                         /* run oconv if necessary */ | 
| 504 |  |  | { | 
| 505 |  |  | char    combuf[512], ocopts[64]; | 
| 506 |  |  |  | 
| 507 | greg | 2.2 | if (octreedate >= scenedate)    /* check dates */ | 
| 508 | greg | 2.1 | return; | 
| 509 |  |  | /* build command */ | 
| 510 |  |  | oconvopts(ocopts); | 
| 511 | greg | 2.4 | if (vdef(MATERIAL)) | 
| 512 |  |  | sprintf(combuf, "oconv%s %s %s > %s", ocopts, | 
| 513 |  |  | vval(MATERIAL), vval(SCENE), vval(OCTREE)); | 
| 514 |  |  | else | 
| 515 |  |  | sprintf(combuf, "oconv%s %s > %s", ocopts, | 
| 516 |  |  | vval(SCENE), vval(OCTREE)); | 
| 517 |  |  |  | 
| 518 |  |  | if (runcom(combuf)) {           /* run it */ | 
| 519 | greg | 2.1 | fprintf(stderr, "%s: error generating octree\n\t%s removed\n", | 
| 520 |  |  | progname, vval(OCTREE)); | 
| 521 |  |  | unlink(vval(OCTREE)); | 
| 522 |  |  | exit(1); | 
| 523 |  |  | } | 
| 524 | greg | 2.2 | octreedate = time(0); | 
| 525 | greg | 2.1 | } | 
| 526 |  |  |  | 
| 527 |  |  |  | 
| 528 |  |  | char * | 
| 529 |  |  | addarg(op, arg)                         /* add argument and advance pointer */ | 
| 530 |  |  | register char   *op, *arg; | 
| 531 |  |  | { | 
| 532 |  |  | *op = ' '; | 
| 533 |  |  | while (*++op = *arg++) | 
| 534 |  |  | ; | 
| 535 |  |  | return(op); | 
| 536 |  |  | } | 
| 537 |  |  |  | 
| 538 |  |  |  | 
| 539 |  |  | oconvopts(oo)                           /* get oconv options */ | 
| 540 | greg | 2.2 | register char   *oo; | 
| 541 | greg | 2.1 | { | 
| 542 | greg | 2.2 | /* BEWARE:  This may be called via setdefaults(), so no assumptions */ | 
| 543 |  |  |  | 
| 544 | greg | 2.1 | *oo = '\0'; | 
| 545 |  |  | if (vdef(OCONV)) | 
| 546 |  |  | addarg(oo, vval(OCONV)); | 
| 547 |  |  | } | 
| 548 |  |  |  | 
| 549 |  |  |  | 
| 550 | greg | 2.2 | double | 
| 551 |  |  | ambval()                                /* compute ambient value */ | 
| 552 | greg | 2.1 | { | 
| 553 | greg | 2.3 | if (vdef(EXPOSURE)) { | 
| 554 | greg | 2.2 | if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') | 
| 555 |  |  | return(.5/pow(2.,atof(vval(EXPOSURE)))); | 
| 556 | greg | 2.3 | if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.') | 
| 557 | greg | 2.2 | return(.5/atof(vval(EXPOSURE))); | 
| 558 | greg | 2.3 | badvalue(EXPOSURE); | 
| 559 |  |  | } | 
| 560 | greg | 2.2 | if (vlet(ZONE) == 'E') | 
| 561 |  |  | return(10.); | 
| 562 | greg | 2.3 | if (vlet(ZONE) == 'I') | 
| 563 | greg | 2.2 | return(.01); | 
| 564 | greg | 2.3 | badvalue(ZONE); | 
| 565 | greg | 2.2 | } | 
| 566 | greg | 2.1 |  | 
| 567 | greg | 2.2 |  | 
| 568 |  |  | lowqopts(op)                            /* low quality rendering options */ | 
| 569 |  |  | register char   *op; | 
| 570 |  |  | { | 
| 571 |  |  | double  d, org[3], siz[3]; | 
| 572 |  |  |  | 
| 573 | greg | 2.1 | *op = '\0'; | 
| 574 | greg | 2.2 | if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], | 
| 575 | greg | 2.3 | &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) | 
| 576 |  |  | badvalue(ZONE); | 
| 577 | greg | 2.2 | siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; | 
| 578 |  |  | getoctcube(org, &d); | 
| 579 |  |  | d *= 3./(siz[0]+siz[1]+siz[2]); | 
| 580 |  |  | switch (vscale(DETAIL)) { | 
| 581 |  |  | case LOW: | 
| 582 | greg | 2.4 | op = addarg(op, "-ps 16 -dp 16"); | 
| 583 | greg | 2.2 | sprintf(op, " -ar %d", (int)(4*d)); | 
| 584 |  |  | op += strlen(op); | 
| 585 |  |  | break; | 
| 586 |  |  | case MEDIUM: | 
| 587 | greg | 2.4 | op = addarg(op, "-ps 8 -dp 32"); | 
| 588 | greg | 2.2 | sprintf(op, " -ar %d", (int)(8*d)); | 
| 589 |  |  | op += strlen(op); | 
| 590 |  |  | break; | 
| 591 |  |  | case HIGH: | 
| 592 | greg | 2.4 | op = addarg(op, "-ps 4 -dp 64"); | 
| 593 | greg | 2.2 | sprintf(op, " -ar %d", (int)(16*d)); | 
| 594 |  |  | op += strlen(op); | 
| 595 |  |  | break; | 
| 596 |  |  | } | 
| 597 |  |  | op = addarg(op, "-pt .16"); | 
| 598 |  |  | if (vbool(PENUMBRAS)) | 
| 599 |  |  | op = addarg(op, "-ds .4"); | 
| 600 | greg | 2.4 | else | 
| 601 |  |  | op = addarg(op, "-ds 0"); | 
| 602 |  |  | op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7"); | 
| 603 | greg | 2.2 | if (vdef(AMBFILE)) { | 
| 604 |  |  | sprintf(op, " -af %s", vval(AMBFILE)); | 
| 605 |  |  | op += strlen(op); | 
| 606 |  |  | } else | 
| 607 |  |  | overture = 0; | 
| 608 |  |  | switch (vscale(VARIABILITY)) { | 
| 609 |  |  | case LOW: | 
| 610 | greg | 2.4 | op = addarg(op, "-aa .4 -ad 32"); | 
| 611 | greg | 2.2 | break; | 
| 612 |  |  | case MEDIUM: | 
| 613 | greg | 2.4 | op = addarg(op, "-aa .3 -ad 64"); | 
| 614 | greg | 2.2 | break; | 
| 615 |  |  | case HIGH: | 
| 616 | greg | 2.4 | op = addarg(op, "-aa .25 -ad 128"); | 
| 617 | greg | 2.2 | break; | 
| 618 |  |  | } | 
| 619 |  |  | op = addarg(op, "-as 0"); | 
| 620 |  |  | d = ambval(); | 
| 621 |  |  | sprintf(op, " -av %.2g %.2g %.2g", d, d, d); | 
| 622 |  |  | op += strlen(op); | 
| 623 | greg | 2.4 | op = addarg(op, "-lr 3 -lw .02"); | 
| 624 | greg | 2.1 | if (vdef(RENDER)) | 
| 625 |  |  | op = addarg(op, vval(RENDER)); | 
| 626 |  |  | } | 
| 627 |  |  |  | 
| 628 |  |  |  | 
| 629 | greg | 2.2 | medqopts(op)                            /* medium quality rendering options */ | 
| 630 |  |  | register char   *op; | 
| 631 | greg | 2.1 | { | 
| 632 | greg | 2.2 | double  d, org[3], siz[3]; | 
| 633 | greg | 2.1 |  | 
| 634 |  |  | *op = '\0'; | 
| 635 | greg | 2.2 | if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], | 
| 636 | greg | 2.3 | &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) | 
| 637 |  |  | badvalue(ZONE); | 
| 638 | greg | 2.2 | siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; | 
| 639 |  |  | getoctcube(org, &d); | 
| 640 |  |  | d *= 3./(siz[0]+siz[1]+siz[2]); | 
| 641 |  |  | switch (vscale(DETAIL)) { | 
| 642 |  |  | case LOW: | 
| 643 |  |  | op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); | 
| 644 |  |  | op = addarg(op, "-dp 64"); | 
| 645 |  |  | sprintf(op, " -ar %d", (int)(8*d)); | 
| 646 |  |  | op += strlen(op); | 
| 647 |  |  | break; | 
| 648 |  |  | case MEDIUM: | 
| 649 |  |  | op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); | 
| 650 |  |  | op = addarg(op, "-dp 128"); | 
| 651 |  |  | sprintf(op, " -ar %d", (int)(16*d)); | 
| 652 |  |  | op += strlen(op); | 
| 653 |  |  | break; | 
| 654 |  |  | case HIGH: | 
| 655 |  |  | op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); | 
| 656 |  |  | op = addarg(op, "-dp 256"); | 
| 657 |  |  | sprintf(op, " -ar %d", (int)(32*d)); | 
| 658 |  |  | op += strlen(op); | 
| 659 |  |  | break; | 
| 660 |  |  | } | 
| 661 |  |  | op = addarg(op, "-pt .08"); | 
| 662 | greg | 2.4 | if (vbool(PENUMBRAS)) | 
| 663 |  |  | op = addarg(op, "-ds .2 -dj .35"); | 
| 664 |  |  | else | 
| 665 | greg | 2.2 | op = addarg(op, "-ds .3"); | 
| 666 | greg | 2.4 | op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15"); | 
| 667 | greg | 2.2 | sprintf(op, " -ab %d", overture=vint(INDIRECT)); | 
| 668 |  |  | op += strlen(op); | 
| 669 |  |  | if (vdef(AMBFILE)) { | 
| 670 |  |  | sprintf(op, " -af %s", vval(AMBFILE)); | 
| 671 |  |  | op += strlen(op); | 
| 672 |  |  | } else | 
| 673 |  |  | overture = 0; | 
| 674 |  |  | switch (vscale(VARIABILITY)) { | 
| 675 |  |  | case LOW: | 
| 676 | greg | 2.4 | op = addarg(op, "-aa .25 -ad 128 -as 0"); | 
| 677 | greg | 2.2 | break; | 
| 678 |  |  | case MEDIUM: | 
| 679 | greg | 2.4 | op = addarg(op, "-aa .2 -ad 300 -as 64"); | 
| 680 | greg | 2.2 | break; | 
| 681 |  |  | case HIGH: | 
| 682 | greg | 2.4 | op = addarg(op, "-aa .15 -ad 500 -as 128"); | 
| 683 | greg | 2.2 | break; | 
| 684 |  |  | } | 
| 685 |  |  | d = ambval(); | 
| 686 |  |  | sprintf(op, " -av %.2g %.2g %.2g", d, d, d); | 
| 687 |  |  | op += strlen(op); | 
| 688 | greg | 2.4 | op = addarg(op, "-lr 6 -lw .002"); | 
| 689 | greg | 2.1 | if (vdef(RENDER)) | 
| 690 |  |  | op = addarg(op, vval(RENDER)); | 
| 691 |  |  | } | 
| 692 |  |  |  | 
| 693 |  |  |  | 
| 694 | greg | 2.2 | hiqopts(op)                             /* high quality rendering options */ | 
| 695 |  |  | register char   *op; | 
| 696 | greg | 2.1 | { | 
| 697 | greg | 2.2 | double  d, org[3], siz[3]; | 
| 698 | greg | 2.1 |  | 
| 699 |  |  | *op = '\0'; | 
| 700 | greg | 2.2 | if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], | 
| 701 | greg | 2.3 | &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) | 
| 702 |  |  | badvalue(ZONE); | 
| 703 | greg | 2.2 | siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; | 
| 704 |  |  | getoctcube(org, &d); | 
| 705 |  |  | d *= 3./(siz[0]+siz[1]+siz[2]); | 
| 706 |  |  | switch (vscale(DETAIL)) { | 
| 707 |  |  | case LOW: | 
| 708 |  |  | op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); | 
| 709 |  |  | op = addarg(op, "-dp 256"); | 
| 710 |  |  | sprintf(op, " -ar %d", (int)(16*d)); | 
| 711 |  |  | op += strlen(op); | 
| 712 |  |  | break; | 
| 713 |  |  | case MEDIUM: | 
| 714 |  |  | op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); | 
| 715 |  |  | op = addarg(op, "-dp 512"); | 
| 716 |  |  | sprintf(op, " -ar %d", (int)(32*d)); | 
| 717 |  |  | op += strlen(op); | 
| 718 |  |  | break; | 
| 719 |  |  | case HIGH: | 
| 720 |  |  | op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); | 
| 721 |  |  | op = addarg(op, "-dp 1024"); | 
| 722 |  |  | sprintf(op, " -ar %d", (int)(64*d)); | 
| 723 |  |  | op += strlen(op); | 
| 724 |  |  | break; | 
| 725 |  |  | } | 
| 726 |  |  | op = addarg(op, "-pt .04"); | 
| 727 | greg | 2.4 | if (vbool(PENUMBRAS)) | 
| 728 |  |  | op = addarg(op, "-ds .1 -dj .7"); | 
| 729 |  |  | else | 
| 730 | greg | 2.2 | op = addarg(op, "-ds .2"); | 
| 731 | greg | 2.4 | op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03"); | 
| 732 | greg | 2.2 | sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); | 
| 733 |  |  | op += strlen(op); | 
| 734 |  |  | if (vdef(AMBFILE)) { | 
| 735 |  |  | sprintf(op, " -af %s", vval(AMBFILE)); | 
| 736 |  |  | op += strlen(op); | 
| 737 |  |  | } else | 
| 738 |  |  | overture = 0; | 
| 739 |  |  | switch (vscale(VARIABILITY)) { | 
| 740 |  |  | case LOW: | 
| 741 | greg | 2.4 | op = addarg(op, "-aa .15 -ad 200 -as 0"); | 
| 742 | greg | 2.2 | break; | 
| 743 |  |  | case MEDIUM: | 
| 744 | greg | 2.4 | op = addarg(op, "-aa .125 -ad 512 -as 128"); | 
| 745 | greg | 2.2 | break; | 
| 746 |  |  | case HIGH: | 
| 747 | greg | 2.4 | op = addarg(op, "-aa .08 -ad 850 -as 256"); | 
| 748 | greg | 2.2 | break; | 
| 749 |  |  | } | 
| 750 |  |  | d = ambval(); | 
| 751 |  |  | sprintf(op, " -av %.2g %.2g %.2g", d, d, d); | 
| 752 |  |  | op += strlen(op); | 
| 753 | greg | 2.4 | op = addarg(op, "-lr 12 -lw .0005"); | 
| 754 | greg | 2.1 | if (vdef(RENDER)) | 
| 755 |  |  | op = addarg(op, vval(RENDER)); | 
| 756 |  |  | } | 
| 757 |  |  |  | 
| 758 |  |  |  | 
| 759 |  |  | xferopts(ro)                            /* transfer options if indicated */ | 
| 760 |  |  | char    *ro; | 
| 761 |  |  | { | 
| 762 |  |  | int     fd, n; | 
| 763 |  |  |  | 
| 764 |  |  | n = strlen(ro); | 
| 765 |  |  | if (n < 2) | 
| 766 |  |  | return; | 
| 767 |  |  | if (vdef(OPTFILE)) { | 
| 768 | greg | 2.3 | if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) | 
| 769 |  |  | syserr(vval(OPTFILE)); | 
| 770 |  |  | if (write(fd, ro+1, n-1) != n-1) | 
| 771 |  |  | syserr(vval(OPTFILE)); | 
| 772 | greg | 2.1 | write(fd, "\n", 1); | 
| 773 |  |  | close(fd); | 
| 774 | greg | 2.4 | sprintf(ro, " \"^%s\"", vval(OPTFILE)); | 
| 775 | greg | 2.1 | } | 
| 776 |  |  | #ifdef MSDOS | 
| 777 |  |  | else if (n > 50) { | 
| 778 |  |  | register char   *evp = bmalloc(n+6); | 
| 779 | greg | 2.3 | if (evp == NULL) | 
| 780 |  |  | syserr(progname); | 
| 781 | greg | 2.1 | strcpy(evp, "ROPT="); | 
| 782 |  |  | strcat(evp, ro); | 
| 783 | greg | 2.2 | if (putenv(evp) != 0) { | 
| 784 |  |  | fprintf(stderr, "%s: out of environment space\n", | 
| 785 |  |  | progname); | 
| 786 |  |  | exit(1); | 
| 787 |  |  | } | 
| 788 | greg | 2.1 | strcpy(ro, " $ROPT"); | 
| 789 |  |  | } | 
| 790 |  |  | #endif | 
| 791 |  |  | } | 
| 792 |  |  |  | 
| 793 |  |  |  | 
| 794 |  |  | pfiltopts(po)                           /* get pfilt options */ | 
| 795 |  |  | register char   *po; | 
| 796 |  |  | { | 
| 797 |  |  | *po = '\0'; | 
| 798 |  |  | if (vdef(EXPOSURE)) { | 
| 799 |  |  | po = addarg(po, "-1 -e"); | 
| 800 |  |  | po = addarg(po, vval(EXPOSURE)); | 
| 801 |  |  | } | 
| 802 |  |  | if (vscale(QUALITY) == HIGH) | 
| 803 |  |  | po = addarg(po, "-r .65"); | 
| 804 |  |  | if (vdef(PFILT)) | 
| 805 |  |  | po = addarg(po, vval(PFILT)); | 
| 806 |  |  | } | 
| 807 |  |  |  | 
| 808 |  |  |  | 
| 809 |  |  | matchword(s1, s2)                       /* match white-delimited words */ | 
| 810 |  |  | register char   *s1, *s2; | 
| 811 |  |  | { | 
| 812 |  |  | while (isspace(*s1)) s1++; | 
| 813 |  |  | while (isspace(*s2)) s2++; | 
| 814 |  |  | while (*s1 && !isspace(*s1)) | 
| 815 |  |  | if (*s1++ != *s2++) | 
| 816 |  |  | return(0); | 
| 817 |  |  | return(!*s2 || isspace(*s2)); | 
| 818 |  |  | } | 
| 819 |  |  |  | 
| 820 |  |  |  | 
| 821 |  |  | char * | 
| 822 |  |  | specview(vs)                            /* get proper view spec from vs */ | 
| 823 |  |  | register char   *vs; | 
| 824 |  |  | { | 
| 825 | greg | 2.3 | static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", | 
| 826 |  |  | "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; | 
| 827 | greg | 2.1 | static char     viewopts[128]; | 
| 828 |  |  | register char   *cp; | 
| 829 | greg | 2.3 | int     xpos, ypos, zpos, viewtype, upax; | 
| 830 |  |  | register int    i; | 
| 831 | greg | 2.1 | double  cent[3], dim[3], mult, d; | 
| 832 |  |  |  | 
| 833 |  |  | if (vs == NULL || *vs == '-') | 
| 834 |  |  | return(vs); | 
| 835 | greg | 2.3 | upax = 0;                       /* get the up vector */ | 
| 836 |  |  | if (vdef(UP)) { | 
| 837 |  |  | if (vval(UP)[0] == '-' || vval(UP)[0] == '+') | 
| 838 |  |  | upax = 1-'X'+UPPER(vval(UP)[1]); | 
| 839 |  |  | else | 
| 840 |  |  | upax = 1-'X'+vlet(UP); | 
| 841 |  |  | if (upax < 1 | upax > 3) | 
| 842 |  |  | badvalue(UP); | 
| 843 |  |  | if (vval(UP)[0] == '-') | 
| 844 |  |  | upax = -upax; | 
| 845 |  |  | } | 
| 846 | greg | 2.1 | /* check standard view names */ | 
| 847 |  |  | xpos = ypos = zpos = 0; | 
| 848 |  |  | if (*vs == 'X') { | 
| 849 |  |  | xpos = 1; vs++; | 
| 850 |  |  | } else if (*vs == 'x') { | 
| 851 |  |  | xpos = -1; vs++; | 
| 852 |  |  | } | 
| 853 |  |  | if (*vs == 'Y') { | 
| 854 |  |  | ypos = 1; vs++; | 
| 855 |  |  | } else if (*vs == 'y') { | 
| 856 |  |  | ypos = -1; vs++; | 
| 857 |  |  | } | 
| 858 |  |  | if (*vs == 'Z') { | 
| 859 |  |  | zpos = 1; vs++; | 
| 860 |  |  | } else if (*vs == 'z') { | 
| 861 |  |  | zpos = -1; vs++; | 
| 862 |  |  | } | 
| 863 | greg | 2.3 | viewtype = 'v'; | 
| 864 | greg | 2.1 | if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h') | 
| 865 |  |  | viewtype = *vs++; | 
| 866 |  |  | cp = viewopts; | 
| 867 | greg | 2.3 | if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */ | 
| 868 | greg | 2.1 | *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; | 
| 869 |  |  | if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", | 
| 870 |  |  | ¢[0], &dim[0], ¢[1], &dim[1], | 
| 871 | greg | 2.3 | ¢[2], &dim[2]) != 6) | 
| 872 |  |  | badvalue(ZONE); | 
| 873 |  |  | for (i = 0; i < 3; i++) { | 
| 874 |  |  | dim[i] -= cent[i]; | 
| 875 |  |  | cent[i] += .5*dim[i]; | 
| 876 | greg | 2.1 | } | 
| 877 | greg | 2.3 | mult = vlet(ZONE)=='E' ? 2. : .45 ; | 
| 878 | greg | 2.1 | sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g", | 
| 879 |  |  | cent[0]+xpos*mult*dim[0], | 
| 880 |  |  | cent[1]+ypos*mult*dim[1], | 
| 881 |  |  | cent[2]+zpos*mult*dim[2], | 
| 882 |  |  | -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]); | 
| 883 |  |  | cp += strlen(cp); | 
| 884 | greg | 2.3 | /* redirect up axis if necessary */ | 
| 885 |  |  | switch (upax) { | 
| 886 |  |  | case 3:                 /* plus or minus Z axis */ | 
| 887 |  |  | case -3: | 
| 888 |  |  | case 0: | 
| 889 |  |  | if (!(xpos|ypos)) | 
| 890 |  |  | upax = 2; | 
| 891 | greg | 2.1 | break; | 
| 892 | greg | 2.3 | case 2:                 /* plus or minus Y axis */ | 
| 893 |  |  | case -2: | 
| 894 |  |  | if (!(xpos|zpos)) | 
| 895 |  |  | upax = 1; | 
| 896 |  |  | break; | 
| 897 |  |  | case 1:                 /* plus or minus X axis */ | 
| 898 |  |  | case -1: | 
| 899 |  |  | if (!(ypos|zpos)) | 
| 900 |  |  | upax = 3; | 
| 901 |  |  | break; | 
| 902 | greg | 2.1 | } | 
| 903 | greg | 2.3 | cp = addarg(cp, vup[upax+3]); | 
| 904 | greg | 2.1 | switch (viewtype) { | 
| 905 |  |  | case 'v': | 
| 906 |  |  | cp = addarg(cp, "-vh 45 -vv 45"); | 
| 907 |  |  | break; | 
| 908 |  |  | case 'l': | 
| 909 |  |  | d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]); | 
| 910 |  |  | sprintf(cp, " -vh %.2g -vv %.2g", d, d); | 
| 911 |  |  | cp += strlen(cp); | 
| 912 |  |  | break; | 
| 913 |  |  | case 'a': | 
| 914 |  |  | case 'h': | 
| 915 |  |  | cp = addarg(cp, "-vh 180 -vv 180"); | 
| 916 |  |  | break; | 
| 917 |  |  | } | 
| 918 | greg | 2.3 | } else { | 
| 919 | greg | 2.4 | while (!isspace(*vs))           /* else skip id */ | 
| 920 |  |  | if (!*vs++) | 
| 921 |  |  | return(NULL); | 
| 922 | greg | 2.3 | if (upax) {                     /* specify up vector */ | 
| 923 |  |  | strcpy(cp, vup[upax+3]); | 
| 924 |  |  | cp += strlen(cp); | 
| 925 |  |  | } | 
| 926 |  |  | } | 
| 927 | greg | 2.1 | /* append any additional options */ | 
| 928 |  |  | strcpy(cp, vs); | 
| 929 |  |  | return(viewopts); | 
| 930 |  |  | } | 
| 931 |  |  |  | 
| 932 |  |  |  | 
| 933 |  |  | char * | 
| 934 |  |  | getview(n, vn)                          /* get view n, or NULL if none */ | 
| 935 |  |  | int     n; | 
| 936 |  |  | char    *vn; | 
| 937 |  |  | { | 
| 938 |  |  | register char   *mv; | 
| 939 |  |  |  | 
| 940 |  |  | if (viewselect != NULL) { | 
| 941 |  |  | if (n)                          /* only do one */ | 
| 942 |  |  | return(NULL); | 
| 943 |  |  | if (viewselect[0] == '-') {     /* already specified */ | 
| 944 |  |  | if (vn != NULL) *vn = '\0'; | 
| 945 |  |  | return(viewselect); | 
| 946 |  |  | } | 
| 947 |  |  | if (vn != NULL) { | 
| 948 |  |  | for (mv = viewselect; *mv && !isspace(*mv); | 
| 949 |  |  | *vn++ = *mv++) | 
| 950 |  |  | ; | 
| 951 |  |  | *vn = '\0'; | 
| 952 |  |  | } | 
| 953 |  |  | /* check list */ | 
| 954 |  |  | while ((mv = nvalue(vv+VIEW, n++)) != NULL) | 
| 955 |  |  | if (matchword(viewselect, mv)) | 
| 956 |  |  | return(specview(mv)); | 
| 957 |  |  | return(specview(viewselect));   /* standard view? */ | 
| 958 |  |  | } | 
| 959 |  |  | if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) { | 
| 960 |  |  | if (*mv != '-') | 
| 961 |  |  | while (*mv && !isspace(*mv)) | 
| 962 |  |  | *vn++ = *mv++; | 
| 963 |  |  | *vn = '\0'; | 
| 964 |  |  | } | 
| 965 |  |  | return(specview(nvalue(vv+VIEW, n)));   /* use view n */ | 
| 966 |  |  | } | 
| 967 |  |  |  | 
| 968 |  |  |  | 
| 969 |  |  | rview(opts)                             /* run rview with first view */ | 
| 970 |  |  | char    *opts; | 
| 971 |  |  | { | 
| 972 |  |  | char    combuf[512]; | 
| 973 |  |  | /* build command */ | 
| 974 |  |  | sprintf(combuf, "rview %s%s ", getview(0, NULL), opts); | 
| 975 |  |  | if (rvdevice != NULL) | 
| 976 |  |  | sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); | 
| 977 |  |  | strcat(combuf, vval(OCTREE)); | 
| 978 | greg | 2.4 | if (runcom(combuf)) {           /* run it */ | 
| 979 | greg | 2.1 | fprintf(stderr, "%s: error running rview\n", progname); | 
| 980 |  |  | exit(1); | 
| 981 |  |  | } | 
| 982 |  |  | } | 
| 983 |  |  |  | 
| 984 |  |  |  | 
| 985 |  |  | rpict(opts)                             /* run rpict and pfilt for each view */ | 
| 986 |  |  | char    *opts; | 
| 987 |  |  | { | 
| 988 | greg | 2.2 | char    combuf[1024]; | 
| 989 | greg | 2.3 | char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32]; | 
| 990 |  |  | char    pfopts[128]; | 
| 991 | greg | 2.1 | char    vs[32], *vw; | 
| 992 |  |  | int     vn, mult; | 
| 993 |  |  | /* get pfilt options */ | 
| 994 |  |  | pfiltopts(pfopts); | 
| 995 |  |  | /* get resolution, reporting */ | 
| 996 |  |  | mult = vscale(QUALITY)+1; | 
| 997 |  |  | { | 
| 998 |  |  | int     xres, yres; | 
| 999 |  |  | double  aspect; | 
| 1000 |  |  | int     n; | 
| 1001 |  |  | n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); | 
| 1002 |  |  | if (n == 3) | 
| 1003 |  |  | sprintf(res, "-x %d -y %d -pa %.3f", | 
| 1004 |  |  | mult*xres, mult*yres, aspect); | 
| 1005 |  |  | else if (n) { | 
| 1006 |  |  | if (n == 1) yres = xres; | 
| 1007 |  |  | sprintf(res, "-x %d -y %d", mult*xres, mult*yres); | 
| 1008 | greg | 2.3 | } else | 
| 1009 |  |  | badvalue(RESOLUTION); | 
| 1010 | greg | 2.1 | } | 
| 1011 |  |  | rep[0] = '\0'; | 
| 1012 |  |  | if (vdef(REPORT)) { | 
| 1013 |  |  | double  minutes; | 
| 1014 |  |  | int     n; | 
| 1015 |  |  | n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); | 
| 1016 |  |  | if (n == 2) | 
| 1017 |  |  | sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); | 
| 1018 |  |  | else if (n == 1) | 
| 1019 |  |  | sprintf(rep, " -t %d", (int)(minutes*60)); | 
| 1020 | greg | 2.3 | else | 
| 1021 |  |  | badvalue(REPORT); | 
| 1022 |  |  | } | 
| 1023 |  |  | /* check date on ambient file */ | 
| 1024 |  |  | if (vdef(AMBFILE)) { | 
| 1025 |  |  | long    afdate = fdate(vval(AMBFILE)); | 
| 1026 | greg | 2.4 | if (afdate >= 0 & octreedate > afdate) | 
| 1027 |  |  | rmfile(vval(AMBFILE)); | 
| 1028 | greg | 2.1 | } | 
| 1029 |  |  | /* do each view */ | 
| 1030 |  |  | vn = 0; | 
| 1031 |  |  | while ((vw = getview(vn++, vs)) != NULL) { | 
| 1032 |  |  | if (!vs[0]) | 
| 1033 |  |  | sprintf(vs, "%d", vn); | 
| 1034 |  |  | sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); | 
| 1035 |  |  | /* check date on picture */ | 
| 1036 |  |  | if (fdate(picfile) > octreedate) | 
| 1037 |  |  | continue; | 
| 1038 |  |  | /* build rpict command */ | 
| 1039 |  |  | sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); | 
| 1040 |  |  | if (fdate(rawfile) > octreedate)        /* recover */ | 
| 1041 |  |  | sprintf(combuf, "rpict%s%s -ro %s %s", | 
| 1042 |  |  | rep, opts, rawfile, vval(OCTREE)); | 
| 1043 |  |  | else { | 
| 1044 |  |  | if (overture) {         /* run overture calculation */ | 
| 1045 |  |  | sprintf(combuf, | 
| 1046 |  |  | "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", | 
| 1047 |  |  | rep, vw, opts, | 
| 1048 |  |  | vval(OCTREE), rawfile); | 
| 1049 | greg | 2.4 | if (runcom(combuf)) { | 
| 1050 | greg | 2.1 | fprintf(stderr, | 
| 1051 |  |  | "%s: error in overture for view %s\n\t%s removed\n", | 
| 1052 |  |  | progname, vs, rawfile); | 
| 1053 |  |  | unlink(rawfile); | 
| 1054 |  |  | exit(1); | 
| 1055 |  |  | } | 
| 1056 |  |  | } | 
| 1057 |  |  | sprintf(combuf, "rpict%s %s %s%s %s > %s", | 
| 1058 |  |  | rep, vw, res, opts, | 
| 1059 |  |  | vval(OCTREE), rawfile); | 
| 1060 |  |  | } | 
| 1061 | greg | 2.4 | if (runcom(combuf)) {           /* run rpict */ | 
| 1062 | greg | 2.1 | fprintf(stderr, "%s: error rendering view %s\n", | 
| 1063 |  |  | progname, vs); | 
| 1064 |  |  | exit(1); | 
| 1065 |  |  | } | 
| 1066 |  |  | /* build pfilt command */ | 
| 1067 |  |  | if (mult > 1) | 
| 1068 |  |  | sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", | 
| 1069 |  |  | pfopts, mult, mult, rawfile, picfile); | 
| 1070 |  |  | else | 
| 1071 |  |  | sprintf(combuf, "pfilt%s %s > %s", pfopts, | 
| 1072 |  |  | rawfile, picfile); | 
| 1073 | greg | 2.4 | if (runcom(combuf)) {           /* run pfilt */ | 
| 1074 | greg | 2.1 | fprintf(stderr, | 
| 1075 |  |  | "%s: error filtering view %s\n\t%s removed\n", | 
| 1076 |  |  | progname, vs, picfile); | 
| 1077 |  |  | unlink(picfile); | 
| 1078 |  |  | exit(1); | 
| 1079 |  |  | } | 
| 1080 |  |  | /* remove raw file */ | 
| 1081 | greg | 2.4 | rmfile(rawfile); | 
| 1082 |  |  | } | 
| 1083 |  |  | } | 
| 1084 |  |  |  | 
| 1085 |  |  |  | 
| 1086 |  |  | runcom(cs)                      /* run command */ | 
| 1087 |  |  | char    *cs; | 
| 1088 |  |  | { | 
| 1089 |  |  | if (!silent)            /* echo it */ | 
| 1090 |  |  | printf("\t%s\n", cs); | 
| 1091 |  |  | if (noaction) | 
| 1092 |  |  | return(0); | 
| 1093 |  |  | fflush(stdout);         /* flush output and pass to shell */ | 
| 1094 |  |  | return(system(cs)); | 
| 1095 |  |  | } | 
| 1096 |  |  |  | 
| 1097 |  |  |  | 
| 1098 |  |  | rmfile(fn)                      /* remove a file */ | 
| 1099 |  |  | char    *fn; | 
| 1100 |  |  | { | 
| 1101 |  |  | if (!silent) | 
| 1102 | greg | 2.1 | #ifdef MSDOS | 
| 1103 | greg | 2.4 | printf("\tdel %s\n", fn); | 
| 1104 | greg | 2.1 | #else | 
| 1105 | greg | 2.4 | printf("\trm -f %s\n", fn); | 
| 1106 | greg | 2.1 | #endif | 
| 1107 | greg | 2.4 | if (noaction) | 
| 1108 |  |  | return(0); | 
| 1109 |  |  | return(unlink(fn)); | 
| 1110 | greg | 2.3 | } | 
| 1111 |  |  |  | 
| 1112 |  |  |  | 
| 1113 |  |  | badvalue(vc)                    /* report bad variable value and exit */ | 
| 1114 |  |  | int     vc; | 
| 1115 |  |  | { | 
| 1116 |  |  | fprintf(stderr, "%s: bad value for variable '%s'\n", | 
| 1117 |  |  | progname, vnam(vc)); | 
| 1118 |  |  | exit(1); | 
| 1119 |  |  | } | 
| 1120 |  |  |  | 
| 1121 |  |  |  | 
| 1122 |  |  | syserr(s)                       /* report a system error and exit */ | 
| 1123 |  |  | char    *s; | 
| 1124 |  |  | { | 
| 1125 |  |  | perror(s); | 
| 1126 |  |  | exit(1); | 
| 1127 | greg | 2.1 | } |