ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/rt/rxcmain.cpp
(Generate patch)

Comparing ray/src/rt/rxcmain.cpp (file contents):
Revision 2.1 by greg, Tue Oct 29 00:36:54 2024 UTC vs.
Revision 2.19 by greg, Thu Oct 16 18:36:23 2025 UTC

# Line 21 | Line 21 | int    nproc = 1;                      /* number of processes requested */
21   int     inpfmt = 'a';                   /* input format */
22   int     outfmt = 'f';                   /* output format */
23  
24 int     contrib = 0;                    /* computing contributions? */
25
26 int     xres = 0;                       /* horizontal (scan) size */
27 int     yres = 0;                       /* vertical resolution */
28
29 int     imm_irrad = 0;                  /* compute immediate irradiance? */
30 int     lim_dist = 0;                   /* limit distance? */
31
24   int     report_intvl = 0;               /* reporting interval (seconds) */
25  
34 extern char *   progname;               // global argv[0]
35
26   RcontribSimulManager    myRCmanager;    // global rcontrib simulation manager
27  
28   #define RCONTRIB_FEATURES       "Multiprocessing\n" \
29                                  "Accumulation\nRecovery\n" \
30                                  "ImmediateIrradiance\n" \
31 <                                "ProgressReporting?\nDistanceLimiting\n" \
31 >                                "ProgressReporting\nDistanceLimiting\n" \
32                                  "InputFormats=a,f,d\nOutputFormats=f,d,c\n" \
33                                  "Outputs=V,W\n" \
34                                  "OutputCS=RGB,spec\n"
# Line 49 | Line 39 | static void
39   printdefaults(void)                     /* print default values to stdout */
40   {
41          printf("-c %-5d\t\t\t# accumulated rays per record\n", myRCmanager.accum);
42 <        printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-',
43 <                        contrib ? "contributions" : "coefficients");
44 <        if (imm_irrad)
42 >        printf(myRCmanager.HasFlag(RCcontrib) ?
43 >                        "-V+\t\t\t\t# output contributions\n" :
44 >                        "-V-\t\t\t\t# output coefficients\n");
45 >        if (myRCmanager.HasFlag(RTimmIrrad))
46                  printf("-I+\t\t\t\t# immediate irradiance on\n");
47          printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc);
48 <        if (xres > 0)
49 <                printf("-x %-9d\t\t\t# x resolution\n", xres);
50 <        printf("-y %-9d\t\t\t# y resolution\n", yres);
51 <        printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" :
48 >        printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres);
49 >        printf("-y %-9d\t\t\t# y resolution\n", myRCmanager.yres);
50 >        printf(myRCmanager.HasFlag(RTlimDist) ?
51 >                        "-ld+\t\t\t\t# limit distance on\n" :
52                          "-ld-\t\t\t\t# limit distance off\n");
53          printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n",
54                          inpfmt, outfmt, formstr(inpfmt), formstr(outfmt));
55          if (report_intvl > 0)
56 <                printf("-t %-9d\t\t\t#  time between reports\n", report_intvl);
56 >                printf("-t %-9d\t\t\t# time between reports\n", report_intvl);
57          printf(erract[WARNING].pf != NULL ?
58                          "-w+\t\t\t\t# warning messages on\n" :
59                          "-w-\t\t\t\t# warning messages off\n");
# Line 81 | Line 72 | onsig(                         /* fatal signal */
72                  _exit(signo);
73  
74   #ifdef SIGALRM
75 <        alarm(15);                      /* allow 15 seconds to clean up */
75 >        alarm(600);                     /* allow 10 minutes to clean up */
76          signal(SIGALRM, SIG_DFL);       /* make certain we do die */
77   #endif
78          eputs("signal - ");
# Line 102 | Line 93 | sigdie(                        /* set fatal signal */
93          sigerr[signo] = msg;
94   }
95  
105 const char *
106 formstr(int f)                          // return format identifier
107 {
108        switch (f) {
109        case 'a': return("ascii");
110        case 'f': return("float");
111        case 'd': return("double");
112        case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT);
113        }
114        return("unknown");
115 }
116
96   /* set input/output format */
97   static void
98   setformat(const char *fmt)
# Line 150 | Line 129 | fmterr:
129          error(USER, errmsg);
130   }
131  
132 + /* Set default options */
133 + static void
134 + default_options(void)
135 + {
136 +        rand_samp = 1;
137 +        dstrsrc = 0.9;
138 +        directrelay = 3;
139 +        vspretest = 512;
140 +        srcsizerat = .2;
141 +        specthresh = .02;
142 +        specjitter = 1.;
143 +        maxdepth = -10;
144 +        minweight = 2e-3;
145 +        ambres = 256;
146 +        ambdiv = 350;
147 +        ambounce = 1;
148 + }
149  
150   /* Set overriding options */
151   static void
# Line 160 | Line 156 | override_options(void)
156          ambacc = 0;
157   }
158  
163
159   int
160   main(int argc, char *argv[])
161   {
# Line 191 | Line 186 | main(int argc, char *argv[])
186                                          /* initialize calcomp routines early */
187          initfunc();
188          calcontext(RCCONTEXT);
189 +                                        /* set rcontrib defaults */
190 +        default_options();
191                                          /* option city */
192          for (i = 1; i < argc; i++) {
193                                                  /* expand arguments */
# Line 218 | Line 215 | main(int argc, char *argv[])
215                          continue;
216                  }
217                  switch (argv[i][1]) {
218 <                case 'n':                       /* number of cores */
218 >                case 'n':                       /* number of processes */
219                          check(2,"i");
220                          nproc = atoi(argv[++i]);
221                          if (nproc < 0 && (nproc += RadSimulManager::GetNCores()) <= 0)
222                                  nproc = 1;
223                          break;
224 <                case 'V':                       /* output contributions */
225 <                        check_bool(2,contrib);
224 >                case 'V':                       /* output contributions? */
225 >                        rval = myRCmanager.HasFlag(RCcontrib);
226 >                        check_bool(2,rval);
227 >                        myRCmanager.SetFlag(RCcontrib, rval);
228                          break;
229                  case 'x':                       /* x resolution */
230                          check(2,"i");
231 <                        xres = atoi(argv[++i]);
231 >                        myRCmanager.xres = atoi(argv[++i]);
232                          break;
233                  case 'y':                       /* y resolution */
234                          check(2,"i");
235 <                        yres = atoi(argv[++i]);
235 >                        myRCmanager.yres = atoi(argv[++i]);
236                          break;
237 <                case 'w':                       /* warnings */
237 >                case 'w':                       /* warnings on/off */
238                          rval = (erract[WARNING].pf != NULL);
239                          check_bool(2,rval);
240                          if (rval) erract[WARNING].pf = wputs;
241                          else erract[WARNING].pf = NULL;
242                          break;
244                case 'e':                       /* expression */
245                        check(2,"s");
246                        scompile(argv[++i], NULL, 0);
247                        break;
243                  case 'l':                       /* limit distance */
244                          if (argv[i][2] != 'd')
245                                  goto badopt;
246 <                        check_bool(3,lim_dist);
246 >                        rval = myRCmanager.HasFlag(RTlimDist);
247 >                        check_bool(3,rval);
248 >                        myRCmanager.SetFlag(RTlimDist, rval);
249                          break;
250                  case 'I':                       /* immed. irradiance */
251 <                        check_bool(2,imm_irrad);
251 >                        rval = myRCmanager.HasFlag(RTimmIrrad);
252 >                        check_bool(2,rval);
253 >                        myRCmanager.SetFlag(RTimmIrrad, rval);
254                          break;
255 <                case 'f':                       /* file or force or format */
257 <                        if (!argv[i][2]) {
258 <                                check(2,"s");
259 <                                loadfunc(argv[++i]);
260 <                                break;
261 <                        }
255 >                case 'f':                       /* force or format */
256                          if (argv[i][2] == 'o') {
257                                  check_bool(3,force_open);
258                                  break;
# Line 266 | Line 260 | main(int argc, char *argv[])
260                          setformat(argv[i]+2);
261                          myRCmanager.SetDataFormat(outfmt);
262                          break;
263 <                case 'o':                       /* output */
263 >                case 'o':                       /* output file */
264                          check(2,"s");
265                          curout = argv[++i];
266                          break;
# Line 294 | Line 288 | main(int argc, char *argv[])
288                          check(2,"s");
289                          myRCmanager.AddModifier(argv[++i], curout, prms, binval, bincnt);
290                          break;
291 <                case 'M':                       /* modifier file */
291 >                case 'M':                       /* file of modifier names */
292                          check(2,"s");
293                          myRCmanager.AddModFile(argv[++i], curout, prms, binval, bincnt);
294                          break;
# Line 308 | Line 302 | main(int argc, char *argv[])
302          }
303          if (i != argc-1)
304                  error(USER, "expected single octree argument");
305 +
306 +        override_options();             /* override some option settings */
307 +
308 +        if (!myRCmanager.GetOutput())   // check that we have work to do
309 +                error(USER, "missing required modifier argument");
310                                          // get ready to rock...
311          if (setspectrsamp(CNDX, WLPART) < 0)
312                  error(USER, "unsupported spectral sampling");
314
315        if (!myRCmanager.GetOutputs(NULL))      // check that we're ready
316                error(USER, "missing required modifier argument");
317                                        /* override some option settings */
318        override_options();
313                                          /* set up signal handling */
314          sigdie(SIGINT, "Interrupt");
315   #ifdef SIGHUP
# Line 339 | Line 333 | main(int argc, char *argv[])
333          myRCmanager.LoadOctree(argv[argc-1]);
334                                          // add to header
335          myRCmanager.AddHeader(argc-1, argv);
336 +        {
337 +                char    buf[128] = "SOFTWARE= ";
338 +                strcpy(buf+10, VersionID);
339 +                myRCmanager.AddHeader(buf);
340 +        }
341                                          // prepare output files
342          if (recover)
343                  myRCmanager.outOp = RCOrecover;
# Line 348 | Line 347 | main(int argc, char *argv[])
347                  myRCmanager.outOp = RCOnew;
348                                          // rval = # rows recovered
349          rval = myRCmanager.PrepOutput();
350 <                                        // check if all done
351 <        if (recover && rval >= myRCmanager.GetRowMax()) {
350 >
351 >        if (rval < 0)                   // PrepOutput() failure?
352 >                error(USER, "issue loading or creating output(s)");
353 >                                        // in case we recovered everything
354 >        if (rval >= myRCmanager.GetRowMax())
355                  error(WARNING, "nothing left to compute");
356 <                quit(0);
357 <        }                               // add processes as requested
356 <        myRCmanager.SetThreadCount(nproc);
356 >        else
357 >                rxcontrib(rval);        // trace ray contributions (loop)
358  
359 <        rxcontrib(rval);                /* trace ray contributions (loop) */
359 >        quit(0);        // exit clean
360  
360        quit(0);        /* exit clean */
361
361   badopt:
362          fprintf(stderr,
363   "Usage: %s [-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",
# Line 409 | Line 408 | getRayBundle(FVECT *orig_dir = NULL)
408          int     n2go = myRCmanager.accum;
409  
410          switch (inpfmt) {
411 <        case 'a':                               // ASCII input
411 >        case 'a':                       // ASCII input
412                  if (!orig_dir)
413                          return skipWords(6*n2go);
414                  while (n2go-- > 0) {
# Line 422 | Line 421 | getRayBundle(FVECT *orig_dir = NULL)
421                          orig_dir += 2;
422                  }
423                  break;
424 <        case 'f':                               // float input
424 >        case 'f':                       // float input
425                  if (!orig_dir)
426                          return skipBytes(6*sizeof(float)*n2go);
427   #ifdef SMLFLT
428                  if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go)
429                          return false;
430 +                orig_dir += 2*n2go;
431   #else
432                  while (n2go-- > 0) {
433                          float   fvecs[6];
# Line 439 | Line 439 | getRayBundle(FVECT *orig_dir = NULL)
439                  }
440   #endif
441                  break;
442 <        case 'd':                               // double input
442 >        case 'd':                       // double input
443                  if (!orig_dir)
444                          return skipBytes(6*sizeof(double)*n2go);
445   #ifndef SMLFLT
446                  if (getbinary(orig_dir, sizeof(FVECT), 2*n2go, stdin) != 2*n2go)
447                          return false;
448 +                orig_dir += 2*n2go;
449   #else
450                  while (n2go-- > 0) {
451                          double  dvecs[6];
# Line 460 | Line 461 | getRayBundle(FVECT *orig_dir = NULL)
461                  error(INTERNAL, "unsupported format in getRayBundle()");
462                  return false;
463          }
464 <        int     warned = 0;             // normalize directions
464 <        n2go = myRCmanager.accum;
464 >        n2go = myRCmanager.accum;       // normalize directions
465          while (n2go-- > 0) {
466                  orig_dir -= 2;
467 <                if (normalize(orig_dir[1]) == 0)
468 <                        if (!warned++)
469 <                                error(WARNING, "zero ray direction on input");
467 >                normalize(orig_dir[1]);
468          }
469          return true;
470   }
# Line 494 | Line 492 | rxcontrib(const int rstart)
492                  }
493                  last_report = tstart = time(0);
494          }
495 <        while (r < totRows) {           // getting to work...
495 >                                        // start children as requested
496 >        myRCmanager.SetThreadCount(nproc);
497 >
498 >        while (r < totRows) {           // loop until done
499                  time_t  tnow;
500                  if (!getRayBundle(odarr))
501                          goto readerr;
502 <                if (myRCmanager.ComputeRecord(odarr) < 0)
502 >                if (myRCmanager.ComputeRecord(odarr) <= 0)
503                          return;         // error reported, hopefully...
504                  r++;
505                  if (report_intvl <= 0)
506                          continue;
507 <                if ((r < totRows) & ((tnow = time(0)) < last_report+report_intvl))
507 >                if (r == totRows)       // need to finish up?
508 >                        myRCmanager.SetThreadCount(1);
509 >                tnow = time(0);
510 >                if ((r < totRows) & (tnow < last_report+report_intvl))
511                          continue;
512                  sprintf(errmsg, "%.2f%% done after %.3f hours\n",
513 <                                100.*r/totRows, (1./3600.)*(tnow - tstart));
513 >                                100.*myRCmanager.GetRowFinished()/totRows,
514 >                                (1./3600.)*(tnow - tstart));
515                  eputs(errmsg);
516                  last_report = tnow;
517          }
# Line 524 | Line 529 | wputs(                         /* warning output function */
529          const char      *s
530   )
531   {
532 +        if (!erract[WARNING].pf) return;
533          int  lasterrno = errno;
534          eputs(s);
535          errno = lasterrno;
# Line 551 | Line 557 | eputs(                         /* put string to stderr */
557   }
558  
559  
560 < /* Quit program */
560 > /* Exit program */
561   void
562   quit(
563          int  code
564   )
565   {
566 <        if (!code && myRCmanager.Ready())       // clean up on normal exit
561 <                code = myRCmanager.Cleanup();
566 >        myRCmanager.FlushQueue();       // leave nothing in queue
567  
568          exit(code);
569   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)