mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-21 14:50:36 +08:00
Updates to cameras and rasterizer to infer camera type correctly
Summary: Small update to the cameras and rasterizer to correctly infer the type of camera (perspective vs orthographic). Reviewed By: jcjohnson Differential Revision: D26267225 fbshipit-source-id: a58ed3bc2ab25553d2a4307c734204c1d41b5176
This commit is contained in:
committed by
Facebook GitHub Bot
parent
39f49c22cd
commit
838b73d3b6
@@ -42,15 +42,16 @@ class CamerasBase(TensorProperties):
|
||||
|
||||
It defines methods that are common to all camera models:
|
||||
- `get_camera_center` that returns the optical center of the camera in
|
||||
world coordinates
|
||||
world coordinates
|
||||
- `get_world_to_view_transform` which returns a 3D transform from
|
||||
world coordinates to the camera view coordinates (R, T)
|
||||
world coordinates to the camera view coordinates (R, T)
|
||||
- `get_full_projection_transform` which composes the projection
|
||||
transform (P) with the world-to-view transform (R, T)
|
||||
transform (P) with the world-to-view transform (R, T)
|
||||
- `transform_points` which takes a set of input points in world coordinates and
|
||||
projects to NDC coordinates ranging from [-1, -1, znear] to [+1, +1, zfar].
|
||||
projects to NDC coordinates ranging from [-1, -1, znear] to [+1, +1, zfar].
|
||||
- `transform_points_screen` which takes a set of input points in world coordinates and
|
||||
projects them to the screen coordinates ranging from [0, 0, znear] to [W-1, H-1, zfar]
|
||||
projects them to the screen coordinates ranging from
|
||||
[0, 0, znear] to [W-1, H-1, zfar]
|
||||
|
||||
For each new camera, one should implement the `get_projection_transform`
|
||||
routine that returns the mapping from camera view coordinates to NDC coordinates.
|
||||
@@ -268,6 +269,12 @@ class CamerasBase(TensorProperties):
|
||||
other = cam_type(device=self.device)
|
||||
return super().clone(other)
|
||||
|
||||
def is_perspective(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_znear(self):
|
||||
return self.znear if hasattr(self, "znear") else None
|
||||
|
||||
|
||||
############################################################
|
||||
# Field of View Camera Classes #
|
||||
@@ -534,6 +541,9 @@ class FoVPerspectiveCameras(CamerasBase):
|
||||
unprojection_transform = to_ndc_transform.inverse()
|
||||
return unprojection_transform.transform_points(xy_sdepth)
|
||||
|
||||
def is_perspective(self):
|
||||
return True
|
||||
|
||||
|
||||
def OpenGLOrthographicCameras(
|
||||
znear=1.0,
|
||||
@@ -752,6 +762,9 @@ class FoVOrthographicCameras(CamerasBase):
|
||||
unprojection_transform = to_ndc_transform.inverse()
|
||||
return unprojection_transform.transform_points(xy_sdepth)
|
||||
|
||||
def is_perspective(self):
|
||||
return False
|
||||
|
||||
|
||||
############################################################
|
||||
# MultiView Camera Classes #
|
||||
@@ -927,6 +940,9 @@ class PerspectiveCameras(CamerasBase):
|
||||
)
|
||||
return unprojection_transform.transform_points(xy_inv_depth)
|
||||
|
||||
def is_perspective(self):
|
||||
return True
|
||||
|
||||
|
||||
def SfMOrthographicCameras(
|
||||
focal_length=1.0, principal_point=((0.0, 0.0),), R=_R, T=_T, device="cpu"
|
||||
@@ -1086,6 +1102,9 @@ class OrthographicCameras(CamerasBase):
|
||||
unprojection_transform = to_ndc_transform.inverse()
|
||||
return unprojection_transform.transform_points(xy_depth)
|
||||
|
||||
def is_perspective(self):
|
||||
return False
|
||||
|
||||
|
||||
################################################
|
||||
# Helper functions for cameras #
|
||||
|
||||
@@ -139,8 +139,13 @@ class MeshRasterizer(nn.Module):
|
||||
if clip_barycentric_coords is None:
|
||||
clip_barycentric_coords = raster_settings.blur_radius > 0.0
|
||||
|
||||
# TODO(jcjohns): Should we try to set perspective_correct automatically
|
||||
# based on the type of the camera?
|
||||
# If not specified, infer perspective_correct from the camera
|
||||
cameras = kwargs.get("cameras", self.cameras)
|
||||
if raster_settings.perspective_correct is not None:
|
||||
perspective_correct = raster_settings.perspective_correct
|
||||
else:
|
||||
perspective_correct = cameras.is_perspective()
|
||||
|
||||
pix_to_face, zbuf, bary_coords, dists = rasterize_meshes(
|
||||
meshes_screen,
|
||||
image_size=raster_settings.image_size,
|
||||
@@ -148,7 +153,7 @@ class MeshRasterizer(nn.Module):
|
||||
faces_per_pixel=raster_settings.faces_per_pixel,
|
||||
bin_size=raster_settings.bin_size,
|
||||
max_faces_per_bin=raster_settings.max_faces_per_bin,
|
||||
perspective_correct=raster_settings.perspective_correct,
|
||||
perspective_correct=perspective_correct,
|
||||
clip_barycentric_coords=clip_barycentric_coords,
|
||||
cull_backfaces=raster_settings.cull_backfaces,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user