--- ray/src/rt/rtmain.c 2009/12/12 19:01:00 2.18 +++ ray/src/rt/rtmain.c 2022/10/18 18:07:50 2.37 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtmain.c,v 2.18 2009/12/12 19:01:00 greg Exp $"; +static const char RCSid[] = "$Id: rtmain.c,v 2.37 2022/10/18 18:07:50 greg Exp $"; #endif /* * rtmain.c - main for rtrace per-ray calculation program @@ -17,6 +17,7 @@ static const char RCSid[] = "$Id: rtmain.c,v 2.18 2009 #include "ambient.h" #include "random.h" #include "paths.h" +#include "pmapray.h" extern char *progname; /* global argv[0] */ @@ -34,7 +35,9 @@ char *errfile = NULL; /* error output file */ int nproc = 1; /* number of processes */ -extern char *formstr(); /* string from format */ +extern char *formstr(int f); /* string from format */ +extern int setrtoutput(void); /* set output values */ + int inform = 'a'; /* input format */ int outform = 'a'; /* output format */ char *outvals = "v"; /* output specification */ @@ -42,6 +45,8 @@ char *outvals = "v"; /* output specification */ int hresolu = 0; /* horizontal (scan) size */ int vresolu = 0; /* vertical resolution */ +extern int castonly; /* only doing ray-casting? */ + int imm_irrad = 0; /* compute immediate irradiance? */ int lim_dist = 0; /* limit distance? */ @@ -68,17 +73,18 @@ 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; \ case 'n': case 'N': case 'f': case 'F': \ case '-': case '0': var = 0; break; \ default: goto badopt; } + extern char *octname; int persist = 0; char *octnm = NULL; - char **tralp; - int duped1; + char **tralp = NULL; + int duped1 = -1; int rval; int i; /* global program name */ @@ -87,9 +93,6 @@ main(int argc, char *argv[]) for (i = 0; addobjnotify[i] != NULL; i++) ; addobjnotify[i] = tranotify; - /* set our defaults */ - maxdepth = -10; - minweight = 2e-3; /* option city */ for (i = 1; i < argc; i++) { /* expand arguments */ @@ -132,7 +135,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; @@ -143,10 +146,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': /* format i/o */ switch (argv[i][2]) { @@ -178,7 +181,7 @@ main(int argc, char *argv[]) break; case 'h': /* header output */ rval = loadflags & IO_INFO; - bool(2,rval); + check_bool(2,rval); loadflags = rval ? loadflags | IO_INFO : loadflags & ~IO_INFO; break; @@ -192,7 +195,7 @@ main(int argc, char *argv[]) tralp = tralist; } if (argv[i][2] == 'I') { /* file */ - rval = wordfile(tralp, + rval = wordfile(tralp, MAXMODLIST-(tralp-tralist), getpath(argv[++i],getrlibpath(),R_OK)); if (rval < 0) { sprintf(errmsg, @@ -214,7 +217,7 @@ main(int argc, char *argv[]) tralp = tralist; } if (argv[i][2] == 'E') { /* file */ - rval = wordfile(tralp, + rval = wordfile(tralp, MAXMODLIST-(tralp-tralist), getpath(argv[++i],getrlibpath(),R_OK)); if (rval < 0) { sprintf(errmsg, @@ -248,16 +251,8 @@ main(int argc, char *argv[]) goto badopt; } } - if (nproc > 1) { - if (persist) - error(USER, "multiprocessing incompatible with persist file"); - if (imm_irrad) - error(USER, "multiprocessing incompatible with immediate irradiance"); - if (hresolu > 0 && hresolu < nproc) - error(WARNING, "number of cores should not exceed horizontal resolution"); - if (trace != NULL) - error(WARNING, "multiprocessing does not work properly with trace mode"); - } + if (nproc > 1 && persist) + error(USER, "multiprocessing incompatible with persist file"); /* initialize object types */ initotypes(); /* initialize urand */ @@ -315,24 +310,36 @@ main(int argc, char *argv[]) #endif if (outform != 'a') SET_FILE_BINARY(stdout); - readoct(octnm, loadflags, &thescene, NULL); + rval = setrtoutput(); + readoct(octname = octnm, loadflags, &thescene, NULL); nsceneobjs = nobjects; if (loadflags & IO_INFO) { /* print header */ printargs(i, argv, stdout); printf("SOFTWARE= %s\n", VersionID); fputnow(stdout); + if (rval > 0) /* saved from setrtoutput() call */ + printf("NCOMP=%d\n", rval); + if ((outform == 'f') | (outform == 'd')) + fputendian(stdout); fputformat(formstr(outform), stdout); putchar('\n'); } - marksources(); /* find and mark sources */ + if (!castonly) { /* any actual ray traversal to do? */ - setambient(); /* initialize ambient calculation */ + ray_init_pmap(); /* PMAP: set up & load photon maps */ + + marksources(); /* find and mark sources */ + setambient(); /* initialize ambient calculation */ + } else + distantsources(); /* else mark only distant sources */ + + fflush(stdout); /* in case we're duplicating header */ + #ifdef PERSIST if (persist) { - fflush(stdout); /* reconnect stdout */ dup2(duped1, fileno(stdout)); close(duped1); @@ -354,10 +361,8 @@ runagain: if (persist) dupheader(); /* send header to stdout */ #endif - if (nproc > 1) /* start multiprocessing */ - ray_popen(nproc); /* trace rays */ - rtrace(NULL); + rtrace(NULL, nproc); /* flush ambient file */ ambsync(); #ifdef PERSIST @@ -377,6 +382,9 @@ runagain: goto runagain; } #endif + + ray_done_pmap(); /* PMAP: free photon maps */ + quit(0); badopt: @@ -385,7 +393,7 @@ badopt: return 1; /* pro forma return */ #undef check -#undef bool +#undef check_bool } @@ -462,7 +470,8 @@ printdefaults(void) /* print default values to stdou if (imm_irrad) printf("-I+\t\t\t\t# immediate irradiance on\n"); printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); - printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu); + printf("-x %-9d\t\t\t# %s\n", hresolu, + vresolu && hresolu ? "x resolution" : "flush interval"); printf("-y %-9d\t\t\t# y resolution\n", vresolu); printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : "-ld-\t\t\t\t# limit distance off\n"); @@ -476,6 +485,10 @@ printdefaults(void) /* print default values to stdou case 't': case 'T': printf(" trace"); break; case 'o': printf(" origin"); break; case 'd': printf(" direction"); break; + case 'r': printf(" reflect_contrib"); break; + case 'R': printf(" reflect_length"); break; + case 'x': printf(" unreflect_contrib"); break; + case 'X': printf(" unreflect_length"); break; case 'v': printf(" value"); break; case 'V': printf(" contribution"); break; case 'l': printf(" length"); break; @@ -488,7 +501,7 @@ printdefaults(void) /* print default values to stdou case 'W': printf(" coefficient"); break; case 'm': printf(" modifier"); break; case 'M': printf(" material"); break; - case '-': printf(" stroke"); break; + case '~': printf(" tilde"); break; } putchar('\n'); printf(erract[WARNING].pf != NULL ?