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 |
|
|
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 |
|
} |
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 |
|
} |
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; |
234 |
|
} |
235 |
|
|
236 |
|
|
218 |
– |
static void |
219 |
– |
trace_sources(void) /* trace rays to light sources, also */ |
220 |
– |
{ |
221 |
– |
int sn; |
222 |
– |
|
223 |
– |
for (sn = 0; sn < nsources; sn++) |
224 |
– |
source[sn].sflags |= SFOLLOW; |
225 |
– |
} |
226 |
– |
|
227 |
– |
|
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; |
243 |
< |
trace_sources(); |
266 |
> |
Tflag++; |
267 |
|
/* fall through */ |
268 |
|
case 't': /* trace */ |
269 |
|
if (!vs[1]) break; |
270 |
|
*table = NULL; |
271 |
|
table = every_out; |
249 |
– |
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 */ |
421 |
– |
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; |
428 |
– |
thisray.revf = rayirrad; |
449 |
|
} else { |
450 |
|
VCOPY(thisray.rorg, org); |
451 |
|
VCOPY(thisray.rdir, dir); |
452 |
|
thisray.rmax = dmax; |
433 |
– |
if (castonly) |
434 |
– |
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]; |
665 |
< |
|
666 |
< |
cval[0] = colval(r->mcol,RED); |
667 |
< |
cval[1] = colval(r->mcol,GRN); |
668 |
< |
cval[2] = colval(r->mcol,BLU); |
669 |
< |
(*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]; |
712 |
< |
|
713 |
< |
cval[0] = colval(r->rcol,RED); |
714 |
< |
cval[1] = colval(r->rcol,GRN); |
715 |
< |
cval[2] = colval(r->rcol,BLU); |
716 |
< |
(*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 |
|
|
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) |
771 |
< |
(*putreal)(r->rop, 3); |
772 |
< |
else |
773 |
< |
(*putreal)(vdummy, 3); |
783 |
> |
(*putreal)(r->rop, 3); /* set to ray origin if distant or no hit */ |
784 |
|
} |
785 |
|
|
786 |
|
|
789 |
|
RAY *r |
790 |
|
) |
791 |
|
{ |
792 |
< |
if (r->rot < FHUGE*.99) { |
783 |
< |
if (r->rflips & 1) { /* undo any flippin' flips */ |
784 |
< |
FVECT unrm; |
785 |
< |
unrm[0] = -r->ron[0]; |
786 |
< |
unrm[1] = -r->ron[1]; |
787 |
< |
unrm[2] = -r->ron[2]; |
788 |
< |
(*putreal)(unrm, 3); |
789 |
< |
} else |
790 |
< |
(*putreal)(r->ron, 3); |
791 |
< |
} 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 |
|
|
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 |
|
} |
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 |
|
} |