ironjr commited on
Commit
aa2f647
1 Parent(s): b229e4a

Delete gaussian_renderer/.ipynb_checkpoints

Browse files
gaussian_renderer/.ipynb_checkpoints/__init__-checkpoint.py DELETED
@@ -1,104 +0,0 @@
1
- #
2
- # Copyright (C) 2023, Inria
3
- # GRAPHDECO research group, https://team.inria.fr/graphdeco
4
- # All rights reserved.
5
- #
6
- # This software is free for non-commercial, research and evaluation use
7
- # under the terms of the LICENSE.md file.
8
- #
9
- # For inquiries contact george.drettakis@inria.fr
10
- #
11
-
12
- import torch
13
- import math
14
- from depth_diff_gaussian_rasterization_min import GaussianRasterizationSettings, GaussianRasterizer
15
- from scene.gaussian_model import GaussianModel
16
- from utils.sh import eval_sh
17
-
18
- def render(viewpoint_camera, pc: GaussianModel, opt, bg_color: torch.Tensor, scaling_modifier=1.0, override_color=None, render_only=False):
19
- """
20
- Render the scene.
21
-
22
- Background tensor (bg_color) must be on GPU!
23
- """
24
-
25
- # Create zero tensor. We will use it to make pytorch return gradients of the 2D (screen-space) means
26
- screenspace_points = torch.zeros_like(pc.get_xyz, dtype=pc.get_xyz.dtype, requires_grad=True, device="cuda") + 0
27
- try:
28
- screenspace_points.retain_grad()
29
- except:
30
- pass
31
-
32
- # Set up rasterization configuration
33
- tanfovx = math.tan(viewpoint_camera.FoVx * 0.5)
34
- tanfovy = math.tan(viewpoint_camera.FoVy * 0.5)
35
-
36
- raster_settings = GaussianRasterizationSettings(
37
- image_height=int(viewpoint_camera.image_height),
38
- image_width=int(viewpoint_camera.image_width),
39
- tanfovx=tanfovx,
40
- tanfovy=tanfovy,
41
- bg=bg_color,
42
- scale_modifier=scaling_modifier,
43
- viewmatrix=viewpoint_camera.world_view_transform,
44
- projmatrix=viewpoint_camera.full_proj_transform,
45
- sh_degree=pc.active_sh_degree,
46
- campos=viewpoint_camera.camera_center,
47
- prefiltered=False,
48
- debug=opt.debug
49
- )
50
-
51
- rasterizer = GaussianRasterizer(raster_settings=raster_settings)
52
-
53
- means3D = pc.get_xyz
54
- means2D = screenspace_points
55
- opacity = pc.get_opacity
56
-
57
- # If precomputed 3d covariance is provided, use it. If not, then it will be computed from
58
- # scaling / rotation by the rasterizer.
59
- scales = None
60
- rotations = None
61
- cov3D_precomp = None
62
- if opt.compute_cov3D_python:
63
- cov3D_precomp = pc.get_covariance(scaling_modifier)
64
- else:
65
- scales = pc.get_scaling
66
- rotations = pc.get_rotation
67
-
68
- # If precomputed colors are provided, use them. Otherwise, if it is desired to precompute colors
69
- # from SHs in Python, do it. If not, then SH -> RGB conversion will be done by rasterizer.
70
- shs = None
71
- colors_precomp = None
72
- if override_color is None:
73
- if opt.convert_SHs_python:
74
- shs_view = pc.get_features.transpose(1, 2).view(-1, 3, (pc.max_sh_degree+1)**2)
75
- dir_pp = (pc.get_xyz - viewpoint_camera.camera_center.repeat(pc.get_features.shape[0], 1))
76
- dir_pp_normalized = dir_pp/dir_pp.norm(dim=1, keepdim=True)
77
- sh2rgb = eval_sh(pc.active_sh_degree, shs_view, dir_pp_normalized)
78
- colors_precomp = torch.clamp_min(sh2rgb + 0.5, 0.0)
79
- else:
80
- shs = pc.get_features
81
- else:
82
- colors_precomp = override_color
83
-
84
- # Rasterize visible Gaussians to image, obtain their radii (on screen).
85
- rendered_image, radii, depth = rasterizer(
86
- means3D = means3D,
87
- means2D = means2D,
88
- shs = shs,
89
- colors_precomp = colors_precomp,
90
- opacities = opacity,
91
- scales = scales,
92
- rotations = rotations,
93
- cov3D_precomp = cov3D_precomp)
94
-
95
- # Those Gaussians that were frustum culled or had a radius of 0 were not visible.
96
- # They will be excluded from value updates used in the splitting criteria.
97
- if render_only:
98
- return {"render": rendered_image, "depth": depth}
99
- else:
100
- return {"render": rendered_image,
101
- "viewspace_points": screenspace_points,
102
- "visibility_filter" : radii > 0,
103
- "radii": radii,
104
- "depth": depth}