| 1 |
greg |
2.1 |
#ifndef lint |
| 2 |
|
|
static const char RCSid[] = "$Id$"; |
| 3 |
|
|
#endif |
| 4 |
|
|
/* |
| 5 |
|
|
* rvmain.c - main for rview interactive viewer |
| 6 |
|
|
*/ |
| 7 |
|
|
|
| 8 |
|
|
/* ==================================================================== |
| 9 |
|
|
* The Radiance Software License, Version 1.0 |
| 10 |
|
|
* |
| 11 |
|
|
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
| 12 |
|
|
* through Lawrence Berkeley National Laboratory. All rights reserved. |
| 13 |
|
|
* |
| 14 |
|
|
* Redistribution and use in source and binary forms, with or without |
| 15 |
|
|
* modification, are permitted provided that the following conditions |
| 16 |
|
|
* are met: |
| 17 |
|
|
* |
| 18 |
|
|
* 1. Redistributions of source code must retain the above copyright |
| 19 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 20 |
|
|
* |
| 21 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 22 |
|
|
* notice, this list of conditions and the following disclaimer in |
| 23 |
|
|
* the documentation and/or other materials provided with the |
| 24 |
|
|
* distribution. |
| 25 |
|
|
* |
| 26 |
|
|
* 3. The end-user documentation included with the redistribution, |
| 27 |
|
|
* if any, must include the following acknowledgment: |
| 28 |
|
|
* "This product includes Radiance software |
| 29 |
|
|
* (http://radsite.lbl.gov/) |
| 30 |
|
|
* developed by the Lawrence Berkeley National Laboratory |
| 31 |
|
|
* (http://www.lbl.gov/)." |
| 32 |
|
|
* Alternately, this acknowledgment may appear in the software itself, |
| 33 |
|
|
* if and wherever such third-party acknowledgments normally appear. |
| 34 |
|
|
* |
| 35 |
|
|
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
| 36 |
|
|
* and "The Regents of the University of California" must |
| 37 |
|
|
* not be used to endorse or promote products derived from this |
| 38 |
|
|
* software without prior written permission. For written |
| 39 |
|
|
* permission, please contact [email protected]. |
| 40 |
|
|
* |
| 41 |
|
|
* 5. Products derived from this software may not be called "Radiance", |
| 42 |
|
|
* nor may "Radiance" appear in their name, without prior written |
| 43 |
|
|
* permission of Lawrence Berkeley National Laboratory. |
| 44 |
|
|
* |
| 45 |
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
| 46 |
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 47 |
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 48 |
|
|
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
| 49 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 50 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 51 |
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 52 |
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 53 |
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 54 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 55 |
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 56 |
|
|
* SUCH DAMAGE. |
| 57 |
|
|
* ==================================================================== |
| 58 |
|
|
* |
| 59 |
|
|
* This software consists of voluntary contributions made by many |
| 60 |
|
|
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
| 61 |
|
|
* information on Lawrence Berkeley National Laboratory, please see |
| 62 |
|
|
* <http://www.lbl.gov/>. |
| 63 |
|
|
*/ |
| 64 |
|
|
|
| 65 |
|
|
#include "ray.h" |
| 66 |
|
|
|
| 67 |
|
|
#include "source.h" |
| 68 |
|
|
|
| 69 |
|
|
#include "ambient.h" |
| 70 |
|
|
|
| 71 |
|
|
#include "random.h" |
| 72 |
|
|
|
| 73 |
|
|
#include "paths.h" |
| 74 |
|
|
|
| 75 |
|
|
#include <signal.h> |
| 76 |
|
|
|
| 77 |
|
|
#include "view.h" |
| 78 |
|
|
|
| 79 |
|
|
char *progname; /* argv[0] */ |
| 80 |
|
|
|
| 81 |
|
|
char *octname; /* octree name */ |
| 82 |
|
|
|
| 83 |
|
|
char *sigerr[NSIG]; /* signal error messages */ |
| 84 |
|
|
|
| 85 |
|
|
char *shm_boundary = NULL; /* boundary of shared memory */ |
| 86 |
|
|
|
| 87 |
|
|
char *errfile = NULL; /* error output file */ |
| 88 |
|
|
|
| 89 |
|
|
extern int greyscale; /* map colors to brightness? */ |
| 90 |
|
|
extern char *dvcname; /* output device name */ |
| 91 |
|
|
extern double exposure; /* exposure compensation */ |
| 92 |
|
|
|
| 93 |
|
|
extern VIEW ourview; /* viewing parameters */ |
| 94 |
|
|
|
| 95 |
|
|
extern char rifname[]; /* rad input file name */ |
| 96 |
|
|
|
| 97 |
|
|
extern int hresolu; /* horizontal resolution */ |
| 98 |
|
|
extern int vresolu; /* vertical resolution */ |
| 99 |
|
|
|
| 100 |
|
|
extern int psample; /* pixel sample size */ |
| 101 |
|
|
extern double maxdiff; /* max. sample difference */ |
| 102 |
|
|
|
| 103 |
|
|
void onsig(); |
| 104 |
|
|
void sigdie(); |
| 105 |
|
|
void printdefaults(); |
| 106 |
|
|
|
| 107 |
|
|
|
| 108 |
|
|
int |
| 109 |
|
|
main(argc, argv) |
| 110 |
|
|
int argc; |
| 111 |
|
|
char *argv[]; |
| 112 |
|
|
{ |
| 113 |
|
|
#define check(ol,al) if (argv[i][ol] || \ |
| 114 |
|
|
badarg(argc-i-1,argv+i+1,al)) \ |
| 115 |
|
|
goto badopt |
| 116 |
|
|
#define bool(olen,var) switch (argv[i][olen]) { \ |
| 117 |
|
|
case '\0': var = !var; break; \ |
| 118 |
|
|
case 'y': case 'Y': case 't': case 'T': \ |
| 119 |
|
|
case '+': case '1': var = 1; break; \ |
| 120 |
|
|
case 'n': case 'N': case 'f': case 'F': \ |
| 121 |
|
|
case '-': case '0': var = 0; break; \ |
| 122 |
|
|
default: goto badopt; } |
| 123 |
|
|
char *err; |
| 124 |
|
|
int rval; |
| 125 |
|
|
int i; |
| 126 |
|
|
/* global program name */ |
| 127 |
|
|
progname = argv[0] = fixargv0(argv[0]); |
| 128 |
|
|
/* option city */ |
| 129 |
|
|
for (i = 1; i < argc; i++) { |
| 130 |
|
|
/* expand arguments */ |
| 131 |
|
|
while ((rval = expandarg(&argc, &argv, i)) > 0) |
| 132 |
|
|
; |
| 133 |
|
|
if (rval < 0) { |
| 134 |
|
|
sprintf(errmsg, "cannot expand '%s'", argv[i]); |
| 135 |
|
|
error(SYSTEM, errmsg); |
| 136 |
|
|
} |
| 137 |
|
|
if (argv[i] == NULL || argv[i][0] != '-') |
| 138 |
|
|
break; /* break from options */ |
| 139 |
|
|
if (!strcmp(argv[i], "-version")) { |
| 140 |
|
|
puts(VersionID); |
| 141 |
|
|
quit(0); |
| 142 |
|
|
} |
| 143 |
|
|
if (!strcmp(argv[i], "-defaults") || |
| 144 |
|
|
!strcmp(argv[i], "-help")) { |
| 145 |
|
|
printdefaults(); |
| 146 |
|
|
quit(0); |
| 147 |
|
|
} |
| 148 |
|
|
if (!strcmp(argv[i], "-devices")) { |
| 149 |
|
|
printdevices(); |
| 150 |
|
|
quit(0); |
| 151 |
|
|
} |
| 152 |
|
|
rval = getrenderopt(argc-i, argv+i); |
| 153 |
|
|
if (rval >= 0) { |
| 154 |
|
|
i += rval; |
| 155 |
|
|
continue; |
| 156 |
|
|
} |
| 157 |
|
|
rval = getviewopt(&ourview, argc-i, argv+i); |
| 158 |
|
|
if (rval >= 0) { |
| 159 |
|
|
i += rval; |
| 160 |
|
|
continue; |
| 161 |
|
|
} |
| 162 |
|
|
switch (argv[i][1]) { |
| 163 |
|
|
case 'v': /* view file */ |
| 164 |
|
|
if (argv[i][2] != 'f') |
| 165 |
|
|
goto badopt; |
| 166 |
|
|
check(3,"s"); |
| 167 |
|
|
rval = viewfile(argv[++i], &ourview, NULL); |
| 168 |
|
|
if (rval < 0) { |
| 169 |
|
|
sprintf(errmsg, |
| 170 |
|
|
"cannot open view file \"%s\"", |
| 171 |
|
|
argv[i]); |
| 172 |
|
|
error(SYSTEM, errmsg); |
| 173 |
|
|
} else if (rval == 0) { |
| 174 |
|
|
sprintf(errmsg, |
| 175 |
|
|
"bad view file \"%s\"", |
| 176 |
|
|
argv[i]); |
| 177 |
|
|
error(USER, errmsg); |
| 178 |
|
|
} |
| 179 |
|
|
break; |
| 180 |
|
|
case 'b': /* grayscale */ |
| 181 |
|
|
bool(2,greyscale); |
| 182 |
|
|
break; |
| 183 |
|
|
case 'p': /* pixel */ |
| 184 |
|
|
switch (argv[i][2]) { |
| 185 |
|
|
case 's': /* sample */ |
| 186 |
|
|
check(3,"i"); |
| 187 |
|
|
psample = atoi(argv[++i]); |
| 188 |
|
|
break; |
| 189 |
|
|
case 't': /* threshold */ |
| 190 |
|
|
check(3,"f"); |
| 191 |
|
|
maxdiff = atof(argv[++i]); |
| 192 |
|
|
break; |
| 193 |
|
|
case 'e': /* exposure */ |
| 194 |
|
|
check(3,"f"); |
| 195 |
|
|
exposure = atof(argv[++i]); |
| 196 |
|
|
if (argv[i][0] == '+' || argv[i][0] == '-') |
| 197 |
|
|
exposure = pow(2.0, exposure); |
| 198 |
|
|
break; |
| 199 |
|
|
default: |
| 200 |
|
|
goto badopt; |
| 201 |
|
|
} |
| 202 |
|
|
break; |
| 203 |
|
|
case 'w': /* warnings */ |
| 204 |
|
|
rval = erract[WARNING].pf != NULL; |
| 205 |
|
|
bool(2,rval); |
| 206 |
|
|
if (rval) erract[WARNING].pf = wputs; |
| 207 |
|
|
else erract[WARNING].pf = NULL; |
| 208 |
|
|
break; |
| 209 |
|
|
case 'e': /* error file */ |
| 210 |
|
|
check(2,"s"); |
| 211 |
|
|
errfile = argv[++i]; |
| 212 |
|
|
break; |
| 213 |
|
|
case 'o': /* output device */ |
| 214 |
|
|
check(2,"s"); |
| 215 |
|
|
dvcname = argv[++i]; |
| 216 |
|
|
break; |
| 217 |
|
|
case 'R': /* render input file */ |
| 218 |
|
|
check(2,"s"); |
| 219 |
|
|
strcpy(rifname, argv[++i]); |
| 220 |
|
|
break; |
| 221 |
|
|
default: |
| 222 |
|
|
goto badopt; |
| 223 |
|
|
} |
| 224 |
|
|
} |
| 225 |
|
|
err = setview(&ourview); /* set viewing parameters */ |
| 226 |
|
|
if (err != NULL) |
| 227 |
|
|
error(USER, err); |
| 228 |
|
|
/* initialize object types */ |
| 229 |
|
|
initotypes(); |
| 230 |
|
|
/* initialize urand */ |
| 231 |
|
|
initurand(2048); |
| 232 |
|
|
/* set up signal handling */ |
| 233 |
|
|
sigdie(SIGINT, "Interrupt"); |
| 234 |
|
|
sigdie(SIGHUP, "Hangup"); |
| 235 |
|
|
sigdie(SIGTERM, "Terminate"); |
| 236 |
|
|
sigdie(SIGPIPE, "Broken pipe"); |
| 237 |
|
|
sigdie(SIGALRM, "Alarm clock"); |
| 238 |
|
|
#ifdef SIGXCPU |
| 239 |
|
|
sigdie(SIGXCPU, "CPU limit exceeded"); |
| 240 |
|
|
sigdie(SIGXFSZ, "File size exceeded"); |
| 241 |
|
|
#endif |
| 242 |
|
|
/* open error file */ |
| 243 |
|
|
if (errfile != NULL) { |
| 244 |
|
|
if (freopen(errfile, "a", stderr) == NULL) |
| 245 |
|
|
quit(2); |
| 246 |
|
|
fprintf(stderr, "**************\n*** PID %5d: ", |
| 247 |
|
|
getpid()); |
| 248 |
|
|
printargs(argc, argv, stderr); |
| 249 |
|
|
putc('\n', stderr); |
| 250 |
|
|
fflush(stderr); |
| 251 |
|
|
} |
| 252 |
|
|
#ifdef NICE |
| 253 |
|
|
nice(NICE); /* lower priority */ |
| 254 |
|
|
#endif |
| 255 |
|
|
/* get octree */ |
| 256 |
|
|
if (i == argc) |
| 257 |
|
|
octname = NULL; |
| 258 |
|
|
else if (i == argc-1) |
| 259 |
|
|
octname = argv[i]; |
| 260 |
|
|
else |
| 261 |
|
|
goto badopt; |
| 262 |
|
|
if (octname == NULL) |
| 263 |
|
|
error(USER, "missing octree argument"); |
| 264 |
|
|
/* set up output */ |
| 265 |
|
|
#ifdef MSDOS |
| 266 |
|
|
setmode(fileno(stdout), O_BINARY); |
| 267 |
|
|
#endif |
| 268 |
|
|
readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); |
| 269 |
|
|
nsceneobjs = nobjects; |
| 270 |
|
|
|
| 271 |
|
|
marksources(); /* find and mark sources */ |
| 272 |
|
|
|
| 273 |
|
|
setambient(); /* initialize ambient calculation */ |
| 274 |
|
|
|
| 275 |
|
|
rview(); /* run interactive viewer */ |
| 276 |
|
|
|
| 277 |
|
|
ambsync(); /* flush ambient file */ |
| 278 |
|
|
|
| 279 |
|
|
quit(0); |
| 280 |
|
|
|
| 281 |
|
|
badopt: |
| 282 |
|
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
| 283 |
|
|
error(USER, errmsg); |
| 284 |
|
|
|
| 285 |
|
|
#undef check |
| 286 |
|
|
#undef bool |
| 287 |
|
|
} |
| 288 |
|
|
|
| 289 |
|
|
|
| 290 |
|
|
void |
| 291 |
|
|
wputs(s) /* warning output function */ |
| 292 |
|
|
char *s; |
| 293 |
|
|
{ |
| 294 |
|
|
int lasterrno = errno; |
| 295 |
|
|
eputs(s); |
| 296 |
|
|
errno = lasterrno; |
| 297 |
|
|
} |
| 298 |
|
|
|
| 299 |
|
|
|
| 300 |
|
|
void |
| 301 |
|
|
eputs(s) /* put string to stderr */ |
| 302 |
|
|
register char *s; |
| 303 |
|
|
{ |
| 304 |
|
|
static int midline = 0; |
| 305 |
|
|
|
| 306 |
|
|
if (!*s) |
| 307 |
|
|
return; |
| 308 |
|
|
if (!midline++) { |
| 309 |
|
|
fputs(progname, stderr); |
| 310 |
|
|
fputs(": ", stderr); |
| 311 |
|
|
} |
| 312 |
|
|
fputs(s, stderr); |
| 313 |
|
|
if (s[strlen(s)-1] == '\n') { |
| 314 |
|
|
fflush(stderr); |
| 315 |
|
|
midline = 0; |
| 316 |
|
|
} |
| 317 |
|
|
} |
| 318 |
|
|
|
| 319 |
|
|
|
| 320 |
|
|
void |
| 321 |
|
|
onsig(signo) /* fatal signal */ |
| 322 |
|
|
int signo; |
| 323 |
|
|
{ |
| 324 |
|
|
static int gotsig = 0; |
| 325 |
|
|
|
| 326 |
|
|
if (gotsig++) /* two signals and we're gone! */ |
| 327 |
|
|
_exit(signo); |
| 328 |
|
|
|
| 329 |
|
|
alarm(15); /* allow 15 seconds to clean up */ |
| 330 |
|
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
| 331 |
|
|
eputs("signal - "); |
| 332 |
|
|
eputs(sigerr[signo]); |
| 333 |
|
|
eputs("\n"); |
| 334 |
|
|
quit(3); |
| 335 |
|
|
} |
| 336 |
|
|
|
| 337 |
|
|
|
| 338 |
|
|
void |
| 339 |
|
|
sigdie(signo, msg) /* set fatal signal */ |
| 340 |
|
|
int signo; |
| 341 |
|
|
char *msg; |
| 342 |
|
|
{ |
| 343 |
|
|
if (signal(signo, onsig) == SIG_IGN) |
| 344 |
|
|
signal(signo, SIG_IGN); |
| 345 |
|
|
sigerr[signo] = msg; |
| 346 |
|
|
} |
| 347 |
|
|
|
| 348 |
|
|
|
| 349 |
|
|
void |
| 350 |
|
|
printdefaults() /* print default values to stdout */ |
| 351 |
|
|
{ |
| 352 |
|
|
register char *cp; |
| 353 |
|
|
|
| 354 |
|
|
printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" : |
| 355 |
|
|
"-b-\t\t\t\t# greyscale off\n"); |
| 356 |
|
|
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
| 357 |
|
|
ourview.type==VT_PER ? "perspective" : |
| 358 |
|
|
ourview.type==VT_PAR ? "parallel" : |
| 359 |
|
|
ourview.type==VT_HEM ? "hemispherical" : |
| 360 |
|
|
ourview.type==VT_ANG ? "angular" : |
| 361 |
|
|
ourview.type==VT_CYL ? "cylindrical" : |
| 362 |
|
|
"unknown"); |
| 363 |
|
|
printf("-vp %f %f %f\t# view point\n", |
| 364 |
|
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
| 365 |
|
|
printf("-vd %f %f %f\t# view direction\n", |
| 366 |
|
|
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
| 367 |
|
|
printf("-vu %f %f %f\t# view up\n", |
| 368 |
|
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
| 369 |
|
|
printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz); |
| 370 |
|
|
printf("-vv %f\t\t\t# view vertical size\n", ourview.vert); |
| 371 |
|
|
printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore); |
| 372 |
|
|
printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft); |
| 373 |
|
|
printf("-vs %f\t\t\t# view shift\n", ourview.hoff); |
| 374 |
|
|
printf("-vl %f\t\t\t# view lift\n", ourview.voff); |
| 375 |
|
|
printf("-pe %f\t\t\t# pixel exposure\n", exposure); |
| 376 |
|
|
printf("-ps %-9d\t\t\t# pixel sample\n", psample); |
| 377 |
|
|
printf("-pt %f\t\t\t# pixel threshold\n", maxdiff); |
| 378 |
|
|
printf("-o %s\t\t\t\t# output device\n", dvcname); |
| 379 |
|
|
printf(erract[WARNING].pf != NULL ? |
| 380 |
|
|
"-w+\t\t\t\t# warning messages on\n" : |
| 381 |
|
|
"-w-\t\t\t\t# warning messages off\n"); |
| 382 |
|
|
print_rdefaults(); |
| 383 |
|
|
} |