Skip to content

Commit 960fd6d

Browse files
classnerfacebook-github-bot
authored andcommitted
pulsar interface unification.
Summary: This diff builds on top of the `pulsar integration` diff to provide a unified interface for the existing PyTorch3D point renderer and Pulsar. For more information about the pulsar backend, see the release notes and the paper (https://arxiv.org/abs/2004.07484). For information on how to use the backend, see the point cloud rendering notebook and the examples in the folder docs/examples. The unified interfaces are completely consistent. Switching the render backend is as easy as using `renderer = PulsarPointsRenderer(rasterizer=rasterizer).to(device)` instead of `renderer = PointsRenderer(rasterizer=rasterizer, compositor=compositor)` and adding the `gamma` parameter to the forward function. All PyTorch3D camera types are supported as far as possible; keyword arguments are properly forwarded to the camera. The `PerspectiveCamera` and `OrthographicCamera` require znear and zfar as additional parameters for the forward pass. Reviewed By: nikhilaravi Differential Revision: D21421443 fbshipit-source-id: 4aa0a83a419592d9a0bb5d62486a1cdea9d73ce6
1 parent b19fe1d commit 960fd6d

18 files changed

+695
-313
lines changed

pytorch3d/renderer/points/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
22

33
from .compositor import AlphaCompositor, NormWeightedCompositor
4+
from .pulsar.unified import PulsarPointsRenderer
45
from .rasterize_points import rasterize_points
56
from .rasterizer import PointsRasterizationSettings, PointsRasterizer
67
from .renderer import PointsRenderer

pytorch3d/renderer/points/pulsar/renderer.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ def _transform_cam_params(
369369
height: int,
370370
orthogonal: bool,
371371
right_handed: bool,
372+
first_R_then_T: bool = False,
372373
) -> Tuple[
373374
torch.Tensor,
374375
torch.Tensor,
@@ -401,6 +402,8 @@ def _transform_cam_params(
401402
(does not use focal length).
402403
* right_handed: bool, whether to use a right handed system
403404
(negative z in camera direction).
405+
* first_R_then_T: bool, whether to first rotate, then translate
406+
the camera (PyTorch3D convention).
404407
405408
Returns:
406409
* pos_vec: the position vector in 3D,
@@ -460,16 +463,18 @@ def _transform_cam_params(
460463
# Always get quadratic pixels.
461464
pixel_size_x = sensor_size_x / float(width)
462465
sensor_size_y = height * pixel_size_x
466+
if continuous_rep:
467+
rot_mat = rotation_6d_to_matrix(rot_vec)
468+
else:
469+
rot_mat = axis_angle_to_matrix(rot_vec)
470+
if first_R_then_T:
471+
pos_vec = torch.matmul(rot_mat, pos_vec[..., None])[:, :, 0]
463472
LOGGER.debug(
464473
"Camera position: %s, rotation: %s. Focal length: %s.",
465474
str(pos_vec),
466475
str(rot_vec),
467476
str(focal_length),
468477
)
469-
if continuous_rep:
470-
rot_mat = rotation_6d_to_matrix(rot_vec)
471-
else:
472-
rot_mat = axis_angle_to_matrix(rot_vec)
473478
sensor_dir_x = torch.matmul(
474479
rot_mat,
475480
torch.tensor(
@@ -576,6 +581,7 @@ def forward(
576581
max_n_hits: int = _C.MAX_UINT,
577582
mode: int = 0,
578583
return_forward_info: bool = False,
584+
first_R_then_T: bool = False,
579585
) -> Union[torch.Tensor, Tuple[torch.Tensor, Optional[torch.Tensor]]]:
580586
"""
581587
Rendering pass to create an image from the provided spheres and camera
@@ -616,6 +622,8 @@ def forward(
616622
the float encoded integer index of a sphere and its weight. They are the
617623
five spheres with the highest color contribution to this pixel color,
618624
ordered descending. Default: False.
625+
* first_R_then_T: bool, whether to first apply rotation to the camera,
626+
then translation (PyTorch3D convention). Default: False.
619627
620628
Returns:
621629
* image: [Bx]HxWx3 float tensor with the resulting image.
@@ -638,6 +646,7 @@ def forward(
638646
self._renderer.height,
639647
self._renderer.orthogonal,
640648
self._renderer.right_handed,
649+
first_R_then_T=first_R_then_T,
641650
)
642651
if (
643652
focal_lengths.min().item() > 0.0

0 commit comments

Comments
 (0)