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

Comparing ray/src/rt/rtrace.c (file contents):
Revision 2.103 by greg, Sun Apr 24 15:40:33 2022 UTC vs.
Revision 2.109 by greg, Sat Nov 18 16:24:06 2023 UTC

# Line 45 | Line 45 | extern int  traincl;                   /* include == 1, exclude == 0 *
45   extern int  hresolu;                    /* horizontal resolution */
46   extern int  vresolu;                    /* vertical resolution */
47  
48 < int  castonly = 0;                      /* only doing ray-casting? */
48 > extern int  castonly;                   /* only doing ray-casting? */
49  
50 + extern double  (*sens_curve)(SCOLOR scol);      /* spectral conversion for 1-channel */
51 + extern double  out_scalefactor;         /* output calibration scale factor */
52 + extern RGBPRIMP  out_prims;             /* output color primitives (NULL if spectral) */
53 +
54   #ifndef  MAXTSET
55   #define  MAXTSET        8191            /* maximum number in trace set */
56   #endif
# Line 63 | Line 67 | static int     inp_qpos = 0;           /* next ray to return */
67   static int      inp_qend = 0;           /* number of rays in this work group */
68  
69   typedef void putf_t(RREAL *v, int n);
70 < static putf_t puta, putd, putf, putrgbe;
70 > static putf_t puta, putd, putf;
71  
72   typedef void oputf_t(RAY *r);
73   static oputf_t  oputo, oputd, oputv, oputV, oputl, oputL, oputc, oputp,
# Line 83 | Line 87 | static double nextray(FVECT org, FVECT dir);
87   static void tabin(RAY *r);
88   static void ourtrace(RAY *r);
89  
90 + static void  putscolor(COLORV *scol);
91 +
92   static oputf_t *ray_out[32], *every_out[32];
93   static putf_t *putreal;
94  
# Line 106 | Line 112 | quit(                  /* quit program */
112   }
113  
114  
115 < char *
115 > const char *
116   formstr(                                /* return format identifier */
117          int  f
118   )
# Line 115 | Line 121 | formstr(                               /* return format identifier */
121          case 'a': return("ascii");
122          case 'f': return("float");
123          case 'd': return("double");
124 <        case 'c': return(COLRFMT);
124 >        case 'c':
125 >                if (out_prims == NULL)
126 >                        return(SPECFMT);
127 >                if (out_prims == xyzprims)
128 >                        return(CIEFMT);
129 >                return(COLRFMT);
130          }
131          return("unknown");
132   }
# Line 160 | Line 171 | rtrace(                                /* trace rays from file */
171                                          /* set up output */
172          if (castonly || every_out[0] != NULL)
173                  nproc = 1;              /* don't bother multiprocessing */
174 <        if (Tflag && every_out[0] != NULL)
175 <                trace_sources();        /* asking to trace light sources */
174 >        if (every_out[0] != NULL) {
175 >                trace = ourtrace;       /* enable full tree tracing */
176 >                if (Tflag)              /* light sources, too? */
177 >                        trace_sources();
178 >        }
179          if ((nextflush > 0) & (nproc > nextflush)) {
180                  error(WARNING, "reducing number of processes to match flush interval");
181                  nproc = nextflush;
# Line 225 | Line 239 | setrtoutput(void)                      /* set up output tables, return #c
239   {
240          char  *vs = outvals;
241          oputf_t **table = ray_out;
242 +        const int       nco = (sens_curve != NULL) ? 1 :
243 +                                (out_prims != NULL) ? 3 : NCSAMP;
244          int  ncomp = 0;
245  
246          if (!*vs)
# Line 237 | Line 253 | setrtoutput(void)                      /* set up output tables, return #c
253          case 'c':
254                  if (outvals[1] || !strchr("vrx", outvals[0]))
255                          error(USER, "color format only with -ov, -or, -ox");
256 <                putreal = putrgbe; break;
256 >                if (nco < 3)
257 >                        error(USER, "color format incompatible with -pY, -pS, -pM");
258 >                break;
259          default:
260                  error(CONSISTENCY, "botched output format");
261          }
# Line 251 | Line 269 | setrtoutput(void)                      /* set up output tables, return #c
269                          if (!vs[1]) break;
270                          *table = NULL;
271                          table = every_out;
254                        trace = ourtrace;
272                          castonly = 0;
273                          break;
274                  case 'o':                               /* origin */
# Line 264 | Line 281 | setrtoutput(void)                      /* set up output tables, return #c
281                          break;
282                  case 'r':                               /* reflected contrib. */
283                          *table++ = oputr;
284 <                        ncomp += 3;
284 >                        ncomp += nco;
285                          castonly = 0;
286                          break;
287                  case 'R':                               /* reflected distance */
# Line 274 | Line 291 | setrtoutput(void)                      /* set up output tables, return #c
291                          break;
292                  case 'x':                               /* xmit contrib. */
293                          *table++ = oputx;
294 <                        ncomp += 3;
294 >                        ncomp += nco;
295                          castonly = 0;
296                          break;
297                  case 'X':                               /* xmit distance */
# Line 284 | Line 301 | setrtoutput(void)                      /* set up output tables, return #c
301                          break;
302                  case 'v':                               /* value */
303                          *table++ = oputv;
304 <                        ncomp += 3;
304 >                        ncomp += nco;
305                          castonly = 0;
306                          break;
307                  case 'V':                               /* contribution */
308                          *table++ = oputV;
309 <                        ncomp += 3;
309 >                        ncomp += nco;
310                          castonly = 0;
311                          if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0))
312                                  error(WARNING,
# Line 331 | Line 348 | setrtoutput(void)                      /* set up output tables, return #c
348                          break;
349                  case 'W':                               /* coefficient */
350                          *table++ = oputW;
351 <                        ncomp += 3;
351 >                        ncomp += nco;
352                          castonly = 0;
353                          if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0))
354                                  error(WARNING,
# Line 691 | Line 708 | oputx(                         /* print unmirrored contribution */
708          RAY  *r
709   )
710   {
711 <        RREAL   cval[3];
711 >        SCOLOR  cdiff;
712  
713 <        cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
714 <        cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
715 <        cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
716 <        (*putreal)(cval, 3);
713 >        copyscolor(cdiff, r->rcol);
714 >        sopscolor(cdiff, -=, r->mcol);
715 >
716 >        putscolor(cdiff);
717   }
718  
719  
# Line 714 | Line 731 | oputv(                         /* print value */
731          RAY  *r
732   )
733   {
734 <        RREAL   cval[3];
718 <
719 <        cval[0] = colval(r->rcol,RED);
720 <        cval[1] = colval(r->rcol,GRN);
721 <        cval[2] = colval(r->rcol,BLU);
722 <        (*putreal)(cval, 3);
734 >        putscolor(r->rcol);
735   }
736  
737  
# Line 728 | Line 740 | oputV(                         /* print value contribution */
740          RAY *r
741   )
742   {
743 <        RREAL   contr[3];
743 >        SCOLOR  contr;
744  
745          raycontrib(contr, r, PRIMARY);
746 <        multcolor(contr, r->rcol);
747 <        (*putreal)(contr, 3);
746 >        smultscolor(contr, r->rcol);
747 >        putscolor(contr);
748   }
749  
750  
# Line 842 | Line 854 | oputW(                         /* print coefficient */
854          RAY  *r
855   )
856   {
857 <        RREAL   contr[3];
857 >        SCOLOR  contr;
858                                  /* shadow ray not on source? */
859          if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
860 <                setcolor(contr, 0.0, 0.0, 0.0);
860 >                scolorblack(contr);
861          else
862                  raycontrib(contr, r, PRIMARY);
863  
864 <        (*putreal)(contr, 3);
864 >        putscolor(contr);
865   }
866  
867  
# Line 947 | Line 959 | putf(RREAL *v, int n)          /* output binary float(s) */
959  
960  
961   static void
962 < putrgbe(RREAL *v, int n)        /* output RGBE color */
962 > putscolor(COLORV *scol)         /* output (spectral) color */
963   {
964 <        COLR  cout;
965 <
966 <        if (n != 3)
967 <                error(INTERNAL, "putrgbe() not called with 3 components");
968 <        setcolr(cout, v[0], v[1], v[2]);
969 <        putbinary(cout, sizeof(cout), 1, stdout);
964 >        static COLORMAT xyz2myrgbmat;
965 >        SCOLOR          my_scol;
966 >        COLOR           col;
967 >                                        /* apply scalefactor if any */
968 >        if (out_scalefactor != 1.) {
969 >                copyscolor(my_scol, scol);
970 >                scalescolor(my_scol, out_scalefactor);
971 >                scol = my_scol;
972 >        }
973 >        if (sens_curve != NULL) {       /* single channel output */
974 >                RREAL   v = (*sens_curve)(scol);
975 >                (*putreal)(&v, 1);
976 >                return;
977 >        }
978 >        if (out_prims == NULL) {        /* full spectral reporting */
979 >                if (outform == 'c') {
980 >                        SCOLR   sclr;
981 >                        scolor_scolr(sclr, scol);
982 >                        putbinary(sclr, LSCOLR, 1, stdout);
983 >                } else if (sizeof(RREAL) != sizeof(COLORV)) {
984 >                        RREAL   sreal[MAXCSAMP];
985 >                        int     i = NCSAMP;
986 >                        while (i--) sreal[i] = scol[i];
987 >                        (*putreal)(sreal, NCSAMP);
988 >                } else
989 >                        (*putreal)((RREAL *)scol, NCSAMP);
990 >                return;
991 >        }
992 >        if (out_prims == xyzprims) {
993 >                scolor_cie(col, scol);
994 >        } else if (out_prims == stdprims) {
995 >                scolor_rgb(col, scol);
996 >        } else {
997 >                COLOR   xyz;
998 >                if (xyz2myrgbmat[0][0] == 0)
999 >                        compxyz2rgbWBmat(xyz2myrgbmat, out_prims);
1000 >                scolor_cie(xyz, scol);
1001 >                colortrans(col, xyz2myrgbmat, xyz);
1002 >                clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite);
1003 >        }
1004 >        if (outform == 'c') {
1005 >                COLR    clr;
1006 >                setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU));
1007 >                putbinary(clr, sizeof(COLR), 1, stdout);
1008 >        } else if (sizeof(RREAL) != sizeof(COLORV)) {
1009 >                RREAL   creal[3];
1010 >                copycolor(creal, col);
1011 >                (*putreal)(creal, 3);
1012 >        } else
1013 >                (*putreal)((RREAL *)col, 3);
1014   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines