MCPcopy Create free account
hub / github.com/Anttwo/SuGaR / eval_sh

Function eval_sh

gsplat_wrapper/utils.py:35–90  ·  view source on GitHub ↗

Evaluate spherical harmonics at unit directions using hardcoded SH polynomials. Works with torch/np/jnp. ... Can be 0 or more batch dimensions. Args: deg: int SH deg. Currently, 0-3 supported sh: jnp.ndarray SH coeffs [..., C, (deg + 1) ** 2] dirs: jnp.nd

(deg, sh, dirs)

Source from the content-addressed store, hash-verified

33
34
35def eval_sh(deg, sh, dirs):
36 """
37 Evaluate spherical harmonics at unit directions
38 using hardcoded SH polynomials.
39 Works with torch/np/jnp.
40 ... Can be 0 or more batch dimensions.
41 Args:
42 deg: int SH deg. Currently, 0-3 supported
43 sh: jnp.ndarray SH coeffs [..., C, (deg + 1) ** 2]
44 dirs: jnp.ndarray unit directions [..., 3]
45 Returns:
46 [..., C]
47 """
48 assert deg <= 4 and deg >= 0
49 coeff = (deg + 1) ** 2
50 assert sh.shape[-1] >= coeff
51
52 result = C0 * sh[..., 0]
53 if deg > 0:
54 x, y, z = dirs[..., 0:1], dirs[..., 1:2], dirs[..., 2:3]
55 result = (result -
56 C1 * y * sh[..., 1] +
57 C1 * z * sh[..., 2] -
58 C1 * x * sh[..., 3])
59
60 if deg > 1:
61 xx, yy, zz = x * x, y * y, z * z
62 xy, yz, xz = x * y, y * z, x * z
63 result = (result +
64 C2[0] * xy * sh[..., 4] +
65 C2[1] * yz * sh[..., 5] +
66 C2[2] * (2.0 * zz - xx - yy) * sh[..., 6] +
67 C2[3] * xz * sh[..., 7] +
68 C2[4] * (xx - yy) * sh[..., 8])
69
70 if deg > 2:
71 result = (result +
72 C3[0] * y * (3 * xx - yy) * sh[..., 9] +
73 C3[1] * xy * z * sh[..., 10] +
74 C3[2] * y * (4 * zz - xx - yy)* sh[..., 11] +
75 C3[3] * z * (2 * zz - 3 * xx - 3 * yy) * sh[..., 12] +
76 C3[4] * x * (4 * zz - xx - yy) * sh[..., 13] +
77 C3[5] * z * (xx - yy) * sh[..., 14] +
78 C3[6] * x * (xx - 3 * yy) * sh[..., 15])
79
80 if deg > 3:
81 result = (result + C4[0] * xy * (xx - yy) * sh[..., 16] +
82 C4[1] * yz * (3 * xx - yy) * sh[..., 17] +
83 C4[2] * xy * (7 * zz - 1) * sh[..., 18] +
84 C4[3] * yz * (7 * zz - 3) * sh[..., 19] +
85 C4[4] * (zz * (35 * zz - 30) + 3) * sh[..., 20] +
86 C4[5] * xz * (7 * zz - 3) * sh[..., 21] +
87 C4[6] * (xx - yy) * (7 * zz - 1) * sh[..., 22] +
88 C4[7] * xz * (xx - 3 * yy) * sh[..., 23] +
89 C4[8] * (xx * (xx - 3 * yy) - yy * (3 * xx - yy)) * sh[..., 24])
90 return result
91
92

Callers 1

renderFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected