8 |
|
#include "copyright.h" |
9 |
|
|
10 |
|
#include <signal.h> |
11 |
+ |
#include <time.h> |
12 |
|
|
13 |
|
#include "platform.h" |
14 |
|
#include "ray.h" |
15 |
|
#include "source.h" |
16 |
|
#include "ambient.h" |
17 |
+ |
#include "rpaint.h" |
18 |
|
#include "random.h" |
19 |
|
#include "paths.h" |
20 |
|
#include "view.h" |
21 |
+ |
#include "pmapray.h" |
22 |
|
|
23 |
< |
char *progname; /* argv[0] */ |
23 |
> |
extern char *progname; /* global argv[0] */ |
24 |
|
|
25 |
< |
char *octname; /* octree name */ |
25 |
> |
VIEW ourview = STDVIEW; /* viewing parameters */ |
26 |
> |
int hresolu, vresolu; /* image resolution */ |
27 |
|
|
28 |
< |
char *sigerr[NSIG]; /* signal error messages */ |
28 |
> |
int psample = 8; /* pixel sample size */ |
29 |
> |
double maxdiff = .15; /* max. sample difference */ |
30 |
|
|
31 |
< |
char *shm_boundary = NULL; /* boundary of shared memory */ |
31 |
> |
int greyscale = 0; /* map colors to brightness? */ |
32 |
> |
char *dvcname = dev_default; /* output device name */ |
33 |
|
|
34 |
< |
char *errfile = NULL; /* error output file */ |
34 |
> |
double exposure = 1.0; /* exposure for scene */ |
35 |
|
|
36 |
< |
extern int greyscale; /* map colors to brightness? */ |
37 |
< |
extern char *dvcname; /* output device name */ |
38 |
< |
extern double exposure; /* exposure compensation */ |
36 |
> |
int newparam = 1; /* parameter setting changed */ |
37 |
> |
|
38 |
> |
struct driver *dev = NULL; /* driver functions */ |
39 |
|
|
40 |
< |
extern VIEW ourview; /* viewing parameters */ |
40 |
> |
char rifname[128]; /* rad input file name */ |
41 |
|
|
42 |
< |
extern char rifname[]; /* rad input file name */ |
42 |
> |
VIEW oldview; /* previous view parameters */ |
43 |
|
|
44 |
< |
extern int hresolu; /* horizontal resolution */ |
45 |
< |
extern int vresolu; /* vertical resolution */ |
44 |
> |
PNODE ptrunk; /* the base of our image */ |
45 |
> |
RECT pframe; /* current frame boundaries */ |
46 |
> |
int pdepth; /* image depth in current frame */ |
47 |
|
|
48 |
< |
extern int psample; /* pixel sample size */ |
42 |
< |
extern double maxdiff; /* max. sample difference */ |
48 |
> |
char *errfile = NULL; /* error output file */ |
49 |
|
|
50 |
< |
void onsig(); |
45 |
< |
void sigdie(); |
46 |
< |
void printdefaults(); |
50 |
> |
int nproc = 1; /* number of processes */ |
51 |
|
|
52 |
+ |
char *sigerr[NSIG]; /* signal error messages */ |
53 |
|
|
54 |
+ |
static void onsig(int signo); |
55 |
+ |
static void sigdie(int signo, char *msg); |
56 |
+ |
static void printdefaults(void); |
57 |
+ |
|
58 |
+ |
|
59 |
|
int |
60 |
< |
main(argc, argv) |
51 |
< |
int argc; |
52 |
< |
char *argv[]; |
60 |
> |
main(int argc, char *argv[]) |
61 |
|
{ |
62 |
|
#define check(ol,al) if (argv[i][ol] || \ |
63 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
64 |
|
goto badopt |
65 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
65 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
66 |
|
case '\0': var = !var; break; \ |
67 |
|
case 'y': case 'Y': case 't': case 'T': \ |
68 |
|
case '+': case '1': var = 1; break; \ |
69 |
|
case 'n': case 'N': case 'f': case 'F': \ |
70 |
|
case '-': case '0': var = 0; break; \ |
71 |
|
default: goto badopt; } |
72 |
+ |
char *octnm = NULL; |
73 |
|
char *err; |
74 |
|
int rval; |
75 |
|
int i; |
76 |
|
/* global program name */ |
77 |
|
progname = argv[0] = fixargv0(argv[0]); |
78 |
+ |
/* set our defaults */ |
79 |
+ |
shadthresh = .1; |
80 |
+ |
shadcert = .25; |
81 |
+ |
directrelay = 0; |
82 |
+ |
vspretest = 128; |
83 |
+ |
srcsizerat = 0.; |
84 |
+ |
specthresh = .3; |
85 |
+ |
specjitter = 1.; |
86 |
+ |
maxdepth = 6; |
87 |
+ |
minweight = 1e-2; |
88 |
+ |
ambacc = 0.3; |
89 |
+ |
ambres = 32; |
90 |
+ |
ambdiv = 256; |
91 |
+ |
ambssamp = 64; |
92 |
|
/* option city */ |
93 |
|
for (i = 1; i < argc; i++) { |
94 |
|
/* expand arguments */ |
124 |
|
continue; |
125 |
|
} |
126 |
|
switch (argv[i][1]) { |
127 |
+ |
case 'n': /* # processes */ |
128 |
+ |
check(2,"i"); |
129 |
+ |
nproc = atoi(argv[++i]); |
130 |
+ |
if (nproc <= 0) |
131 |
+ |
error(USER, "bad number of processes"); |
132 |
+ |
break; |
133 |
|
case 'v': /* view file */ |
134 |
|
if (argv[i][2] != 'f') |
135 |
|
goto badopt; |
148 |
|
} |
149 |
|
break; |
150 |
|
case 'b': /* grayscale */ |
151 |
< |
bool(2,greyscale); |
151 |
> |
check_bool(2,greyscale); |
152 |
|
break; |
153 |
|
case 'p': /* pixel */ |
154 |
|
switch (argv[i][2]) { |
172 |
|
break; |
173 |
|
case 'w': /* warnings */ |
174 |
|
rval = erract[WARNING].pf != NULL; |
175 |
< |
bool(2,rval); |
175 |
> |
check_bool(2,rval); |
176 |
|
if (rval) erract[WARNING].pf = wputs; |
177 |
|
else erract[WARNING].pf = NULL; |
178 |
|
break; |
195 |
|
err = setview(&ourview); /* set viewing parameters */ |
196 |
|
if (err != NULL) |
197 |
|
error(USER, err); |
198 |
< |
/* initialize object types */ |
170 |
< |
initotypes(); |
171 |
< |
/* initialize urand */ |
172 |
< |
initurand(2048); |
173 |
< |
/* set up signal handling */ |
198 |
> |
/* set up signal handling */ |
199 |
|
sigdie(SIGINT, "Interrupt"); |
175 |
– |
sigdie(SIGHUP, "Hangup"); |
200 |
|
sigdie(SIGTERM, "Terminate"); |
201 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
202 |
+ |
sigdie(SIGHUP, "Hangup"); |
203 |
|
sigdie(SIGPIPE, "Broken pipe"); |
204 |
|
sigdie(SIGALRM, "Alarm clock"); |
179 |
– |
#ifdef SIGXCPU |
180 |
– |
sigdie(SIGXCPU, "CPU limit exceeded"); |
181 |
– |
sigdie(SIGXFSZ, "File size exceeded"); |
205 |
|
#endif |
206 |
|
/* open error file */ |
207 |
|
if (errfile != NULL) { |
218 |
|
#endif |
219 |
|
/* get octree */ |
220 |
|
if (i == argc) |
221 |
< |
octname = NULL; |
221 |
> |
octnm = NULL; |
222 |
|
else if (i == argc-1) |
223 |
< |
octname = argv[i]; |
223 |
> |
octnm = argv[i]; |
224 |
|
else |
225 |
|
goto badopt; |
226 |
< |
if (octname == NULL) |
226 |
> |
if (octnm == NULL) |
227 |
|
error(USER, "missing octree argument"); |
228 |
< |
/* set up output */ |
228 |
> |
/* set up output & start process(es) */ |
229 |
|
SET_FILE_BINARY(stdout); |
230 |
< |
readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); |
231 |
< |
nsceneobjs = nobjects; |
232 |
< |
|
210 |
< |
marksources(); /* find and mark sources */ |
211 |
< |
|
212 |
< |
setambient(); /* initialize ambient calculation */ |
213 |
< |
|
230 |
> |
|
231 |
> |
ray_init(octnm); /* also calls ray_init_pmap() */ |
232 |
> |
|
233 |
|
rview(); /* run interactive viewer */ |
234 |
|
|
235 |
< |
ambsync(); /* flush ambient file */ |
235 |
> |
devclose(); /* close output device */ |
236 |
|
|
237 |
+ |
/* PMAP: free photon maps */ |
238 |
+ |
ray_done_pmap(); |
239 |
+ |
|
240 |
|
quit(0); |
241 |
|
|
242 |
|
badopt: |
243 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
244 |
|
error(USER, errmsg); |
245 |
+ |
return 1; /* pro forma return */ |
246 |
|
|
247 |
|
#undef check |
248 |
< |
#undef bool |
248 |
> |
#undef check_bool |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
|
void |
253 |
< |
wputs(s) /* warning output function */ |
254 |
< |
char *s; |
253 |
> |
wputs( /* warning output function */ |
254 |
> |
char *s |
255 |
> |
) |
256 |
|
{ |
257 |
|
int lasterrno = errno; |
258 |
|
eputs(s); |
261 |
|
|
262 |
|
|
263 |
|
void |
264 |
< |
eputs(s) /* put string to stderr */ |
265 |
< |
register char *s; |
264 |
> |
eputs( /* put string to stderr */ |
265 |
> |
char *s |
266 |
> |
) |
267 |
|
{ |
268 |
|
static int midline = 0; |
269 |
|
|
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
< |
void |
285 |
< |
onsig(signo) /* fatal signal */ |
286 |
< |
int signo; |
284 |
> |
static void |
285 |
> |
onsig( /* fatal signal */ |
286 |
> |
int signo |
287 |
> |
) |
288 |
|
{ |
289 |
|
static int gotsig = 0; |
290 |
|
|
291 |
|
if (gotsig++) /* two signals and we're gone! */ |
292 |
|
_exit(signo); |
293 |
|
|
294 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
295 |
|
alarm(15); /* allow 15 seconds to clean up */ |
296 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
297 |
+ |
#endif |
298 |
|
eputs("signal - "); |
299 |
|
eputs(sigerr[signo]); |
300 |
|
eputs("\n"); |
301 |
+ |
devclose(); |
302 |
|
quit(3); |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
< |
void |
307 |
< |
sigdie(signo, msg) /* set fatal signal */ |
308 |
< |
int signo; |
309 |
< |
char *msg; |
306 |
> |
static void |
307 |
> |
sigdie( /* set fatal signal */ |
308 |
> |
int signo, |
309 |
> |
char *msg |
310 |
> |
) |
311 |
|
{ |
312 |
|
if (signal(signo, onsig) == SIG_IGN) |
313 |
|
signal(signo, SIG_IGN); |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
< |
void |
319 |
< |
printdefaults() /* print default values to stdout */ |
318 |
> |
static void |
319 |
> |
printdefaults(void) /* print default values to stdout */ |
320 |
|
{ |
321 |
< |
register char *cp; |
292 |
< |
|
321 |
> |
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
322 |
|
printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" : |
323 |
|
"-b-\t\t\t\t# greyscale off\n"); |
324 |
|
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
327 |
|
ourview.type==VT_HEM ? "hemispherical" : |
328 |
|
ourview.type==VT_ANG ? "angular" : |
329 |
|
ourview.type==VT_CYL ? "cylindrical" : |
330 |
+ |
ourview.type==VT_PLS ? "planisphere" : |
331 |
|
"unknown"); |
332 |
|
printf("-vp %f %f %f\t# view point\n", |
333 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |