38 |
|
CMATRIX *cm; |
39 |
|
|
40 |
|
if ((nrows <= 0) | (ncols <= 0)) |
41 |
< |
return(NULL); |
41 |
> |
error(USER, "attempt to create empty matrix"); |
42 |
|
cm = (CMATRIX *)malloc(sizeof(CMATRIX) + |
43 |
|
3*sizeof(COLORV)*(nrows*ncols - 1)); |
44 |
|
if (cm == NULL) |
160 |
|
int maxrow = (nrows > 0 ? nrows : 32000); |
161 |
|
int r, c; |
162 |
|
for (r = 0; r < maxrow; r++) { |
163 |
< |
if (r >= cm->nrows) /* need more space? */ |
163 |
> |
if (r >= cm->nrows) /* need more space? */ |
164 |
|
cm = cm_resize(cm, 2*cm->nrows); |
165 |
|
for (c = 0; c < ncols; c++) { |
166 |
|
COLORV *cv = cm_lval(cm,r,c); |
167 |
|
if (fscanf(fp, COLSPEC, cv, cv+1, cv+2) != 3) |
168 |
< |
if ((nrows <= 0) & (r > 0) & (c == 0)) { |
168 |
> |
if ((nrows <= 0) & (r > 0) & !c) { |
169 |
|
cm = cm_resize(cm, maxrow=r); |
170 |
|
break; |
171 |
|
} else |
193 |
|
if (nread == cm->nrows*cm->ncols) |
194 |
|
/* need more space? */ |
195 |
|
cm = cm_resize(cm, 2*cm->nrows); |
196 |
< |
else if (nread % cm->ncols == 0) |
196 |
> |
else if (nread && !(nread % cm->ncols)) |
197 |
|
/* seem to be done */ |
198 |
|
cm = cm_resize(cm, nread/cm->ncols); |
199 |
|
else /* ended mid-row */ |
294 |
|
cm_bsdf(const struct BSDF_data *bsdf) |
295 |
|
{ |
296 |
|
CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); |
297 |
< |
COLORV *mp = cm->cmem; |
297 |
> |
int nbadohm = 0; |
298 |
> |
int nneg = 0; |
299 |
|
int r, c; |
300 |
|
|
301 |
< |
for (r = 0; r < cm->nrows; r++) |
302 |
< |
for (c = 0; c < cm->ncols; c++, mp += 3) |
303 |
< |
mp[0] = mp[1] = mp[2] = BSDF_value(bsdf,c,r); |
301 |
> |
for (c = 0; c < cm->ncols; c++) { |
302 |
> |
float dom = getBSDF_incohm(bsdf,c); |
303 |
> |
FVECT v; |
304 |
> |
|
305 |
> |
if (dom <= .0) { |
306 |
> |
nbadohm++; |
307 |
> |
continue; |
308 |
> |
} |
309 |
> |
if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY) |
310 |
> |
error(USER, "illegal incoming BTDF direction"); |
311 |
> |
dom *= -v[2]; |
312 |
> |
|
313 |
> |
for (r = 0; r < cm->nrows; r++) { |
314 |
> |
float f = BSDF_value(bsdf,c,r); |
315 |
> |
COLORV *mp = cm_lval(cm,r,c); |
316 |
> |
|
317 |
> |
if (f <= .0) { |
318 |
> |
nneg += (f < -FTINY); |
319 |
> |
f = .0f; |
320 |
> |
} |
321 |
> |
mp[0] = mp[1] = mp[2] = f * dom; |
322 |
> |
} |
323 |
> |
} |
324 |
> |
if (nneg || nbadohm) { |
325 |
> |
sprintf(errmsg, |
326 |
> |
"BTDF has %d negatives and %d bad incoming solid angles", |
327 |
> |
nneg, nbadohm); |
328 |
> |
error(WARNING, errmsg); |
329 |
> |
} |
330 |
|
return(cm); |
331 |
|
} |
332 |
|
|
432 |
|
progname); |
433 |
|
return(1); |
434 |
|
} |
435 |
+ |
/* load Tregenza vector */ |
436 |
|
tvec = cm_load(argv[4], 0, 1, DTascii); /* argv[4]==NULL iff argc==4 */ |
437 |
< |
Dmat = cm_load(argv[3], 0, tvec->nrows, DTfromHeader); |
437 |
> |
/* load BTDF */ |
438 |
|
btdf = load_BSDF(argv[2]); |
439 |
|
if (btdf == NULL) |
440 |
|
return(1); |
441 |
< |
if (btdf->ninc != Dmat->nrows) { |
442 |
< |
sprintf(errmsg, "Incoming BTDF dir (%d) mismatch to D (%d)", |
415 |
< |
btdf->ninc, Dmat->nrows); |
416 |
< |
error(USER, errmsg); |
417 |
< |
} |
441 |
> |
/* load Daylight matrix */ |
442 |
> |
Dmat = cm_load(argv[3], btdf->ninc, tvec->nrows, DTfromHeader); |
443 |
|
/* multiply vector through */ |
444 |
|
ivec = cm_multiply(Dmat, tvec); |
445 |
|
cm_free(Dmat); cm_free(tvec); |