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.1 by greg, Wed Aug 14 20:05:23 2024 UTC vs.
Revision 2.3 by greg, Sun Aug 18 17:24:48 2024 UTC

# Line 50 | Line 50 | PixelAccess::SetPixel(int x, int y, const RAY *rp)
50                  scolor_out(col, primp, rp->rcol);
51                  return SetPixel(x, y, col, zv);
52          default:
53 <                error(INTERNAL, "missing color space type in SetPixel()");
53 >                error(INTERNAL, "botched color space type in SetPixel()");
54          }
55          return false;
56   }
# Line 79 | Line 79 | PixelAccess::SetColorSpace(RenderDataType cs, RGBPRIMP
79          case RDTrgb:
80                  primp = pr ? pr : stdprims;
81                  break;
82 <        default:                        // RDTscolr | RDTscolor
82 >        case RDTscolr:
83 >        case RDTscolor:
84                  primp = NULL;
85                  break;
86 +        default:
87 +                error(INTERNAL, "botched color space type in SetColorSpace()");
88          }
89          dtyp = RDTnewCT(dtyp, cs);
87        if (primp)
88                xyz2myrgbmat[0][0] = 0;
90          return true;
91   }
92  
# Line 138 | Line 139 | int
139   RpictSimulManager::RtCall(RAY *r, void *cd)
140   {
141          RpictSimulManager *     rsp = (RpictSimulManager *)cd;
142 <        const int               ty = r->rno / rsp->TWidth();
143 <        const int               tx = r->rno - (RNUMBER)ty*rsp->TWidth();
142 >        const int               ty = (r->rno-1) / rsp->TWidth();
143 >        const int               tx = r->rno-1 - (RNUMBER)ty*rsp->TWidth();
144  
145          if (ty >= rsp->THeight()) {
146                  error(INTERNAL, "bad pixel calculation position in RtCall()");
# Line 227 | Line 228 | RpictSimulManager::ComputePixel(int x, int y)
228          for (i = (dlim > FTINY)*3; i--; )
229                  rodir[1][i] *= dlim;
230  
231 <        return EnqueueRay(rodir[0], rodir[1], (RNUMBER)y*TWidth()+x);
231 >        return EnqueueRay(rodir[0], rodir[1], (RNUMBER)y*TWidth()+x+1);
232   }
233  
234   // Check if neighbor differences are below pixel sampling threshold
# Line 261 | Line 262 | RpictSimulManager::BelowSampThresh(int x, int y, const
262  
263   // Fill an interior square patch with interpolated values
264   void
265 < RpictSimulManager::FillSquare(int x, int y, const int noff[4][2])
265 > RpictSimulManager::FillSquare(const int x, const int y, const int noff[4][2])
266   {
267          SCOLOR  pval[4];
268          float   dist[4];
# Line 271 | Line 272 | RpictSimulManager::FillSquare(int x, int y, const int
272                  pacc.GetPixel(x+noff[i][0], y+noff[i][1], pval[i], &dist[i]);
273  
274          i = abs(noff[1][0]-noff[0][0]);
275 <        j = abs(noff[1][1]-noff[0][1]);
276 <        const int       slen =  i > j ? i : j;
276 <        const double    sf = 1./slen;
275 >        j = abs(noff[1][1]-noff[0][1]); // i==j for diamond fill
276 >        const int       slen =  (i > j) ? i : j;
277          const bool      spectr = (pacc.NC() > 3);
278 <        for (i = 0; i <= slen; i++) {   // bilinear interpolant
279 <            const double        c1 = i*sf;
280 <            for (j = 0; j <= slen; j++) {
281 <                const double    c2 = j*sf;
278 >        for (i = slen+1 + (i==j)*slen; i--; ) {
279 >            const double        c1 = (i>slen ? i-slen-.5 : (double)i)/slen;
280 >            for (j = slen + (i<=slen); j--; ) {
281 >                const double    c2 = (j + (i>slen)*.5)/slen;
282                  const int       px = int(x + (1.-c1)*(1.-c2)*noff[0][0] +
283                                                  c1*(1.-c2)*noff[1][0] +
284                                                  (1.-c1)*c2*noff[2][0] +
# Line 331 | Line 331 | static void
331   SetQuincunx(ABitMap2 *bmp2, int noff[4][2], const int spc, const bool odd)
332   {
333          for (int y = 0; y < bmp2->Height(); y += spc>>1)
334 <            for (int x = odd*(spc>>1); x < bmp2->Width(); x += spc)
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) {
# Line 359 | Line 359 | RpictSimulManager::RenderRect()
359          int             sp2 = ceil(log2((TWidth()>THeight() ? TWidth() : THeight()) - 1.));
360          int             layer = 0;
361          int             x, y;
362 < fprintf(stderr, "Rendering %dx%d tile with psample=%d, maxdiff=%.3f ...\n",
363 < TWidth(), THeight(), psample, maxdiff);
362 > // fprintf(stderr, "Rendering %dx%d tile with psample=%d, maxdiff=%.3f ...\n",
363 > // TWidth(), THeight(), psample, maxdiff);
364          while (sp2 > 0) {
365                  ABitMap2        sampMap(TWidth(), THeight());
366                  int             noff[4][2];
# Line 370 | Line 370 | TWidth(), THeight(), psample, maxdiff);
370                  sampMap -= doneSamples; // avoid resampling pixels
371                  // Are we into adaptive sampling realm?
372                  if (noff[0][0]*noff[0][0] + noff[0][1]*noff[0][1] < psample*psample) {
373 <                        if (FlushQueue() < 0)   // need results to check threshold
373 >                        if (FlushQueue() < 0)   // need results to check thresholds
374                                  return false;
375                          ABitMap2        fillMap = sampMap;
376                          for (x = y = 0; sampMap.Find(&x, &y); x++)
# Line 378 | Line 378 | TWidth(), THeight(), psample, maxdiff);
378                                          sampMap.Reset(x, y);
379                                          // spread sampling to neighbors...
380                          const ABitMap2  origSampMap = sampMap;
381 <                        for (int yoff = -(1<<(sp2-1));
382 <                                        yoff <= 1<<(sp2-1); yoff += 1<<sp2)
383 <                            for (int xoff = -(1<<(sp2-1));
384 <                                        xoff <= 1<<(sp2-1); xoff += 1<<sp2) {
381 >                        for (x = 4; x--; ) {
382                                  ABitMap2        stamp = origSampMap;
383 <                                stamp.Shift(xoff, yoff);
383 >                                stamp.Shift(noff[x][0], noff[x][1]);
384                                  sampMap |= stamp;
385                          }               // ...but don't resample what's done
386                          sampMap -= doneSamples;
# Line 397 | Line 394 | TWidth(), THeight(), psample, maxdiff);
394                          if (!ComputePixel(x, y))
395                                  return false;
396                  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()));
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()));
402                  sp2 -= layer++ & 1;     // next denser sampling
403          }
404          if (FlushQueue() < 0)           // make sure we got everyone
# Line 504 | Line 501 | RpictSimulManager::NewBar(int ht)
501  
502   // Shift render bar area the specified amount down the frame
503   bool
504 < RpictSimulManager::LowerBar(int v)
504 > RpictSimulManager::LowerBar(int v, int ytop)
505   {
509        if (v <= 0) return !v;
506          if (!barPix | !barDepth | (v > THeight()) | !tvw.type)
507                  return false;
508 <        tvw.voff -= double(v)/GetHeight();
509 <        ptvw.voff -= double(v)/GetHeight();
508 >        if (v <= 0) return !v;
509 >        if ((ytop -= v) <= 0)
510 >                return true;
511 >        tvw.voff -= double(v)/THeight();
512 >        ptvw.voff -= double(v)/THeight();
513          if (v == THeight()) {
514                  doneMap.ClearBitMap();
515                  return true;
# Line 521 | Line 520 | RpictSimulManager::LowerBar(int v)
520                          sizeof(COLORV)*NC*TWidth()*(THeight()-v));
521          memmove(barDepth, barDepth + TWidth()*v,
522                          sizeof(float)*TWidth()*(THeight()-v));
523 +        if (ytop < THeight()) {                 // mark what we won't do as finished
524 +                doneMap.ClearRect(0, 0, TWidth(), THeight()-ytop, true);
525 +                memset(barPix, 0, sizeof(COLORV)*NC*TWidth()*(THeight()-ytop));
526 +                memset(barDepth, 0, sizeof(float)*TWidth()*(THeight()-ytop));
527 +        }
528          return true;
529   }
530  
# Line 562 | Line 566 | RpictSimulManager::RenderBelow(int ytop, const int vst
566          }
567          int             lastOut = ytop;         // render down frame
568          while (ytop > 0) {
569 <                if (ytop < THeight())           // mark what we won't do as finished
566 <                        doneMap.ClearRect(0, 0, TWidth(), THeight()-ytop, true);
569 > // fprintf(stderr, "At y=%d, source drawing %s...\n", ytop, parr ? "ON" : "OFF");
570                  if (prCB)
571                          (*prCB)(100.*(GetHeight()-ytop)/GetHeight());
572                  if (!RenderRect())              // render this bar
# Line 605 | Line 608 | RpictSimulManager::RenderBelow(int ytop, const int vst
608                                          error(SYSTEM, "cannot write SCOLOR output");
609                                  break;
610                          default:
611 <                                error(INTERNAL, "missing output color type in RenderBelow()");
611 >                                error(INTERNAL, "botched output color type in RenderBelow()");
612                                  break;
613                          }
614                          bpos += pacc.NC()*TWidth();
# Line 614 | Line 617 | RpictSimulManager::RenderBelow(int ytop, const int vst
617                  if (fflush(pfp) == EOF || (dfp && fflush(dfp) == EOF))
618                          error(SYSTEM, "output write error");
619                                                  // advance down the frame
620 <                if (lastOut > 0 && !LowerBar(vstep))
620 >                if (lastOut > 0 && !LowerBar(vstep, ytop))
621                          return false;
622                  ytop -= vstep;
623          }
# Line 629 | Line 632 | RpictSimulManager::RenderBelow(int ytop, const int vst
632   * Render and write a frame to the named file
633   * Include any header lines set prior to call
634   * Picture file must not already exist
635 < * Picture to stdout if pfname==NULL
636 < * Depth written to a command if dfname[0]=='!'
635 > * Write pixels to stdout if !pfname
636 > * Write depth to a command if dfname[0]=='!'
637   */
638   RenderDataType
639   RpictSimulManager::RenderFrame(const char *pfname, RenderDataType dt, const char *dfname)
# Line 640 | Line 643 | RpictSimulManager::RenderFrame(const char *pfname, Ren
643          FILE *  dfp = NULL;
644  
645          if (!RDTcolorT(dt))
646 <                error(INTERNAL, "missing pixel output type in RenderFrame()");
646 >                error(INTERNAL, "botched color output type in RenderFrame()");
647          if (NCSAMP == 3) {
648                  if (RDTcolorT(dt) == RDTscolr)
649                          dt = RDTnewCT(dt, prims==xyzprims ? RDTxyze : RDTrgbe);
# Line 676 | Line 679 | RpictSimulManager::RenderFrame(const char *pfname, Ren
679          if (frameNo > 0)
680                  fprintf(pfp, "FRAME=%d\n", frameNo);
681          double  pasp = viewaspect(&vw) * GetWidth() / GetHeight();
682 <        if (!FABSEQ(pasp, 1.0))
682 >        if ((0.99 > pasp) | (pasp > 1.01))
683                  fputaspect(pasp, pfp);
684          fputnow(pfp);
685          switch (RDTcolorT(dt)) {                // set primaries and picture format

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines