--- ray/src/rt/rcmain.c 2013/08/07 05:10:09 2.10 +++ ray/src/rt/rcmain.c 2024/04/05 16:41:17 2.36 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcmain.c,v 2.10 2013/08/07 05:10:09 greg Exp $"; +static const char RCSid[] = "$Id: rcmain.c,v 2.36 2024/04/05 16:41:17 greg Exp $"; #endif /* * rcmain.c - main for rtcontrib ray contribution tracer @@ -13,6 +13,8 @@ static const char RCSid[] = "$Id: rcmain.c,v 2.10 2013 #include "random.h" #include "source.h" #include "ambient.h" +#include "pmapray.h" +#include "pmapcontrib.h" int gargc; /* global argc */ char **gargv; /* global argv */ @@ -41,13 +43,32 @@ int using_stdout = 0; /* are we using stdout? */ int imm_irrad = 0; /* compute immediate irradiance? */ int lim_dist = 0; /* limit distance? */ -const char *modname[MAXMODLIST]; /* ordered modifier name list */ -int nmods = 0; /* number of modifiers */ +int report_intvl = 0; /* reporting interval (seconds) */ +char **modname = NULL; /* ordered modifier name list */ +int nmods = 0; /* number of modifiers */ +int modasiz = 0; /* allocated modifier array size */ + void (*addobjnotify[8])() = {ambnotify, NULL}; -char RCCONTEXT[] = "RC"; /* our special evaluation context */ +char RCCONTEXT[] = "RC."; /* our special evaluation context */ +#if defined(_WIN32) || defined(_WIN64) +#define RCONTRIB_FEATURES "Accumulation\nSummation\nRecovery\n" \ + "ImmediateIrradiance\n" \ + "ProgressReporting\nDistanceLimiting\n" \ + "InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ + "Outputs=V,W\n" \ + "OutputCS=RGB,spec\n" +#else +#define RCONTRIB_FEATURES "Multiprocessing\n" \ + "Accumulation\nSummation\nRecovery\n" \ + "ImmediateIrradiance\n" \ + "ProgressReporting\nDistanceLimiting\n" \ + "InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ + "Outputs=V,W\n" \ + "OutputCS=RGB,spec\n" +#endif static void printdefaults(void) /* print default values to stdout */ @@ -63,8 +84,8 @@ printdefaults(void) /* print default values to stdou printf("-y %-9d\t\t\t# y resolution\n", yres); printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : "-ld-\t\t\t\t# limit distance off\n"); - printf("-h%c\t\t\t\t# %s header\n", header ? '+' : '-', - header ? "output" : "no"); + printf(header ? "-h+\t\t\t\t# output header\n" : + "-h-\t\t\t\t# no header\n"); printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", inpfmt, outfmt, formstr(inpfmt), formstr(outfmt)); printf(erract[WARNING].pf != NULL ? @@ -161,7 +182,7 @@ 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; \ @@ -169,6 +190,7 @@ main(int argc, char *argv[]) case '-': case '0': var = 0; break; \ default: goto badopt; } char *curout = NULL; + char *prms = NULL; char *binval = NULL; int bincnt = 0; int rval; @@ -177,9 +199,18 @@ main(int argc, char *argv[]) progname = argv[0] = fixargv0(argv[0]); gargv = argv; gargc = argc; + /* feature check only? */ + strcat(RFeatureList, RCONTRIB_FEATURES); + if (argc > 1 && !strcmp(argv[1], "-features")) + return feature_status(argc-2, argv+2); +#if defined(_WIN32) || defined(_WIN64) /* increase file limit to maximum */ + for (i = 8192; i > _IOB_ENTRIES; i >>= 1) + if (_setmaxstdio(i) == i) + break; +#endif /* initialize calcomp routines early */ initfunc(); - setcontext(RCCONTEXT); + calcontext(RCCONTEXT); /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ @@ -214,7 +245,7 @@ main(int argc, char *argv[]) error(USER, "bad number of processes"); break; case 'V': /* output contributions */ - bool(2,contrib); + check_bool(2,contrib); break; case 'x': /* x resolution */ check(2,"i"); @@ -226,7 +257,7 @@ main(int argc, char *argv[]) break; 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; @@ -237,10 +268,10 @@ main(int argc, char *argv[]) case 'l': /* limit distance */ if (argv[i][2] != 'd') goto badopt; - bool(3,lim_dist); + check_bool(3,lim_dist); break; case 'I': /* immed. irradiance */ - bool(2,imm_irrad); + check_bool(2,imm_irrad); break; case 'f': /* file or force or format */ if (!argv[i][2]) { @@ -249,7 +280,7 @@ main(int argc, char *argv[]) break; } if (argv[i][2] == 'o') { - bool(3,force_open); + check_bool(3,force_open); break; } setformat(argv[i]+2); @@ -258,16 +289,20 @@ main(int argc, char *argv[]) check(2,"s"); curout = argv[++i]; break; - case 'c': /* input rays per output */ - check(2,"i"); - accumulate = atoi(argv[++i]); - break; case 'r': /* recover output */ - bool(2,recover); + check_bool(2,recover); break; case 'h': /* header output */ - bool(2,header); + check_bool(2,header); break; + case 'p': /* parameter setting(s) */ + check(2,"s"); + set_eparams(prms = argv[++i]); + break; + case 'c': /* sample count */ + check(2,"i"); + accumulate = atoi(argv[++i]); + break; case 'b': /* bin expression/count */ if (argv[i][2] == 'n') { check(3,"s"); @@ -279,18 +314,27 @@ main(int argc, char *argv[]) break; case 'm': /* modifier name */ check(2,"s"); - addmodifier(argv[++i], curout, binval, bincnt); + addmodifier(argv[++i], curout, prms, binval, bincnt); break; case 'M': /* modifier file */ check(2,"s"); - addmodfile(argv[++i], curout, binval, bincnt); + addmodfile(argv[++i], curout, prms, binval, bincnt); break; + case 't': /* reporting interval */ + check(2,"i"); + report_intvl = atoi(argv[++i]); + break; default: goto badopt; } } + if (nmods <= 0) + error(USER, "missing required modifier argument"); /* override some option settings */ override_options(); + /* set/check spectral sampling */ + if (setspectrsamp(CNDX, WLPART) < 0) + error(USER, "unsupported spectral sampling"); /* initialize object types */ initotypes(); /* initialize urand */ @@ -333,32 +377,41 @@ main(int argc, char *argv[]) readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); nsceneobjs = nobjects; + /* PMAP: set up & load photon maps */ + ray_init_pmap(); + marksources(); /* find and mark sources */ + + /* PMAP: init photon map for light source contributions */ + initPmapContrib(&modconttab, nmods); setambient(); /* initialize ambient calculation */ - + rcontrib(); /* trace ray contributions (loop) */ ambsync(); /* flush ambient file */ + /* PMAP: free photon maps */ + ray_done_pmap(); + quit(0); /* exit clean */ badopt: fprintf(stderr, -"Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", +"Usage: %s [-n nprocs][-V][-c count][-r][-e expr][-f source][-o ospec][-p p1=V1,p2=V2][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", progname); 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( /* warning output function */ - char *s + const char *s ) { int lasterrno = errno; @@ -369,7 +422,7 @@ wputs( /* warning output function */ void eputs( /* put string to stderr */ - char *s + const char *s ) { static int midline = 0;