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

Comparing ray/src/rt/rxtrace.cpp (file contents):
Revision 2.1 by greg, Mon Aug 21 22:39:05 2023 UTC vs.
Revision 2.5 by greg, Thu May 2 22:10:43 2024 UTC

# Line 39 | Line 39 | extern int  vresolu;                   /* vertical resolution */
39  
40   extern int  castonly;                   /* only doing ray-casting? */
41  
42 + extern double  (*sens_curve)(SCOLOR scol);      /* spectral conversion for 1-channel */
43 + extern double  out_scalefactor;         /* output calibration scale factor */
44 + extern RGBPRIMP  out_prims;             /* output color primitives (NULL if spectral) */
45 +
46   #ifndef  MAXTSET
47   #define  MAXTSET        8191            /* maximum number in trace set */
48   #endif
# Line 66 | Line 70 | static void tabin(RAY *r);
70   static RayReportCall ourtrace;
71   static RayReportCall printvals;
72  
73 + static void  putscolor(COLORV *scol);
74 +
75   static oputf_t *ray_out[32], *every_out[32];
76   static putf_t *putreal;
77  
# Line 74 | Line 80 | quit(                  /* quit program */
80          int  code
81   )
82   {
83 +        if (ray_pnprocs < 0)
84 +                _exit(code);            /* avoid flush in child */
85 +
86          int     ec = myRTmanager.Cleanup();
87  
88          if (ec) code = ec;
# Line 90 | Line 99 | formstr(                               /* return format identifier */
99          case 'a': return("ascii");
100          case 'f': return("float");
101          case 'd': return("double");
102 <        case 'c': return(COLRFMT);
102 >        case 'c':
103 >                if (out_prims == NULL)
104 >                        return(SPECFMT);
105 >                if (out_prims == xyzprims)
106 >                        return(CIEFMT);
107 >                return(COLRFMT);
108          }
109          return("unknown");
110   }
# Line 181 | Line 195 | rtrace(                                /* trace rays from stdin or file */
195                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
196                  error(SYSTEM, errmsg);
197          }
184 #ifdef getc_unlocked
185        flockfile(inpfp);               /* avoid lock/unlock overhead */
186 #endif
198          if (inform != 'a')
199                  SET_FILE_BINARY(inpfp);
200                                          /* set up output */
201 <        if (castonly || every_out[0] != NULL)
201 >        if (castonly || every_out[0] != NULL) {
202                  nproc = 1;              /* don't bother multiprocessing */
203 <        else if (nproc <= 0)            // need to get default for system?
204 <                nproc = myRTmanager.GetNCores();
203 >        } else if (nproc <= 0) {        // need to get default for system?
204 >                nproc = myRTmanager.GetNCores() + nproc;
205 >                if (nproc <= 0) nproc = 1;
206 >        }
207          if ((flushIntvl > 0) & (nproc > flushIntvl)) {
208                  error(WARNING, "reducing number of processes to match flush interval");
209                  nproc = flushIntvl;
# Line 201 | Line 214 | rtrace(                                /* trace rays from stdin or file */
214          if (every_out[0])
215                  myRTmanager.SetTraceCall(ourtrace);
216          myRTmanager.rtFlags |= RTdoFIFO;
217 + #ifdef getc_unlocked
218 +        flockfile(inpfp);               /* avoid lock/unlock overhead */
219 +        flockfile(stdout);
220 + #endif
221          if (hresolu > 0) {              // print resolution string if appropriate
222                  if (vresolu > 0)
223                          fprtresolu(hresolu, vresolu, stdout);
# Line 219 | Line 236 | rtrace(                                /* trace rays from stdin or file */
236                  pending |= (n > 1);     // time to flush output?
237                  bool    atZero = IsZeroVec(ivbuf[2*n-1]);
238                  if (pending & (atZero | (n == flushIntvl))) {
239 <                        if (!myRTmanager.FlushQueue())
239 >                        if (myRTmanager.FlushQueue() <= 0)
240                                  error(USER, "ray flush error");
241                          fflush(stdout);
242                          pending = false;
# Line 233 | Line 250 | rtrace(                                /* trace rays from stdin or file */
250          if (vcount)
251                  error(WARNING, feof(inpfp) ? "unexpected EOF on input" :
252                                  "input read error");
253 <        if (fflush(stdout) < 0)
254 <                error(SYSTEM, "write error");
253 >        if (myRTmanager.FlushQueue() < 0 || fflush(stdout) < 0)
254 >                error(SYSTEM, "final flush error");
255          if (fname != NULL) {
256                  fclose(inpfp);
257                  inpfp = NULL;
# Line 247 | Line 264 | setrtoutput(const char *outvals)       /* set up output tabl
264   {
265          const char  *vs = outvals;
266          oputf_t **table = ray_out;
267 +        const int       nco = (sens_curve != NULL) ? 1 :
268 +                                (out_prims != NULL) ? 3 : NCSAMP;
269          int  ncomp = 0;
270  
271          if (!*vs)
# Line 285 | Line 304 | setrtoutput(const char *outvals)       /* set up output tabl
304                          break;
305                  case 'r':                               /* reflected contrib. */
306                          *table++ = oputr;
307 <                        ncomp += 3;
307 >                        ncomp += nco;
308                          castonly = 0;
309                          break;
310                  case 'R':                               /* reflected distance */
# Line 295 | Line 314 | setrtoutput(const char *outvals)       /* set up output tabl
314                          break;
315                  case 'x':                               /* xmit contrib. */
316                          *table++ = oputx;
317 <                        ncomp += 3;
317 >                        ncomp += nco;
318                          castonly = 0;
319                          break;
320                  case 'X':                               /* xmit distance */
# Line 305 | Line 324 | setrtoutput(const char *outvals)       /* set up output tabl
324                          break;
325                  case 'v':                               /* value */
326                          *table++ = oputv;
327 <                        ncomp += 3;
327 >                        ncomp += nco;
328                          castonly = 0;
329                          break;
330                  case 'V':                               /* contribution */
331                          *table++ = oputV;
332 <                        ncomp += 3;
332 >                        ncomp += nco;
333                          castonly = 0;
334                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
335                                  error(WARNING,
# Line 352 | Line 371 | setrtoutput(const char *outvals)       /* set up output tabl
371                          break;
372                  case 'W':                               /* coefficient */
373                          *table++ = oputW;
374 <                        ncomp += 3;
374 >                        ncomp += nco;
375                          castonly = 0;
376                          if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0))
377                                  error(WARNING,
# Line 392 | Line 411 | setrtoutput(const char *outvals)       /* set up output tabl
411          return(ncomp);
412   }
413  
414 < static void
414 > static int
415   printvals(                      /* print requested ray values */
416          RAY  *r, void *cd
417   )
# Line 400 | Line 419 | printvals(                     /* print requested ray values */
419          oputf_t **tp;
420  
421          if (ray_out[0] == NULL)
422 <                return;
404 < #ifdef getc_unlocked
405 <        flockfile(stdout);
406 < #endif
422 >                return 0;
423          for (tp = ray_out; *tp != NULL; tp++)
424                  (**tp)(r);
425          if (outform == 'a')
426                  putchar('\n');
427 < #ifdef getc_unlocked
412 <        funlockfile(stdout);
413 < #endif
427 >        return 1;
428   }
429  
430   void
# Line 441 | Line 455 | tranotify(                     /* record new modifier */
455                  }
456   }
457  
458 < static void
458 > static int
459   ourtrace(                               /* print ray values */
460          RAY  *r, void *cd
461   )
# Line 449 | Line 463 | ourtrace(                              /* print ray values */
463          oputf_t **tp;
464  
465          if (every_out[0] == NULL)
466 <                return;
466 >                return 0;
467          if (r->ro == NULL) {
468                  if (traincl == 1)
469 <                        return;
469 >                        return 0;
470          } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
471 <                return;
458 < #ifdef getc_unlocked
459 <        flockfile(stdout);
460 < #endif
471 >                return 0;
472          tabin(r);
473          for (tp = every_out; *tp != NULL; tp++)
474                  (**tp)(r);
475          if (outform == 'a')
476                  putchar('\n');
477 < #ifdef getc_unlocked
467 <        funlockfile(stdout);
468 < #endif
477 >        return 1;
478   }
479  
480   static void
# Line 500 | Line 509 | oputr(                         /* print mirrored contribution */
509          RAY  *r
510   )
511   {
512 <        RREAL   cval[3];
504 <
505 <        cval[0] = colval(r->mcol,RED);
506 <        cval[1] = colval(r->mcol,GRN);
507 <        cval[2] = colval(r->mcol,BLU);
508 <        (*putreal)(cval, 3);
512 >        putscolor(r->mcol);
513   }
514  
515   static void
# Line 521 | Line 525 | oputx(                         /* print unmirrored contribution */
525          RAY  *r
526   )
527   {
528 <        RREAL   cval[3];
528 >        SCOLOR  cdiff;
529  
530 <        cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
531 <        cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
532 <        cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
533 <        (*putreal)(cval, 3);
530 >        copyscolor(cdiff, r->rcol);
531 >        sopscolor(cdiff, -=, r->mcol);
532 >
533 >        putscolor(cdiff);
534   }
535  
536   static void
# Line 542 | Line 546 | oputv(                         /* print value */
546          RAY  *r
547   )
548   {
549 <        RREAL   cval[3];
546 <
547 <        cval[0] = colval(r->rcol,RED);
548 <        cval[1] = colval(r->rcol,GRN);
549 <        cval[2] = colval(r->rcol,BLU);
550 <        (*putreal)(cval, 3);
549 >        putscolor(r->rcol);
550   }
551  
552   static void
# Line 555 | Line 554 | oputV(                         /* print value contribution */
554          RAY *r
555   )
556   {
557 <        RREAL   contr[3];
557 >        SCOLOR  contr;
558  
559          raycontrib(contr, r, PRIMARY);
560 <        multcolor(contr, r->rcol);
561 <        (*putreal)(contr, 3);
560 >        smultscolor(contr, r->rcol);
561 >        putscolor(contr);
562   }
563  
564   static void
# Line 659 | Line 658 | oputW(                         /* print coefficient */
658          RAY  *r
659   )
660   {
661 <        RREAL   contr[3];
661 >        SCOLOR  contr;
662                                  /* shadow ray not on source? */
663          if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
664 <                setcolor(contr, 0.0, 0.0, 0.0);
664 >                scolorblack(contr);
665          else
666                  raycontrib(contr, r, PRIMARY);
667  
668 <        (*putreal)(contr, 3);
668 >        putscolor(contr);
669   }
670  
671   static void
# Line 765 | Line 764 | putrgbe(RREAL *v, int n)       /* output RGBE color */
764                  error(INTERNAL, "putrgbe() not called with 3 components");
765          setcolr(cout, v[0], v[1], v[2]);
766          putbinary(cout, sizeof(cout), 1, stdout);
767 + }
768 +
769 + static void
770 + putscolor(COLORV *scol)         /* output (spectral) color */
771 + {
772 +        static COLORMAT xyz2myrgbmat;
773 +        SCOLOR          my_scol;
774 +        COLOR           col;
775 +                                        /* single channel output? */
776 +        if (sens_curve != NULL) {
777 +                RREAL   v = (*sens_curve)(scol) * out_scalefactor;
778 +                (*putreal)(&v, 1);
779 +                return;
780 +        }
781 +        if (out_scalefactor != 1.) {    /* apply scalefactor if any */
782 +                copyscolor(my_scol, scol);
783 +                scalescolor(my_scol, out_scalefactor);
784 +                scol = my_scol;
785 +        }
786 +        if (out_prims == NULL) {        /* full spectral reporting */
787 +                if (outform == 'c') {
788 +                        SCOLR   sclr;
789 +                        scolor_scolr(sclr, scol);
790 +                        putbinary(sclr, LSCOLR, 1, stdout);
791 +                } else if (sizeof(RREAL) != sizeof(COLORV)) {
792 +                        RREAL   sreal[MAXCSAMP];
793 +                        int     i = NCSAMP;
794 +                        while (i--) sreal[i] = scol[i];
795 +                        (*putreal)(sreal, NCSAMP);
796 +                } else
797 +                        (*putreal)((RREAL *)scol, NCSAMP);
798 +                return;
799 +        }
800 +        if (out_prims == xyzprims) {
801 +                scolor_cie(col, scol);
802 +        } else if (out_prims == stdprims) {
803 +                scolor_rgb(col, scol);
804 +        } else {
805 +                COLOR   xyz;
806 +                if (xyz2myrgbmat[0][0] == 0)
807 +                        compxyz2rgbWBmat(xyz2myrgbmat, out_prims);
808 +                scolor_cie(xyz, scol);
809 +                colortrans(col, xyz2myrgbmat, xyz);
810 +                clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite);
811 +        }
812 +        if (outform == 'c') {
813 +                COLR    clr;
814 +                setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU));
815 +                putbinary(clr, sizeof(COLR), 1, stdout);
816 +        } else if (sizeof(RREAL) != sizeof(COLORV)) {
817 +                RREAL   creal[3];
818 +                copycolor(creal, col);
819 +                (*putreal)(creal, 3);
820 +        } else
821 +                (*putreal)((RREAL *)col, 3);
822   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines