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.112 by greg, Sat Jan 6 01:21:34 2024 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 667 | Line 684 | oputr(                         /* print mirrored contribution */
684          RAY  *r
685   )
686   {
687 <        RREAL   cval[3];
671 <
672 <        cval[0] = colval(r->mcol,RED);
673 <        cval[1] = colval(r->mcol,GRN);
674 <        cval[2] = colval(r->mcol,BLU);
675 <        (*putreal)(cval, 3);
687 >        putscolor(r->mcol);
688   }
689  
690  
# Line 691 | Line 703 | oputx(                         /* print unmirrored contribution */
703          RAY  *r
704   )
705   {
706 <        RREAL   cval[3];
706 >        SCOLOR  cdiff;
707  
708 <        cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED);
709 <        cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN);
710 <        cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU);
711 <        (*putreal)(cval, 3);
708 >        copyscolor(cdiff, r->rcol);
709 >        sopscolor(cdiff, -=, r->mcol);
710 >
711 >        putscolor(cdiff);
712   }
713  
714  
# Line 714 | Line 726 | oputv(                         /* print value */
726          RAY  *r
727   )
728   {
729 <        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);
729 >        putscolor(r->rcol);
730   }
731  
732  
# Line 728 | Line 735 | oputV(                         /* print value contribution */
735          RAY *r
736   )
737   {
738 <        RREAL   contr[3];
738 >        SCOLOR  contr;
739  
740          raycontrib(contr, r, PRIMARY);
741 <        multcolor(contr, r->rcol);
742 <        (*putreal)(contr, 3);
741 >        smultscolor(contr, r->rcol);
742 >        putscolor(contr);
743   }
744  
745  
# Line 842 | Line 849 | oputW(                         /* print coefficient */
849          RAY  *r
850   )
851   {
852 <        RREAL   contr[3];
852 >        SCOLOR  contr;
853                                  /* shadow ray not on source? */
854          if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
855 <                setcolor(contr, 0.0, 0.0, 0.0);
855 >                scolorblack(contr);
856          else
857                  raycontrib(contr, r, PRIMARY);
858  
859 <        (*putreal)(contr, 3);
859 >        putscolor(contr);
860   }
861  
862  
# Line 914 | Line 921 | static void
921   putd(RREAL *v, int n)           /* output binary double(s) */
922   {
923   #ifdef  SMLFLT
924 <        double  da[3];
924 >        double  da[MAXCSAMP];
925          int     i;
926  
927 <        if (n > 3)
927 >        if (n > MAXCSAMP)
928                  error(INTERNAL, "code error in putd()");
929          for (i = n; i--; )
930                  da[i] = v[i];
# Line 932 | Line 939 | static void
939   putf(RREAL *v, int n)           /* output binary float(s) */
940   {
941   #ifndef SMLFLT
942 <        float   fa[3];
942 >        float   fa[MAXCSAMP];
943          int     i;
944  
945 <        if (n > 3)
945 >        if (n > MAXCSAMP)
946                  error(INTERNAL, "code error in putf()");
947          for (i = n; i--; )
948                  fa[i] = v[i];
# Line 947 | Line 954 | putf(RREAL *v, int n)          /* output binary float(s) */
954  
955  
956   static void
957 < putrgbe(RREAL *v, int n)        /* output RGBE color */
957 > putscolor(COLORV *scol)         /* output (spectral) color */
958   {
959 <        COLR  cout;
960 <
961 <        if (n != 3)
962 <                error(INTERNAL, "putrgbe() not called with 3 components");
963 <        setcolr(cout, v[0], v[1], v[2]);
964 <        putbinary(cout, sizeof(cout), 1, stdout);
959 >        static COLORMAT xyz2myrgbmat;
960 >        SCOLOR          my_scol;
961 >        COLOR           col;
962 >                                        /* single channel output? */
963 >        if (sens_curve != NULL) {
964 >                RREAL   v = (*sens_curve)(scol) * out_scalefactor;
965 >                (*putreal)(&v, 1);
966 >                return;
967 >        }
968 >        if (out_scalefactor != 1.) {    /* apply scalefactor if any */
969 >                copyscolor(my_scol, scol);
970 >                scalescolor(my_scol, out_scalefactor);
971 >                scol = my_scol;
972 >        }
973 >        if (out_prims == NULL) {        /* full spectral reporting */
974 >                if (outform == 'c') {
975 >                        SCOLR   sclr;
976 >                        scolor_scolr(sclr, scol);
977 >                        putbinary(sclr, LSCOLR, 1, stdout);
978 >                } else if (sizeof(RREAL) != sizeof(COLORV)) {
979 >                        RREAL   sreal[MAXCSAMP];
980 >                        int     i = NCSAMP;
981 >                        while (i--) sreal[i] = scol[i];
982 >                        (*putreal)(sreal, NCSAMP);
983 >                } else
984 >                        (*putreal)((RREAL *)scol, NCSAMP);
985 >                return;
986 >        }
987 >        if (out_prims == xyzprims) {
988 >                scolor_cie(col, scol);
989 >        } else if (out_prims == stdprims) {
990 >                scolor_rgb(col, scol);
991 >        } else {
992 >                COLOR   xyz;
993 >                if (xyz2myrgbmat[0][0] == 0)
994 >                        compxyz2rgbWBmat(xyz2myrgbmat, out_prims);
995 >                scolor_cie(xyz, scol);
996 >                colortrans(col, xyz2myrgbmat, xyz);
997 >                clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite);
998 >        }
999 >        if (outform == 'c') {
1000 >                COLR    clr;
1001 >                setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU));
1002 >                putbinary(clr, sizeof(COLR), 1, stdout);
1003 >        } else if (sizeof(RREAL) != sizeof(COLORV)) {
1004 >                RREAL   creal[3];
1005 >                copycolor(creal, col);
1006 >                (*putreal)(creal, 3);
1007 >        } else
1008 >                (*putreal)((RREAL *)col, 3);
1009   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines