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

Comparing ray/src/rt/rxfluxmtx.cpp (file contents):
Revision 2.1 by greg, Wed Oct 22 02:38:27 2025 UTC vs.
Revision 2.2 by greg, Thu Oct 23 01:26:48 2025 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12  
13   #include <ctype.h>
14   #include <signal.h>
15 + #include <time.h>
16   #include "RcontribSimulManager.h"
17   #include "bsdf.h"
18   #include "bsdf_m.h"
# Line 34 | Line 35 | const char     *sigerr[NSIG];          /* signal error messages */
35   int     inpfmt = 'a';                   /* input format */
36   int     outfmt = 'f';                   /* output format */
37  
38 + int     report_intvl = 0;               /* reporting interval (seconds) */
39 +
40   RcontribSimulManager    myRCmanager;    // global rcontrib simulation manager
41  
42   #define PARAMSNAME      "rfluxmtx"      /* string indicating parameters */
# Line 300 | Line 303 | finish_receiver()
303   {
304          bool            uniform = false;
305          const char      *calfn = NULL;
306 <        char            binv[64] = "";
306 >        char            binv[64] = "0";
307          char            params[128] = "";
308          const char      *binf = NULL;
309          const char      *nbins = NULL;
# Line 321 | Line 324 | finish_receiver()
324          }
325                                          /* determine sample type/bin */
326          if ((tolower(curparams.hemis[0]) == 'u') | (curparams.hemis[0] == '1')) {
327 <                sprintf(binv, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
328 <                        curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
327 >                if (curparams.slist->styp != ST_SOURCE)
328 >                        sprintf(binv, "if(-Dx*%g-Dy*%g-Dz*%g,0,-1)",
329 >                                curparams.nrm[0], curparams.nrm[1], curparams.nrm[2]);
330                  uniform = true;         /* uniform sampling -- one bin */
331          } else if (tolower(curparams.hemis[0]) == 's' &&
332                                  tolower(curparams.hemis[1]) == 'c') {
# Line 622 | Line 626 | sample_shirchiu(PARAMS *p, int b, FVECT orig_dir[])
626  
627          while (n--) {                   /* stratified sampling */
628                  SDmultiSamp(samp3, 3, (n+frandom())/myRCmanager.accum);
629 <                square2disk(duvw, (b/p->hsiz + samp3[1])/curparams.hsiz,
630 <                                (b%p->hsiz + samp3[2])/curparams.hsiz);
629 >                square2disk(duvw, (b/p->hsiz + samp3[1])/p->hsiz,
630 >                                (b%p->hsiz + samp3[2])/p->hsiz);
631                  duvw[2] = sqrt(1. - duvw[0]*duvw[0] - duvw[1]*duvw[1]);
632                  for (i = 3; i--; )
633                          orig_dir[1][i] = -duvw[0]*p->udir[i] -
# Line 1251 | Line 1255 | sigdie(                        /* set fatal signal */
1255          sigerr[signo] = msg;
1256   }
1257  
1258 + // report progress
1259 + void
1260 + report_progress(bool force = false)
1261 + {
1262 +        static time_t   last_report=0, tstart=time(0);
1263 +        time_t          tnow;
1264 +
1265 +        if (!force & (report_intvl <= 0))
1266 +                return;
1267 +
1268 +        tnow = time(0);
1269 +        if (!force & (tnow < last_report + report_intvl))
1270 +                return;
1271 +
1272 +        sprintf(errmsg, "%.2f%% done after %.3f hours\n",
1273 +                        100. * myRCmanager.GetRowFinished() /
1274 +                                (double)myRCmanager.GetRowMax(),
1275 +                        (tnow - tstart)*(1./3600.));
1276 +        eputs(errmsg);
1277 +        last_report = tnow;
1278 + }
1279 +
1280   /* Run rfluxmtx equivalent without leaning on r[x]contrib */
1281   int
1282   main(int argc, char *argv[])
# Line 1287 | Line 1313 | main(int argc, char *argv[])
1313                                          /* set rcontrib defaults */
1314          default_options();
1315                                          /* get command-line options */
1316 <        for (a = 1; a < argc-2; a++) {
1316 >        for (a = 1; a < argc; a++) {
1317                                          /* check for argument expansion */
1318                  while ((rval = expandarg(&argc, &argv, a)) > 0)
1319                          ;
# Line 1395 | Line 1421 | main(int argc, char *argv[])
1421                          check(2,"i");
1422                          myRCmanager.accum = atoi(argv[++a]);
1423                          break;
1424 +                case 't':                       /* reporting interval */
1425 +                        check(2,"i");
1426 +                        report_intvl = atoi(argv[++a]);
1427 +                        break;
1428                  default:                /* anything else is verbotten */
1429                          goto userr;
1430                  }
1431          }
1432 <        if (a > argc-2)
1432 >        if (a > argc-1)
1433                  goto userr;
1434  
1435          override_options();             /* override critical options */
1436  
1437 <        if (!gotView)
1437 >        if (!gotView) {
1438                  sendfn = argv[a++];
1439 <        else if (argv[a][0] == '-')
1439 >                if (a > argc-1)
1440 >                        goto userr;
1441 >        } else if (argv[a][0] == '-')
1442                  error(USER, "view specification incompatible with pass-through mode");
1443                                          /* assign sender & receiver inputs */
1444          if (gotView) {                  // picture output?
# Line 1499 | Line 1531 | main(int argc, char *argv[])
1531                                  op != NULL; op = op->Next())
1532                          ++nout;
1533          if (nproc > 1) {                // set #processes
1534 <                if (verby)
1535 <                        fprintf(stderr, "%s: starting %d subprocesses\n", progname, nproc);
1534 >                if (verby) {
1535 >                        sprintf(errmsg, "starting %d subprocesses\n", nproc);
1536 >                        eputs(errmsg);
1537 >                }
1538                  myRCmanager.SetThreadCount(nproc);
1539          }
1540          if (gotView) {                  // picture generation mode?
1541                  if (verby) {
1542 <                        fprintf(stderr, "%s: computing %d %dx%d pictures",
1543 <                                        progname, nout, myRCmanager.xres, myRCmanager.yres);
1542 >                        sprintf(errmsg, "computing %d %dx%d pictures\n",
1543 >                                        nout, myRCmanager.xres, myRCmanager.yres);
1544                          if (myRCmanager.accum > 1)
1545 <                                fprintf(stderr, " with %d samples/pixel\n", myRCmanager.accum);
1546 <                        else
1547 <                                fputc('\n', stderr);
1545 >                                sprintf(errmsg+strlen(errmsg)-1, " with %d samples/pixel\n",
1546 >                                                myRCmanager.accum);
1547 >                        eputs(errmsg);
1548                  }
1549                  for (i = myRCmanager.yres; i--; )       // from the top!
1550                          for (int x = 0; x < myRCmanager.xres; x++) {
1551 +                                report_progress();
1552                                  if (!viewRays(rayarr, x, i))
1553                                          quit(1);
1554                                  if (myRCmanager.ComputeRecord(rayarr) != myRCmanager.accum)
# Line 1523 | Line 1558 | main(int argc, char *argv[])
1558   #ifdef getc_unlocked
1559                  flockfile(stdin);
1560   #endif
1561 <                if (verby)
1562 <                        fprintf(stderr,
1563 <                                "%s: computing %d rows in %d matrices with %d samples/row\n",
1564 <                                progname, myRCmanager.GetRowMax(), nout, myRCmanager.accum);
1565 <                for (i = myRCmanager.GetRowMax(); i-- > 0; ) {
1561 >                if (verby) {
1562 >                        sprintf(errmsg, "computing %d rows in %d matrices\n",
1563 >                                        myRCmanager.GetRowMax(), nout);
1564 >                        if (myRCmanager.accum > 1)
1565 >                                sprintf(errmsg+strlen(errmsg)-1, " with %d samples/row\n",
1566 >                                                myRCmanager.accum);
1567 >                        eputs(errmsg);
1568 >                }
1569 >                for (i = 0; i < myRCmanager.GetRowMax(); i++) {
1570 >                        report_progress();
1571                          if (getRays(rayarr) != myRCmanager.accum) {
1572                                  sprintf(errmsg, "ray read error after %d of %d",
1573                                                  myRCmanager.GetRowCount(),
# Line 1539 | Line 1579 | main(int argc, char *argv[])
1579                  }
1580          } else {                        // else surface-sampling mode
1581                  if (verby) {
1582 <                        fprintf(stderr,
1583 <                                "%s: sampling %d directions in %d matrices with %d samples/direction",
1544 <                                        progname, myRCmanager.yres, nout, myRCmanager.accum);
1582 >                        sprintf(errmsg, "sampling %d directions in %d matrices with %d samples/direction\n",
1583 >                                        myRCmanager.yres, nout, myRCmanager.accum);
1584                          if (sendparams.nsurfs > 1)
1585 <                                fprintf(stderr, " (%d surface elements)\n", sendparams.nsurfs);
1586 <                        else
1548 <                                fputc('\n', stderr);
1585 >                                sprintf(errmsg+strlen(errmsg)-1, " (%d surface elements)\n", sendparams.nsurfs);
1586 >                        eputs(errmsg);
1587                  }
1588                  for (i = 0; i < myRCmanager.yres; i++) {
1589 +                        report_progress();
1590                          if (!(*sendparams.sample_basis)(&sendparams, i, rayarr))
1591                                  quit(1);
1592                          if (myRCmanager.ComputeRecord(rayarr) != myRCmanager.accum)
# Line 1556 | Line 1595 | main(int argc, char *argv[])
1595                  clear_params(&sendparams);
1596          }
1597          delete [] rayarr;
1598 <        quit(0);                        /* flushes and waits on children */
1598 >        myRCmanager.FlushQueue();
1599 >        report_progress((report_intvl > 0) | verby);
1600 >        quit(0);                        /* waits on children */
1601   userr:
1602          if (a < argc-2)
1603 <                fprintf(stderr, "%s: unsupported option '%s'", progname, argv[a]);
1603 >                fprintf(stderr, "%s: unsupported option '%s'\n", progname, argv[a]);
1604          fprintf(stderr, "Usage: %s [-W] [rxcontrib options] { sender.rad | view | - } receiver.rad [-i system.oct] [system.rad ..]\n",
1605                                  progname);
1606          quit(1);
# Line 1571 | Line 1612 | quit(
1612          int  code
1613   )
1614   {
1615 <        myRCmanager.FlushQueue();       // leave nothing in queue
1615 >        if (!code)
1616 >                myRCmanager.ClearModifiers();
1617  
1618          exit(code);
1619   }

Diff Legend

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