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.97 by greg, Mon Jun 15 20:27:42 2020 UTC vs.
Revision 2.111 by greg, Mon Dec 11 18:54:42 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
57   OBJECT  traset[MAXTSET+1]={0};          /* trace include/exclude set */
58  
59 + static int  Tflag = 0;                  /* source tracing enabled? */
60 +
61   static RAY  thisray;                    /* for our convenience */
62  
63   static FILE  *inpfp = NULL;             /* input stream pointer */
# Line 61 | 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 81 | 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 92 | Line 100 | quit(                  /* quit program */
100   {
101          if (ray_pnprocs > 0)    /* close children if any */
102                  ray_pclose(0);          
103 +        else if (ray_pnprocs < 0)
104 +                _exit(code);    /* avoid flush() in child */
105   #ifndef  NON_POSIX
106 <        else if (!ray_pnprocs) {
106 >        else {
107                  headclean();    /* delete header file */
108                  pfclean();      /* clean up persist files */
109          }
# Line 102 | Line 112 | quit(                  /* quit program */
112   }
113  
114  
115 < char *
115 > const char *
116   formstr(                                /* return format identifier */
117          int  f
118   )
# Line 111 | 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   }
133  
134  
135 + static void
136 + trace_sources(void)                     /* trace rays to light sources, also */
137 + {
138 +        int     sn;
139 +
140 +        for (sn = 0; sn < nsources; sn++)
141 +                source[sn].sflags |= SFOLLOW;
142 + }
143 +
144 +
145   void
146   rtrace(                         /* trace rays from file */
147          char  *fname,
# Line 146 | 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 (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;
182          }
153        switch (outform) {
154        case 'a': putreal = puta; break;
155        case 'f': putreal = putf; break;
156        case 'd': putreal = putd; break;
157        case 'c':
158                if (outvals[1] || !strchr("vrx", outvals[0]))
159                        error(USER, "color format only with -ov, -or, -ox");
160                putreal = putrgbe; break;
161        default:
162                error(CONSISTENCY, "botched output format");
163        }
183          if (nproc > 1) {                /* start multiprocessing */
184                  ray_popen(nproc);
185                  ray_fifo_out = printvals;
167                ray_pnbatch = !nextflush;
186          }
187          if (hresolu > 0) {
188                  if (vresolu > 0)
# Line 216 | Line 234 | rtrace(                                /* trace rays from file */
234   }
235  
236  
219 static void
220 trace_sources(void)                     /* trace rays to light sources, also */
221 {
222        int     sn;
223        
224        for (sn = 0; sn < nsources; sn++)
225                source[sn].sflags |= SFOLLOW;
226 }
227
228
237   int
238   setrtoutput(void)                       /* set up output tables, return #comp */
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)
247                  error(USER, "empty output specification");
248  
249 +        switch (outform) {      /* make sure (*putreal)() calls someone! */
250 +        case 'a': putreal = puta; break;
251 +        case 'f': putreal = putf; break;
252 +        case 'd': putreal = putd; break;
253 +        case 'c':
254 +                if (outvals[1] || !strchr("vrx", outvals[0]))
255 +                        error(USER, "color format only with -ov, -or, -ox");
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 +        }
262          castonly = 1;                   /* sets castonly as side-effect */
263          do
264                  switch (*vs) {
265                  case 'T':                               /* trace sources */
266 <                        if (!vs[1]) break;
244 <                        trace_sources();
266 >                        Tflag++;
267                          /* fall through */
268                  case 't':                               /* trace */
269                          if (!vs[1]) break;
270                          *table = NULL;
271                          table = every_out;
250                        trace = ourtrace;
272                          castonly = 0;
273                          break;
274                  case 'o':                               /* origin */
# Line 260 | 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 270 | 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 280 | 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 327 | 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 419 | Line 440 | rtcompute(                     /* compute and print ray value(s) */
440   )
441   {
442                                          /* set up ray */
422        rayorigin(&thisray, PRIMARY, NULL, NULL);
443          if (imm_irrad) {
444                  VSUM(thisray.rorg, org, dir, 1.1e-4);
445                  thisray.rdir[0] = -dir[0];
446                  thisray.rdir[1] = -dir[1];
447                  thisray.rdir[2] = -dir[2];
448                  thisray.rmax = 0.0;
429                thisray.revf = rayirrad;
449          } else {
450                  VCOPY(thisray.rorg, org);
451                  VCOPY(thisray.rdir, dir);
452                  thisray.rmax = dmax;
434                if (castonly)
435                        thisray.revf = raycast;
453          }
454 +        rayorigin(&thisray, PRIMARY, NULL, NULL);
455 +        if (imm_irrad)
456 +                thisray.revf = rayirrad;
457 +        else if (castonly)
458 +                thisray.revf = raycast;
459          if (ray_pnprocs > 1) {          /* multiprocessing FIFO? */
460                  if (ray_fifo_in(&thisray) < 0)
461                          error(USER, "lost children");
# Line 662 | Line 684 | oputr(                         /* print mirrored contribution */
684          RAY  *r
685   )
686   {
687 <        RREAL   cval[3];
666 <
667 <        cval[0] = colval(r->mcol,RED);
668 <        cval[1] = colval(r->mcol,GRN);
669 <        cval[2] = colval(r->mcol,BLU);
670 <        (*putreal)(cval, 3);
687 >        putscolor(r->mcol);
688   }
689  
690  
# Line 686 | 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 709 | Line 726 | oputv(                         /* print value */
726          RAY  *r
727   )
728   {
729 <        RREAL   cval[3];
713 <
714 <        cval[0] = colval(r->rcol,RED);
715 <        cval[1] = colval(r->rcol,GRN);
716 <        cval[2] = colval(r->rcol,BLU);
717 <        (*putreal)(cval, 3);
729 >        putscolor(r->rcol);
730   }
731  
732  
# Line 723 | 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 764 | Line 776 | static RREAL   vdummy[3] = {0.0, 0.0, 0.0};
776  
777  
778   static void
779 < oputp(                          /* print point */
779 > oputp(                          /* print intersection point */
780          RAY  *r
781   )
782   {
783 <        if (r->rot < FHUGE*.99)
772 <                (*putreal)(r->rop, 3);
773 <        else
774 <                (*putreal)(vdummy, 3);
783 >        (*putreal)(r->rop, 3);  /* set to ray origin if distant or no hit */
784   }
785  
786  
# Line 780 | Line 789 | oputN(                         /* print unperturbed normal */
789          RAY  *r
790   )
791   {
792 <        if (r->rot < FHUGE*.99) {
784 <                if (r->rflips & 1) {    /* undo any flippin' flips */
785 <                        FVECT   unrm;
786 <                        unrm[0] = -r->ron[0];
787 <                        unrm[1] = -r->ron[1];
788 <                        unrm[2] = -r->ron[2];
789 <                        (*putreal)(unrm, 3);
790 <                } else
791 <                        (*putreal)(r->ron, 3);
792 <        } else
792 >        if (r->ro == NULL) {    /* zero vector if clipped or no hit */
793                  (*putreal)(vdummy, 3);
794 +                return;
795 +        }
796 +        if (r->rflips & 1) {    /* undo any flippin' flips */
797 +                FVECT   unrm;
798 +                unrm[0] = -r->ron[0];
799 +                unrm[1] = -r->ron[1];
800 +                unrm[2] = -r->ron[2];
801 +                (*putreal)(unrm, 3);
802 +        } else
803 +                (*putreal)(r->ron, 3);
804   }
805  
806  
# Line 801 | Line 811 | oputn(                         /* print perturbed normal */
811   {
812          FVECT  pnorm;
813  
814 <        if (r->rot >= FHUGE*.99) {
814 >        if (r->ro == NULL) {    /* clipped or no hit */
815                  (*putreal)(vdummy, 3);
816                  return;
817          }
# Line 839 | 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 911 | 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 929 | 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 944 | 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 >                                        /* apply scalefactor if any */
963 >        if (out_scalefactor != 1.) {
964 >                copyscolor(my_scol, scol);
965 >                scalescolor(my_scol, out_scalefactor);
966 >                scol = my_scol;
967 >        }
968 >        if (sens_curve != NULL) {       /* single channel output */
969 >                RREAL   v = (*sens_curve)(scol);
970 >                (*putreal)(&v, 1);
971 >                return;
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