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

Comparing ray/src/rt/RpictSimulManager.cpp (file contents):
Revision 2.6 by greg, Wed Aug 21 23:52:24 2024 UTC vs.
Revision 2.8 by greg, Fri Aug 23 02:08:28 2024 UTC

# Line 196 | Line 196 | RpictSimulManager::SetTile(const int ti[2])
196   bool
197   RpictSimulManager::ComputePixel(int x, int y)
198   {
199        static const SCOLOR     scBlack = {0};
199          int     i;
200          FVECT   rodir[2];
201          double  hpos = (x+pixjitter())/TWidth();
202          double  vpos = (y+pixjitter())/THeight();
203          double  dlim = viewray(rodir[0], rodir[1], &tvw, hpos, vpos);
204          if (dlim < -FTINY) {    // off view?
205 <                pacc.SetPixel(x, y, scBlack);
205 >                pacc.SetPixel(x, y, scblack);
206                  doneMap.Set(x, y);
207                  return true;
208          }
# Line 328 | Line 327 | RpictSimulManager::FillSquare(const int x, const int y
327  
328   // helper function to set up quincunx sampling
329   static void
330 < SetQuincunx(ABitMap2 *bmp2, int noff[4][2], const int spc, const bool odd)
330 > SetQuincunx(ABitMap2 *bmp2, int noff[4][2], const int spc, bool odd, int x0, int y)
331   {
332 <        for (int y = 0; y < bmp2->Height(); y += spc>>1)
334 <            for (int x = (odd^(y&1))*(spc>>1); x < bmp2->Width(); x += spc)
335 <                bmp2->Set(x, y);
336 <                                        // order neighbors CCW
337 <        if (odd) {
332 >        if (odd) {                      // order neighbors CCW
333                  noff[0][0] = spc>>1; noff[0][1] = 0;
334                  noff[1][0] = 0; noff[1][1] = spc>>1;
335                  noff[2][0] = -(spc>>1); noff[2][1] = 0;
# Line 345 | Line 340 | SetQuincunx(ABitMap2 *bmp2, int noff[4][2], const int
340                  noff[2][0] = -(spc>>1); noff[2][1] = -(spc>>1);
341                  noff[3][0] = spc>>1; noff[3][1] = -(spc>>1);
342          }
343 +        int     nsteps;                 // non-negative range
344 +        if (x0 < -(spc>>1)) {
345 +                nsteps = (spc-1 - x0 - (spc>>1))/spc;
346 +                x0 += nsteps*spc;
347 +        }
348 +        if (y < 0) {                    // get past y==0
349 +                nsteps = ((spc>>1)-1 - y)/(spc>>1);
350 +                y += nsteps*(spc>>1);
351 +                odd ^= nsteps&1;
352 +        }
353 +        while (y < bmp2->Height()) {
354 +            for (int x = x0 + odd*(spc>>1); x < bmp2->Width(); x += spc)
355 +                bmp2->Set(x, y);
356 +            y += spc>>1;
357 +            odd = !odd;
358 +        }
359   }
360  
361   // Render (or finish rendering) current tile
362   bool
363 < RpictSimulManager::RenderRect()
363 > RpictSimulManager::RenderRect(const int x0, const int y0)
364   {
365          if (!tvw.type || !Ready()) {
366                  error(INTERNAL, "need octree and view for RenderRect()");
# Line 359 | Line 370 | RpictSimulManager::RenderRect()
370          int             sp2 = ceil(log2((TWidth()>THeight() ? TWidth() : THeight()) - 1.));
371          int             layer = 0;
372          int             x, y;
362 // fprintf(stderr, "Rendering %dx%d tile with psample=%d, maxdiff=%.3f ...\n",
363 // TWidth(), THeight(), psample, maxdiff);
373          while (sp2 > 0) {
374                  ABitMap2        sampMap(TWidth(), THeight());
375                  int             noff[4][2];
376                  if ((prCB != NULL) & (barPix == NULL))
377                          (*prCB)(100.*doneMap.SumTotal()/doneMap.Width()/doneMap.Height());
378 <                SetQuincunx(&sampMap, noff, 1<<sp2, layer&1);
378 >                SetQuincunx(&sampMap, noff, 1<<sp2, layer&1, x0, y0);
379                  sampMap -= doneSamples; // avoid resampling pixels
380                  // Are we into adaptive sampling realm?
381 <                if (noff[0][0]*noff[0][0] + noff[0][1]*noff[0][1] < psample*psample) {
381 >                if (noff[0][0]*noff[0][0] + noff[0][1]*noff[0][1] < 4*psample*psample) {
382                          if (FlushQueue() < 0)   // need results to check thresholds
383                                  return false;
384                          ABitMap2        fillMap = sampMap;
# Line 394 | Line 403 | RpictSimulManager::RenderRect()
403                          if (!ComputePixel(x, y))
404                                  return false;
405                  doneSamples |= sampMap; // samples now done or at least queued
397 // fprintf(stderr, "Sampled %ld pixels at (sp2,layer)=(%d,%d)\n",
398 // (long)sampMap.SumTotal(), sp2, layer);
399 // fprintf(stderr, "\t%ld pixels (%.3f%%) completed (+%ld in process)\n",
400 // (long)doneMap.SumTotal(), 100.*doneMap.SumTotal()/doneMap.Width()/doneMap.Height(),
401 // (long)(doneSamples.SumTotal()-doneMap.SumTotal()));
406                  sp2 -= layer++ & 1;     // next denser sampling
407          }
408          if (FlushQueue() < 0)           // make sure we got everyone
# Line 433 | Line 437 | RpictSimulManager::RenderTile(COLORV *rp, int ystride,
437                  pacc.SetColorSpace(RDTxyz);
438          else if (prims)
439                  pacc.SetColorSpace(RDTrgb, prims);
440 <                
441 <        return SetTile(tile) && RenderRect();
440 >
441 >        int     x0=0, y0=0;
442 >        if (tile) {
443 >                x0 = -tile[0]*TWidth();
444 >                y0 = -tile[1]*THeight();
445 >        }
446 >        return SetTile(tile) && RenderRect(x0, y0);
447   }
448  
449   // Same but store as common-exponent COLR or SCOLR
# Line 451 | Line 460 | RpictSimulManager::RenderTile(COLRV *bp, int ystride,
460          else if (prims)
461                  pacc.SetColorSpace(RDTrgbe, prims);
462  
463 <        return SetTile(tile) && RenderRect();
463 >        int     x0=0, y0=0;
464 >        if (tile) {
465 >                x0 = -tile[0]*TWidth();
466 >                y0 = -tile[1]*THeight();
467 >        }
468 >        return SetTile(tile) && RenderRect(x0, y0);
469   }
470  
471   // Same but also use 16-bit encoded depth buffer
# Line 468 | Line 482 | RpictSimulManager::RenderTile(COLRV *bp, int ystride,
482          else if (prims)
483                  pacc.SetColorSpace(RDTrgbe, prims);
484  
485 <        return SetTile(tile) && RenderRect();
485 >        int     x0=0, y0=0;
486 >        if (tile) {
487 >                x0 = -tile[0]*TWidth();
488 >                y0 = -tile[1]*THeight();
489 >        }
490 >        return SetTile(tile) && RenderRect(x0, y0);
491   }
492  
493   // Back to float color with 16-bit depth
# Line 485 | Line 504 | RpictSimulManager::RenderTile(COLORV *rp, int ystride,
504          else if (prims)
505                  pacc.SetColorSpace(RDTrgb, prims);
506  
507 <        return SetTile(tile) && RenderRect();
507 >        int     x0=0, y0=0;
508 >        if (tile) {
509 >                x0 = -tile[0]*TWidth();
510 >                y0 = -tile[1]*THeight();
511 >        }
512 >        return SetTile(tile) && RenderRect(x0, y0);
513   }
514  
515   // Allocate a new render bar
# Line 583 | Line 607 | RpictSimulManager::RenderBelow(int ytop, const int vst
607          }
608          int             lastOut = ytop;         // render down frame
609          while (ytop > 0) {
586 // fprintf(stderr, "At y=%d, source drawing %s...\n", ytop, parr ? "ON" : "OFF");
610                  if (prCB)
611                          (*prCB)(100.*(GetHeight()-ytop)/GetHeight());
612 <                if (!RenderRect())              // render this bar
612 >                if (!RenderRect(0, THeight()-ytop))     // render this bar
613                          return false;
614                  int     nlines = lastOut - ytop + THeight();
615                  if (nlines > ytop)
# Line 791 | Line 814 | RpictSimulManager::RenderFrame(const char *pfname, Ren
814          if (RDTdepthT(dt) == RDTdshort)
815                  fprtresolu(GetWidth(), GetHeight(), pdfp[1]);
816  
817 <        const int       bheight = (psample > 1) ? int(2*psample+.99) : 4;
818 <        const int       vstep =  bheight >> (psample > 1);
817 >        const int       bheight = (psample > 1) ? int(4*psample+.99) : 8;
818 >        const int       vstep = bheight >> (psample > 1);
819  
820          NewBar(bheight);                        // render frame if we can
821          if (!RenderBelow(GetHeight(), vstep, pdfp[0], dt, pdfp[1])) {
# Line 1005 | Line 1028 | RpictSimulManager::ReopenOutput(FILE *pdfp[2], const c
1028          SET_FILE_BINARY(pdfp[1]);
1029          int     n, len = strlen(HDRSTR);
1030          char    buf[32];                // sniff for 16-bit header
1031 <        if (read(fileno(pdfp[1]), buf, len+1) < len+1) {
1031 >        if (getbinary(buf, 1, len+1, pdfp[1]) < len+1) {
1032                  sprintf(errmsg, "empty depth file '%s'", dfname);
1033                  error(SYSTEM, errmsg);
1034                  fclose(pdfp[0]); fclose(pdfp[1]);
# Line 1015 | Line 1038 | RpictSimulManager::ReopenOutput(FILE *pdfp[2], const c
1038          for (n = 0; n < len; n++)
1039                  if (buf[n] != HDRSTR[n])
1040                          break;          // not a Radiance header
1041 <        lseek(fileno(pdfp[1]), 0, SEEK_SET);
1041 >        rewind(pdfp[1]);
1042          if ((n < len) | !isprint(buf[len]))
1043                  return RDTnewDT(dt, RDTdfloat);
1044  
# Line 1154 | Line 1177 | RpictSimulManager::ResumeFrame(const char *pfname, con
1177                  fclose(pdfp[0]); fclose(pdfp[1]);
1178                  return RDTnone;
1179          }
1180 <        int     bheight = (psample > 1) ? int(2*psample+.99) : 4;
1180 >        int     bheight = (psample > 1) ? int(4*psample+.99) : 8;
1181          if (bheight > GetHeight()-doneScans)
1182                  bheight = GetHeight()-doneScans;
1183          int     vstep =  bheight >> (psample > 1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines