Skip to content

Commit 1b6182b

Browse files
bottlerfacebook-github-bot
authored andcommitted
Plotly subsampling fix
Summary: When viewing two or more pointclouds in a single plot, we should be subsampling each one separately rather than subsampling their union. Reviewed By: nikhilaravi Differential Revision: D27010770 fbshipit-source-id: 3c7e04a6049edd39756047f985d5a82c2601b3a2
1 parent ff9c661 commit 1b6182b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pytorch3d/vis/plotly_vis.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ def plot_scene(
6161
**kwargs,
6262
):
6363
"""
64-
Main function to visualize Meshes and Pointclouds.
64+
Main function to visualize Meshes, Cameras and Pointclouds.
6565
Plots input Pointclouds, Meshes, and Cameras data into named subplots,
6666
with named traces based on the dictionary keys. Cameras are
6767
rendered at the camera center location using a wireframe.
6868
6969
Args:
7070
plots: A dict containing subplot and trace names,
71-
as well as the Meshes and Pointclouds objects to be rendered.
71+
as well as the Meshes, Cameras and Pointclouds objects to be rendered.
7272
See below for examples of the format.
7373
viewpoint_cameras: an instance of a Cameras object providing a location
7474
to view the plotly plot from. If the batch size is equal
@@ -574,11 +574,21 @@ def _add_pointcloud_trace(
574574
pointclouds = pointclouds.detach().cpu()
575575
verts = pointclouds.points_packed()
576576
features = pointclouds.features_packed()
577-
total_points_count = max_points_per_pointcloud * len(pointclouds)
578577

579578
indices = None
580-
if verts.shape[0] > total_points_count:
581-
indices = np.random.choice(verts.shape[0], total_points_count, replace=False)
579+
if pointclouds.num_points_per_cloud().max() > max_points_per_pointcloud:
580+
start_index = 0
581+
index_list = []
582+
for num_points in pointclouds.num_points_per_cloud():
583+
if num_points > max_points_per_pointcloud:
584+
indices_cloud = np.random.choice(
585+
num_points, max_points_per_pointcloud, replace=False
586+
)
587+
index_list.append(start_index + indices_cloud)
588+
else:
589+
index_list.append(start_index + np.arange(num_points))
590+
start_index += num_points
591+
indices = np.concatenate(index_list)
582592
verts = verts[indices]
583593

584594
color = None

0 commit comments

Comments
 (0)