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.2 by greg, Tue Mar 12 16:54:51 2024 UTC vs.
Revision 2.9 by greg, Thu Jan 2 02:59:15 2025 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 64 | Line 68 | static oputf_t  oputo, oputd, oputv, oputV, oputl, opu
68   extern void tranotify(OBJECT obj);
69   static void tabin(RAY *r);
70   static RayReportCall ourtrace;
67 static RayReportCall printvals;
71  
72 + RayReportCall printvals;                /* print selected ray values */
73 +
74 + void  putscolor(COLORV *scol, double sf = 1.);          /* convert/print spectral color */
75 +
76   static oputf_t *ray_out[32], *every_out[32];
70 static putf_t *putreal;
77  
78 + putf_t *putreal;                        /* put out real vector */
79 +
80   void
81   quit(                   /* quit program */
82          int  code
83   )
84   {
85 <        int     ec = myRTmanager.Cleanup();
85 >        if (ray_pnprocs < 0)
86 >                _exit(code);            /* avoid flush in child */
87  
88 <        if (ec) code = ec;
88 >        if (ray_pnprocs > 1)
89 >                myRTmanager.SetThreadCount(1);
90  
91          exit(code);
92   }
# Line 90 | Line 100 | formstr(                               /* return format identifier */
100          case 'a': return("ascii");
101          case 'f': return("float");
102          case 'd': return("double");
103 <        case 'c': return(COLRFMT);
103 >        case 'c':
104 >                if (out_prims == NULL)
105 >                        return(SPECFMT);
106 >                if (out_prims == xyzprims)
107 >                        return(CIEFMT);
108 >                return(COLRFMT);
109          }
110          return("unknown");
111   }
# Line 181 | Line 196 | rtrace(                                /* trace rays from stdin or file */
196                  sprintf(errmsg, "cannot open input file \"%s\"", fname);
197                  error(SYSTEM, errmsg);
198          }
184 #ifdef getc_unlocked
185        flockfile(inpfp);               /* avoid lock/unlock overhead */
186 #endif
199          if (inform != 'a')
200                  SET_FILE_BINARY(inpfp);
201                                          /* set up output */
# Line 203 | Line 215 | rtrace(                                /* trace rays from stdin or file */
215          if (every_out[0])
216                  myRTmanager.SetTraceCall(ourtrace);
217          myRTmanager.rtFlags |= RTdoFIFO;
218 + #ifdef getc_unlocked
219 +        flockfile(inpfp);               /* avoid lock/unlock overhead */
220 +        flockfile(stdout);
221 + #endif
222          if (hresolu > 0) {              // print resolution string if appropriate
223                  if (vresolu > 0)
224                          fprtresolu(hresolu, vresolu, stdout);
# Line 221 | Line 237 | rtrace(                                /* trace rays from stdin or file */
237                  pending |= (n > 1);     // time to flush output?
238                  bool    atZero = IsZeroVec(ivbuf[2*n-1]);
239                  if (pending & (atZero | (n == flushIntvl))) {
240 <                        if (!myRTmanager.FlushQueue())
240 >                        if (myRTmanager.FlushQueue() <= 0)
241                                  error(USER, "ray flush error");
242                          fflush(stdout);
243                          pending = false;
# Line 235 | Line 251 | rtrace(                                /* trace rays from stdin or file */
251          if (vcount)
252                  error(WARNING, feof(inpfp) ? "unexpected EOF on input" :
253                                  "input read error");
254 <        if (fflush(stdout) < 0)
255 <                error(SYSTEM, "write error");
254 >        if (myRTmanager.FlushQueue() < 0 || fflush(stdout) < 0)
255 >                error(SYSTEM, "final flush error");
256          if (fname != NULL) {
257                  fclose(inpfp);
258                  inpfp = NULL;
# Line 249 | Line 265 | setrtoutput(const char *outvals)       /* set up output tabl
265   {
266          const char  *vs = outvals;
267          oputf_t **table = ray_out;
268 +        const int       nco = (sens_curve != NULL) ? 1 :
269 +                                (out_prims != NULL) ? 3 : NCSAMP;
270          int  ncomp = 0;
271  
272          if (!*vs)
# Line 287 | Line 305 | setrtoutput(const char *outvals)       /* set up output tabl
305                          break;
306                  case 'r':                               /* reflected contrib. */
307                          *table++ = oputr;
308 <                        ncomp += 3;
308 >                        ncomp += nco;
309                          castonly = 0;
310                          break;
311                  case 'R':                               /* reflected distance */
# Line 297 | Line 315 | setrtoutput(const char *outvals)       /* set up output tabl
315                          break;
316                  case 'x':                               /* xmit contrib. */
317                          *table++ = oputx;
318 <                        ncomp += 3;
318 >                        ncomp += nco;
319                          castonly = 0;
320                          break;
321                  case 'X':                               /* xmit distance */
# Line 307 | Line 325 | setrtoutput(const char *outvals)       /* set up output tabl
325                          break;
326                  case 'v':                               /* value */
327                          *table++ = oputv;
328 <                        ncomp += 3;
328 >                        ncomp += nco;
329                          castonly = 0;
330                          break;
331                  case 'V':                               /* contribution */
332                          *table++ = oputV;
333 <                        ncomp += 3;
333 >                        ncomp += nco;
334                          castonly = 0;
335                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
336                                  error(WARNING,
# Line 354 | Line 372 | setrtoutput(const char *outvals)       /* set up output tabl
372                          break;
373                  case 'W':                               /* coefficient */
374                          *table++ = oputW;
375 <                        ncomp += 3;
375 >                        ncomp += nco;
376                          castonly = 0;
377                          if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0))
378                                  error(WARNING,
# Line 394 | Line 412 | setrtoutput(const char *outvals)       /* set up output tabl
412          return(ncomp);
413   }
414  
415 < static void
415 > int
416   printvals(                      /* print requested ray values */
417          RAY  *r, void *cd
418   )
# Line 402 | Line 420 | printvals(                     /* print requested ray values */
420          oputf_t **tp;
421  
422          if (ray_out[0] == NULL)
423 <                return;
406 < #ifdef getc_unlocked
407 <        flockfile(stdout);
408 < #endif
423 >                return 0;
424          for (tp = ray_out; *tp != NULL; tp++)
425                  (**tp)(r);
426          if (outform == 'a')
427                  putchar('\n');
428 < #ifdef getc_unlocked
414 <        funlockfile(stdout);
415 < #endif
428 >        return 1;
429   }
430  
431   void
# Line 443 | Line 456 | tranotify(                     /* record new modifier */
456                  }
457   }
458  
459 < static void
459 > static int
460   ourtrace(                               /* print ray values */
461          RAY  *r, void *cd
462   )
# Line 451 | Line 464 | ourtrace(                              /* print ray values */
464          oputf_t **tp;
465  
466          if (every_out[0] == NULL)
467 <                return;
467 >                return 0;
468          if (r->ro == NULL) {
469                  if (traincl == 1)
470 <                        return;
470 >                        return 0;
471          } else if (traincl != -1 && traincl != inset(traset, r->ro->omod))
472 <                return;
460 < #ifdef getc_unlocked
461 <        flockfile(stdout);
462 < #endif
472 >                return 0;
473          tabin(r);
474          for (tp = every_out; *tp != NULL; tp++)
475                  (**tp)(r);
476          if (outform == 'a')
477                  putchar('\n');
478 < #ifdef getc_unlocked
469 <        funlockfile(stdout);
470 < #endif
478 >        return 1;
479   }
480  
481   static void
# Line 502 | Line 510 | oputr(                         /* print mirrored contribution */
510          RAY  *r
511   )
512   {
513 <        RREAL   cval[3];
506 <
507 <        cval[0] = colval(r->mcol,RED);
508 <        cval[1] = colval(r->mcol,GRN);
509 <        cval[2] = colval(r->mcol,BLU);
510 <        (*putreal)(cval, 3);
513 >        putscolor(r->mcol, out_scalefactor);
514   }
515  
516   static void
# Line 523 | Line 526 | oputx(                         /* print unmirrored contribution */
526          RAY  *r
527   )
528   {
529 <        RREAL   cval[3];
529 >        SCOLOR  cdiff;
530  
531 <        cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
532 <        cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
533 <        cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
534 <        (*putreal)(cval, 3);
531 >        copyscolor(cdiff, r->rcol);
532 >        sopscolor(cdiff, -=, r->mcol);
533 >
534 >        putscolor(cdiff, out_scalefactor);
535   }
536  
537   static void
# Line 544 | Line 547 | oputv(                         /* print value */
547          RAY  *r
548   )
549   {
550 <        RREAL   cval[3];
548 <
549 <        cval[0] = colval(r->rcol,RED);
550 <        cval[1] = colval(r->rcol,GRN);
551 <        cval[2] = colval(r->rcol,BLU);
552 <        (*putreal)(cval, 3);
550 >        putscolor(r->rcol, out_scalefactor);
551   }
552  
553   static void
# Line 557 | Line 555 | oputV(                         /* print value contribution */
555          RAY *r
556   )
557   {
558 <        RREAL   contr[3];
558 >        SCOLOR  contr;
559  
560          raycontrib(contr, r, PRIMARY);
561 <        multcolor(contr, r->rcol);
562 <        (*putreal)(contr, 3);
561 >        smultscolor(contr, r->rcol);
562 >        putscolor(contr, out_scalefactor);
563   }
564  
565   static void
# Line 661 | Line 659 | oputW(                         /* print coefficient */
659          RAY  *r
660   )
661   {
662 <        RREAL   contr[3];
662 >        SCOLOR  contr;
663                                  /* shadow ray not on source? */
664          if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
665 <                setcolor(contr, 0.0, 0.0, 0.0);
665 >                scolorblack(contr);
666          else
667                  raycontrib(contr, r, PRIMARY);
668  
669 <        (*putreal)(contr, 3);
669 >        putscolor(contr);
670   }
671  
672   static void
# Line 767 | Line 765 | putrgbe(RREAL *v, int n)       /* output RGBE color */
765                  error(INTERNAL, "putrgbe() not called with 3 components");
766          setcolr(cout, v[0], v[1], v[2]);
767          putbinary(cout, sizeof(cout), 1, stdout);
768 + }
769 +
770 + void
771 + putscolor(COLORV *scol, double sf)              /* output (spectral) color */
772 + {
773 +        static COLORMAT xyz2myrgbmat;
774 +        SCOLOR          my_scol;
775 +        COLOR           col;
776 +                                        /* single channel output? */
777 +        if (sens_curve != NULL) {
778 +                RREAL   v = (*sens_curve)(scol) * sf;
779 +                (*putreal)(&v, 1);
780 +                return;
781 +        }
782 +        if (sf != 1.) {                 /* apply scalefactor if any */
783 +                copyscolor(my_scol, scol);
784 +                scalescolor(my_scol, sf);
785 +                scol = my_scol;
786 +        }
787 +        if (out_prims == NULL) {        /* full spectral reporting */
788 +                if (outform == 'c') {
789 +                        SCOLR   sclr;
790 +                        scolor_scolr(sclr, scol);
791 +                        putbinary(sclr, LSCOLR, 1, stdout);
792 +                } else if (sizeof(RREAL) != sizeof(COLORV)) {
793 +                        RREAL   sreal[MAXCSAMP];
794 +                        int     i = NCSAMP;
795 +                        while (i--) sreal[i] = scol[i];
796 +                        (*putreal)(sreal, NCSAMP);
797 +                } else
798 +                        (*putreal)((RREAL *)scol, NCSAMP);
799 +                return;
800 +        }
801 +        if (out_prims == xyzprims) {
802 +                scolor_cie(col, scol);
803 +        } else if (out_prims == stdprims) {
804 +                scolor_rgb(col, scol);
805 +        } else {
806 +                COLOR   xyz;
807 +                if (xyz2myrgbmat[0][0] == 0)
808 +                        compxyz2rgbWBmat(xyz2myrgbmat, out_prims);
809 +                scolor_cie(xyz, scol);
810 +                colortrans(col, xyz2myrgbmat, xyz);
811 +                clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite);
812 +        }
813 +        if (outform == 'c') {
814 +                COLR    clr;
815 +                setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU));
816 +                putbinary(clr, sizeof(COLR), 1, stdout);
817 +        } else if (sizeof(RREAL) != sizeof(COLORV)) {
818 +                RREAL   creal[3];
819 +                copycolor(creal, col);
820 +                (*putreal)(creal, 3);
821 +        } else
822 +                (*putreal)((RREAL *)col, 3);
823   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines