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 */ |
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, |
87 |
|
static void tabin(RAY *r); |
88 |
|
static void ourtrace(RAY *r); |
89 |
|
|
90 |
+ |
static void putscolor(const COLORV *scol); |
91 |
+ |
|
92 |
|
static oputf_t *ray_out[32], *every_out[32]; |
93 |
|
static putf_t *putreal; |
94 |
|
|
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
< |
char * |
115 |
> |
const char * |
116 |
|
formstr( /* return format identifier */ |
117 |
|
int f |
118 |
|
) |
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, |
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 |
|
} |
155 |
– |
switch (outform) { |
156 |
– |
case 'a': putreal = puta; break; |
157 |
– |
case 'f': putreal = putf; break; |
158 |
– |
case 'd': putreal = putd; break; |
159 |
– |
case 'c': |
160 |
– |
if (outvals[1] || !strchr("vrx", outvals[0])) |
161 |
– |
error(USER, "color format only with -ov, -or, -ox"); |
162 |
– |
putreal = putrgbe; break; |
163 |
– |
default: |
164 |
– |
error(CONSISTENCY, "botched output format"); |
165 |
– |
} |
183 |
|
if (nproc > 1) { /* start multiprocessing */ |
184 |
|
ray_popen(nproc); |
185 |
|
ray_fifo_out = printvals; |
234 |
|
} |
235 |
|
|
236 |
|
|
220 |
– |
static void |
221 |
– |
trace_sources(void) /* trace rays to light sources, also */ |
222 |
– |
{ |
223 |
– |
int sn; |
224 |
– |
|
225 |
– |
for (sn = 0; sn < nsources; sn++) |
226 |
– |
source[sn].sflags |= SFOLLOW; |
227 |
– |
} |
228 |
– |
|
229 |
– |
|
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 |
+ |
break; |
257 |
+ |
default: |
258 |
+ |
error(CONSISTENCY, "botched output format"); |
259 |
+ |
} |
260 |
|
castonly = 1; /* sets castonly as side-effect */ |
261 |
|
do |
262 |
|
switch (*vs) { |
263 |
|
case 'T': /* trace sources */ |
264 |
< |
if (!vs[1]) break; |
245 |
< |
trace_sources(); |
264 |
> |
Tflag++; |
265 |
|
/* fall through */ |
266 |
|
case 't': /* trace */ |
267 |
|
if (!vs[1]) break; |
268 |
|
*table = NULL; |
269 |
|
table = every_out; |
251 |
– |
trace = ourtrace; |
270 |
|
castonly = 0; |
271 |
|
break; |
272 |
|
case 'o': /* origin */ |
279 |
|
break; |
280 |
|
case 'r': /* reflected contrib. */ |
281 |
|
*table++ = oputr; |
282 |
< |
ncomp += 3; |
282 |
> |
ncomp += nco; |
283 |
|
castonly = 0; |
284 |
|
break; |
285 |
|
case 'R': /* reflected distance */ |
289 |
|
break; |
290 |
|
case 'x': /* xmit contrib. */ |
291 |
|
*table++ = oputx; |
292 |
< |
ncomp += 3; |
292 |
> |
ncomp += nco; |
293 |
|
castonly = 0; |
294 |
|
break; |
295 |
|
case 'X': /* xmit distance */ |
299 |
|
break; |
300 |
|
case 'v': /* value */ |
301 |
|
*table++ = oputv; |
302 |
< |
ncomp += 3; |
302 |
> |
ncomp += nco; |
303 |
|
castonly = 0; |
304 |
|
break; |
305 |
|
case 'V': /* contribution */ |
306 |
|
*table++ = oputV; |
307 |
< |
ncomp += 3; |
307 |
> |
ncomp += nco; |
308 |
|
castonly = 0; |
309 |
|
if (ambounce > 0 && (ambacc > FTINY || ambssamp > 0)) |
310 |
|
error(WARNING, |
346 |
|
break; |
347 |
|
case 'W': /* coefficient */ |
348 |
|
*table++ = oputW; |
349 |
< |
ncomp += 3; |
349 |
> |
ncomp += nco; |
350 |
|
castonly = 0; |
351 |
|
if (ambounce > 0 && (ambacc > FTINY) | (ambssamp > 0)) |
352 |
|
error(WARNING, |
438 |
|
) |
439 |
|
{ |
440 |
|
/* set up ray */ |
423 |
– |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
441 |
|
if (imm_irrad) { |
442 |
|
VSUM(thisray.rorg, org, dir, 1.1e-4); |
443 |
|
thisray.rdir[0] = -dir[0]; |
444 |
|
thisray.rdir[1] = -dir[1]; |
445 |
|
thisray.rdir[2] = -dir[2]; |
446 |
|
thisray.rmax = 0.0; |
430 |
– |
thisray.revf = rayirrad; |
447 |
|
} else { |
448 |
|
VCOPY(thisray.rorg, org); |
449 |
|
VCOPY(thisray.rdir, dir); |
450 |
|
thisray.rmax = dmax; |
435 |
– |
if (castonly) |
436 |
– |
thisray.revf = raycast; |
451 |
|
} |
452 |
+ |
rayorigin(&thisray, PRIMARY, NULL, NULL); |
453 |
+ |
if (imm_irrad) |
454 |
+ |
thisray.revf = rayirrad; |
455 |
+ |
else if (castonly) |
456 |
+ |
thisray.revf = raycast; |
457 |
|
if (ray_pnprocs > 1) { /* multiprocessing FIFO? */ |
458 |
|
if (ray_fifo_in(&thisray) < 0) |
459 |
|
error(USER, "lost children"); |
706 |
|
RAY *r |
707 |
|
) |
708 |
|
{ |
709 |
< |
RREAL cval[3]; |
709 |
> |
SCOLOR cdiff; |
710 |
|
|
711 |
< |
cval[0] = colval(r->rcol,RED) - colval(r->mcol,RED); |
712 |
< |
cval[1] = colval(r->rcol,GRN) - colval(r->mcol,GRN); |
713 |
< |
cval[2] = colval(r->rcol,BLU) - colval(r->mcol,BLU); |
714 |
< |
(*putreal)(cval, 3); |
711 |
> |
copyscolor(cdiff, r->rcol); |
712 |
> |
sopscolor(cdiff, -=, r->mcol); |
713 |
> |
|
714 |
> |
putscolor(cdiff); |
715 |
|
} |
716 |
|
|
717 |
|
|
729 |
|
RAY *r |
730 |
|
) |
731 |
|
{ |
732 |
< |
RREAL cval[3]; |
714 |
< |
|
715 |
< |
cval[0] = colval(r->rcol,RED); |
716 |
< |
cval[1] = colval(r->rcol,GRN); |
717 |
< |
cval[2] = colval(r->rcol,BLU); |
718 |
< |
(*putreal)(cval, 3); |
732 |
> |
putscolor(r->rcol); |
733 |
|
} |
734 |
|
|
735 |
|
|
738 |
|
RAY *r |
739 |
|
) |
740 |
|
{ |
741 |
< |
RREAL contr[3]; |
741 |
> |
SCOLOR contr; |
742 |
|
|
743 |
|
raycontrib(contr, r, PRIMARY); |
744 |
< |
multcolor(contr, r->rcol); |
745 |
< |
(*putreal)(contr, 3); |
744 |
> |
smultscolor(contr, r->rcol); |
745 |
> |
putscolor(contr); |
746 |
|
} |
747 |
|
|
748 |
|
|
779 |
|
|
780 |
|
|
781 |
|
static void |
782 |
< |
oputp( /* print point */ |
782 |
> |
oputp( /* print intersection point */ |
783 |
|
RAY *r |
784 |
|
) |
785 |
|
{ |
786 |
< |
if (r->rot < FHUGE*.99) |
773 |
< |
(*putreal)(r->rop, 3); |
774 |
< |
else |
775 |
< |
(*putreal)(vdummy, 3); |
786 |
> |
(*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */ |
787 |
|
} |
788 |
|
|
789 |
|
|
792 |
|
RAY *r |
793 |
|
) |
794 |
|
{ |
795 |
< |
if (r->rot < FHUGE*.99) { |
785 |
< |
if (r->rflips & 1) { /* undo any flippin' flips */ |
786 |
< |
FVECT unrm; |
787 |
< |
unrm[0] = -r->ron[0]; |
788 |
< |
unrm[1] = -r->ron[1]; |
789 |
< |
unrm[2] = -r->ron[2]; |
790 |
< |
(*putreal)(unrm, 3); |
791 |
< |
} else |
792 |
< |
(*putreal)(r->ron, 3); |
793 |
< |
} else |
795 |
> |
if (r->ro == NULL) { /* zero vector if clipped or no hit */ |
796 |
|
(*putreal)(vdummy, 3); |
797 |
+ |
return; |
798 |
+ |
} |
799 |
+ |
if (r->rflips & 1) { /* undo any flippin' flips */ |
800 |
+ |
FVECT unrm; |
801 |
+ |
unrm[0] = -r->ron[0]; |
802 |
+ |
unrm[1] = -r->ron[1]; |
803 |
+ |
unrm[2] = -r->ron[2]; |
804 |
+ |
(*putreal)(unrm, 3); |
805 |
+ |
} else |
806 |
+ |
(*putreal)(r->ron, 3); |
807 |
|
} |
808 |
|
|
809 |
|
|
814 |
|
{ |
815 |
|
FVECT pnorm; |
816 |
|
|
817 |
< |
if (r->rot >= FHUGE*.99) { |
817 |
> |
if (r->ro == NULL) { /* clipped or no hit */ |
818 |
|
(*putreal)(vdummy, 3); |
819 |
|
return; |
820 |
|
} |
852 |
|
RAY *r |
853 |
|
) |
854 |
|
{ |
855 |
< |
RREAL contr[3]; |
855 |
> |
SCOLOR contr; |
856 |
|
/* shadow ray not on source? */ |
857 |
|
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
858 |
< |
setcolor(contr, 0.0, 0.0, 0.0); |
858 |
> |
scolorblack(contr); |
859 |
|
else |
860 |
|
raycontrib(contr, r, PRIMARY); |
861 |
|
|
862 |
< |
(*putreal)(contr, 3); |
862 |
> |
putscolor(contr); |
863 |
|
} |
864 |
|
|
865 |
|
|
957 |
|
|
958 |
|
|
959 |
|
static void |
960 |
< |
putrgbe(RREAL *v, int n) /* output RGBE color */ |
960 |
> |
putscolor(const COLORV *scol) /* output (spectral) color */ |
961 |
|
{ |
962 |
< |
COLR cout; |
963 |
< |
|
964 |
< |
if (n != 3) |
965 |
< |
error(INTERNAL, "putrgbe() not called with 3 components"); |
966 |
< |
setcolr(cout, v[0], v[1], v[2]); |
967 |
< |
putbinary(cout, sizeof(cout), 1, stdout); |
962 |
> |
static COLORMAT xyz2myrgbmat; |
963 |
> |
SCOLOR my_scol; |
964 |
> |
COLOR col; |
965 |
> |
/* apply scalefactor if any */ |
966 |
> |
if (out_scalefactor != 1.) { |
967 |
> |
copyscolor(my_scol, scol); |
968 |
> |
scalescolor(my_scol, out_scalefactor); |
969 |
> |
scol = my_scol; |
970 |
> |
} |
971 |
> |
if (sens_curve != NULL) { /* single channel output */ |
972 |
> |
RREAL v = (*sens_curve)(scol); |
973 |
> |
(*putreal)(&v, 1); |
974 |
> |
return; |
975 |
> |
} |
976 |
> |
if (out_prims == NULL) { /* full spectral reporting */ |
977 |
> |
if (outform == 'c') { |
978 |
> |
SCOLR sclr; |
979 |
> |
scolor_scolr(sclr, scol); |
980 |
> |
putbinary(sclr, LSCOLR, 1, stdout); |
981 |
> |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
982 |
> |
RREAL sreal[MAXCSAMP]; |
983 |
> |
int i = NCSAMP; |
984 |
> |
while (i--) sreal[i] = scol[i]; |
985 |
> |
(*putreal)(sreal, NCSAMP); |
986 |
> |
} else |
987 |
> |
(*putreal)((RREAL *)scol, NCSAMP); |
988 |
> |
return; |
989 |
> |
} |
990 |
> |
if (out_prims == xyzprims) { |
991 |
> |
scolor_cie(col, scol); |
992 |
> |
} else if (out_prims == stdprims) { |
993 |
> |
scolor_rgb(col, scol); |
994 |
> |
} else { |
995 |
> |
COLOR xyz; |
996 |
> |
if (xyz2myrgbmat[0][0] == 0) |
997 |
> |
compxyz2rgbWBmat(xyz2myrgbmat, out_prims); |
998 |
> |
scolor_cie(xyz, scol); |
999 |
> |
colortrans(col, xyz2myrgbmat, xyz); |
1000 |
> |
clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite); |
1001 |
> |
} |
1002 |
> |
if (outform == 'c') { |
1003 |
> |
COLR clr; |
1004 |
> |
setcolr(clr, colval(col,RED), colval(col,GRN), colval(col,BLU)); |
1005 |
> |
putbinary(clr, sizeof(COLR), 1, stdout); |
1006 |
> |
} else if (sizeof(RREAL) != sizeof(COLORV)) { |
1007 |
> |
RREAL creal[3]; |
1008 |
> |
copycolor(creal, col); |
1009 |
> |
(*putreal)(creal, 3); |
1010 |
> |
} else |
1011 |
> |
(*putreal)((RREAL *)col, 3); |
1012 |
|
} |