| 259 |
|
*c_cmaterial = *(C_MATERIAL *)lp->data; |
| 260 |
|
c_cmaterial->clock = i + 1; |
| 261 |
|
return(MG_OK); |
| 262 |
+ |
case MG_E_IR: /* set index of refraction */ |
| 263 |
+ |
if (ac != 3) |
| 264 |
+ |
return(MG_EARGC); |
| 265 |
+ |
if (!isflt(av[1]) | !isflt(av[2])) |
| 266 |
+ |
return(MG_ETYPE); |
| 267 |
+ |
c_cmaterial->nr = atof(av[1]); |
| 268 |
+ |
c_cmaterial->ni = atof(av[2]); |
| 269 |
+ |
if (c_cmaterial->nr <= FTINY) |
| 270 |
+ |
return(MG_EILL); |
| 271 |
+ |
c_cmaterial->clock++; |
| 272 |
+ |
return(MG_OK); |
| 273 |
|
case MG_E_RD: /* set diffuse reflectance */ |
| 274 |
|
if (ac != 2) |
| 275 |
|
return(MG_EARGC); |
| 565 |
|
int n, imax; |
| 566 |
|
int wl; |
| 567 |
|
double wl0, wlstep; |
| 568 |
+ |
double boxpos, boxstep; |
| 569 |
|
/* check bounds */ |
| 570 |
|
if (wlmax <= C_CMINWL | wlmax <= wlmin | wlmin >= C_CMAXWL) |
| 571 |
|
return(MG_EILL); |
| 578 |
|
wlmax -= wlstep; |
| 579 |
|
ac--; |
| 580 |
|
} |
| 569 |
– |
if (ac < 2) |
| 570 |
– |
return(MG_EILL); |
| 581 |
|
imax = ac; /* box filter if necessary */ |
| 582 |
+ |
boxpos = 0; |
| 583 |
+ |
boxstep = 1; |
| 584 |
|
if (wlstep < C_CWLI) { |
| 585 |
+ |
imax = (wlmax - wlmin)/C_CWLI + (1-FTINY); |
| 586 |
+ |
boxpos = (wlmin - C_CMINWL)/C_CWLI; |
| 587 |
+ |
boxstep = wlstep/C_CWLI; |
| 588 |
|
wlstep = C_CWLI; |
| 574 |
– |
imax = (wlmax - wlmin)/wlstep; |
| 589 |
|
} |
| 590 |
|
scale = 0.; /* get values and maximum */ |
| 591 |
|
pos = 0; |
| 592 |
|
for (i = 0; i < imax; i++) { |
| 593 |
|
va[i] = 0.; n = 0; |
| 594 |
< |
while (pos < (i+.5)*ac/imax) { |
| 594 |
> |
while (boxpos < i+.5 && pos < ac) { |
| 595 |
|
if (!isflt(av[pos])) |
| 596 |
|
return(MG_ETYPE); |
| 597 |
|
va[i] += atof(av[pos++]); |
| 598 |
|
n++; |
| 599 |
+ |
boxpos += boxstep; |
| 600 |
|
} |
| 601 |
|
if (n > 1) |
| 602 |
|
va[i] /= (double)n; |
| 605 |
|
if (va[i] > scale) |
| 606 |
|
scale = va[i]; |
| 607 |
|
} |
| 608 |
< |
if (scale == 0.) |
| 608 |
> |
if (scale <= FTINY) |
| 609 |
|
return(MG_EILL); |
| 610 |
|
scale = C_CMAXV / scale; |
| 611 |
|
clr->ssum = 0; /* convert to our spacing */ |