--- ray/src/rt/rpmain.c 2003/07/03 18:03:58 2.5 +++ ray/src/rt/rpmain.c 2024/01/17 01:31:08 2.30 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpmain.c,v 2.5 2003/07/03 18:03:58 greg Exp $"; +static const char RCSid[] = "$Id: rpmain.c,v 2.30 2024/01/17 01:31:08 greg Exp $"; #endif /* * rpmain.c - main for rpict batch rendering program @@ -7,19 +7,18 @@ static const char RCSid[] = "$Id: rpmain.c,v 2.5 2003/ #include "copyright.h" -#include +#include #include -#ifdef _WIN32 - #include /* getpid */ -#endif #include "platform.h" +#include "rtprocess.h" /* getpid() */ #include "ray.h" #include "source.h" #include "ambient.h" #include "random.h" #include "paths.h" #include "view.h" +#include "pmapray.h" /* persistent processes define */ #ifdef F_SETLKW @@ -29,13 +28,9 @@ static const char RCSid[] = "$Id: rpmain.c,v 2.5 2003/ #endif char *progname; /* argv[0] */ - char *octname; /* octree name */ - char *sigerr[NSIG]; /* signal error messages */ - char *shm_boundary = NULL; /* boundary of shared memory */ - char *errfile = NULL; /* error output file */ extern time_t time(); @@ -55,20 +50,40 @@ extern double dstrpix; /* square pixel distribution extern double mblur; /* motion blur parameter */ -void onsig(); -void sigdie(); -void printdefaults(); +extern double dblur; /* depth-of-field blur parameter */ +RGBPRIMP out_prims = stdprims; /* output color primitives */ +static RGBPRIMS our_prims; /* private output color primitives */ +static void onsig(int signo); +static void sigdie(int signo, char *msg); +static void printdefaults(void); + /* rpict additional features */ +#ifdef PERSIST +#define RPICT_FEATURES "Persist\nParallelPersist\n" \ + "ParticipatingMedia=Mist\n" \ + "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \ + "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \ + "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \ + "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \ + "AdaptiveShadowTesting\nOutputs=v,l\n" +#else +#define RPICT_FEATURES "Recovery\nIrradianceCalc\nViewTypes=v,l,a,h,s,c\n" \ + "ParticipatingMedia=Mist\n" \ + "HessianAmbientCache\nAmbientAveraging\nAmbientValueSharing\n" \ + "PixelJitter\nPixelSampling\nPixelMotion\nPixelDepthOfField\n" \ + "SmallSourceDrawing\nViewSequence\nProgressReporting\n" \ + "AdaptiveShadowTesting\nOutputs=v,l\n" +#endif + + int -main(argc, argv) -int argc; -char *argv[]; +main(int argc, char *argv[]) { #define check(ol,al) if (argv[i][ol] || \ badarg(argc-i-1,argv+i+1,al)) \ goto badopt -#define bool(olen,var) switch (argv[i][olen]) { \ +#define check_bool(olen,var) switch (argv[i][olen]) { \ case '\0': var = !var; break; \ case 'y': case 'Y': case 't': case 'T': \ case '+': case '1': var = 1; break; \ @@ -82,13 +97,17 @@ char *argv[]; int loadflags = ~IO_FILES; int seqstart = 0; int persist = 0; - int duped1; + int duped1 = -1; int rval; int i; /* record start time */ tstart = time((time_t *)NULL); /* global program name */ progname = argv[0] = fixargv0(argv[0]); + /* feature check only? */ + strcat(RFeatureList, RPICT_FEATURES); + if (argc > 1 && !strcmp(argv[1], "-features")) + return feature_status(argc-2, argv+2); /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ @@ -160,6 +179,35 @@ char *argv[]; check(3,"f"); mblur = atof(argv[++i]); break; + case 'd': /* aperture */ + check(3,"f"); + dblur = atof(argv[++i]); + break; + case 'R': /* standard RGB output */ + if (strcmp(argv[i]+2, "RGB")) + goto badopt; + out_prims = stdprims; + break; + case 'X': /* XYZ output */ + if (strcmp(argv[i]+2, "XYZ")) + goto badopt; + out_prims = xyzprims; + break; + case 'c': { /* chromaticities */ + int j; + check(3,"ffffffff"); + rval = 0; + for (j = 0; j < 8; j++) { + our_prims[0][j] = atof(argv[++i]); + rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001; + } + if (rval) { + if (!colorprimsOK(our_prims)) + error(USER, "illegal primary chromaticities"); + out_prims = our_prims; + } else + out_prims = stdprims; + } break; default: goto badopt; } @@ -210,7 +258,7 @@ char *argv[]; #endif case 'w': /* warnings */ rval = erract[WARNING].pf != NULL; - bool(2,rval); + check_bool(2,rval); if (rval) erract[WARNING].pf = wputs; else erract[WARNING].pf = NULL; break; @@ -222,13 +270,24 @@ char *argv[]; goto badopt; } } + /* set/check spectral sampling */ + rval = setspectrsamp(CNDX, WLPART); + if (rval < 0) + error(USER, "unsupported spectral sampling"); + err = setview(&ourview); /* set viewing parameters */ if (err != NULL) error(USER, err); /* initialize object types */ initotypes(); /* initialize urand */ - initurand(2048); + if (rand_samp) { + srandom((long)time(0)); + initurand(0); + } else { + srandom(0L); + initurand(2048); + } /* set up signal handling */ sigdie(SIGINT, "Interrupt"); #ifdef SIGHUP @@ -281,11 +340,9 @@ char *argv[]; #endif if (outfile != NULL) openheader(); -#ifdef _WIN32 SET_FILE_BINARY(stdout); if (octname == NULL) SET_FILE_BINARY(stdin); -#endif readoct(octname, loadflags, &thescene, NULL); nsceneobjs = nobjects; @@ -293,14 +350,17 @@ char *argv[]; printargs(i, argv, stdout); printf("SOFTWARE= %s\n", VersionID); } + + ray_init_pmap(); /* PMAP: set up & load photon maps */ marksources(); /* find and mark sources */ setambient(); /* initialize ambient calculation */ + + fflush(stdout); /* in case we're duplicating header */ #ifdef PERSIST if (persist) { - fflush(stdout); if (outfile == NULL) { /* reconnect stdout */ dup2(duped1, fileno(stdout)); close(duped1); @@ -313,18 +373,20 @@ char *argv[]; pflock(1); pfhold(); tstart = time((time_t *)NULL); + ambsync(); /* load new values */ } if (rval < 0) error(SYSTEM, "cannot fork child for persist function"); - pfdetach(); /* parent exits */ + pfdetach(); /* parent will run then exit */ } } runagain: - if (persist) + if (persist) { if (outfile == NULL) /* if out to stdout */ dupheader(); /* send header */ else /* if out to file */ duped1 = dup(fileno(stdout)); /* hang onto pipe */ + } #endif /* batch render picture(s) */ rpict(seqstart, outfile, zfile, recover); @@ -350,20 +412,26 @@ runagain: goto runagain; } #endif + + + ray_done_pmap(); /* PMAP: free photon maps */ + quit(0); badopt: sprintf(errmsg, "command line error at '%s'", argv[i]); error(USER, errmsg); + return 1; /* pro forma return */ #undef check -#undef bool +#undef check_bool } void -wputs(s) /* warning output function */ -char *s; +wputs( /* warning output function */ + const char *s +) { int lasterrno = errno; eputs(s); @@ -372,8 +440,9 @@ char *s; void -eputs(s) /* put string to stderr */ -register char *s; +eputs( /* put string to stderr */ + const char *s +) { static int midline = 0; @@ -391,9 +460,10 @@ register char *s; } -void -onsig(signo) /* fatal signal */ -int signo; +static void +onsig( /* fatal signal */ + int signo +) { static int gotsig = 0; @@ -411,10 +481,11 @@ int signo; } -void -sigdie(signo, msg) /* set fatal signal */ -int signo; -char *msg; +static void +sigdie( /* set fatal signal */ + int signo, + char *msg +) { if (signal(signo, onsig) == SIG_IGN) signal(signo, SIG_IGN); @@ -422,17 +493,16 @@ char *msg; } -void -printdefaults() /* print default values to stdout */ +static void +printdefaults(void) /* print default values to stdout */ { - register char *cp; - printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, ourview.type==VT_PER ? "perspective" : ourview.type==VT_PAR ? "parallel" : ourview.type==VT_HEM ? "hemispherical" : ourview.type==VT_ANG ? "angular" : ourview.type==VT_CYL ? "cylindrical" : + ourview.type==VT_PLS ? "planisphere" : "unknown"); printf("-vp %f %f %f\t# view point\n", ourview.vp[0], ourview.vp[1], ourview.vp[2]); @@ -448,9 +518,20 @@ printdefaults() /* print default values to stdout */ printf("-vl %f\t\t\t# view lift\n", ourview.voff); printf("-x %-9d\t\t\t# x resolution\n", hresolu); printf("-y %-9d\t\t\t# y resolution\n", vresolu); + if (out_prims == stdprims) + printf("-pRGB\t\t\t\t# standard RGB color output\n"); + else if (out_prims == xyzprims) + printf("-pXYZ\t\t\t\t# CIE XYZ color output\n"); + else if (out_prims != NULL) + printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n", + out_prims[RED][0], out_prims[RED][1], + out_prims[GRN][0], out_prims[GRN][1], + out_prims[BLU][0], out_prims[BLU][1], + out_prims[WHT][0], out_prims[WHT][1]); printf("-pa %f\t\t\t# pixel aspect ratio\n", pixaspect); printf("-pj %f\t\t\t# pixel jitter\n", dstrpix); printf("-pm %f\t\t\t# pixel motion\n", mblur); + printf("-pd %f\t\t\t# pixel depth-of-field\n", dblur); printf("-ps %-9d\t\t\t# pixel sample\n", psample); printf("-pt %f\t\t\t# pixel threshold\n", maxdiff); printf("-t %-9d\t\t\t# time between reports\n", ralrm);