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 */ |
295 |
|
{ |
296 |
|
CMATRIX *cm = cm_alloc(bsdf->nout, bsdf->ninc); |
297 |
|
COLORV *mp = cm->cmem; |
298 |
+ |
int nbadohm = 0; |
299 |
+ |
int nneg = 0; |
300 |
|
int r, c; |
301 |
|
|
302 |
< |
for (r = 0; r < cm->nrows; r++) |
303 |
< |
for (c = 0; c < cm->ncols; c++, mp += 3) |
304 |
< |
mp[0] = mp[1] = mp[2] = BSDF_value(bsdf,c,r); |
302 |
> |
for (c = 0; c < cm->ncols; c++) { |
303 |
> |
float dom = getBSDF_incohm(bsdf,c); |
304 |
> |
FVECT v; |
305 |
> |
|
306 |
> |
if (dom <= .0) { |
307 |
> |
nbadohm++; |
308 |
> |
continue; |
309 |
> |
} |
310 |
> |
if (!getBSDF_incvec(v,bsdf,c) || v[2] > FTINY) |
311 |
> |
error(USER, "illegal incoming BTDF direction"); |
312 |
> |
dom *= -v[2]; |
313 |
> |
|
314 |
> |
for (r = 0; r < cm->nrows; r++) { |
315 |
> |
float f = BSDF_value(bsdf,c,r); |
316 |
> |
|
317 |
> |
if (f <= .0) { |
318 |
> |
nneg += (f < -FTINY); |
319 |
> |
f = .0f; |
320 |
> |
} |
321 |
> |
mp = cm_lval(cm,r,c); |
322 |
> |
mp[0] = mp[1] = mp[2] = f * dom; |
323 |
> |
} |
324 |
> |
} |
325 |
> |
if (nneg || nbadohm) { |
326 |
> |
sprintf(errmsg, |
327 |
> |
"BTDF has %d negatives and %d bad incoming solid angles", |
328 |
> |
nneg, nbadohm); |
329 |
> |
error(WARNING, errmsg); |
330 |
> |
} |
331 |
|
return(cm); |
332 |
|
} |
333 |
|
|
433 |
|
progname); |
434 |
|
return(1); |
435 |
|
} |
436 |
+ |
/* load Tregenza vector */ |
437 |
|
tvec = cm_load(argv[4], 0, 1, DTascii); /* argv[4]==NULL iff argc==4 */ |
438 |
< |
Dmat = cm_load(argv[3], 0, tvec->nrows, DTfromHeader); |
438 |
> |
/* load BTDF */ |
439 |
|
btdf = load_BSDF(argv[2]); |
440 |
|
if (btdf == NULL) |
441 |
|
return(1); |
442 |
< |
if (btdf->ninc != Dmat->nrows) { |
443 |
< |
sprintf(errmsg, "Incoming BTDF dir (%d) mismatch to D (%d)", |
415 |
< |
btdf->ninc, Dmat->nrows); |
416 |
< |
error(USER, errmsg); |
417 |
< |
} |
442 |
> |
/* load Daylight matrix */ |
443 |
> |
Dmat = cm_load(argv[3], btdf->ninc, tvec->nrows, DTfromHeader); |
444 |
|
/* multiply vector through */ |
445 |
|
ivec = cm_multiply(Dmat, tvec); |
446 |
|
cm_free(Dmat); cm_free(tvec); |