MCPcopy Create free account
hub / github.com/OpenImagingLab/4DSloMo / eval_shfs_4d

Function eval_shfs_4d

utils/sh_utils.py:115–223  ·  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, deg_t, sh, dirs, dirs_t, l = torch.pi)

Source from the content-addressed store, hash-verified

113 return result
114
115def eval_shfs_4d(deg, deg_t, sh, dirs, dirs_t, l = torch.pi):
116 """
117 Evaluate spherical harmonics at unit directions
118 using hardcoded SH polynomials.
119 Works with torch/np/jnp.
120 ... Can be 0 or more batch dimensions.
121 Args:
122 deg: int SH deg. Currently, 0-3 supported
123 sh: jnp.ndarray SH coeffs [..., C, (deg + 1) ** 2]
124 dirs: jnp.ndarray unit directions [..., 3]
125 Returns:
126 [..., C]
127 """
128 assert deg <= 4 and deg >= 0
129 # coeff = (deg + 1) ** 2
130 # assert sh.shape[-1] >= coeff
131
132 l0m0 = C0
133 result = l0m0 * sh[..., 0]
134
135 if deg > 0:
136 x, y, z = dirs[..., 0:1], dirs[..., 1:2], dirs[..., 2:3]
137 l1m1 = -1 * C1 * y
138 l1m0 = C1 * z
139 l1p1 = -1 * C1 * x
140
141 result = (result +
142 l1m1 * sh[..., 1] +
143 l1m0 * sh[..., 2] +
144 l1p1 * sh[..., 3])
145
146 if deg > 1:
147 xx, yy, zz = x * x, y * y, z * z
148 xy, yz, xz = x * y, y * z, x * z
149
150 l2m2 = C2[0] * xy
151 l2m1 = C2[1] * yz
152 l2m0 = C2[2] * (2.0 * zz - xx - yy)
153 l2p1 = C2[3] * xz
154 l2p2 = C2[4] * (xx - yy)
155
156 result = (result +
157 l2m2 * sh[..., 4] +
158 l2m1 * sh[..., 5] +
159 l2m0 * sh[..., 6] +
160 l2p1 * sh[..., 7] +
161 l2p2 * sh[..., 8])
162
163 if deg > 2:
164 l3m3 = C3[0] * y * (3 * xx - yy)
165 l3m2 = C3[1] * xy * z
166 l3m1 = C3[2] * y * (4 * zz - xx - yy)
167 l3m0 = C3[3] * z * (2 * zz - 3 * xx - 3 * yy)
168 l3p1 = C3[4] * x * (4 * zz - xx - yy)
169 l3p2 = C3[5] * z * (xx - yy)
170 l3p3 = C3[6] * x * (xx - 3 * yy)
171
172 result = (result +

Callers 1

renderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected