18 |
|
#include "random.h" |
19 |
|
#include "paths.h" |
20 |
|
#include "view.h" |
21 |
+ |
#include "pmapray.h" |
22 |
|
|
23 |
|
extern char *progname; /* global argv[0] */ |
24 |
|
|
55 |
|
static void sigdie(int signo, char *msg); |
56 |
|
static void printdefaults(void); |
57 |
|
|
57 |
– |
|
58 |
|
int |
59 |
|
main(int argc, char *argv[]) |
60 |
|
{ |
61 |
|
#define check(ol,al) if (argv[i][ol] || \ |
62 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
63 |
|
goto badopt |
64 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
64 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
65 |
|
case '\0': var = !var; break; \ |
66 |
|
case 'y': case 'Y': case 't': case 'T': \ |
67 |
|
case '+': case '1': var = 1; break; \ |
83 |
|
specthresh = .3; |
84 |
|
specjitter = 1.; |
85 |
|
maxdepth = 6; |
86 |
< |
minweight = 1e-2; |
86 |
> |
minweight = 1e-3; |
87 |
|
ambacc = 0.3; |
88 |
|
ambres = 32; |
89 |
|
ambdiv = 256; |
147 |
|
} |
148 |
|
break; |
149 |
|
case 'b': /* grayscale */ |
150 |
< |
bool(2,greyscale); |
150 |
> |
check_bool(2,greyscale); |
151 |
|
break; |
152 |
|
case 'p': /* pixel */ |
153 |
|
switch (argv[i][2]) { |
171 |
|
break; |
172 |
|
case 'w': /* warnings */ |
173 |
|
rval = erract[WARNING].pf != NULL; |
174 |
< |
bool(2,rval); |
174 |
> |
check_bool(2,rval); |
175 |
|
if (rval) erract[WARNING].pf = wputs; |
176 |
|
else erract[WARNING].pf = NULL; |
177 |
|
break; |
191 |
|
goto badopt; |
192 |
|
} |
193 |
|
} |
194 |
+ |
/* set/check spectral sampling */ |
195 |
+ |
if (setspectrsamp(CNDX, WLPART) <= 0) |
196 |
+ |
error(USER, "unsupported spectral sampling"); |
197 |
+ |
|
198 |
|
err = setview(&ourview); /* set viewing parameters */ |
199 |
|
if (err != NULL) |
200 |
|
error(USER, err); |
201 |
|
/* set up signal handling */ |
202 |
|
sigdie(SIGINT, "Interrupt"); |
199 |
– |
sigdie(SIGHUP, "Hangup"); |
203 |
|
sigdie(SIGTERM, "Terminate"); |
204 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
205 |
+ |
sigdie(SIGHUP, "Hangup"); |
206 |
|
sigdie(SIGPIPE, "Broken pipe"); |
207 |
|
sigdie(SIGALRM, "Alarm clock"); |
208 |
+ |
#endif |
209 |
|
/* open error file */ |
210 |
|
if (errfile != NULL) { |
211 |
|
if (freopen(errfile, "a", stderr) == NULL) |
231 |
|
/* set up output & start process(es) */ |
232 |
|
SET_FILE_BINARY(stdout); |
233 |
|
|
234 |
< |
ray_pinit(octnm, 0); |
235 |
< |
|
234 |
> |
ray_init(octnm); /* also calls ray_init_pmap() */ |
235 |
> |
|
236 |
> |
/* temporary shortcut, until winrview is refactored into a "device" */ |
237 |
> |
#ifndef WIN_RVIEW |
238 |
|
rview(); /* run interactive viewer */ |
239 |
|
|
240 |
+ |
|
241 |
|
devclose(); /* close output device */ |
242 |
+ |
#endif |
243 |
|
|
244 |
+ |
/* PMAP: free photon maps */ |
245 |
+ |
ray_done_pmap(); |
246 |
+ |
|
247 |
+ |
#ifdef WIN_RVIEW |
248 |
+ |
return 1; |
249 |
+ |
#endif |
250 |
|
quit(0); |
251 |
|
|
252 |
|
badopt: |
255 |
|
return 1; /* pro forma return */ |
256 |
|
|
257 |
|
#undef check |
258 |
< |
#undef bool |
258 |
> |
#undef check_bool |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
void |
263 |
|
wputs( /* warning output function */ |
264 |
< |
char *s |
264 |
> |
const char *s |
265 |
|
) |
266 |
|
{ |
267 |
|
int lasterrno = errno; |
268 |
+ |
if (erract[WARNING].pf == NULL) |
269 |
+ |
return; /* called by calcomp or someone */ |
270 |
|
eputs(s); |
271 |
|
errno = lasterrno; |
272 |
|
} |
274 |
|
|
275 |
|
void |
276 |
|
eputs( /* put string to stderr */ |
277 |
< |
char *s |
277 |
> |
const char *s |
278 |
|
) |
279 |
|
{ |
280 |
|
static int midline = 0; |
303 |
|
if (gotsig++) /* two signals and we're gone! */ |
304 |
|
_exit(signo); |
305 |
|
|
306 |
+ |
#if !defined(_WIN32) && !defined(_WIN64) |
307 |
|
alarm(15); /* allow 15 seconds to clean up */ |
308 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
309 |
+ |
#endif |
310 |
|
eputs("signal - "); |
311 |
|
eputs(sigerr[signo]); |
312 |
|
eputs("\n"); |