ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/spharm.cal
Revision: 1.5
Committed: Thu Feb 10 17:07:45 2005 UTC (19 years, 2 months ago) by greg
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad3R7P2, rad3R7P1, rad4R2, rad4R1, rad4R0, rad3R8, rad3R9, rad4R2P1, rad5R3, HEAD
Changes since 1.4: +4 -3 lines
Log Message:
Corrected real series coefficients to include -m factors

File Contents

# User Rev Content
1 greg 1.5 { RCSid $Id: spharm.cal,v 1.4 2005/02/10 04:53:20 greg Exp $ }
2 greg 1.1 {
3     The first few Spherical Harmonics
4    
5     Feb 2005 G. Ward
6     }
7     { Factorial (n!) }
8     fact(n) : if(n-1.5, n*fact(n-1), 1);
9    
10     { Associated Legendre Polynomials 0-8 }
11     LegendreP2(n,m,x,s) : select(n+1,
12     select(m+1, 1),
13     select(m+1, x, s),
14     select(m+1, .5*(3*x*x - 1), 3*x*s, 3*(1-x*x)),
15     select(m+1, .5*x*(5*x*x-3), 1.5*(5*x*x-1)*s, 15*x*(1-x*x), 15*s*s*s),
16     select(m+1,
17     .125*(3 + x*x*(-30 + x*x*35)),
18     2.5*x*(-3 + x*x*7)*s,
19     7.5*(7*x*x-1)*(1-x*x),
20     105*x*s*s*s,
21     105*s*s*s*s),
22     select(m+1,
23     .125*x*(15 + x*x*(-70 + x*x*63)),
24     1.875*s*(1 + x*x*(-14 + x*x*21)),
25     52.5*x*(1-x*x)*(3*x*x-1),
26     52.5*s*s*s*(9*x*x-1),
27     945*x*s*s*s*s,
28     945*s*s*s*s*s),
29     select(m+1,
30     .0625*(-5 + x*x*(105 + x*x*(-315 + x*x*231))),
31     2.625*(5 + x*x*(-30 + x*x*33))*s,
32     13.125*s*s*(1 + x*x*(-18 + x*x*33)),
33     157.5*(11*x*x-3)*x*s*s*s,
34     472.5*s*s*s*s*(11*x*x-1),
35     10395*x*s*s*s*s*s,
36     10395*s*s*s*s*s*s),
37     select(m+1,
38     .0625*x*(-35 + x*x*(315 + x*x*(-693 + x*x*429))),
39     .4375*s*(-5 + x*x*(135 + x*x*(-495 + x*x*429))),
40     7.875*x*s*s*(15 + x*x*(-110 + x*x*143)),
41     39.375*s*s*(1 + x*x*(-18 + x*x*33)),
42     157.5*(11*x*x-3)*x*s*s*s,
43     472.5*s*s*s*s*(11*x*x-1),
44     10395*x*s*s*s*s*s,
45     10395*s*s*s*s*s*s),
46     select(m+1,
47     .0078125*(35 + x*x*(-1260 + x*x*(6930 + x*x*(-12012 + x*x*6435)))),
48     .5625*x*s*(-35 + x*x*(385 + x*x*(-1001 + x*x*715))),
49     19.6875*s*s*(-1 + x*x*(33 + x*x*(-143 + x*x*143))),
50     433.125*x*s*s*s*(3 + x*x*(-26 + x*x*39)),
51     1299.375*s*s*s*s*(1 + x*x*(-26 + x*x*65)),
52     67567.5*x*s*s*s*s*s*(5*x*x-1),
53     67567.5*s*s*s*s*s*s*(15*x*x-1),
54     2027025*x*s*s*s*s*s*s*s,
55     2027025*s*s*s*s*s*s*s*s)
56     );
57     { Relation for Legendre with -M }
58     odd(n) : .5*n - floor(.5*n) - .25;
59     LegendreP(n,m,x) : if(m+.5,
60     LegendreP2(n,m,x,sqrt(1-x*x)),
61 greg 1.4 fact(n+m)/fact(n-m) * LegendreP2(n,-m,x,sqrt(1-x*x))
62 greg 1.1 );
63     { SH normalization factor }
64     SHnormF(l,m) : sqrt(0.25/PI*(2*l+1)*fact(l-m)/fact(l+m));
65     { Spherical Harmonics theta function }
66     SHthetaF(l,m,theta) : SHnormF(l,m)*LegendreP(l,m,cos(theta));
67    
68     { Spherical Harmonic real portion }
69     SphericalHarmonicYr(l,m,theta,phi) : SHthetaF(l,m,theta)*cos(m*phi);
70     { Spherical Harmonic imag. portion }
71     SphericalHarmonicYi(l,m,theta,phi) : SHthetaF(l,m,theta)*sin(m*phi);
72    
73     { Ordered, real SH basis functions }
74 greg 1.3 { Coeff. order based on Basri & Jacobs paper, "Lambertian Reflectance and
75     Linear Subspaces," IEEE Trans. on Pattern Analysis & Machine Intel.,
76     vol. 25, no. 2, Feb. 2003, pp. 218-33, Eq. (7):
77    
78     i n m even/odd
79     = = = ========
80     1 0 0 x
81     2 1 0 x
82     3 1 1 e
83     4 1 1 o
84     5 2 0 x
85     6 2 1 e
86     7 2 1 o
87     8 2 2 e
88     9 2 2 o
89     10 3 0 x
90     11 3 1 e
91     ...
92     }
93 greg 1.5 SH_B4(l,m,o,theta,phi) : if(m-.5, sqrt(2) *
94     if(o, SphericalHarmonicYi(l,m,theta,phi),
95 greg 1.1 SphericalHarmonicYr(l,m,theta,phi)),
96 greg 1.5 SHthetaF(l,0,theta) );
97 greg 1.1 SH_B3(l,r,theta,phi) : SH_B4(l,floor((r+1.00001)/2),odd(r+1),theta,phi);
98     SH_B2(l,i,theta,phi) : SH_B3(l,i-l*l-1,theta,phi);
99     SphericalHarmonicB(i,theta,phi) : SH_B2(ceil(sqrt(i)-1.00001),i,theta,phi);
100    
101 greg 1.3 { Application of SH coeff. f(i) }
102 greg 1.1 SH_F2(n,f,theta,phi) : if(n-.5, f(n)*SphericalHarmonicB(n,theta,phi) +
103     SH_F2(n-1,f,theta,phi), 0);
104     SphericalHarmonicF(f,theta,phi) : SH_F2(f(0),f,theta,phi);