Move util functions out of splatfacto (#3538)

* Move util functions out of splatfacto

Nothing else currently uses some of the SH utils, but it might make sense to get them out of splatfacto.

I also moved the k nearest neighbors to utils since it doesn't depend on the model class.

* fix assert

* fix sh test

* convert to using degrees, not levels
This commit is contained in:
Alexander Kristoffersen authored and GitHub committed 2024-12-05 13:25:55 -05:00
1 parent e8bf472692
commit a8888e7d9e
8 files changed
+207 -181

No files matched your search

-16
View File
@@ -1,16 +0,0 @@
import pytest
import torch
from nerfstudio.utils.math import components_from_spherical_harmonics
@pytest.mark.parametrize("components", list(range(1, 5 + 1)))
def test_spherical_harmonics(components):
torch.manual_seed(0)
N = 1000000
dx = torch.normal(0, 1, size=(N, 3))
dx = dx / torch.linalg.norm(dx, dim=-1, keepdim=True)
sh = components_from_spherical_harmonics(components, dx)
matrix = (sh.T @ sh) / N * 4 * torch.pi
torch.testing.assert_close(matrix, torch.eye(components**2), rtol=0, atol=1.5e-2)
+16
View File
@@ -0,0 +1,16 @@
import pytest
import torch
from nerfstudio.utils.spherical_harmonics import components_from_spherical_harmonics, num_sh_bases
@pytest.mark.parametrize("degree", list(range(0, 5)))
def test_spherical_harmonics(degree):
torch.manual_seed(0)
N = 1000000
dx = torch.normal(0, 1, size=(N, 3))
dx = dx / torch.linalg.norm(dx, dim=-1, keepdim=True)
sh = components_from_spherical_harmonics(degree, dx)
matrix = (sh.T @ sh) / N * 4 * torch.pi
torch.testing.assert_close(matrix, torch.eye(num_sh_bases(degree)), rtol=0, atol=1.5e-2)