13 |
|
#include "platform.h" |
14 |
|
#include "rtprocess.h" /* getpid() */ |
15 |
|
#include "ray.h" |
16 |
+ |
#include "func.h" |
17 |
|
#include "source.h" |
18 |
|
#include "ambient.h" |
19 |
|
#include "random.h" |
20 |
|
#include "paths.h" |
21 |
|
#include "view.h" |
22 |
+ |
#include "pmapray.h" |
23 |
|
|
24 |
|
/* persistent processes define */ |
25 |
|
#ifdef F_SETLKW |
31 |
|
char *progname; /* argv[0] */ |
32 |
|
char *octname; /* octree name */ |
33 |
|
char *sigerr[NSIG]; /* signal error messages */ |
32 |
– |
char *shm_boundary = NULL; /* boundary of shared memory */ |
34 |
|
char *errfile = NULL; /* error output file */ |
35 |
|
|
35 |
– |
extern time_t time(); |
36 |
|
extern time_t tstart; /* start time */ |
37 |
|
|
38 |
|
extern int ralrm; /* seconds between reports */ |
51 |
|
|
52 |
|
extern double dblur; /* depth-of-field blur parameter */ |
53 |
|
|
54 |
+ |
RGBPRIMP out_prims = stdprims; /* output color primitives */ |
55 |
+ |
static RGBPRIMS our_prims; /* private output color primitives */ |
56 |
+ |
|
57 |
|
static void onsig(int signo); |
58 |
|
static void sigdie(int signo, char *msg); |
59 |
|
static void printdefaults(void); |
60 |
+ |
/* rpict additional features */ |
61 |
+ |
#ifdef PERSIST |
62 |
+ |
#define RPICT_FEATURES "Persist\nParallelPersist\n" \ |
63 |
+ |
"ParticipatingMedia=Mist\n" \ |
64 |
+ |
"Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \ |
65 |
+ |
"HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \ |
66 |
+ |
"PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \ |
67 |
+ |
"SmallSourceDrawing\nViewSequence\nProgressReporting\n" \ |
68 |
+ |
"AdaptiveShadowTesting\nOutputs=v,l\n" \ |
69 |
+ |
"OutputCS=RGB,XYZ,prims\n" |
70 |
+ |
#else |
71 |
+ |
#define RPICT_FEATURES "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \ |
72 |
+ |
"ParticipatingMedia=Mist\n" \ |
73 |
+ |
"HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \ |
74 |
+ |
"PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \ |
75 |
+ |
"SmallSourceDrawing\nViewSequence\nProgressReporting\n" \ |
76 |
+ |
"AdaptiveShadowTesting\nOutputs=v,l\n" \ |
77 |
+ |
"OutputCS=RGB,XYZ,prims\n" |
78 |
+ |
#endif |
79 |
|
|
80 |
|
|
81 |
|
int |
84 |
|
#define check(ol,al) if (argv[i][ol] || \ |
85 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
86 |
|
goto badopt |
87 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
87 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
88 |
|
case '\0': var = !var; break; \ |
89 |
|
case 'y': case 'Y': case 't': case 'T': \ |
90 |
|
case '+': case '1': var = 1; break; \ |
105 |
|
tstart = time((time_t *)NULL); |
106 |
|
/* global program name */ |
107 |
|
progname = argv[0] = fixargv0(argv[0]); |
108 |
+ |
/* feature check only? */ |
109 |
+ |
strcat(RFeatureList, RPICT_FEATURES); |
110 |
+ |
if (argc > 1 && !strcmp(argv[1], "-features")) |
111 |
+ |
return feature_status(argc-2, argv+2); |
112 |
+ |
/* initialize calcomp routines */ |
113 |
+ |
initfunc(); |
114 |
|
/* option city */ |
115 |
|
for (i = 1; i < argc; i++) { |
116 |
|
/* expand arguments */ |
186 |
|
check(3,"f"); |
187 |
|
dblur = atof(argv[++i]); |
188 |
|
break; |
189 |
+ |
case 'R': /* standard RGB output */ |
190 |
+ |
if (strcmp(argv[i]+2, "RGB")) |
191 |
+ |
goto badopt; |
192 |
+ |
out_prims = stdprims; |
193 |
+ |
break; |
194 |
+ |
case 'X': /* XYZ output */ |
195 |
+ |
if (strcmp(argv[i]+2, "XYZ")) |
196 |
+ |
goto badopt; |
197 |
+ |
out_prims = xyzprims; |
198 |
+ |
break; |
199 |
+ |
case 'c': { /* chromaticities */ |
200 |
+ |
int j; |
201 |
+ |
check(3,"ffffffff"); |
202 |
+ |
rval = 0; |
203 |
+ |
for (j = 0; j < 8; j++) { |
204 |
+ |
our_prims[0][j] = atof(argv[++i]); |
205 |
+ |
rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001; |
206 |
+ |
} |
207 |
+ |
if (rval) { |
208 |
+ |
if (!colorprimsOK(our_prims)) |
209 |
+ |
error(USER, "illegal primary chromaticities"); |
210 |
+ |
out_prims = our_prims; |
211 |
+ |
} else |
212 |
+ |
out_prims = stdprims; |
213 |
+ |
} break; |
214 |
|
default: |
215 |
|
goto badopt; |
216 |
|
} |
243 |
|
check(2,"s"); |
244 |
|
recover = argv[++i]; |
245 |
|
break; |
193 |
– |
case 't': /* timer */ |
194 |
– |
check(2,"i"); |
195 |
– |
ralrm = atoi(argv[++i]); |
196 |
– |
break; |
246 |
|
#ifdef PERSIST |
247 |
|
case 'P': /* persist file */ |
248 |
|
if (argv[i][2] == 'P') { |
255 |
|
persistfile(argv[++i]); |
256 |
|
break; |
257 |
|
#endif |
258 |
+ |
case 't': /* timer */ |
259 |
+ |
check(2,"i"); |
260 |
+ |
ralrm = atoi(argv[++i]); |
261 |
+ |
break; |
262 |
|
case 'w': /* warnings */ |
263 |
|
rval = erract[WARNING].pf != NULL; |
264 |
< |
bool(2,rval); |
264 |
> |
check_bool(2,rval); |
265 |
|
if (rval) erract[WARNING].pf = wputs; |
266 |
|
else erract[WARNING].pf = NULL; |
267 |
|
break; |
273 |
|
goto badopt; |
274 |
|
} |
275 |
|
} |
276 |
+ |
/* set/check spectral sampling */ |
277 |
+ |
if (setspectrsamp(CNDX, WLPART) <= 0) |
278 |
+ |
error(USER, "unsupported spectral sampling"); |
279 |
+ |
|
280 |
|
err = setview(&ourview); /* set viewing parameters */ |
281 |
|
if (err != NULL) |
282 |
|
error(USER, err); |
342 |
|
#endif |
343 |
|
if (outfile != NULL) |
344 |
|
openheader(); |
288 |
– |
#ifdef _WIN32 |
345 |
|
SET_FILE_BINARY(stdout); |
346 |
|
if (octname == NULL) |
347 |
|
SET_FILE_BINARY(stdin); |
292 |
– |
#endif |
348 |
|
readoct(octname, loadflags, &thescene, NULL); |
349 |
|
nsceneobjs = nobjects; |
350 |
|
|
352 |
|
printargs(i, argv, stdout); |
353 |
|
printf("SOFTWARE= %s\n", VersionID); |
354 |
|
} |
355 |
+ |
|
356 |
+ |
ray_init_pmap(); /* PMAP: set up & load photon maps */ |
357 |
|
|
358 |
|
marksources(); /* find and mark sources */ |
302 |
– |
|
359 |
|
setambient(); /* initialize ambient calculation */ |
360 |
+ |
|
361 |
+ |
fflush(stdout); /* in case we're duplicating header */ |
362 |
|
|
363 |
|
#ifdef PERSIST |
364 |
|
if (persist) { |
307 |
– |
fflush(stdout); |
365 |
|
if (outfile == NULL) { /* reconnect stdout */ |
366 |
|
dup2(duped1, fileno(stdout)); |
367 |
|
close(duped1); |
368 |
|
} |
369 |
|
if (persist == PARALLEL) { /* multiprocessing */ |
370 |
< |
preload_objs(); /* preload scene */ |
314 |
< |
shm_boundary = (char *)malloc(16); |
315 |
< |
strcpy(shm_boundary, "SHM_BOUNDARY"); |
370 |
> |
cow_memshare(); /* preloads scene */ |
371 |
|
while ((rval=fork()) == 0) { /* keep on forkin' */ |
372 |
|
pflock(1); |
373 |
|
pfhold(); |
411 |
|
goto runagain; |
412 |
|
} |
413 |
|
#endif |
414 |
+ |
|
415 |
+ |
|
416 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
417 |
+ |
|
418 |
|
quit(0); |
419 |
|
|
420 |
|
badopt: |
423 |
|
return 1; /* pro forma return */ |
424 |
|
|
425 |
|
#undef check |
426 |
< |
#undef bool |
426 |
> |
#undef check_bool |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
|
void |
431 |
|
wputs( /* warning output function */ |
432 |
< |
char *s |
432 |
> |
const char *s |
433 |
|
) |
434 |
|
{ |
435 |
|
int lasterrno = errno; |
436 |
+ |
if (erract[WARNING].pf == NULL) |
437 |
+ |
return; /* called by calcomp or someone */ |
438 |
|
eputs(s); |
439 |
|
errno = lasterrno; |
440 |
|
} |
442 |
|
|
443 |
|
void |
444 |
|
eputs( /* put string to stderr */ |
445 |
< |
register char *s |
445 |
> |
const char *s |
446 |
|
) |
447 |
|
{ |
448 |
|
static int midline = 0; |
519 |
|
printf("-vl %f\t\t\t# view lift\n", ourview.voff); |
520 |
|
printf("-x %-9d\t\t\t# x resolution\n", hresolu); |
521 |
|
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
522 |
+ |
if (out_prims == stdprims) |
523 |
+ |
printf("-pRGB\t\t\t\t# standard RGB color output\n"); |
524 |
+ |
else if (out_prims == xyzprims) |
525 |
+ |
printf("-pXYZ\t\t\t\t# CIE XYZ color output\n"); |
526 |
+ |
else if (out_prims != NULL) |
527 |
+ |
printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n", |
528 |
+ |
out_prims[RED][0], out_prims[RED][1], |
529 |
+ |
out_prims[GRN][0], out_prims[GRN][1], |
530 |
+ |
out_prims[BLU][0], out_prims[BLU][1], |
531 |
+ |
out_prims[WHT][0], out_prims[WHT][1]); |
532 |
|
printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect); |
533 |
|
printf("-pj %f\t\t\t# pixel jitter\n", dstrpix); |
534 |
|
printf("-pm %f\t\t\t# pixel motion\n", mblur); |