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(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 |
+ |
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; |
245 |
< |
trace_sources(); |
266 |
> |
Tflag++; |
267 |
|
/* fall through */ |
268 |
|
case 't': /* trace */ |
269 |
|
if (!vs[1]) break; |
270 |
|
*table = NULL; |
271 |
|
table = every_out; |
251 |
– |
trace = ourtrace; |
272 |
|
castonly = 0; |
273 |
|
break; |
274 |
|
case 'o': /* origin */ |
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 */ |
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 */ |
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, |
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, |
440 |
|
) |
441 |
|
{ |
442 |
|
/* set up ray */ |
423 |
– |
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; |
430 |
– |
thisray.revf = rayirrad; |
449 |
|
} else { |
450 |
|
VCOPY(thisray.rorg, org); |
451 |
|
VCOPY(thisray.rdir, dir); |
452 |
|
thisray.rmax = dmax; |
435 |
– |
if (castonly) |
436 |
– |
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"); |
684 |
|
RAY *r |
685 |
|
) |
686 |
|
{ |
687 |
< |
RREAL cval[3]; |
667 |
< |
|
668 |
< |
cval[0] = colval(r->mcol,RED); |
669 |
< |
cval[1] = colval(r->mcol,GRN); |
670 |
< |
cval[2] = colval(r->mcol,BLU); |
671 |
< |
(*putreal)(cval, 3); |
687 |
> |
putscolor(r->mcol); |
688 |
|
} |
689 |
|
|
690 |
|
|
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 |
|
|
726 |
|
RAY *r |
727 |
|
) |
728 |
|
{ |
729 |
< |
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); |
729 |
> |
putscolor(r->rcol); |
730 |
|
} |
731 |
|
|
732 |
|
|
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 |
|
|
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 |
|
|
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]; |
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]; |
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 |
|
} |