--- ray/src/rt/rxcmain.cpp 2024/11/06 19:45:59 2.6 +++ ray/src/rt/rxcmain.cpp 2025/03/05 17:29:57 2.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rxcmain.cpp,v 2.6 2024/11/06 19:45:59 greg Exp $"; +static const char RCSid[] = "$Id: rxcmain.cpp,v 2.16 2025/03/05 17:29:57 greg Exp $"; #endif /* * rxcmain.c - main for rxcontrib ray contribution tracer @@ -42,13 +42,12 @@ printdefaults(void) /* print default values to stdou { printf("-c %-5d\t\t\t# accumulated rays per record\n", myRCmanager.accum); printf(myRCmanager.HasFlag(RCcontrib) ? - "-V+\t\t\t\t# output contributions" : - "-V-\t\t\t\t# output coefficients"); + "-V+\t\t\t\t# output contributions\n" : + "-V-\t\t\t\t# output coefficients\n"); if (myRCmanager.HasFlag(RTimmIrrad)) printf("-I+\t\t\t\t# immediate irradiance on\n"); printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); - if (myRCmanager.xres > 0) - printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres); + printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres); printf("-y %-9d\t\t\t# y resolution\n", myRCmanager.yres); printf(myRCmanager.HasFlag(RTlimDist) ? "-ld+\t\t\t\t# limit distance on\n" : @@ -56,7 +55,7 @@ printdefaults(void) /* print default values to stdou printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", inpfmt, outfmt, formstr(inpfmt), formstr(outfmt)); if (report_intvl > 0) - printf("-t %-9d\t\t\t# time between reports\n", report_intvl); + printf("-t %-9d\t\t\t# time between reports\n", report_intvl); printf(erract[WARNING].pf != NULL ? "-w+\t\t\t\t# warning messages on\n" : "-w-\t\t\t\t# warning messages off\n"); @@ -75,7 +74,7 @@ onsig( /* fatal signal */ _exit(signo); #ifdef SIGALRM - alarm(180); /* allow 3 minutes to clean up */ + alarm(600); /* allow 10 minutes to clean up */ signal(SIGALRM, SIG_DFL); /* make certain we do die */ #endif eputs("signal - "); @@ -96,18 +95,6 @@ sigdie( /* set fatal signal */ sigerr[signo] = msg; } -const char * -formstr(int f) // return format identifier -{ - switch (f) { - case 'a': return("ascii"); - case 'f': return("float"); - case 'd': return("double"); - case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); - } - return("unknown"); -} - /* set input/output format */ static void setformat(const char *fmt) @@ -144,6 +131,23 @@ fmterr: error(USER, errmsg); } +/* Set default options */ +static void +default_options(void) +{ + rand_samp = 1; + dstrsrc = 0.9; + directrelay = 3; + vspretest = 512; + srcsizerat = .2; + specthresh = .02; + specjitter = 1.; + maxdepth = -10; + minweight = 2e-3; + ambres = 256; + ambdiv = 350; + ambounce = 1; +} /* Set overriding options */ static void @@ -154,7 +158,6 @@ override_options(void) ambacc = 0; } - int main(int argc, char *argv[]) { @@ -185,6 +188,8 @@ main(int argc, char *argv[]) /* initialize calcomp routines early */ initfunc(); calcontext(RCCONTEXT); + /* set rcontrib defaults */ + default_options(); /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ @@ -339,6 +344,11 @@ main(int argc, char *argv[]) myRCmanager.LoadOctree(argv[argc-1]); // add to header myRCmanager.AddHeader(argc-1, argv); + { + char buf[128] = "SOFTWARE= "; + strcpy(buf+10, VersionID); + myRCmanager.AddHeader(buf); + } // prepare output files if (recover) myRCmanager.outOp = RCOrecover; @@ -349,12 +359,10 @@ main(int argc, char *argv[]) // rval = # rows recovered rval = myRCmanager.PrepOutput(); // check if recovered everything - if (recover && rval >= myRCmanager.GetRowMax()) { + if (rval >= myRCmanager.GetRowMax()) { error(WARNING, "nothing left to compute"); quit(0); - } // add processes as requested - myRCmanager.SetThreadCount(nproc); - + } rxcontrib(rval); /* trace ray contributions (loop) */ quit(0); /* exit clean */ @@ -409,7 +417,7 @@ getRayBundle(FVECT *orig_dir = NULL) int n2go = myRCmanager.accum; switch (inpfmt) { - case 'a': // ASCII input + case 'a': // ASCII input if (!orig_dir) return skipWords(6*n2go); while (n2go-- > 0) { @@ -422,12 +430,13 @@ getRayBundle(FVECT *orig_dir = NULL) orig_dir += 2; } break; - case 'f': // float input + case 'f': // float input if (!orig_dir) return skipBytes(6*sizeof(float)*n2go); #ifdef SMLFLT if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) return false; + orig_dir += 2*n2go; #else while (n2go-- > 0) { float fvecs[6]; @@ -439,12 +448,13 @@ getRayBundle(FVECT *orig_dir = NULL) } #endif break; - case 'd': // double input + case 'd': // double input if (!orig_dir) return skipBytes(6*sizeof(double)*n2go); #ifndef SMLFLT if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go) return false; + orig_dir += 2*n2go; #else while (n2go-- > 0) { double dvecs[6]; @@ -460,13 +470,10 @@ getRayBundle(FVECT *orig_dir = NULL) error(INTERNAL, "unsupported format in getRayBundle()"); return false; } - int warned = 0; // normalize directions - n2go = myRCmanager.accum; + n2go = myRCmanager.accum; // normalize directions while (n2go-- > 0) { orig_dir -= 2; - if (normalize(orig_dir[1]) == 0) - if (!warned++) - error(WARNING, "zero ray direction on input"); + normalize(orig_dir[1]); } return true; } @@ -494,7 +501,10 @@ rxcontrib(const int rstart) } last_report = tstart = time(0); } - while (r < totRows) { // getting to work... + // start children as requested + myRCmanager.SetThreadCount(nproc); + + while (r < totRows) { // loop until done time_t tnow; if (!getRayBundle(odarr)) goto readerr; @@ -503,10 +513,14 @@ rxcontrib(const int rstart) r++; if (report_intvl <= 0) continue; - if ((r < totRows) & ((tnow = time(0)) < last_report+report_intvl)) + if (r == totRows) // need to finish up? + myRCmanager.SetThreadCount(1); + tnow = time(0); + if ((r < totRows) & (tnow < last_report+report_intvl)) continue; sprintf(errmsg, "%.2f%% done after %.3f hours\n", - 100.*r/totRows, (1./3600.)*(tnow - tstart)); + 100.*myRCmanager.GetRowFinished()/totRows, + (1./3600.)*(tnow - tstart)); eputs(errmsg); last_report = tnow; } @@ -558,8 +572,7 @@ quit( int code ) { - if (!code && myRCmanager.Ready()) // clean up on normal exit - code = myRCmanager.Cleanup(); + myRCmanager.FlushQueue(); // leave nothing in queue exit(code); }