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.7 by greg, Thu Nov 7 18:09:39 2024 UTC vs.
Revision 2.19 by greg, Thu Oct 16 18:36:23 2025 UTC

# Line 23 | Line 23 | int    outfmt = 'f';                   /* output format */
23  
24   int     report_intvl = 0;               /* reporting interval (seconds) */
25  
26 extern char *   progname;               // global argv[0]
27
26   RcontribSimulManager    myRCmanager;    // global rcontrib simulation manager
27  
28   #define RCONTRIB_FEATURES       "Multiprocessing\n" \
# Line 47 | Line 45 | printdefaults(void)                    /* print default values to stdou
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 (myRCmanager.xres > 0)
51 <                printf("-x %-9d\t\t\t# x resolution\n", myRCmanager.xres);
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" :
# Line 56 | Line 53 | printdefaults(void)                    /* print default values to stdou
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 75 | Line 72 | onsig(                         /* fatal signal */
72                  _exit(signo);
73  
74   #ifdef SIGALRM
75 <        alarm(180);                     /* allow 3 minutes 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 96 | Line 93 | sigdie(                        /* set fatal signal */
93          sigerr[signo] = msg;
94   }
95  
99 const char *
100 formstr(int f)                          // return format identifier
101 {
102        switch (f) {
103        case 'a': return("ascii");
104        case 'f': return("float");
105        case 'd': return("double");
106        case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT);
107        }
108        return("unknown");
109 }
110
96   /* set input/output format */
97   static void
98   setformat(const char *fmt)
# Line 144 | 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 154 | Line 156 | override_options(void)
156          ambacc = 0;
157   }
158  
157
159   int
160   main(int argc, char *argv[])
161   {
# Line 185 | 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 237 | Line 240 | main(int argc, char *argv[])
240                          if (rval) erract[WARNING].pf = wputs;
241                          else erract[WARNING].pf = NULL;
242                          break;
240                case 'e':                       /* .cal expression */
241                        check(2,"s");
242                        scompile(argv[++i], NULL, 0);
243                        break;
243                  case 'l':                       /* limit distance */
244                          if (argv[i][2] != 'd')
245                                  goto badopt;
# Line 253 | Line 252 | main(int argc, char *argv[])
252                          check_bool(2,rval);
253                          myRCmanager.SetFlag(RTimmIrrad, rval);
254                          break;
255 <                case 'f':                       /* .cal 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 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 recovered everything
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;
# Line 503 | Line 504 | rxcontrib(const int rstart)
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 558 | Line 563 | quit(
563          int  code
564   )
565   {
566 <        if (!code && myRCmanager.Ready())       // clean up on normal exit
562 <                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)