|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +import unittest |
| 8 | + |
| 9 | +import torch |
| 10 | +from pytorch3d.renderer import HeterogeneousRayBundle, PerspectiveCameras, RayBundle |
| 11 | +from pytorch3d.structures import Meshes, Pointclouds |
| 12 | +from pytorch3d.transforms import random_rotations |
| 13 | + |
| 14 | +# Some of these imports are only needed for testing code coverage |
| 15 | +from pytorch3d.vis import ( # noqa: F401 |
| 16 | + get_camera_wireframe, # noqa: F401 |
| 17 | + plot_batch_individually, # noqa: F401 |
| 18 | + plot_scene, |
| 19 | + texturesuv_image_PIL, # noqa: F401 |
| 20 | +) |
| 21 | + |
| 22 | + |
| 23 | +class TestPlotlyVis(unittest.TestCase): |
| 24 | + def test_plot_scene( |
| 25 | + self, |
| 26 | + B: int = 3, |
| 27 | + n_rays: int = 128, |
| 28 | + n_pts_per_ray: int = 32, |
| 29 | + n_verts: int = 32, |
| 30 | + n_edges: int = 64, |
| 31 | + n_pts: int = 256, |
| 32 | + ): |
| 33 | + """ |
| 34 | + Tests plotting of all supported structures using plot_scene. |
| 35 | + """ |
| 36 | + for device in ["cpu", "cuda:0"]: |
| 37 | + plot_scene( |
| 38 | + { |
| 39 | + "scene": { |
| 40 | + "ray_bundle": RayBundle( |
| 41 | + origins=torch.randn(B, n_rays, 3, device=device), |
| 42 | + xys=torch.randn(B, n_rays, 2, device=device), |
| 43 | + directions=torch.randn(B, n_rays, 3, device=device), |
| 44 | + lengths=torch.randn( |
| 45 | + B, n_rays, n_pts_per_ray, device=device |
| 46 | + ), |
| 47 | + ), |
| 48 | + "heterogeneous_ray_bundle": HeterogeneousRayBundle( |
| 49 | + origins=torch.randn(B * n_rays, 3, device=device), |
| 50 | + xys=torch.randn(B * n_rays, 2, device=device), |
| 51 | + directions=torch.randn(B * n_rays, 3, device=device), |
| 52 | + lengths=torch.randn( |
| 53 | + B * n_rays, n_pts_per_ray, device=device |
| 54 | + ), |
| 55 | + camera_ids=torch.randint( |
| 56 | + low=0, high=B, size=(B * n_rays,), device=device |
| 57 | + ), |
| 58 | + ), |
| 59 | + "camera": PerspectiveCameras( |
| 60 | + R=random_rotations(B, device=device), |
| 61 | + T=torch.randn(B, 3, device=device), |
| 62 | + ), |
| 63 | + "mesh": Meshes( |
| 64 | + verts=torch.randn(B, n_verts, 3, device=device), |
| 65 | + faces=torch.randint( |
| 66 | + low=0, high=n_verts, size=(B, n_edges, 3), device=device |
| 67 | + ), |
| 68 | + ), |
| 69 | + "point_clouds": Pointclouds( |
| 70 | + points=torch.randn(B, n_pts, 3, device=device), |
| 71 | + ), |
| 72 | + } |
| 73 | + } |
| 74 | + ) |
0 commit comments