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.2 by greg, Tue Sep 17 00:05:11 2024 UTC vs.
Revision 2.9 by greg, Thu Jan 2 20:19:48 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 >        if (nproc < 0) {
64 >                ray_pnprocs = -1;       // hack to avoid cleanup in child
65 >                _exit(code);
66 >        }
67 >        exit(code);                     // don't bother to free data structs
68   }
69  
70 + /* Set default options */
71 + static void
72 + default_options(void)
73 + {
74 +        shadthresh = .05;
75 +        shadcert = .5;
76 +        srcsizerat = .25;
77 +        directrelay = 1;
78 +        ambacc = 0.2;
79 +        ambres = 64;
80 +        ambdiv = 512;
81 +        ambssamp = 128;
82 +        maxdepth = 7;
83 + }
84  
85   int
86   main(int  argc, char  *argv[])
# Line 88 | Line 108 | main(int  argc, char  *argv[])
108          strcat(RFeatureList, RXPIECE_FEATURES);
109          if (argc > 1 && !strcmp(argv[1], "-features"))
110                  return feature_status(argc-2, argv+2);
111 +                                        /* set defaults */
112 +        default_options();
113                                          /* option city */
114          for (i = 1; i < argc; i++) {
115                                                  /* expand arguments */
# Line 315 | Line 337 | main(int  argc, char  *argv[])
337                                          // render tiles
338          dtype = rpiece(outfile, dtype, zfile);
339  
340 <        quit(dtype==RDTnone);           // clean up and exit
340 >        ambsync();                      // flush ambient cache
341  
342 +        ray_done_pmap();                /* PMAP: free photon maps */
343 +
344 +        quit(dtype==RDTnone);           // status is 1 on failure
345 +
346   badopt:
347          sprintf(errmsg, "command line error at '%s'", argv[i]);
348          error(USER, errmsg);
# Line 332 | Line 358 | wputs(                         /* warning output function */
358          const char      *s
359   )
360   {
361 +        if (!erract[WARNING].pf)
362 +                return;         // warnings were disabled!
363          int  lasterrno = errno;
364          eputs(s);
365          errno = lasterrno;
# Line 499 | Line 527 | children_finished()
527  
528          if (cpid == 0) {                // children render tiles
529                  sleep(nproc - cnt);     // avoid race conditions
530 +                nproc = -1;             // flag as child
531                  return false;
532          }
533          cow_doneshare();                // parent frees memory and waits
# Line 598 | Line 627 | rpiece(char *pout, RenderDataType dt, char *zout)
627  
628          const bool      newOutput = (access(pout, F_OK) < 0);
629          FILE            *pdfp[2];
630 <        if (!newOutput) {                       // output exists?
630 >        if (newOutput) {                        // new output file?
631 >                CHECK((tileGrid[0] <= 1) & (tileGrid[1] <= 1),
632 >                                 USER, "bad tiling specification");
633 >        } else {
634                  dt = myRPmanager.ReopenOutput(pdfp, pout, zout);
635                  if (dt == RDTnone)
636 <                        quit(1);
636 >                        return RDTnone;
637                  if (!fscnresolu(&hresolu, &vresolu, pdfp[0]))
638                          error(USER, "missing picture resolution");
639                  pixaspect = .0;                 // need to leave this as is
640                  myRPmanager.NewHeader(pout);    // get prev. header info
641                  const char *    tval = myRPmanager.GetHeadStr("TILED=");
642                  if (tval) sscanf(tval, "%d %d", &tileGrid[0], &tileGrid[1]);
643 <                if (!myRPmanager.GetView()) {
644 <                        sprintf(errmsg, "missing view in picture file '%s'", pout);
613 <                        error(USER, errmsg);
614 <                }
643 >                CHECK(myRPmanager.GetView()==NULL,
644 >                                USER, "missing view in picture file");
645                  ourview = *myRPmanager.GetView();
646          }
647          int     hvdim[2] = {hresolu, vresolu};  // set up tiled frame
# Line 633 | Line 663 | rpiece(char *pout, RenderDataType dt, char *zout)
663                  myRPmanager.AddHeader(buf);
664                  dt = myRPmanager.NewOutput(pdfp, pout, dt, zout);
665                  if (dt == RDTnone)
666 <                        quit(1);
666 >                        return RDTnone;
667                  fprtresolu(hresolu, vresolu, pdfp[0]);
668 <        }
669 <        if (RDTdepthT(dt) == RDTdshort) {
640 <                if (newOutput)
668 >                fflush(pdfp[0]);
669 >                if (RDTdepthT(dt) == RDTdshort) {
670                          fprtresolu(hresolu, vresolu, pdfp[1]);
671 <                else if (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
672 <                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu))
673 <                        error(USER, "mismatched depth file resolution");
674 <        }
671 >                        fflush(pdfp[1]);
672 >                }
673 >        } else if (RDTdepthT(dt) == RDTdshort &&
674 >                        (!fscnresolu(&hvdim[0], &hvdim[1], pdfp[1]) ||
675 >                                (hvdim[0] != hresolu) | (hvdim[1] != vresolu)))
676 >                error(USER, "mismatched depth file resolution");
677                                                  // prepare (flat) pixel buffer
678          const long      pdata_beg = ftell(pdfp[0]);
679          const size_t    pixSiz = (RDTcolorT(dt)==RDTrgbe)|(RDTcolorT(dt)==RDTxyze) ? sizeof(COLR)
# Line 653 | Line 684 | rpiece(char *pout, RenderDataType dt, char *zout)
684          if (pmlen&7) pmlen += 8 - (pmlen&7);    // 8-byte alignment to be safe
685          pmlen += sizeof(TileProg)*tileGrid[0]*tileGrid[1];
686                                                  // map picture file to memory
687 <        if (ftruncate(fileno(pdfp[0]), pmlen) < 0)
687 >        if (newOutput && ftruncate(fileno(pdfp[0]), pmlen) < 0)
688                  error(SYSTEM, "cannot extend picture buffer");
689          uby8 *          pixMap = (uby8 *)mmap(NULL, pmlen, PROT_READ|PROT_WRITE,
690                                                  MAP_SHARED, fileno(pdfp[0]), 0);
# Line 666 | Line 697 | rpiece(char *pout, RenderDataType dt, char *zout)
697          const size_t    zmlen = zdata_beg + zdpSiz*hresolu*vresolu;
698          uby8 *          zdMap = NULL;
699          if (RDTdepthT(dt)) {
700 <                if (ftruncate(fileno(pdfp[1]), zmlen) < 0)
700 >                if (newOutput && ftruncate(fileno(pdfp[1]), zmlen) < 0)
701                          error(SYSTEM, "cannot extend depth buffer");
702                  zdMap = (uby8 *)mmap(NULL, zmlen, PROT_READ|PROT_WRITE,
703                                                  MAP_SHARED, fileno(pdfp[1]), 0);
# Line 714 | Line 745 | rpiece(char *pout, RenderDataType dt, char *zout)
745                          error(USER, errmsg);
746                  }
747                  tile_p(ti)->status = 1;         // mark tile completed
748 +                ndone++;
749          }
750          if (!ndone)
751                  error(WARNING, "no tiles need rendering, exit");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines