MCPcopy Create free account
hub / github.com/apple/ml-sharp / render_gaussians

Function render_gaussians

src/sharp/cli/render.py:70–120  ·  view source on GitHub ↗

Render a single gaussian checkpoint file.

(
    gaussians: Gaussians3D,
    metadata: SceneMetaData,
    output_path: Path,
    params: camera.TrajectoryParams | None = None,
)

Source from the content-addressed store, hash-verified

68
69
70def render_gaussians(
71 gaussians: Gaussians3D,
72 metadata: SceneMetaData,
73 output_path: Path,
74 params: camera.TrajectoryParams | None = None,
75) -> None:
76 """Render a single gaussian checkpoint file."""
77 (width, height) = metadata.resolution_px
78 f_px = metadata.focal_length_px
79
80 if params is None:
81 params = camera.TrajectoryParams()
82
83 if not torch.cuda.is_available():
84 raise RuntimeError("Rendering a checkpoint requires CUDA.")
85
86 device = torch.device("cuda")
87
88 intrinsics = torch.tensor(
89 [
90 [f_px, 0, (width - 1) / 2.0, 0],
91 [0, f_px, (height - 1) / 2.0, 0],
92 [0, 0, 1, 0],
93 [0, 0, 0, 1],
94 ],
95 device=device,
96 dtype=torch.float32,
97 )
98 camera_model = camera.create_camera_model(
99 gaussians, intrinsics, resolution_px=metadata.resolution_px
100 )
101
102 trajectory = camera.create_eye_trajectory(
103 gaussians, params, resolution_px=metadata.resolution_px, f_px=f_px
104 )
105 renderer = gsplat.GSplatRenderer(color_space=metadata.color_space)
106 video_writer = io.VideoWriter(output_path)
107
108 for _, eye_position in enumerate(trajectory):
109 camera_info = camera_model.compute(eye_position)
110 rendering_output = renderer(
111 gaussians.to(device),
112 extrinsics=camera_info.extrinsics[None].to(device),
113 intrinsics=camera_info.intrinsics[None].to(device),
114 image_width=camera_info.width,
115 image_height=camera_info.height,
116 )
117 color = (rendering_output.color[0].permute(1, 2, 0) * 255.0).to(dtype=torch.uint8)
118 depth = rendering_output.depth[0]
119 video_writer.add_frame(color, depth)
120 video_writer.close()

Callers 2

predict_cliFunction · 0.85
render_cliFunction · 0.85

Calls 4

add_frameMethod · 0.95
closeMethod · 0.95
computeMethod · 0.80
toMethod · 0.80

Tested by

no test coverage detected