mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 20:02:49 +08:00
fix pts scale, save ply
Summary: Fix: * Scaling of point clouds for scalars * save_ply compatible cat Reviewed By: nikhilaravi Differential Revision: D22298609 fbshipit-source-id: abe94a5b64baf325587202d20adfc36912cc1478
This commit is contained in:
parent
275ddade66
commit
2f0fd60186
@ -783,7 +783,11 @@ def save_ply(
|
|||||||
decimal_places: Number of decimal places for saving.
|
decimal_places: Number of decimal places for saving.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
verts_normals = torch.FloatTensor([]) if verts_normals is None else verts_normals
|
verts_normals = (
|
||||||
|
torch.tensor([], dtype=torch.float32, device=verts.device)
|
||||||
|
if verts_normals is None
|
||||||
|
else verts_normals
|
||||||
|
)
|
||||||
faces = torch.LongTensor([]) if faces is None else faces
|
faces = torch.LongTensor([]) if faces is None else faces
|
||||||
|
|
||||||
if len(verts) and not (verts.dim() == 2 and verts.size(1) == 3):
|
if len(verts) and not (verts.dim() == 2 and verts.size(1) == 3):
|
||||||
|
@ -511,7 +511,6 @@ class Pointclouds(object):
|
|||||||
Returns:
|
Returns:
|
||||||
1D tensor of indices.
|
1D tensor of indices.
|
||||||
"""
|
"""
|
||||||
self._compute_packed()
|
|
||||||
if self._padded_to_packed_idx is not None:
|
if self._padded_to_packed_idx is not None:
|
||||||
return self._padded_to_packed_idx
|
return self._padded_to_packed_idx
|
||||||
if self._N == 0:
|
if self._N == 0:
|
||||||
@ -520,7 +519,7 @@ class Pointclouds(object):
|
|||||||
self._padded_to_packed_idx = torch.cat(
|
self._padded_to_packed_idx = torch.cat(
|
||||||
[
|
[
|
||||||
torch.arange(v, dtype=torch.int64, device=self.device) + i * self._P
|
torch.arange(v, dtype=torch.int64, device=self.device) + i * self._P
|
||||||
for (i, v) in enumerate(self._num_points_per_cloud)
|
for (i, v) in enumerate(self.num_points_per_cloud())
|
||||||
],
|
],
|
||||||
dim=0,
|
dim=0,
|
||||||
)
|
)
|
||||||
@ -797,7 +796,7 @@ class Pointclouds(object):
|
|||||||
self.
|
self.
|
||||||
"""
|
"""
|
||||||
if not torch.is_tensor(scale):
|
if not torch.is_tensor(scale):
|
||||||
scale = torch.full(len(self), scale)
|
scale = torch.full((len(self),), scale, device=self.device)
|
||||||
new_points_list = []
|
new_points_list = []
|
||||||
points_list = self.points_list()
|
points_list = self.points_list()
|
||||||
for i, old_points in enumerate(points_list):
|
for i, old_points in enumerate(points_list):
|
||||||
|
@ -510,8 +510,8 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
|
|||||||
|
|
||||||
N = 5
|
N = 5
|
||||||
for test in ["tensor", "scalar"]:
|
for test in ["tensor", "scalar"]:
|
||||||
|
for force in (False, True):
|
||||||
mesh = TestMeshes.init_mesh(N, 10, 100)
|
mesh = TestMeshes.init_mesh(N, 10, 100)
|
||||||
for force in [0, 1]:
|
|
||||||
if force:
|
if force:
|
||||||
# force mesh to have computed attributes
|
# force mesh to have computed attributes
|
||||||
mesh.verts_packed()
|
mesh.verts_packed()
|
||||||
|
@ -460,7 +460,7 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
|
|||||||
def test_scale(self):
|
def test_scale(self):
|
||||||
def naive_scale(cloud, scale):
|
def naive_scale(cloud, scale):
|
||||||
if not torch.is_tensor(scale):
|
if not torch.is_tensor(scale):
|
||||||
scale = torch.full(len(cloud), scale)
|
scale = torch.full((len(cloud),), scale, device=cloud.device)
|
||||||
new_points_list = [
|
new_points_list = [
|
||||||
scale[i] * points.clone()
|
scale[i] * points.clone()
|
||||||
for (i, points) in enumerate(cloud.points_list())
|
for (i, points) in enumerate(cloud.points_list())
|
||||||
@ -470,18 +470,29 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
N = 5
|
N = 5
|
||||||
clouds = self.init_cloud(N, 100, 10)
|
for test in ["tensor", "scalar"]:
|
||||||
for force in (False, True):
|
for force in (False, True):
|
||||||
|
clouds = self.init_cloud(N, 100, 10)
|
||||||
if force:
|
if force:
|
||||||
clouds._compute_packed(refresh=True)
|
clouds._compute_packed(refresh=True)
|
||||||
clouds._compute_padded()
|
clouds._compute_padded()
|
||||||
clouds.padded_to_packed_idx()
|
clouds.padded_to_packed_idx()
|
||||||
|
if test == "tensor":
|
||||||
scales = torch.rand(N)
|
scales = torch.rand(N)
|
||||||
|
elif test == "scalar":
|
||||||
|
scales = torch.rand(1)[0].item()
|
||||||
new_clouds_naive = naive_scale(clouds, scales)
|
new_clouds_naive = naive_scale(clouds, scales)
|
||||||
new_clouds = clouds.scale(scales)
|
new_clouds = clouds.scale(scales)
|
||||||
for i in range(N):
|
for i in range(N):
|
||||||
|
if test == "tensor":
|
||||||
self.assertClose(
|
self.assertClose(
|
||||||
scales[i] * clouds.points_list()[i], new_clouds.points_list()[i]
|
scales[i] * clouds.points_list()[i],
|
||||||
|
new_clouds.points_list()[i],
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.assertClose(
|
||||||
|
scales * clouds.points_list()[i],
|
||||||
|
new_clouds.points_list()[i],
|
||||||
)
|
)
|
||||||
self.assertClose(
|
self.assertClose(
|
||||||
clouds.normals_list()[i], new_clouds_naive.normals_list()[i]
|
clouds.normals_list()[i], new_clouds_naive.normals_list()[i]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user