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

Comparing ray/src/rt/rxpiece.cpp (file contents):
Revision 2.1 by greg, Mon Sep 16 23:49:13 2024 UTC vs.
Revision 2.10 by greg, Thu Jan 9 17:25:37 2025 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14  
15   #include  "platform.h"
16   #include  "RpictSimulManager.h"
17 + #include  "ambient.h"
18 + #include  "pmapray.h"
19   #include  "random.h"
20  
21   extern char  *progname;                 /* argv[0] */
# Line 35 | Line 37 | double  mblur = 0.;                    /* motion blur parameter (unused
37  
38   double  dblur = 0.;                     /* depth-of-field blur parameter */
39  
40 < int  nproc = 1;                         /* number of processes to run */
40 > int  nproc = 1;                         /* number of processes to run (-1 in child) */
41  
42   RpictSimulManager       myRPmanager;    // global simulation manager
43  
# Line 54 | Line 56 | static RenderDataType rpiece(char *pout, RenderDataTyp
56                  "AdaptiveShadowTesting\nOutputs=v,l\n" \
57                  "OutputCS=RGB,XYZ,prims,spec\n"
58  
59 <
59 > // Exit program
60   void
61   quit(int code)                          /* quit program */
62   {
63 <        exit(code);
63 >        exit(code);                     // don't bother to free data structs
64   }
65  
66 + /* Set default options */
67 + static void
68 + default_options(void)
69 + {
70 +        shadthresh = .05;
71 +        shadcert = .5;
72 +        srcsizerat = .25;
73 +        directrelay = 1;
74 +        ambacc = 0.2;
75 +        ambres = 64;
76 +        ambdiv = 512;
77 +        ambssamp = 128;
78 +        maxdepth = 7;
79 + }
80  
81   int
82   main(int  argc, char  *argv[])
# Line 88 | Line 104 | main(int  argc, char  *argv[])
104          strcat(RFeatureList, RXPIECE_FEATURES);
105          if (argc > 1 && !strcmp(argv[1], "-features"))
106                  return feature_status(argc-2, argv+2);
107 +                                        /* set defaults */
108 +        default_options();
109                                          /* option city */
110          for (i = 1; i < argc; i++) {
111                                                  /* expand arguments */
# Line 315 | Line 333 | main(int  argc, char  *argv[])
333                                          // render tiles
334          dtype = rpiece(outfile, dtype, zfile);
335  
336 <        quit(dtype==RDTnone);           // clean up and exit
336 >        ambsync();                      // flush ambient cache
337  
338 +        ray_done_pmap();                /* PMAP: free photon maps */
339 +
340 +        quit(dtype==RDTnone);           // status is 1 on failure
341 +
342   badopt:
343          sprintf(errmsg, "command line error at '%s'", argv[i]);
344          error(USER, errmsg);
# Line 332 | Line 354 | wputs(                         /* warning output function */
354          const char      *s
355   )
356   {
357 +        if (!erract[WARNING].pf)
358 +                return;         // warnings were disabled!
359          int  lasterrno = errno;
360          eputs(s);
361          errno = lasterrno;
# Line 482 | Line 506 | children_finished()
506          for (ti[1] = 0; ti[1] < tileGrid[1]; ti[1]++)
507                  for (ti[0] = 0; ti[0] < tileGrid[0]; ti[0]++)
508                          cnt += renderable_tile(tile_p(ti));
509 <        if (!cnt) {                     // nothing left to do?
510 <                error(WARNING, "output appears to be complete, nothing added");
487 <                return true;
488 <        }
509 >        if (!cnt)
510 >                return false;           // parent can do nothing
511          if (cnt < nproc) {
512                  sprintf(errmsg, "only %d renderable tiles, reducing process count", cnt);
513                  error(WARNING, errmsg);
# Line 501 | Line 523 | children_finished()
523  
524          if (cpid == 0) {                // children render tiles
525                  sleep(nproc - cnt);     // avoid race conditions
526 +                nproc = -1;             // flag as child
527                  return false;
528          }
529          cow_doneshare();                // parent frees memory and waits
# Line 600 | Line 623 | rpiece(char *pout, RenderDataType dt, char *zout)
623  
624          const bool      newOutput = (access(pout, F_OK) < 0);
625          FILE            *pdfp[2];
626 <        if (!newOutput) {                       // output exists?
626 >        if (newOutput) {                        // new output file?
627 >                CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1),
628 >                                 USER, "bad tiling specification");
629 >        } else {
630                  dt = myRPmanager.ReopenOutput(pdfp, pout, zout);
631                  if (dt == RDTnone)
632 <                        quit(1);
632 >                        return RDTnone;
633                  if (!fscnresolu(&hresolu, &vresolu, pdfp[0]))
634                          error(USER, "missing picture resolution");
635 +                pixaspect = .0;                 // need to leave this as is
636                  myRPmanager.NewHeader(pout);    // get prev. header info
637                  const char *    tval = myRPmanager.GetHeadStr("TILED=");
638                  if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]);
639 <                if (!myRPmanager.GetView()) {
640 <                        sprintf(errmsg, "missing view in picture file '%s'", pout);
614 <                        error(USER, errmsg);
615 <                }
639 >                CHECK(myRPmanager.GetView()==NULL,
640 >                                USER, "missing view in picture file");
641                  ourview = *myRPmanager.GetView();
642          }
643          int     hvdim[2] = {hresolu, vresolu};  // set up tiled frame
# Line 634 | Line 659 | rpiece(char *pout, RenderDataType dt, char *zout)
659                  myRPmanager.AddHeader(buf);
660                  dt = myRPmanager.NewOutput(pdfp, pout, dt, zout);
661                  if (dt == RDTnone)
662 <                        quit(1);
662 >                        return RDTnone;
663                  fprtresolu(hresolu, vresolu, pdfp[0]);
664 <        }
665 <        if (RDTdepthT(dt) == RDTdshort) {
641 <                if (newOutput)
664 >                fflush(pdfp[0]);
665 >                if (RDTdepthT(dt) == RDTdshort) {
666                          fprtresolu(hresolu, vresolu, pdfp[1]);
667 <                else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
668 <                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu))
669 <                        error(USER, "mismatched depth file resolution");
670 <        }
667 >                        fflush(pdfp[1]);
668 >                }
669 >        } else if (RDTdepthT(dt) == RDTdshort &&
670 >                        (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
671 >                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu)))
672 >                error(USER, "mismatched depth file resolution");
673                                                  // prepare (flat) pixel buffer
674          const long      pdata_beg = ftell(pdfp[0]);
675          const size_t    pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR)
# Line 654 | Line 680 | rpiece(char *pout, RenderDataType dt, char *zout)
680          if (pmlen&7) pmlen += 8 - (pmlen&7);    // 8-byte alignment to be safe
681          pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1];
682                                                  // map picture file to memory
683 <        if (ftruncate(fileno(pdfp[0]), pmlen) < 0)
683 >        if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0)
684                  error(SYSTEM, "cannot extend picture buffer");
685          uby8 *          pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE,
686                                                  MAP_SHARED, fileno(pdfp[0]), 0);
# Line 667 | Line 693 | rpiece(char *pout, RenderDataType dt, char *zout)
693          const size_t    zmlen = zdata_beg + zdpSiz*hresolu*vresolu;
694          uby8 *          zdMap = NULL;
695          if (RDTdepthT(dt)) {
696 <                if (ftruncate(fileno(pdfp[1]), zmlen) < 0)
696 >                if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0)
697                          error(SYSTEM, "cannot extend depth buffer");
698                  zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE,
699                                                  MAP_SHARED, fileno(pdfp[1]), 0);
# Line 682 | Line 708 | rpiece(char *pout, RenderDataType dt, char *zout)
708          if (children_finished())                // work done in children?
709                  return dt;
710  
711 <        int     ti[2];                          // else render tiles
711 >        int     ndone = 0;                      // else render tiles
712 >        int     ti[2];
713          while (nexttile(ti)) {
714                  const int       offset = (tileGrid[1]-1-ti[1])*myRPmanager.GetWidth()*myRPmanager.THeight() +
715                                                  (myRPmanager.THeight()-1)*myRPmanager.GetWidth() +
# Line 714 | Line 741 | rpiece(char *pout, RenderDataType dt, char *zout)
741                          error(USER, errmsg);
742                  }
743                  tile_p(ti)->status = 1;         // mark tile completed
744 +                ndone++;
745          }
746 +        if (!ndone)
747 +                error(WARNING, "no tiles need rendering, exit");
748          /*
749          munmap(pixMap, pmlen);                  // technically unnecessary...
750          if (zdMap) munmap(zdMap, zmlen);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines