ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/klems_full.cal
Revision: 1.3
Committed: Fri Mar 27 18:58:06 2015 UTC (7 years, 6 months ago) by greg
Branch: MAIN
CVS Tags: rad5R0, rad5R2, rad5R1, rad5R3, HEAD
Changes since 1.2: +4 -2 lines
Log Message:
Hopeful fix to bugs in genBSDF due to lack of left-handed coordinates

File Contents

# Content
1 { RCSid $Id: klems_full.cal,v 1.2 2014/07/21 15:59:47 greg Exp $ }
2 {
3 Compute interior bin for (full) Klems BSDF basis (0-144)
4 Returns -1 for wrong-side rays
5
6 Modified from Tregenza.cal, which is similar but different
7
8 6/14/2009 G. Ward
9 }
10 DEGREE : PI/180;
11 Acos(x) : if(x-1, 0, if(-1-x, PI, acos(x))) / DEGREE;
12 posangle(a) : if(-a, a + 2*PI, a) / DEGREE;
13 Atan2(y,x) : posangle(atan2(y,x));
14
15 kpola(r) : select(r, 5, 15, 25, 35, 45, 55, 65, 75, 90);
16 knaz(r) : select(r, 1, 8, 16, 20, 24, 24, 24, 16, 12);
17 kaccum(r) : if(r-.5, knaz(r) + kaccum(r-1), 0);
18 kfindrow(r, pol) : if(r-kpola(0)+.5, r,
19 if(pol-kpola(r), kfindrow(r+1, pol), r) );
20
21 kazn(azi,inc) : if((360-.5*inc)-azi, floor((azi+.5*inc)/inc), 0);
22
23 kbin2(pol,azi) = if(pol-90, -1,
24 select(kfindrow(1, pol),
25 kazn(azi,360/knaz(1)),
26 kaccum(1) + kazn(azi,360/knaz(2)),
27 kaccum(2) + kazn(azi,360/knaz(3)),
28 kaccum(3) + kazn(azi,360/knaz(4)),
29 kaccum(4) + kazn(azi,360/knaz(5)),
30 kaccum(5) + kazn(azi,360/knaz(6)),
31 kaccum(6) + kazn(azi,360/knaz(7)),
32 kaccum(7) + kazn(azi,360/knaz(8)),
33 kaccum(8) + kazn(azi,360/knaz(9))
34 ) );
35
36 RHS = 1; { set to -1 for left-handed system }
37
38 kbin(Nx,Ny,Nz,Ux,Uy,Uz) = kbin2(Acos(-Dx*Nx-Dy*Ny-Dz*Nz),
39 Atan2(-Dx*Ux-Dy*Uy-Dz*Uz + (Nx*Dx+Ny*Dy+Nz*Dz)*(Nx*Ux+Ny*Uy+Nz*Uz),
40 -RHS*(Dx*(Uy*Nz-Uz*Ny) + Dy*(Uz*Nx-Ux*Nz) + Dz*(Ux*Ny-Uy*Nx))));
41
42 kbinN = kbin(0,-1,0, 0,0,1); { North bins }
43 kbinE = kbin(-1,0,0, 0,0,1); { East bins }
44 kbinS = kbin(0,1,0, 0,0,1); { South bins }
45 kbinW = kbin(1,0,0, 0,0,1); { West bins }
46
47 kbinD = kbin(0,0,-1, 0,1,0); { Skylight bins }
48
49 Nkbins : kaccum(knaz(0)); { Number of bins for one elevation }