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

Class PinholeCameraModel

src/sharp/utils/camera.py:271–350  ·  view source on GitHub ↗

Camera model that focuses on point.

Source from the content-addressed store, hash-verified

269
270
271class PinholeCameraModel:
272 """Camera model that focuses on point."""
273
274 def __init__(
275 self,
276 scene: Gaussians3D,
277 screen_extrinsics: torch.Tensor,
278 screen_intrinsics: torch.Tensor,
279 screen_resolution_px: tuple[int, int],
280 focus_depth_quantile: float = 0.1,
281 min_depth_focus: float = 2.0,
282 lookat_point: tuple[float, float, float] | None = None,
283 lookat_mode: LookAtMode = "point",
284 ) -> None:
285 """Initialize GeneralPinholeCameraModel.
286
287 Args:
288 scene: The scene to display.
289 screen_extrinsics: Extrinsics of the default position.
290 screen_intrinsics: Intrinsics to use for rendering.
291 screen_resolution_px: Width and height to render.
292 focus_depth_quantile: Where inside the depth range to focus on.
293 min_depth_focus: Depth to focus at.
294 lookat_point: a point that the camera's Z axis directs towards.
295 lookat_mode: "point" to look at a fixed point,
296 "ahead" to look straight ahead.
297 """
298 self.scene = scene
299 self.screen_extrinsics = screen_extrinsics
300 self.screen_intrinsics = screen_intrinsics
301 self.screen_resolution_px = screen_resolution_px
302
303 self.focus_depth_quantile = focus_depth_quantile
304 self.min_depth_focus = min_depth_focus
305 self.lookat_point = lookat_point
306 self.lookat_mode = lookat_mode
307
308 scene_points = scene.mean_vectors
309 if scene_points.ndim == 3:
310 scene_points = scene_points[0]
311 elif scene_points.ndim != 2:
312 raise ValueError("Unsupported dimensionality of scene points.")
313 self._scene_points = scene_points.cpu()
314
315 self.depth_quantiles = _compute_depth_quantiles(
316 self._scene_points,
317 self.screen_extrinsics,
318 q_focus=self.focus_depth_quantile,
319 )
320
321 def compute(self, eye_pos: torch.Tensor) -> CameraInfo:
322 """Compute camera for eye position."""
323 extrinsics = self.screen_extrinsics.clone()
324
325 origin = eye_pos if self.lookat_mode == "ahead" else torch.zeros(3)
326
327 if self.lookat_point is None:
328 depth_focus = max(self.min_depth_focus, self.depth_quantiles.focus)

Callers 1

create_camera_modelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected