Skip to content

Commit b64fe51

Browse files
bottlerfacebook-github-bot
authored andcommitted
join_meshes_as_batch
Summary: rename join_meshes to join_meshes_as_batch. Reviewed By: nikhilaravi Differential Revision: D20671293 fbshipit-source-id: e84d6a67d6c1ec28fb5e52d4607db8e92561a4cd
1 parent 27eb791 commit b64fe51

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

pytorch3d/io/obj_io.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import torch
1313
from fvcore.common.file_io import PathManager
1414
from PIL import Image
15-
from pytorch3d.structures import Meshes, Textures, join_meshes
15+
from pytorch3d.structures import Meshes, Textures, join_meshes_as_batch
1616

1717

1818
def _make_tensor(data, cols: int, dtype: torch.dtype) -> torch.Tensor:
@@ -249,7 +249,7 @@ def load_objs_as_meshes(files: list, device=None, load_textures: bool = True):
249249
mesh_list.append(mesh)
250250
if len(mesh_list) == 1:
251251
return mesh_list[0]
252-
return join_meshes(mesh_list)
252+
return join_meshes_as_batch(mesh_list)
253253

254254

255255
def _parse_face(

pytorch3d/structures/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
22

3-
from .meshes import Meshes, join_meshes
3+
from .meshes import Meshes, join_meshes_as_batch
44
from .pointclouds import Pointclouds
55
from .textures import Textures
66
from .utils import list_to_packed, list_to_padded, packed_to_list, padded_to_list

pytorch3d/structures/meshes.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ def extend(self, N: int):
13461346
return Meshes(verts=new_verts_list, faces=new_faces_list, textures=tex)
13471347

13481348

1349-
def join_meshes(meshes: List[Meshes], include_textures: bool = True):
1349+
def join_meshes_as_batch(meshes: List[Meshes], include_textures: bool = True):
13501350
"""
13511351
Merge multiple Meshes objects, i.e. concatenate the meshes objects. They
13521352
must all be on the same device. If include_textures is true, they must all
@@ -1363,58 +1363,58 @@ def join_meshes(meshes: List[Meshes], include_textures: bool = True):
13631363
"""
13641364
if isinstance(meshes, Meshes):
13651365
# Meshes objects can be iterated and produce single Meshes. We avoid
1366-
# letting join_meshes(mesh1, mesh2) silently do the wrong thing.
1367-
raise ValueError("Wrong first argument to join_meshes.")
1366+
# letting join_meshes_as_batch(mesh1, mesh2) silently do the wrong thing.
1367+
raise ValueError("Wrong first argument to join_meshes_as_batch.")
13681368
verts = [v for mesh in meshes for v in mesh.verts_list()]
13691369
faces = [f for mesh in meshes for f in mesh.faces_list()]
13701370
if len(meshes) == 0 or not include_textures:
13711371
return Meshes(verts=verts, faces=faces)
13721372

13731373
if meshes[0].textures is None:
13741374
if any(mesh.textures is not None for mesh in meshes):
1375-
raise ValueError("Inconsistent textures in join_meshes.")
1375+
raise ValueError("Inconsistent textures in join_meshes_as_batch.")
13761376
return Meshes(verts=verts, faces=faces)
13771377

13781378
if any(mesh.textures is None for mesh in meshes):
1379-
raise ValueError("Inconsistent textures in join_meshes.")
1379+
raise ValueError("Inconsistent textures in join_meshes_as_batch.")
13801380

13811381
# Now we know there are multiple meshes and they have textures to merge.
13821382
first = meshes[0].textures
13831383
kwargs = {}
13841384
if first.maps_padded() is not None:
13851385
if any(mesh.textures.maps_padded() is None for mesh in meshes):
1386-
raise ValueError("Inconsistent maps_padded in join_meshes.")
1386+
raise ValueError("Inconsistent maps_padded in join_meshes_as_batch.")
13871387
maps = [m for mesh in meshes for m in mesh.textures.maps_padded()]
13881388
kwargs["maps"] = maps
13891389
elif any(mesh.textures.maps_padded() is not None for mesh in meshes):
1390-
raise ValueError("Inconsistent maps_padded in join_meshes.")
1390+
raise ValueError("Inconsistent maps_padded in join_meshes_as_batch.")
13911391

13921392
if first.verts_uvs_padded() is not None:
13931393
if any(mesh.textures.verts_uvs_padded() is None for mesh in meshes):
1394-
raise ValueError("Inconsistent verts_uvs_padded in join_meshes.")
1394+
raise ValueError("Inconsistent verts_uvs_padded in join_meshes_as_batch.")
13951395
uvs = [uv for mesh in meshes for uv in mesh.textures.verts_uvs_list()]
13961396
V = max(uv.shape[0] for uv in uvs)
13971397
kwargs["verts_uvs"] = struct_utils.list_to_padded(uvs, (V, 2), -1)
13981398
elif any(mesh.textures.verts_uvs_padded() is not None for mesh in meshes):
1399-
raise ValueError("Inconsistent verts_uvs_padded in join_meshes.")
1399+
raise ValueError("Inconsistent verts_uvs_padded in join_meshes_as_batch.")
14001400

14011401
if first.faces_uvs_padded() is not None:
14021402
if any(mesh.textures.faces_uvs_padded() is None for mesh in meshes):
1403-
raise ValueError("Inconsistent faces_uvs_padded in join_meshes.")
1403+
raise ValueError("Inconsistent faces_uvs_padded in join_meshes_as_batch.")
14041404
uvs = [uv for mesh in meshes for uv in mesh.textures.faces_uvs_list()]
14051405
F = max(uv.shape[0] for uv in uvs)
14061406
kwargs["faces_uvs"] = struct_utils.list_to_padded(uvs, (F, 3), -1)
14071407
elif any(mesh.textures.faces_uvs_padded() is not None for mesh in meshes):
1408-
raise ValueError("Inconsistent faces_uvs_padded in join_meshes.")
1408+
raise ValueError("Inconsistent faces_uvs_padded in join_meshes_as_batch.")
14091409

14101410
if first.verts_rgb_padded() is not None:
14111411
if any(mesh.textures.verts_rgb_padded() is None for mesh in meshes):
1412-
raise ValueError("Inconsistent verts_rgb_padded in join_meshes.")
1412+
raise ValueError("Inconsistent verts_rgb_padded in join_meshes_as_batch.")
14131413
rgb = [i for mesh in meshes for i in mesh.textures.verts_rgb_list()]
14141414
V = max(i.shape[0] for i in rgb)
14151415
kwargs["verts_rgb"] = struct_utils.list_to_padded(rgb, (V, 3))
14161416
elif any(mesh.textures.verts_rgb_padded() is not None for mesh in meshes):
1417-
raise ValueError("Inconsistent verts_rgb_padded in join_meshes.")
1417+
raise ValueError("Inconsistent verts_rgb_padded in join_meshes_as_batch.")
14181418

14191419
tex = Textures(**kwargs)
14201420
return Meshes(verts=verts, faces=faces, textures=tex)

tests/test_obj_io.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import torch
99
from common_testing import TestCaseMixin
1010
from pytorch3d.io import load_obj, load_objs_as_meshes, save_obj
11-
from pytorch3d.structures import Meshes, Textures, join_meshes
11+
from pytorch3d.structures import Meshes, Textures, join_meshes_as_batch
1212
from pytorch3d.utils import torus
1313

1414

@@ -523,10 +523,10 @@ def test_load_obj_missing_mtl_noload(self):
523523
self.assertTrue(aux.material_colors is None)
524524
self.assertTrue(aux.texture_images is None)
525525

526-
def test_join_meshes(self):
526+
def test_join_meshes_as_batch(self):
527527
"""
528-
Test that join_meshes and load_objs_as_meshes are consistent with single
529-
meshes.
528+
Test that join_meshes_as_batch and load_objs_as_meshes are consistent
529+
with single meshes.
530530
"""
531531

532532
def check_triple(mesh, mesh3):
@@ -575,7 +575,7 @@ def check_item(x, y):
575575
)
576576
tex = Textures(verts_rgb=vert_tex[None, :])
577577
mesh_rgb = Meshes(verts=[verts], faces=[faces], textures=tex)
578-
mesh_rgb3 = join_meshes([mesh_rgb, mesh_rgb, mesh_rgb])
578+
mesh_rgb3 = join_meshes_as_batch([mesh_rgb, mesh_rgb, mesh_rgb])
579579
check_triple(mesh_rgb, mesh_rgb3)
580580

581581
teapot_obj = DATA_DIR / "teapot.obj"
@@ -588,7 +588,7 @@ def check_item(x, y):
588588
self.assertClose(mix_mesh.verts_list()[1], teapot_verts)
589589
self.assertClose(mix_mesh.faces_list()[1], teapot_faces)
590590

591-
cow3_tea = join_meshes([mesh3, mesh_teapot], include_textures=False)
591+
cow3_tea = join_meshes_as_batch([mesh3, mesh_teapot], include_textures=False)
592592
self.assertEqual(len(cow3_tea), 4)
593593
check_triple(mesh_notex, cow3_tea[:3])
594594
self.assertClose(cow3_tea.verts_list()[3], mesh_teapot.verts_list()[0])

0 commit comments

Comments
 (0)