(
per_view_color: bool, sh_degree: Optional[int], render_mode: str, packed: bool
)
| 20 | @pytest.mark.parametrize("render_mode", ["RGB", "RGB+D", "D"]) |
| 21 | @pytest.mark.parametrize("packed", [True, False]) |
| 22 | def test_rasterization( |
| 23 | per_view_color: bool, sh_degree: Optional[int], render_mode: str, packed: bool |
| 24 | ): |
| 25 | from gsplat.rendering import _rasterization, rasterization |
| 26 | |
| 27 | torch.manual_seed(42) |
| 28 | |
| 29 | C, N = 2, 10_000 |
| 30 | means = torch.rand(N, 3, device=device) |
| 31 | quats = torch.randn(N, 4, device=device) |
| 32 | scales = torch.rand(N, 3, device=device) |
| 33 | opacities = torch.rand(N, device=device) |
| 34 | if per_view_color: |
| 35 | if sh_degree is None: |
| 36 | colors = torch.rand(C, N, 3, device=device) |
| 37 | else: |
| 38 | colors = torch.rand(C, N, (sh_degree + 1) ** 2, 3, device=device) |
| 39 | else: |
| 40 | if sh_degree is None: |
| 41 | colors = torch.rand(N, 3, device=device) |
| 42 | else: |
| 43 | colors = torch.rand(N, (sh_degree + 1) ** 2, 3, device=device) |
| 44 | |
| 45 | width, height = 300, 200 |
| 46 | focal = 300.0 |
| 47 | Ks = torch.tensor( |
| 48 | [[focal, 0.0, width / 2.0], [0.0, focal, height / 2.0], [0.0, 0.0, 1.0]], |
| 49 | device=device, |
| 50 | ).expand(C, -1, -1) |
| 51 | viewmats = torch.eye(4, device=device).expand(C, -1, -1) |
| 52 | |
| 53 | renders, alphas, meta = rasterization( |
| 54 | means=means, |
| 55 | quats=quats, |
| 56 | scales=scales, |
| 57 | opacities=opacities, |
| 58 | colors=colors, |
| 59 | viewmats=viewmats, |
| 60 | Ks=Ks, |
| 61 | width=width, |
| 62 | height=height, |
| 63 | sh_degree=sh_degree, |
| 64 | render_mode=render_mode, |
| 65 | packed=packed, |
| 66 | ) |
| 67 | |
| 68 | if render_mode == "D": |
| 69 | assert renders.shape == (C, height, width, 1) |
| 70 | elif render_mode == "RGB": |
| 71 | assert renders.shape == (C, height, width, 3) |
| 72 | elif render_mode == "RGB+D": |
| 73 | assert renders.shape == (C, height, width, 4) |
| 74 | |
| 75 | _renders, _alphas, _meta = _rasterization( |
| 76 | means=means, |
| 77 | quats=quats, |
| 78 | scales=scales, |
| 79 | opacities=opacities, |
nothing calls this directly
no test coverage detected