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 |
+ |
static void |
59 |
+ |
set_defaults(void) |
60 |
+ |
{ |
61 |
+ |
shadthresh = .1; |
62 |
+ |
shadcert = .25; |
63 |
+ |
directrelay = 0; |
64 |
+ |
vspretest = 128; |
65 |
+ |
srcsizerat = 0.; |
66 |
+ |
specthresh = .3; |
67 |
+ |
specjitter = 1.; |
68 |
+ |
maxdepth = 6; |
69 |
+ |
minweight = 1e-3; |
70 |
+ |
ambacc = 0.3; |
71 |
+ |
ambres = 32; |
72 |
+ |
ambdiv = 256; |
73 |
+ |
ambssamp = 64; |
74 |
+ |
} |
75 |
+ |
|
76 |
|
int |
77 |
< |
main(argc, argv) |
51 |
< |
int argc; |
52 |
< |
char *argv[]; |
77 |
> |
main(int argc, char *argv[]) |
78 |
|
{ |
79 |
|
#define check(ol,al) if (argv[i][ol] || \ |
80 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
81 |
|
goto badopt |
82 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
82 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
83 |
|
case '\0': var = !var; break; \ |
84 |
|
case 'y': case 'Y': case 't': case 'T': \ |
85 |
|
case '+': case '1': var = 1; break; \ |
86 |
|
case 'n': case 'N': case 'f': case 'F': \ |
87 |
|
case '-': case '0': var = 0; break; \ |
88 |
|
default: goto badopt; } |
89 |
+ |
char *octnm = NULL; |
90 |
|
char *err; |
91 |
|
int rval; |
92 |
|
int i; |
93 |
|
/* global program name */ |
94 |
|
progname = argv[0] = fixargv0(argv[0]); |
95 |
+ |
/* set our defaults */ |
96 |
+ |
set_defaults(); |
97 |
|
/* option city */ |
98 |
|
for (i = 1; i < argc; i++) { |
99 |
|
/* expand arguments */ |
129 |
|
continue; |
130 |
|
} |
131 |
|
switch (argv[i][1]) { |
132 |
+ |
case 'n': /* # processes */ |
133 |
+ |
check(2,"i"); |
134 |
+ |
nproc = atoi(argv[++i]); |
135 |
+ |
if (nproc <= 0) |
136 |
+ |
error(USER, "bad number of processes"); |
137 |
+ |
break; |
138 |
|
case 'v': /* view file */ |
139 |
|
if (argv[i][2] != 'f') |
140 |
|
goto badopt; |
153 |
|
} |
154 |
|
break; |
155 |
|
case 'b': /* grayscale */ |
156 |
< |
bool(2,greyscale); |
156 |
> |
check_bool(2,greyscale); |
157 |
|
break; |
158 |
|
case 'p': /* pixel */ |
159 |
|
switch (argv[i][2]) { |
177 |
|
break; |
178 |
|
case 'w': /* warnings */ |
179 |
|
rval = erract[WARNING].pf != NULL; |
180 |
< |
bool(2,rval); |
180 |
> |
check_bool(2,rval); |
181 |
|
if (rval) erract[WARNING].pf = wputs; |
182 |
|
else erract[WARNING].pf = NULL; |
183 |
|
break; |
197 |
|
goto badopt; |
198 |
|
} |
199 |
|
} |
200 |
+ |
/* set/check spectral sampling */ |
201 |
+ |
if (setspectrsamp(CNDX, WLPART) <= 0) |
202 |
+ |
error(USER, "unsupported spectral sampling"); |
203 |
+ |
|
204 |
|
err = setview(&ourview); /* set viewing parameters */ |
205 |
|
if (err != NULL) |
206 |
|
error(USER, err); |
207 |
< |
/* initialize object types */ |
170 |
< |
initotypes(); |
171 |
< |
/* initialize urand */ |
172 |
< |
initurand(2048); |
173 |
< |
/* set up signal handling */ |
207 |
> |
/* set up signal handling */ |
208 |
|
sigdie(SIGINT, "Interrupt"); |
175 |
– |
sigdie(SIGHUP, "Hangup"); |
209 |
|
sigdie(SIGTERM, "Terminate"); |
210 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
211 |
+ |
sigdie(SIGHUP, "Hangup"); |
212 |
|
sigdie(SIGPIPE, "Broken pipe"); |
213 |
|
sigdie(SIGALRM, "Alarm clock"); |
179 |
– |
#ifdef SIGXCPU |
180 |
– |
sigdie(SIGXCPU, "CPU limit exceeded"); |
181 |
– |
sigdie(SIGXFSZ, "File size exceeded"); |
214 |
|
#endif |
215 |
|
/* open error file */ |
216 |
|
if (errfile != NULL) { |
227 |
|
#endif |
228 |
|
/* get octree */ |
229 |
|
if (i == argc) |
230 |
< |
octname = NULL; |
230 |
> |
octnm = NULL; |
231 |
|
else if (i == argc-1) |
232 |
< |
octname = argv[i]; |
232 |
> |
octnm = argv[i]; |
233 |
|
else |
234 |
|
goto badopt; |
235 |
< |
if (octname == NULL) |
235 |
> |
if (octnm == NULL) |
236 |
|
error(USER, "missing octree argument"); |
237 |
< |
/* set up output */ |
237 |
> |
/* set up output & start process(es) */ |
238 |
|
SET_FILE_BINARY(stdout); |
239 |
< |
readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); |
240 |
< |
nsceneobjs = nobjects; |
241 |
< |
|
242 |
< |
marksources(); /* find and mark sources */ |
243 |
< |
|
212 |
< |
setambient(); /* initialize ambient calculation */ |
213 |
< |
|
239 |
> |
|
240 |
> |
ray_init(octnm); /* also calls ray_init_pmap() */ |
241 |
> |
|
242 |
> |
/* temporary shortcut, until winrview is refactored into a "device" */ |
243 |
> |
#ifndef WIN_RVIEW |
244 |
|
rview(); /* run interactive viewer */ |
245 |
|
|
216 |
– |
ambsync(); /* flush ambient file */ |
246 |
|
|
247 |
+ |
devclose(); /* close output device */ |
248 |
+ |
#endif |
249 |
+ |
|
250 |
+ |
/* PMAP: free photon maps */ |
251 |
+ |
ray_done_pmap(); |
252 |
+ |
|
253 |
+ |
#ifdef WIN_RVIEW |
254 |
+ |
return 1; |
255 |
+ |
#endif |
256 |
|
quit(0); |
257 |
|
|
258 |
|
badopt: |
259 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
260 |
|
error(USER, errmsg); |
261 |
+ |
return 1; /* pro forma return */ |
262 |
|
|
263 |
|
#undef check |
264 |
< |
#undef bool |
264 |
> |
#undef check_bool |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
|
void |
269 |
< |
wputs(s) /* warning output function */ |
270 |
< |
char *s; |
269 |
> |
wputs( /* warning output function */ |
270 |
> |
const char *s |
271 |
> |
) |
272 |
|
{ |
273 |
|
int lasterrno = errno; |
274 |
+ |
if (erract[WARNING].pf == NULL) |
275 |
+ |
return; /* called by calcomp or someone */ |
276 |
|
eputs(s); |
277 |
|
errno = lasterrno; |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
|
void |
282 |
< |
eputs(s) /* put string to stderr */ |
283 |
< |
register char *s; |
282 |
> |
eputs( /* put string to stderr */ |
283 |
> |
const char *s |
284 |
> |
) |
285 |
|
{ |
286 |
|
static int midline = 0; |
287 |
|
|
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
< |
void |
303 |
< |
onsig(signo) /* fatal signal */ |
304 |
< |
int signo; |
302 |
> |
static void |
303 |
> |
onsig( /* fatal signal */ |
304 |
> |
int signo |
305 |
> |
) |
306 |
|
{ |
307 |
|
static int gotsig = 0; |
308 |
|
|
309 |
|
if (gotsig++) /* two signals and we're gone! */ |
310 |
|
_exit(signo); |
311 |
|
|
312 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
313 |
|
alarm(15); /* allow 15 seconds to clean up */ |
314 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
315 |
+ |
#endif |
316 |
|
eputs("signal - "); |
317 |
|
eputs(sigerr[signo]); |
318 |
|
eputs("\n"); |
319 |
+ |
devclose(); |
320 |
|
quit(3); |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
< |
void |
325 |
< |
sigdie(signo, msg) /* set fatal signal */ |
326 |
< |
int signo; |
327 |
< |
char *msg; |
324 |
> |
static void |
325 |
> |
sigdie( /* set fatal signal */ |
326 |
> |
int signo, |
327 |
> |
char *msg |
328 |
> |
) |
329 |
|
{ |
330 |
|
if (signal(signo, onsig) == SIG_IGN) |
331 |
|
signal(signo, SIG_IGN); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
< |
void |
337 |
< |
printdefaults() /* print default values to stdout */ |
336 |
> |
static void |
337 |
> |
printdefaults(void) /* print default values to stdout */ |
338 |
|
{ |
339 |
< |
register char *cp; |
292 |
< |
|
339 |
> |
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
340 |
|
printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" : |
341 |
|
"-b-\t\t\t\t# greyscale off\n"); |
342 |
|
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
345 |
|
ourview.type==VT_HEM ? "hemispherical" : |
346 |
|
ourview.type==VT_ANG ? "angular" : |
347 |
|
ourview.type==VT_CYL ? "cylindrical" : |
348 |
+ |
ourview.type==VT_PLS ? "planisphere" : |
349 |
|
"unknown"); |
350 |
|
printf("-vp %f %f %f\t# view point\n", |
351 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |