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

Comparing ray/src/rt/RpictSimulManager.h (file contents):
Revision 2.1 by greg, Wed Aug 14 20:05:23 2024 UTC vs.
Revision 2.9 by greg, Mon Sep 16 23:49:13 2024 UTC

# Line 27 | Line 27 | enum RenderDataType {
27   #define RDTcolorT(f)    RenderDataType((f) & RDTcolorM)
28   #define RDTdepthT(f)    RenderDataType((f) & RDTdepthM)
29   #define RDTcommonE(f)   (RDTcolorT(f) >= RDTscolr)
30 < #define RDTnewCT(f,c)   RenderDataType((f) & ~RDTcolorM | (c))
31 < #define RDTnewDT(f,d)   RenderDataType((f) & ~RDTdepthM | (d))
30 > #define RDTnewCT(f,c)   RenderDataType((f) & ~RDTcolorM | (c) & RDTcolorM)
31 > #define RDTnewDT(f,d)   RenderDataType((f) & ~RDTdepthM | (d) & RDTdepthM)
32  
33   /// Pixel accessor (read/write to caller's buffer with possible conversion)
34   class PixelAccess {
# Line 43 | Line 43 | class PixelAccess {
43          long            rowStride;      // # values to next y position
44          int             dtyp;           // data type flags
45          RGBPRIMP        primp;          // color primaries if tristimulus
46 <        COLORMAT        xyz2myrgbmat;   // custom color conversion matrix
46 >        bool            swap2d;         // need to swap 16-bit depths?
47 >        const COLORV *  CF3(int x, int y) const {
48 >                                return pbase.f + (rowStride*y + x)*3;
49 >                        }
50          COLORV *        CF3(int x, int y) {
51                                  return pbase.f + (rowStride*y + x)*3;
52                          }
53 <        COLORV *        GetCF3(int x, int y) const {
54 <                                return const_cast<COLORV *>(pbase.f + (rowStride*y + x)*3);
53 >        const COLRV *   CB3(int x, int y) const {
54 >                                return pbase.b + (rowStride*y + x)*4;
55                          }
53        COLORV *        SCF(int x, int y) {
54                                return pbase.f + (rowStride*y + x)*NCSAMP;
55                        }
56        COLORV *        GetSCF(int x, int y) const {
57                                return const_cast<COLORV *>(pbase.f + (rowStride*y + x)*NCSAMP);
58                        }
56          COLRV *         CB3(int x, int y) {
57                                  return pbase.b + (rowStride*y + x)*4;
58                          }
59 <        COLRV *         GetCB3(int x, int y) const {
60 <                                return const_cast<COLRV *>(pbase.b + (rowStride*y + x)*4);
59 >        const COLORV *  SCF(int x, int y) const {
60 >                                return pbase.f + (rowStride*y + x)*NCSAMP;
61                          }
62 +        COLORV *        SCF(int x, int y) {
63 +                                return pbase.f + (rowStride*y + x)*NCSAMP;
64 +                        }
65 +        const COLRV *   SCB(int x, int y) const {
66 +                                return pbase.b + (rowStride*y + x)*(NCSAMP+1);
67 +                        }
68          COLRV *         SCB(int x, int y) {
69                                  return pbase.b + (rowStride*y + x)*(NCSAMP+1);
70                          }
71 <        COLRV *         GetSCB(int x, int y) const {
72 <                                return const_cast<COLRV *>(pbase.b + (rowStride*y + x)*(NCSAMP+1));
71 >        void            EncodeDepth16(int x, int y, float z) {
72 >                                short * sp = dbase.s + rowStride*y + x;
73 >                                *sp = depth2code(z, refDepth);
74 >                                if (swap2d) swap16((char *)sp, 1);
75                          }
76 +        float           DecodeDepth16(int x, int y) const {
77 +                                short   sv = dbase.s[rowStride*y + x];
78 +                                if (swap2d) swap16((char *)&sv, 1);
79 +                                return code2depth(sv, refDepth);
80 +                        }
81   public:
82          double          refDepth;       // reference depth
83                          PixelAccess() {
84                                  refDepth = 1.;
85 +                                swap2d = !nativebigendian();
86                                  Init();
87                          }
88                          PixelAccess(COLORV *rp, int ystride, float *zp=NULL) {
89                                  refDepth = 1.;
90 +                                swap2d = !nativebigendian();
91                                  Init(rp, ystride, zp);
92                          }
93                          PixelAccess(COLRV *bp, int ystride, float *zp=NULL) {
94                                  refDepth = 1.;
95 +                                swap2d = !nativebigendian();
96                                  Init(bp, ystride, zp);
97                          }
98                          PixelAccess(COLRV *bp, int ystride, short *dp) {
99                                  refDepth = 1.;
100 +                                swap2d = !nativebigendian();
101                                  Init(bp, ystride, dp);
102                          }
103 +                        PixelAccess(COLORV *rp, int ystride, short *dp) {
104 +                                refDepth = 1.;
105 +                                swap2d = !nativebigendian();
106 +                                Init(rp, ystride, dp);
107 +                        }
108          void            Init() {
109                                  pbase.f = NULL; dbase.f = NULL;
110                                  rowStride = 0;
# Line 123 | Line 142 | class PixelAccess {
142                                  }
143                                  if (dp) dtyp |= RDTdshort;
144                          }
145 +        void            Init(COLORV *rp, int ystride, short *dp) {
146 +                                pbase.f = rp; dbase.s = dp;
147 +                                rowStride = ystride;
148 +                                if (NCSAMP > 3) {
149 +                                        dtyp = RDTscolor; primp = NULL;
150 +                                } else {
151 +                                        dtyp = RDTrgb; primp = stdprims;
152 +                                }
153 +                                if (dp) dtyp |= RDTdshort;
154 +                        }
155                          /// Set color space after non-empty initialization
156          bool            SetColorSpace(RenderDataType cs, RGBPRIMP pr=NULL);
157                          /// Get color space
# Line 166 | Line 195 | class PixelAccess {
195                                          scolor_scolr(SCB(x,y), pv);
196                                  else
197                                          copyscolor(SCF(x,y), pv);
198 <                                if (RDTdepthT(dtyp) == RDTdfloat)
198 >                                if (DepthType() == RDTdfloat)
199                                          dbase.f[rowStride*y + x] = z;
200 <                                else if (RDTdepthT(dtyp) == RDTdshort)
201 <                                        dbase.s[rowStride*y + x] = depth2code(z, refDepth);
200 >                                else if (DepthType() == RDTdshort)
201 >                                        EncodeDepth16(x, y, z);
202                                  return true;
203                          }
204                          /// Retrieve pixel color (& depth) -- may convert either/both
205          bool            GetPixel(int x, int y, COLORV *pv, float *zp=NULL) const {
206                                  if (NC() == 3) {
207                                          if (RDTcommonE(dtyp))
208 <                                                colr_color(pv, GetCB3(x,y));
208 >                                                colr_color(pv, CB3(x,y));
209                                          else
210 <                                                copycolor(pv, GetCF3(x,y));
210 >                                                copycolor(pv, CF3(x,y));
211                                  } else if (RDTcommonE(dtyp))
212 <                                        scolr_scolor(pv, GetSCB(x,y));
212 >                                        scolr_scolor(pv, SCB(x,y));
213                                  else
214 <                                        copyscolor(pv, GetSCF(x,y));
214 >                                        copyscolor(pv, SCF(x,y));
215                                  if (!zp) return true;
216 <                                if (RDTdepthT(dtyp) == RDTdfloat)
216 >                                if (DepthType() == RDTdfloat)
217                                          *zp = dbase.f[rowStride*y + x];
218 <                                else if (RDTdepthT(dtyp) == RDTdshort)
219 <                                        *zp = code2depth(dbase.s[rowStride*y + x], refDepth);
218 >                                else if (DepthType() == RDTdshort)
219 >                                        *zp = DecodeDepth16(x, y);
220                                  else
221                                          *zp = .0f;
222                                  return true;
# Line 198 | Line 227 | class PixelAccess {
227                                  const int       nc = NC();
228                                  if (nc == 3) {
229                                          if (RDTcommonE(dtyp))
230 <                                                copycolr(CB3(dx,dy), GetCB3(sx,sy));
230 >                                                copycolr(CB3(dx,dy), CB3(sx,sy));
231                                          else
232 <                                                copycolor(CF3(dx,dy), GetCF3(sx,sy));
232 >                                                copycolor(CF3(dx,dy), CF3(sx,sy));
233                                  } else if (RDTcommonE(dtyp))
234 <                                        copyscolr(SCB(dx,dy), GetSCB(sx,sy));
234 >                                        copyscolr(SCB(dx,dy), SCB(sx,sy));
235                                  else
236 <                                        copyscolor(SCF(dx,dy), GetSCF(sx,sy));
237 <                                switch (RDTdepthT(dtyp)) {
236 >                                        copyscolor(SCF(dx,dy), SCF(sx,sy));
237 >                                switch (DepthType()) {
238                                  case RDTdfloat:
239                                          dbase.f[rowStride*dy + dx] =
240                                                          dbase.f[rowStride*sy + sx];
# Line 238 | Line 267 | class RpictSimulManager : protected RtraceSimulManager
267          COLORV *                barPix;                 // current render bar pixels
268          float *                 barDepth;               // current render bar depths
269          bool                    SetTile(const int ti[2]);
270 <        bool                    RenderRect();
270 >        bool                    RenderRect(const int x0 = 0, const int y0 = 0);
271          bool                    ComputePixel(int x, int y);
272 <        bool                    BelowSampThresh(int x, int y, const int noff[4][2]) const;
273 <        void                    FillSquare(int x, int y, const int noff[4][2]);
272 >        bool                    BelowSampThresh(const int x, const int y,
273 >                                                        const int noff[4][2]) const;
274 >        void                    FillSquare(const int x, const int y, const int noff[4][2]);
275          void                    NewBar(int ht = 0);
276 <        bool                    LowerBar(int v);
276 >        bool                    LowerBar(int v, int ytop);
277          bool                    RenderBelow(int ytop, const int vstep, FILE *pfp,
278                                                          const int dt, FILE *dfp=NULL);
279   public:
# Line 262 | Line 292 | class RpictSimulManager : protected RtraceSimulManager
292                                          frameNo = 0;
293                                  }
294                                  ~RpictSimulManager() {
295 <                                        NewBar();
295 >                                        delete [] barPix; delete [] barDepth;
296                                  }
297                                  /// Load octree and prepare renderer
298          bool                    LoadOctree(const char *octn) {
# Line 281 | Line 311 | class RpictSimulManager : protected RtraceSimulManager
311                                          return RtraceSimulManager::AddHeader(ac, av);
312                                  }
313                                  /// Get header lines if any
314 <        const char *            GetHeader() const {
315 <                                        return RtraceSimulManager::GetHeader();
314 >        const char *            GetHeadStr() const {
315 >                                        return RtraceSimulManager::GetHeadStr();
316                                  }
317 +                                /// Look for specific header keyword, return value
318 +        const char *            GetHeadStr(const char *key, bool inOK = false) const {
319 +                                        return RtraceSimulManager::GetHeadStr(key, inOK);
320 +                                }
321                                  /// Set number of computation threads (0 => #cores)
322          int                     SetThreadCount(int nt = 0) {
323                                          return RtraceSimulManager::SetThreadCount(nt);
# Line 326 | Line 360 | class RpictSimulManager : protected RtraceSimulManager
360                                  /// Increments frameNo if >0
361          bool                    NewFrame(const VIEW &v, int xydim[2], double *ap=NULL,
362                                                  const int *tgrid=NULL);
363 +                                /// Get current view if set
364 +        const VIEW *            GetView() const {
365 +                                        if (!vw.type) return NULL;
366 +                                        return &vw;
367 +                                }
368 +                                /// Writeable previous view (for motion blur)
369 +        VIEW &                  PreView() {
370 +                                        return pvw;
371 +                                }
372                                  /// Get current picture width
373          int                     GetWidth() const {
374                                          return hvres[0];
# Line 354 | Line 397 | class RpictSimulManager : protected RtraceSimulManager
397                                  /// Same but also use 16-bit encoded depth buffer
398          bool                    RenderTile(COLRV *bp, int ystride, short *dp,
399                                                  const int *tile=NULL);
400 +                                /// Back to float color with 16-bit depth
401 +        bool                    RenderTile(COLORV *rp, int ystride, short *dp,
402 +                                                const int *tile=NULL);
403                                  /// Render and write a frame to the named file
404                                  /// Include any header lines set prior to call
405 <                                /// Picture file must not already exist
406 <                                /// Picture to stdout if pfname==NULL
407 <                                /// Depth written to a command if dfname[0]=='!'
405 >                                /// Picture file must not exist
406 >                                /// Write pixels to stdout if !pfname
407 >                                /// Write depth to a command if dfname[0]=='!'
408          RenderDataType          RenderFrame(const char *pfname,
409                                                  RenderDataType dt=RDTrgbe,
410                                                  const char *dfname=NULL);
411                                  /// Resume partially finished rendering
412                                  /// Picture file must exist with valid header
413          RenderDataType          ResumeFrame(const char *pfname,
414 +                                                const char *dfname=NULL);
415 +                                /// Prepare new picture (and depth) output
416 +                                /// Called by RenderFrame() after NewFrame()
417 +        RenderDataType          NewOutput(FILE *pdfp[2], const char *pfname,
418 +                                                RenderDataType dt=RDTrgbe,
419 +                                                const char *dfname=NULL);
420 +                                /// Reopen existing picture (and depth) file
421 +                                /// Called by ResumeFrame()
422 +                                /// File pointers @ end of header (before res.)
423 +        RenderDataType          ReopenOutput(FILE *pdfp[2], const char *pfname,
424                                                  const char *dfname=NULL);
425                                  /// Close octree, free data, return status
426          int                     Cleanup(bool everything = false) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines