--- ray/src/rt/rpmain.c 2003/07/14 20:02:30 2.6 +++ ray/src/rt/rpmain.c 2024/10/30 16:47:03 2.35 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpmain.c,v 2.6 2003/07/14 20:02:30 schorsch Exp $"; +static const char RCSid[] = "$Id: rpmain.c,v 2.35 2024/10/30 16:47:03 greg Exp $"; #endif /* * rpmain.c - main for rpict batch rendering program @@ -7,7 +7,7 @@ static const char RCSid[] = "$Id: rpmain.c,v 2.6 2003/ #include "copyright.h" -#include +#include #include #include "platform.h" @@ -18,6 +18,7 @@ static const char RCSid[] = "$Id: rpmain.c,v 2.6 2003/ #include "random.h" #include "paths.h" #include "view.h" +#include "pmapray.h" /* persistent processes define */ #ifdef F_SETLKW @@ -27,13 +28,8 @@ static const char RCSid[] = "$Id: rpmain.c,v 2.6 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(); @@ -53,20 +49,42 @@ 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" \ + "OutputCS=RGB,XYZ,prims\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" \ + "OutputCS=RGB,XYZ,prims\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; \ @@ -80,13 +98,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 */ @@ -158,6 +180,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; } @@ -208,7 +259,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; @@ -220,13 +271,23 @@ char *argv[]; goto badopt; } } + /* set/check spectral sampling */ + if (setspectrsamp(CNDX, WLPART) <= 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 @@ -279,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; @@ -291,38 +350,41 @@ 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); } if (persist == PARALLEL) { /* multiprocessing */ - preload_objs(); /* preload scene */ - shm_boundary = (char *)malloc(16); - strcpy(shm_boundary, "SHM_BOUNDARY"); + cow_memshare(); /* preloads scene */ while ((rval=fork()) == 0) { /* keep on forkin' */ 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); @@ -348,30 +410,39 @@ 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; + if (erract[WARNING].pf == NULL) + return; /* called by calcomp or someone */ eputs(s); errno = lasterrno; } void -eputs(s) /* put string to stderr */ -register char *s; +eputs( /* put string to stderr */ + const char *s +) { static int midline = 0; @@ -389,9 +460,10 @@ register char *s; } -void -onsig(signo) /* fatal signal */ -int signo; +static void +onsig( /* fatal signal */ + int signo +) { static int gotsig = 0; @@ -409,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); @@ -420,8 +493,8 @@ char *msg; } -void -printdefaults() /* print default values to stdout */ +static void +printdefaults(void) /* print default values to stdout */ { printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, ourview.type==VT_PER ? "perspective" : @@ -429,6 +502,7 @@ printdefaults() /* print default values to stdout */ 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]); @@ -444,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);