mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-21 07:05:44 +08:00
Get rid of redundant projection matrix computations in Splatfacto (needs a gsplat update) (#3019)
Get rid of projection matrix in ProjectGaussians with gsplat >= 0.1.9
This commit is contained in:
1 parent
71de07163a
commit
05ce76db99
2 files changed
+1
-26
No files matched your search
@@ -79,27 +79,6 @@ def SH2RGB(sh):
|
||||
return sh * C0 + 0.5
|
||||
|
||||
|
||||
def projection_matrix(znear, zfar, fovx, fovy, device: Union[str, torch.device] = "cpu"):
|
||||
"""
|
||||
Constructs an OpenGL-style perspective projection matrix.
|
||||
"""
|
||||
t = znear * math.tan(0.5 * fovy)
|
||||
b = -t
|
||||
r = znear * math.tan(0.5 * fovx)
|
||||
l = -r
|
||||
n = znear
|
||||
f = zfar
|
||||
return torch.tensor(
|
||||
[
|
||||
[2 * n / (r - l), 0.0, (r + l) / (r - l), 0.0],
|
||||
[0.0, 2 * n / (t - b), (t + b) / (t - b), 0.0],
|
||||
[0.0, 0.0, (f + n) / (f - n), -1.0 * f * n / (f - n)],
|
||||
[0.0, 0.0, 1.0, 0.0],
|
||||
],
|
||||
device=device,
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class SplatfactoModelConfig(ModelConfig):
|
||||
"""Splatfacto Model Config, nerfstudio's implementation of Gaussian Splatting"""
|
||||
@@ -709,11 +688,8 @@ class SplatfactoModel(Model):
|
||||
# calculate the FOV of the camera given fx and fy, width and height
|
||||
cx = camera.cx.item()
|
||||
cy = camera.cy.item()
|
||||
fovx = 2 * math.atan(camera.width / (2 * camera.fx))
|
||||
fovy = 2 * math.atan(camera.height / (2 * camera.fy))
|
||||
W, H = int(camera.width.item()), int(camera.height.item())
|
||||
self.last_size = (H, W)
|
||||
projmat = projection_matrix(0.001, 1000, fovx, fovy, device=self.device)
|
||||
|
||||
if crop_ids is not None:
|
||||
opacities_crop = self.opacities[crop_ids]
|
||||
@@ -738,7 +714,6 @@ class SplatfactoModel(Model):
|
||||
1,
|
||||
quats_crop / quats_crop.norm(dim=-1, keepdim=True),
|
||||
viewmat.squeeze()[:3, :],
|
||||
projmat.squeeze() @ viewmat.squeeze(),
|
||||
camera.fx.item(),
|
||||
camera.fy.item(),
|
||||
cx,
|
||||
|
||||
Reference in new issue
Block a user