16 |
|
#include "ambient.h" |
17 |
|
#include "rpaint.h" |
18 |
|
#include "random.h" |
19 |
– |
#include "paths.h" |
19 |
|
#include "view.h" |
20 |
+ |
#include "pmapray.h" |
21 |
|
|
22 |
– |
extern char *progname; /* global argv[0] */ |
23 |
– |
|
22 |
|
VIEW ourview = STDVIEW; /* viewing parameters */ |
23 |
|
int hresolu, vresolu; /* image resolution */ |
24 |
|
|
52 |
|
static void sigdie(int signo, char *msg); |
53 |
|
static void printdefaults(void); |
54 |
|
|
55 |
+ |
static void |
56 |
+ |
set_defaults(void) |
57 |
+ |
{ |
58 |
+ |
shadthresh = .1; |
59 |
+ |
shadcert = .25; |
60 |
+ |
directrelay = 0; |
61 |
+ |
vspretest = 128; |
62 |
+ |
srcsizerat = 0.; |
63 |
+ |
specthresh = .3; |
64 |
+ |
specjitter = 1.; |
65 |
+ |
maxdepth = 6; |
66 |
+ |
minweight = 1e-3; |
67 |
+ |
ambacc = 0.3; |
68 |
+ |
ambres = 32; |
69 |
+ |
ambdiv = 256; |
70 |
+ |
ambssamp = 64; |
71 |
+ |
} |
72 |
|
|
73 |
|
int |
74 |
|
main(int argc, char *argv[]) |
76 |
|
#define check(ol,al) if (argv[i][ol] || \ |
77 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
78 |
|
goto badopt |
79 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
79 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
80 |
|
case '\0': var = !var; break; \ |
81 |
|
case 'y': case 'Y': case 't': case 'T': \ |
82 |
|
case '+': case '1': var = 1; break; \ |
90 |
|
/* global program name */ |
91 |
|
progname = argv[0] = fixargv0(argv[0]); |
92 |
|
/* set our defaults */ |
93 |
< |
shadthresh = .1; |
79 |
< |
shadcert = .25; |
80 |
< |
directrelay = 0; |
81 |
< |
vspretest = 128; |
82 |
< |
srcsizerat = 0.; |
83 |
< |
specthresh = .3; |
84 |
< |
specjitter = 1.; |
85 |
< |
maxdepth = 6; |
86 |
< |
minweight = 1e-2; |
87 |
< |
ambacc = 0.3; |
88 |
< |
ambres = 32; |
89 |
< |
ambdiv = 256; |
90 |
< |
ambssamp = 64; |
93 |
> |
set_defaults(); |
94 |
|
/* option city */ |
95 |
|
for (i = 1; i < argc; i++) { |
96 |
|
/* expand arguments */ |
150 |
|
} |
151 |
|
break; |
152 |
|
case 'b': /* grayscale */ |
153 |
< |
bool(2,greyscale); |
153 |
> |
check_bool(2,greyscale); |
154 |
|
break; |
155 |
|
case 'p': /* pixel */ |
156 |
|
switch (argv[i][2]) { |
174 |
|
break; |
175 |
|
case 'w': /* warnings */ |
176 |
|
rval = erract[WARNING].pf != NULL; |
177 |
< |
bool(2,rval); |
177 |
> |
check_bool(2,rval); |
178 |
|
if (rval) erract[WARNING].pf = wputs; |
179 |
|
else erract[WARNING].pf = NULL; |
180 |
|
break; |
194 |
|
goto badopt; |
195 |
|
} |
196 |
|
} |
197 |
+ |
/* set/check spectral sampling */ |
198 |
+ |
if (setspectrsamp(CNDX, WLPART) <= 0) |
199 |
+ |
error(USER, "unsupported spectral sampling"); |
200 |
+ |
|
201 |
|
err = setview(&ourview); /* set viewing parameters */ |
202 |
|
if (err != NULL) |
203 |
|
error(USER, err); |
204 |
|
/* set up signal handling */ |
205 |
|
sigdie(SIGINT, "Interrupt"); |
199 |
– |
sigdie(SIGHUP, "Hangup"); |
206 |
|
sigdie(SIGTERM, "Terminate"); |
207 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
208 |
+ |
sigdie(SIGHUP, "Hangup"); |
209 |
|
sigdie(SIGPIPE, "Broken pipe"); |
210 |
|
sigdie(SIGALRM, "Alarm clock"); |
211 |
+ |
#endif |
212 |
|
/* open error file */ |
213 |
|
if (errfile != NULL) { |
214 |
|
if (freopen(errfile, "a", stderr) == NULL) |
234 |
|
/* set up output & start process(es) */ |
235 |
|
SET_FILE_BINARY(stdout); |
236 |
|
|
237 |
< |
ray_init(octnm); |
238 |
< |
|
237 |
> |
ray_init(octnm); /* also calls ray_init_pmap() */ |
238 |
> |
|
239 |
> |
/* temporary shortcut, until winrview is refactored into a "device" */ |
240 |
> |
#ifndef WIN_RVIEW |
241 |
|
rview(); /* run interactive viewer */ |
242 |
|
|
243 |
+ |
|
244 |
|
devclose(); /* close output device */ |
245 |
+ |
#endif |
246 |
|
|
247 |
+ |
/* PMAP: free photon maps */ |
248 |
+ |
ray_done_pmap(); |
249 |
+ |
|
250 |
+ |
#ifdef WIN_RVIEW |
251 |
+ |
return 1; |
252 |
+ |
#endif |
253 |
|
quit(0); |
254 |
|
|
255 |
|
badopt: |
258 |
|
return 1; /* pro forma return */ |
259 |
|
|
260 |
|
#undef check |
261 |
< |
#undef bool |
261 |
> |
#undef check_bool |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
void |
266 |
|
wputs( /* warning output function */ |
267 |
< |
char *s |
267 |
> |
const char *s |
268 |
|
) |
269 |
|
{ |
270 |
|
int lasterrno = errno; |
271 |
+ |
if (erract[WARNING].pf == NULL) |
272 |
+ |
return; /* called by calcomp or someone */ |
273 |
|
eputs(s); |
274 |
|
errno = lasterrno; |
275 |
|
} |
277 |
|
|
278 |
|
void |
279 |
|
eputs( /* put string to stderr */ |
280 |
< |
char *s |
280 |
> |
const char *s |
281 |
|
) |
282 |
|
{ |
283 |
|
static int midline = 0; |
306 |
|
if (gotsig++) /* two signals and we're gone! */ |
307 |
|
_exit(signo); |
308 |
|
|
309 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
310 |
|
alarm(15); /* allow 15 seconds to clean up */ |
311 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
312 |
+ |
#endif |
313 |
|
eputs("signal - "); |
314 |
|
eputs(sigerr[signo]); |
315 |
|
eputs("\n"); |