mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 03:42:50 +08:00
Simplify transforms in point rasterizer
Summary: Update the transform step in the pointcloud rasterizer to use the `update_padded` method on `Pointclouds`. There was an inefficient step using `offset_points` which went via the packed represntation (and required unecessary additional memory). I think this was before the `update_padded` method was added to `Pointclouds`. Reviewed By: gkioxari Differential Revision: D22329166 fbshipit-source-id: 76db8a19654fb2f7807635d4f1c1729debdf3320
This commit is contained in:
parent
876bdff2f6
commit
ce3da64917
@ -86,22 +86,18 @@ class PointsRasterizer(nn.Module):
|
||||
raise ValueError(msg)
|
||||
|
||||
pts_world = point_clouds.points_padded()
|
||||
pts_world_packed = point_clouds.points_packed()
|
||||
pts_screen = cameras.transform_points(pts_world, **kwargs)
|
||||
|
||||
# NOTE: Retaining view space z coordinate for now.
|
||||
# TODO: Remove this line when the convention for the z coordinate in
|
||||
# the rasterizer is decided. i.e. retain z in view space or transform
|
||||
# to a different range.
|
||||
view_transform = get_world_to_view_transform(R=cameras.R, T=cameras.T)
|
||||
verts_view = view_transform.transform_points(pts_world)
|
||||
pts_screen[..., 2] = verts_view[..., 2]
|
||||
|
||||
# Offset points of input pointcloud to reuse cached padded/packed calculations.
|
||||
pad_to_packed_idx = point_clouds.padded_to_packed_idx()
|
||||
pts_screen_packed = pts_screen.view(-1, 3)[pad_to_packed_idx, :]
|
||||
pts_packed_offset = pts_screen_packed - pts_world_packed
|
||||
point_clouds = point_clouds.offset(pts_packed_offset)
|
||||
pts_view = cameras.get_world_to_view_transform(**kwargs).transform_points(
|
||||
pts_world
|
||||
)
|
||||
pts_screen = cameras.get_projection_transform(**kwargs).transform_points(
|
||||
pts_view
|
||||
)
|
||||
pts_screen[..., 2] = pts_view[..., 2]
|
||||
point_clouds = point_clouds.update_padded(pts_screen)
|
||||
return point_clouds
|
||||
|
||||
def forward(self, point_clouds, **kwargs) -> PointFragments:
|
||||
|
Loading…
x
Reference in New Issue
Block a user