From a696c97db2fe8fe160691cc984014d44c8af4c9b Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Fri, 6 Jan 2023 11:33:54 +0100 Subject: [PATCH 1/7] docs: fix point cloud display with colors using enum Signed-off-by: anna-charlotte --- docs/datatypes/mesh/index.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/datatypes/mesh/index.md b/docs/datatypes/mesh/index.md index d6fdbb413db..7d495786756 100644 --- a/docs/datatypes/mesh/index.md +++ b/docs/datatypes/mesh/index.md @@ -2576,13 +2576,16 @@ init(); " width="100%" height="500px" style="border:none;"> Date: Fri, 6 Jan 2023 11:43:41 +0100 Subject: [PATCH 2/7] fix: revert previous commit Signed-off-by: anna-charlotte --- docs/datatypes/mesh/index.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/datatypes/mesh/index.md b/docs/datatypes/mesh/index.md index 7d495786756..d6fdbb413db 100644 --- a/docs/datatypes/mesh/index.md +++ b/docs/datatypes/mesh/index.md @@ -2576,16 +2576,13 @@ init(); " width="100%" height="500px" style="border:none;"> Date: Fri, 6 Jan 2023 11:44:12 +0100 Subject: [PATCH 3/7] fix: enum value extraction in display point cloud Signed-off-by: anna-charlotte --- docarray/document/mixins/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docarray/document/mixins/plot.py b/docarray/document/mixins/plot.py index 00f6570c6e0..27809dae5e2 100644 --- a/docarray/document/mixins/plot.py +++ b/docarray/document/mixins/plot.py @@ -191,7 +191,7 @@ def display_point_cloud_tensor(self) -> None: for chunk in self.chunks: if ( 'name' in chunk.tags.keys() - and chunk.tags['name'] == PointCloudEnum.COLORS + and chunk.tags['name'] == PointCloudEnum.COLORS.value and chunk.tensor.shape[-1] in [3, 4] ): colors = chunk.tensor From 18197cb79a8730b3aa8b4b62d9422d6fcaf8e8cc Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Fri, 6 Jan 2023 11:54:04 +0100 Subject: [PATCH 4/7] test: add test for mesh and point cloud enum value extraction Signed-off-by: anna-charlotte --- tests/unit/document/test_converters.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/unit/document/test_converters.py b/tests/unit/document/test_converters.py index 9316c4a9b6f..b999f32c461 100644 --- a/tests/unit/document/test_converters.py +++ b/tests/unit/document/test_converters.py @@ -6,7 +6,7 @@ from docarray import Document from docarray.document.generators import from_files -from docarray.document.mixins.mesh import MeshEnum +from docarray.document.mixins.mesh import MeshEnum, PointCloudEnum __windows__ = sys.platform == 'win32' @@ -417,3 +417,16 @@ def test_load_uris_to_rgbd_tensor_doc_wo_uri_raise_exception(): match='A chunk of the given Document does not provide a uri.', ): doc.load_uris_to_rgbd_tensor() + + +@pytest.mark.parametrize( + 'enum_value,expected_value', + [ + (PointCloudEnum.COLORS.value, 'point_cloud_colors'), + (MeshEnum.VERTICES.value, 'vertices'), + (MeshEnum.FACES.value, 'faces'), + (MeshEnum.FILE_EXTENSIONS.value, ['glb', 'obj', 'ply']), + ], +) +def test_enum_value_extraction(enum_value, expected_value): + assert enum_value == expected_value From 2a9c256f65cfbec98af58e6a1114d60e397d1ef8 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Fri, 6 Jan 2023 12:54:50 +0100 Subject: [PATCH 5/7] test: fix test for point cloud enum Signed-off-by: anna-charlotte --- tests/unit/document/test_converters.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/unit/document/test_converters.py b/tests/unit/document/test_converters.py index b999f32c461..e082ea82a9f 100644 --- a/tests/unit/document/test_converters.py +++ b/tests/unit/document/test_converters.py @@ -419,14 +419,12 @@ def test_load_uris_to_rgbd_tensor_doc_wo_uri_raise_exception(): doc.load_uris_to_rgbd_tensor() -@pytest.mark.parametrize( - 'enum_value,expected_value', - [ - (PointCloudEnum.COLORS.value, 'point_cloud_colors'), - (MeshEnum.VERTICES.value, 'vertices'), - (MeshEnum.FACES.value, 'faces'), - (MeshEnum.FILE_EXTENSIONS.value, ['glb', 'obj', 'ply']), - ], -) -def test_enum_value_extraction(enum_value, expected_value): - assert enum_value == expected_value +def test_load_colors_to_point_cloud_doc(): + n_samples = 1000 + colors = np.random.rand(n_samples, 3) + coords = np.random.rand(n_samples, 3) + doc = Document(uri='mesh_man.glb', tensor=coords) + doc.chunks = [Document(tensor=colors, name='point_cloud_colors')] + + assert np.allclose(doc.tensor, coords) + assert np.allclose(doc.chunks[0].tensor, colors) From f78c4ad50dc9b42c61e250d8d80ffb1d8664b89e Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Fri, 6 Jan 2023 13:29:36 +0100 Subject: [PATCH 6/7] test: remove useless test again Signed-off-by: anna-charlotte --- tests/unit/document/test_converters.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/unit/document/test_converters.py b/tests/unit/document/test_converters.py index e082ea82a9f..9402b92737f 100644 --- a/tests/unit/document/test_converters.py +++ b/tests/unit/document/test_converters.py @@ -417,14 +417,3 @@ def test_load_uris_to_rgbd_tensor_doc_wo_uri_raise_exception(): match='A chunk of the given Document does not provide a uri.', ): doc.load_uris_to_rgbd_tensor() - - -def test_load_colors_to_point_cloud_doc(): - n_samples = 1000 - colors = np.random.rand(n_samples, 3) - coords = np.random.rand(n_samples, 3) - doc = Document(uri='mesh_man.glb', tensor=coords) - doc.chunks = [Document(tensor=colors, name='point_cloud_colors')] - - assert np.allclose(doc.tensor, coords) - assert np.allclose(doc.chunks[0].tensor, colors) From 0f235d4e4cd9ff7889406c684280389bcdc7c813 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Fri, 6 Jan 2023 17:18:10 +0100 Subject: [PATCH 7/7] fix: value extraction for mesh enum Signed-off-by: anna-charlotte --- docarray/document/mixins/mesh.py | 8 ++++---- docarray/document/mixins/plot.py | 15 ++++++++++----- tests/unit/document/test_converters.py | 4 ++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docarray/document/mixins/mesh.py b/docarray/document/mixins/mesh.py index 8f5de66918b..6997f3a192c 100644 --- a/docarray/document/mixins/mesh.py +++ b/docarray/document/mixins/mesh.py @@ -85,8 +85,8 @@ def load_uri_to_vertices_and_faces(self: 'T') -> 'T': faces = mesh.faces.view(np.ndarray) self.chunks = [ - Document(name=MeshEnum.VERTICES, tensor=vertices), - Document(name=MeshEnum.FACES, tensor=faces), + Document(name=MeshEnum.VERTICES.value, tensor=vertices), + Document(name=MeshEnum.FACES.value, tensor=faces), ] return self @@ -101,9 +101,9 @@ def load_vertices_and_faces_to_point_cloud(self: 'T', samples: int) -> 'T': faces = None for chunk in self.chunks: - if chunk.tags['name'] == MeshEnum.VERTICES: + if chunk.tags['name'] == MeshEnum.VERTICES.value: vertices = chunk.tensor - if chunk.tags['name'] == MeshEnum.FACES: + if chunk.tags['name'] == MeshEnum.FACES.value: faces = chunk.tensor if vertices is not None and faces is not None: diff --git a/docarray/document/mixins/plot.py b/docarray/document/mixins/plot.py index 27809dae5e2..f9c6f2e52b6 100644 --- a/docarray/document/mixins/plot.py +++ b/docarray/document/mixins/plot.py @@ -133,7 +133,10 @@ def _is_3d_vertices_and_faces(self): """ if self.chunks is not None: name_tags = [c.tags['name'] for c in self.chunks] - if MeshEnum.VERTICES in name_tags and MeshEnum.FACES in name_tags: + if ( + MeshEnum.VERTICES.value in name_tags + and MeshEnum.FACES.value in name_tags + ): return True else: return False @@ -173,11 +176,13 @@ def display_vertices_and_faces(self): import trimesh vertices = [ - c.tensor for c in self.chunks if c.tags['name'] == MeshEnum.VERTICES + c.tensor + for c in self.chunks + if c.tags['name'] == MeshEnum.VERTICES.value + ][-1] + faces = [ + c.tensor for c in self.chunks if c.tags['name'] == MeshEnum.FACES.value ][-1] - faces = [c.tensor for c in self.chunks if c.tags['name'] == MeshEnum.FACES][ - -1 - ] mesh = trimesh.Trimesh(vertices=vertices, faces=faces) display(mesh.show()) diff --git a/tests/unit/document/test_converters.py b/tests/unit/document/test_converters.py index 9402b92737f..28d8922b704 100644 --- a/tests/unit/document/test_converters.py +++ b/tests/unit/document/test_converters.py @@ -321,9 +321,9 @@ def test_load_uri_to_vertices_and_faces(uri): doc.load_uri_to_vertices_and_faces() assert len(doc.chunks) == 2 - assert doc.chunks[0].tags['name'] == MeshEnum.VERTICES + assert doc.chunks[0].tags['name'] == MeshEnum.VERTICES.value assert doc.chunks[0].tensor.shape[1] == 3 - assert doc.chunks[1].tags['name'] == MeshEnum.FACES + assert doc.chunks[1].tags['name'] == MeshEnum.FACES.value assert doc.chunks[1].tensor.shape[1] == 3