ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rpmain.c
Revision: 2.33
Committed: Mon Apr 8 17:08:15 2024 UTC (5 weeks, 4 days ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.32: +3 -3 lines
Log Message:
fix(rpict): Error in -features OutputCS support string

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 greg 2.33 static const char RCSid[] = "$Id: rpmain.c,v 2.32 2024/04/05 16:41:17 greg Exp $";
3 greg 2.1 #endif
4     /*
5     * rpmain.c - main for rpict batch rendering program
6     */
7    
8 greg 2.2 #include "copyright.h"
9 greg 2.1
10 greg 2.10 #include <time.h>
11 schorsch 2.3 #include <signal.h>
12    
13     #include "platform.h"
14 schorsch 2.6 #include "rtprocess.h" /* getpid() */
15 greg 2.1 #include "ray.h"
16     #include "source.h"
17     #include "ambient.h"
18     #include "random.h"
19     #include "paths.h"
20     #include "view.h"
21 greg 2.16 #include "pmapray.h"
22 greg 2.1
23     /* persistent processes define */
24     #ifdef F_SETLKW
25     #define PERSIST 1 /* normal persist */
26     #define PARALLEL 2 /* parallel persist */
27     #define PCHILD 3 /* child of normal persist */
28     #endif
29    
30     char *progname; /* argv[0] */
31     char *octname; /* octree name */
32     char *sigerr[NSIG]; /* signal error messages */
33     char *shm_boundary = NULL; /* boundary of shared memory */
34     char *errfile = NULL; /* error output file */
35    
36     extern time_t time();
37     extern time_t tstart; /* start time */
38    
39     extern int ralrm; /* seconds between reports */
40    
41     extern VIEW ourview; /* viewing parameters */
42    
43     extern int hresolu; /* horizontal resolution */
44     extern int vresolu; /* vertical resolution */
45     extern double pixaspect; /* pixel aspect ratio */
46    
47     extern int psample; /* pixel sample size */
48     extern double maxdiff; /* max. sample difference */
49     extern double dstrpix; /* square pixel distribution */
50    
51     extern double mblur; /* motion blur parameter */
52    
53 greg 2.9 extern double dblur; /* depth-of-field blur parameter */
54    
55 greg 2.28 RGBPRIMP out_prims = stdprims; /* output color primitives */
56     static RGBPRIMS our_prims; /* private output color primitives */
57    
58 schorsch 2.8 static void onsig(int signo);
59     static void sigdie(int signo, char *msg);
60     static void printdefaults(void);
61 greg 2.21 /* rpict additional features */
62     #ifdef PERSIST
63     #define RPICT_FEATURES "Persist\nParallelPersist\n" \
64 greg 2.29 "ParticipatingMedia=Mist\n" \
65 greg 2.22 "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
66     "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
67     "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
68     "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
69 greg 2.32 "AdaptiveShadowTesting\nOutputs=v,l\n" \
70 greg 2.33 "OutputCS=RGB,XYZ,prims\n"
71 greg 2.21 #else
72     #define RPICT_FEATURES "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \
73 greg 2.29 "ParticipatingMedia=Mist\n" \
74 greg 2.22 "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \
75     "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \
76     "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \
77 greg 2.32 "AdaptiveShadowTesting\nOutputs=v,l\n" \
78 greg 2.33 "OutputCS=RGB,XYZ,prims\n"
79 greg 2.21 #endif
80 greg 2.1
81    
82     int
83 schorsch 2.8 main(int argc, char *argv[])
84 greg 2.1 {
85     #define check(ol,al) if (argv[i][ol] || \
86     badarg(argc-i-1,argv+i+1,al)) \
87     goto badopt
88 schorsch 2.18 #define check_bool(olen,var) switch (argv[i][olen]) { \
89 greg 2.1 case '\0': var = !var; break; \
90     case 'y': case 'Y': case 't': case 'T': \
91     case '+': case '1': var = 1; break; \
92     case 'n': case 'N': case 'f': case 'F': \
93     case '-': case '0': var = 0; break; \
94     default: goto badopt; }
95     char *err;
96     char *recover = NULL;
97     char *outfile = NULL;
98     char *zfile = NULL;
99     int loadflags = ~IO_FILES;
100     int seqstart = 0;
101     int persist = 0;
102 greg 2.15 int duped1 = -1;
103 greg 2.1 int rval;
104     int i;
105     /* record start time */
106     tstart = time((time_t *)NULL);
107     /* global program name */
108     progname = argv[0] = fixargv0(argv[0]);
109 greg 2.21 /* feature check only? */
110     strcat(RFeatureList, RPICT_FEATURES);
111 greg 2.25 if (argc > 1 && !strcmp(argv[1], "-features"))
112 greg 2.21 return feature_status(argc-2, argv+2);
113 greg 2.1 /* option city */
114     for (i = 1; i < argc; i++) {
115     /* expand arguments */
116     while ((rval = expandarg(&argc, &argv, i)) > 0)
117     ;
118     if (rval < 0) {
119     sprintf(errmsg, "cannot expand '%s'", argv[i]);
120     error(SYSTEM, errmsg);
121     }
122     if (argv[i] == NULL || argv[i][0] != '-')
123     break; /* break from options */
124     if (!strcmp(argv[i], "-version")) {
125     puts(VersionID);
126     quit(0);
127     }
128     if (!strcmp(argv[i], "-defaults") ||
129     !strcmp(argv[i], "-help")) {
130     printdefaults();
131     quit(0);
132     }
133     rval = getrenderopt(argc-i, argv+i);
134     if (rval >= 0) {
135     i += rval;
136     continue;
137     }
138     rval = getviewopt(&ourview, argc-i, argv+i);
139     if (rval >= 0) {
140     i += rval;
141     continue;
142     }
143     /* rpict options */
144     switch (argv[i][1]) {
145     case 'v': /* view file */
146     if (argv[i][2] != 'f')
147     goto badopt;
148     check(3,"s");
149     rval = viewfile(argv[++i], &ourview, NULL);
150     if (rval < 0) {
151     sprintf(errmsg,
152     "cannot open view file \"%s\"",
153     argv[i]);
154     error(SYSTEM, errmsg);
155     } else if (rval == 0) {
156     sprintf(errmsg,
157     "bad view file \"%s\"",
158     argv[i]);
159     error(USER, errmsg);
160     }
161     break;
162     case 'p': /* pixel */
163     switch (argv[i][2]) {
164     case 's': /* sample */
165     check(3,"i");
166     psample = atoi(argv[++i]);
167     break;
168     case 't': /* threshold */
169     check(3,"f");
170     maxdiff = atof(argv[++i]);
171     break;
172     case 'j': /* jitter */
173     check(3,"f");
174     dstrpix = atof(argv[++i]);
175     break;
176     case 'a': /* aspect */
177     check(3,"f");
178     pixaspect = atof(argv[++i]);
179     break;
180     case 'm': /* motion */
181     check(3,"f");
182     mblur = atof(argv[++i]);
183     break;
184 greg 2.9 case 'd': /* aperture */
185     check(3,"f");
186     dblur = atof(argv[++i]);
187     break;
188 greg 2.28 case 'R': /* standard RGB output */
189     if (strcmp(argv[i]+2, "RGB"))
190     goto badopt;
191     out_prims = stdprims;
192     break;
193     case 'X': /* XYZ output */
194     if (strcmp(argv[i]+2, "XYZ"))
195     goto badopt;
196     out_prims = xyzprims;
197     break;
198     case 'c': { /* chromaticities */
199     int j;
200     check(3,"ffffffff");
201     rval = 0;
202     for (j = 0; j < 8; j++) {
203     our_prims[0][j] = atof(argv[++i]);
204     rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001;
205     }
206     if (rval) {
207     if (!colorprimsOK(our_prims))
208     error(USER, "illegal primary chromaticities");
209     out_prims = our_prims;
210     } else
211     out_prims = stdprims;
212     } break;
213 greg 2.1 default:
214     goto badopt;
215     }
216     break;
217     case 'x': /* x resolution */
218     check(2,"i");
219     hresolu = atoi(argv[++i]);
220     break;
221     case 'y': /* y resolution */
222     check(2,"i");
223     vresolu = atoi(argv[++i]);
224     break;
225     case 'S': /* slave index */
226     check(2,"i");
227     seqstart = atoi(argv[++i]);
228     break;
229     case 'o': /* output file */
230     check(2,"s");
231     outfile = argv[++i];
232     break;
233     case 'z': /* z file */
234     check(2,"s");
235     zfile = argv[++i];
236     break;
237     case 'r': /* recover file */
238     if (argv[i][2] == 'o') { /* +output */
239     check(3,"s");
240     outfile = argv[i+1];
241     } else
242     check(2,"s");
243     recover = argv[++i];
244     break;
245     case 't': /* timer */
246     check(2,"i");
247     ralrm = atoi(argv[++i]);
248     break;
249     #ifdef PERSIST
250     case 'P': /* persist file */
251     if (argv[i][2] == 'P') {
252     check(3,"s");
253     persist = PARALLEL;
254     } else {
255     check(2,"s");
256     persist = PERSIST;
257     }
258     persistfile(argv[++i]);
259     break;
260     #endif
261     case 'w': /* warnings */
262     rval = erract[WARNING].pf != NULL;
263 schorsch 2.18 check_bool(2,rval);
264 greg 2.1 if (rval) erract[WARNING].pf = wputs;
265     else erract[WARNING].pf = NULL;
266     break;
267     case 'e': /* error file */
268     check(2,"s");
269     errfile = argv[++i];
270     break;
271     default:
272     goto badopt;
273     }
274     }
275 greg 2.30 /* set/check spectral sampling */
276 greg 2.31 if (setspectrsamp(CNDX, WLPART) <= 0)
277 greg 2.30 error(USER, "unsupported spectral sampling");
278    
279 greg 2.1 err = setview(&ourview); /* set viewing parameters */
280     if (err != NULL)
281     error(USER, err);
282     /* initialize object types */
283     initotypes();
284     /* initialize urand */
285 greg 2.12 if (rand_samp) {
286     srandom((long)time(0));
287     initurand(0);
288     } else {
289     srandom(0L);
290     initurand(2048);
291     }
292 greg 2.1 /* set up signal handling */
293     sigdie(SIGINT, "Interrupt");
294 schorsch 2.4 #ifdef SIGHUP
295 greg 2.1 sigdie(SIGHUP, "Hangup");
296 schorsch 2.4 #endif
297 greg 2.1 sigdie(SIGTERM, "Terminate");
298 schorsch 2.4 #ifdef SIGPIPE
299 greg 2.1 sigdie(SIGPIPE, "Broken pipe");
300 schorsch 2.4 #endif
301     #ifdef SIGALRM
302 greg 2.1 sigdie(SIGALRM, "Alarm clock");
303 schorsch 2.4 #endif
304 greg 2.1 #ifdef SIGXCPU
305     sigdie(SIGXCPU, "CPU limit exceeded");
306     sigdie(SIGXFSZ, "File size exceeded");
307     #endif
308     /* open error file */
309     if (errfile != NULL) {
310     if (freopen(errfile, "a", stderr) == NULL)
311     quit(2);
312     fprintf(stderr, "**************\n*** PID %5d: ",
313     getpid());
314     printargs(argc, argv, stderr);
315     putc('\n', stderr);
316     fflush(stderr);
317     }
318     #ifdef NICE
319     nice(NICE); /* lower priority */
320     #endif
321     /* get octree */
322     if (i == argc)
323     octname = NULL;
324     else if (i == argc-1)
325     octname = argv[i];
326     else
327     goto badopt;
328     if (seqstart > 0 && octname == NULL)
329     error(USER, "missing octree argument");
330     /* set up output */
331     #ifdef PERSIST
332     if (persist) {
333     if (recover != NULL)
334     error(USER, "persist option used with recover file");
335     if (seqstart <= 0)
336     error(USER, "persist option only for sequences");
337     if (outfile == NULL)
338     duped1 = dup(fileno(stdout)); /* don't lose our output */
339     openheader();
340     } else
341     #endif
342     if (outfile != NULL)
343     openheader();
344 schorsch 2.3 SET_FILE_BINARY(stdout);
345 greg 2.1 if (octname == NULL)
346 schorsch 2.3 SET_FILE_BINARY(stdin);
347 greg 2.1 readoct(octname, loadflags, &thescene, NULL);
348     nsceneobjs = nobjects;
349    
350     if (loadflags & IO_INFO) { /* print header */
351     printargs(i, argv, stdout);
352     printf("SOFTWARE= %s\n", VersionID);
353     }
354 greg 2.16
355     ray_init_pmap(); /* PMAP: set up & load photon maps */
356 greg 2.1
357     marksources(); /* find and mark sources */
358    
359     setambient(); /* initialize ambient calculation */
360 greg 2.16
361 greg 2.20 fflush(stdout); /* in case we're duplicating header */
362    
363 greg 2.1 #ifdef PERSIST
364     if (persist) {
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 */
371     shm_boundary = (char *)malloc(16);
372     strcpy(shm_boundary, "SHM_BOUNDARY");
373     while ((rval=fork()) == 0) { /* keep on forkin' */
374     pflock(1);
375     pfhold();
376     tstart = time((time_t *)NULL);
377 greg 2.13 ambsync(); /* load new values */
378 greg 2.1 }
379     if (rval < 0)
380     error(SYSTEM, "cannot fork child for persist function");
381 greg 2.13 pfdetach(); /* parent will run then exit */
382 greg 2.1 }
383     }
384     runagain:
385 schorsch 2.7 if (persist) {
386 greg 2.1 if (outfile == NULL) /* if out to stdout */
387     dupheader(); /* send header */
388     else /* if out to file */
389     duped1 = dup(fileno(stdout)); /* hang onto pipe */
390 schorsch 2.7 }
391 greg 2.1 #endif
392     /* batch render picture(s) */
393     rpict(seqstart, outfile, zfile, recover);
394     /* flush ambient file */
395     ambsync();
396     #ifdef PERSIST
397     if (persist == PERSIST) { /* first run-through */
398     if ((rval=fork()) == 0) { /* child loops until killed */
399     pflock(1);
400     persist = PCHILD;
401     } else { /* original process exits */
402     if (rval < 0)
403     error(SYSTEM, "cannot fork child for persist function");
404     pfdetach(); /* parent exits */
405     }
406     }
407     if (persist == PCHILD) { /* wait for a signal then go again */
408     if (outfile != NULL)
409     close(duped1); /* release output handle */
410     pfhold();
411     tstart = time((time_t *)NULL); /* reinitialize */
412     raynum = nrays = 0;
413     goto runagain;
414     }
415     #endif
416 greg 2.16
417    
418     ray_done_pmap(); /* PMAP: free photon maps */
419    
420 greg 2.1 quit(0);
421    
422     badopt:
423     sprintf(errmsg, "command line error at '%s'", argv[i]);
424     error(USER, errmsg);
425 schorsch 2.8 return 1; /* pro forma return */
426 greg 2.1
427     #undef check
428 schorsch 2.18 #undef check_bool
429 greg 2.1 }
430    
431    
432     void
433 schorsch 2.8 wputs( /* warning output function */
434 greg 2.26 const char *s
435 schorsch 2.8 )
436 greg 2.1 {
437     int lasterrno = errno;
438     eputs(s);
439     errno = lasterrno;
440     }
441    
442    
443     void
444 schorsch 2.8 eputs( /* put string to stderr */
445 greg 2.26 const char *s
446 schorsch 2.8 )
447 greg 2.1 {
448     static int midline = 0;
449    
450     if (!*s)
451     return;
452     if (!midline++) {
453     fputs(progname, stderr);
454     fputs(": ", stderr);
455     }
456     fputs(s, stderr);
457     if (s[strlen(s)-1] == '\n') {
458     fflush(stderr);
459     midline = 0;
460     }
461     }
462    
463    
464 schorsch 2.8 static void
465     onsig( /* fatal signal */
466     int signo
467     )
468 greg 2.1 {
469     static int gotsig = 0;
470    
471     if (gotsig++) /* two signals and we're gone! */
472     _exit(signo);
473    
474 schorsch 2.4 #ifdef SIGALRM /* XXX how critical is this? */
475 greg 2.1 alarm(15); /* allow 15 seconds to clean up */
476     signal(SIGALRM, SIG_DFL); /* make certain we do die */
477 schorsch 2.4 #endif
478 greg 2.1 eputs("signal - ");
479     eputs(sigerr[signo]);
480     eputs("\n");
481     quit(3);
482     }
483    
484    
485 schorsch 2.8 static void
486     sigdie( /* set fatal signal */
487     int signo,
488     char *msg
489     )
490 greg 2.1 {
491     if (signal(signo, onsig) == SIG_IGN)
492     signal(signo, SIG_IGN);
493     sigerr[signo] = msg;
494     }
495    
496    
497 schorsch 2.8 static void
498     printdefaults(void) /* print default values to stdout */
499 greg 2.1 {
500     printf("-vt%c\t\t\t\t# view type %s\n", ourview.type,
501     ourview.type==VT_PER ? "perspective" :
502     ourview.type==VT_PAR ? "parallel" :
503     ourview.type==VT_HEM ? "hemispherical" :
504     ourview.type==VT_ANG ? "angular" :
505     ourview.type==VT_CYL ? "cylindrical" :
506 greg 2.14 ourview.type==VT_PLS ? "planisphere" :
507 greg 2.1 "unknown");
508     printf("-vp %f %f %f\t# view point\n",
509     ourview.vp[0], ourview.vp[1], ourview.vp[2]);
510     printf("-vd %f %f %f\t# view direction\n",
511     ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
512     printf("-vu %f %f %f\t# view up\n",
513     ourview.vup[0], ourview.vup[1], ourview.vup[2]);
514     printf("-vh %f\t\t\t# view horizontal size\n", ourview.horiz);
515     printf("-vv %f\t\t\t# view vertical size\n", ourview.vert);
516     printf("-vo %f\t\t\t# view fore clipping plane\n", ourview.vfore);
517     printf("-va %f\t\t\t# view aft clipping plane\n", ourview.vaft);
518     printf("-vs %f\t\t\t# view shift\n", ourview.hoff);
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 greg 2.28 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 greg 2.1 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);
535 greg 2.9 printf("-pd %f\t\t\t# pixel depth-of-field\n", dblur);
536 greg 2.1 printf("-ps %-9d\t\t\t# pixel sample\n", psample);
537     printf("-pt %f\t\t\t# pixel threshold\n", maxdiff);
538     printf("-t %-9d\t\t\t# time between reports\n", ralrm);
539     printf(erract[WARNING].pf != NULL ?
540     "-w+\t\t\t\t# warning messages on\n" :
541     "-w-\t\t\t\t# warning messages off\n");
542     print_rdefaults();
543     }