12 |
|
#include "otypes.h" |
13 |
|
#include "source.h" |
14 |
|
|
15 |
– |
char *shm_boundary = NULL; /* boundary of shared memory */ |
16 |
– |
|
15 |
|
CUBE thescene; /* our scene */ |
16 |
|
OBJECT nsceneobjs; /* number of objects in our scene */ |
17 |
|
|
66 |
|
|
67 |
|
static void trace_contrib(RAY *r); /* our trace callback */ |
68 |
|
|
69 |
< |
static void mcfree(void *p) { epfree((*(MODCONT *)p).binv); free(p); } |
69 |
> |
static void mcfree(void *p) { epfree((*(MODCONT *)p).binv,1); free(p); } |
70 |
|
|
71 |
|
LUTAB modconttab = LU_SINIT(NULL,mcfree); /* modifier lookup table */ |
72 |
|
|
73 |
|
/************************** INITIALIZATION ROUTINES ***********************/ |
74 |
|
|
75 |
< |
char * |
75 |
> |
const char * |
76 |
|
formstr( /* return format identifier */ |
77 |
|
int f |
78 |
|
) |
81 |
|
case 'a': return("ascii"); |
82 |
|
case 'f': return("float"); |
83 |
|
case 'd': return("double"); |
84 |
< |
case 'c': return(COLRFMT); |
84 |
> |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
85 |
|
} |
86 |
|
return("unknown"); |
87 |
|
} |
91 |
|
MODCONT * |
92 |
|
addmodifier(char *modn, char *outf, char *prms, char *binv, int bincnt) |
93 |
|
{ |
94 |
< |
LUENT *lep = lu_find(&modconttab,modn); |
95 |
< |
MODCONT *mp; |
96 |
< |
EPNODE *ebinv; |
97 |
< |
int i; |
98 |
< |
|
94 |
> |
static int lastNCS = 0; |
95 |
> |
LUENT *lep = lu_find(&modconttab,modn); |
96 |
> |
MODCONT *mp; |
97 |
> |
EPNODE *ebinv; |
98 |
> |
int i; |
99 |
> |
|
100 |
> |
if (!lastNCS) |
101 |
> |
lastNCS = NCSAMP; |
102 |
> |
else if (NCSAMP != lastNCS) |
103 |
> |
error(INTERNAL, |
104 |
> |
"number of spectral samples must be set before first modifier"); |
105 |
|
if (lep->data != NULL) { |
106 |
|
sprintf(errmsg, "duplicate modifier '%s'", modn); |
107 |
|
error(USER, errmsg); |
117 |
|
else |
118 |
|
modname = (char **)realloc(modname, modasiz*sizeof(char *)); |
119 |
|
if (modname == NULL) |
120 |
< |
error(SYSTEM, "Out of memory in addmodifier()"); |
120 |
> |
error(SYSTEM, "out of memory in addmodifier()"); |
121 |
|
} |
122 |
|
modname[nmods++] = modn; /* XXX assumes static string */ |
123 |
|
lep->key = modn; /* XXX assumes static string */ |
138 |
|
error(USER, errmsg); |
139 |
|
} |
140 |
|
/* initialize results holder */ |
141 |
< |
mp = (MODCONT *)malloc(sizeof(MODCONT)+sizeof(DCOLOR)*(bincnt-1)); |
141 |
> |
mp = (MODCONT *)malloc(mcsize(bincnt)); |
142 |
|
if (mp == NULL) |
143 |
|
error(SYSTEM, "out of memory in addmodifier"); |
144 |
|
mp->outspec = outf; /* XXX assumes static string */ |
147 |
|
mp->binv = ebinv; |
148 |
|
mp->bin0 = 0; |
149 |
|
mp->nbins = bincnt; |
150 |
< |
memset(mp->cbin, 0, sizeof(DCOLOR)*bincnt); |
150 |
> |
memset(mp->cbin, 0, DCOLORSIZ*bincnt); |
151 |
|
/* figure out starting bin */ |
152 |
|
while (!getostream(mp->outspec, mp->modname, mp->bin0, 1)) |
153 |
|
mp->bin0++; |
230 |
|
if (nproc > MAXPROCESS) |
231 |
|
sprintf(errmsg, "too many processes requested -- reducing to %d", |
232 |
|
nproc = MAXPROCESS); |
233 |
< |
if (nproc > 1) { |
234 |
< |
preload_objs(); /* preload auxiliary data */ |
231 |
< |
/* set shared memory boundary */ |
232 |
< |
shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY"); |
233 |
< |
} |
233 |
> |
if (nproc > 1) |
234 |
> |
cow_memshare(); /* preload auxiliary data */ |
235 |
|
trace = trace_contrib; /* set up trace call-back */ |
236 |
|
for (i = 0; i < nsources; i++) /* tracing to sources as well */ |
237 |
|
source[i].sflags |= SFOLLOW; |
274 |
|
MODCONT *mp; |
275 |
|
double bval; |
276 |
|
int bn; |
277 |
< |
RREAL contr[3]; |
277 |
> |
SCOLOR contr; |
278 |
> |
DCOLORV *dvp; |
279 |
> |
int i; |
280 |
|
|
281 |
|
if (r->ro == NULL || r->ro->omod == OVOID) |
282 |
|
return; |
300 |
|
} |
301 |
|
raycontrib(contr, r, PRIMARY); /* compute coefficient */ |
302 |
|
if (contrib) |
303 |
< |
multcolor(contr, r->rcol); /* -> contribution */ |
304 |
< |
addcolor(mp->cbin[bn], contr); |
303 |
> |
smultscolor(contr, r->rcol); /* -> contribution */ |
304 |
> |
dvp = mcbin(mp, bn); |
305 |
> |
for (i = 0; i < NCSAMP; i++) /* add it in */ |
306 |
> |
*dvp++ += contr[i]; |
307 |
|
} |
308 |
|
|
309 |
|
|
357 |
|
for (i = 0; i < nmods; i++) { /* output records & clear */ |
358 |
|
mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; |
359 |
|
mod_output(mp); |
360 |
< |
memset(mp->cbin, 0, sizeof(DCOLOR)*mp->nbins); |
360 |
> |
memset(mp->cbin, 0, DCOLORSIZ*mp->nbins); |
361 |
|
} |
362 |
|
end_record(); /* end lines & flush if time */ |
363 |
|
|