From 0477ace26f347977f42cc4172834f791171ef43a Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 09:37:18 +0100 Subject: [PATCH 01/24] feat: add color to pointcloud display Signed-off-by: anna-charlotte --- docarray/document/mixins/plot.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/docarray/document/mixins/plot.py b/docarray/document/mixins/plot.py index af1779c2362..b64ca189e42 100644 --- a/docarray/document/mixins/plot.py +++ b/docarray/document/mixins/plot.py @@ -185,15 +185,24 @@ def display_point_cloud_tensor(self) -> None: from IPython.display import display from hubble.utils.notebook import is_notebook + colors = np.tile(np.array([0, 0, 0]), (len(self.tensor), 1)) + for chunk in self.chunks: + if ( + 'name' in chunk.tags.keys() + and chunk.tags['name'] == 'point_colors' + and (chunk.tensor.shape[-1] == 3 or chunk.tensor.shape[-1] == 4) + ): + colors = chunk.tensor + + pc = trimesh.points.PointCloud( + vertices=self.tensor, + colors=colors, + ) + if is_notebook(): - pc = trimesh.points.PointCloud( - vertices=self.tensor, - colors=np.tile(np.array([0, 0, 0, 1]), (len(self.tensor), 1)), - ) s = trimesh.Scene(geometry=pc) display(s.show()) else: - pc = trimesh.points.PointCloud(vertices=self.tensor) display(pc.show()) def display_rgbd_tensor(self) -> None: From a4130ad5be6e7ec25a42dcd7566a5b0ec8143293 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 09:51:05 +0100 Subject: [PATCH 02/24] test: add test plot point cloud Signed-off-by: anna-charlotte --- tests/unit/document/test_summary.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 0db81cc01b3..18576d9b881 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -69,3 +69,18 @@ def test_plot_embedding(): c = Document(embedding=[1, 2, 3], tensor=np.random.random(128)) d.chunks.append(c) d.summary() + + +@pytest.mark.parametrize( + 'colors', [None, np.random.rand(100, 3), np.random.rand(100, 4)] +) +def test_plot_point_cloud(colors): + point_cloud = np.random.randint(20, size=(100, 3)) + if colors is not None: + d = Document( + tensor=point_cloud, chunks=[Document(tensor=colors, name='point_colors')] + ) + else: + d = Document(tensor=point_cloud) + + d.display() From 0f521b36ddd52617ace0b1f84e2c04742d955b67 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 10:16:51 +0100 Subject: [PATCH 03/24] docs: add documentation for colored pc display Signed-off-by: anna-charlotte --- docs/datatypes/mesh/index.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/datatypes/mesh/index.md b/docs/datatypes/mesh/index.md index 0e3c68e75c9..463eb3c4acb 100644 --- a/docs/datatypes/mesh/index.md +++ b/docs/datatypes/mesh/index.md @@ -2576,6 +2576,16 @@ init(); " width="100%" height="500px" style="border:none;"> Date: Tue, 27 Dec 2022 11:02:05 +0100 Subject: [PATCH 04/24] fix: import pyglet Signed-off-by: anna-charlotte --- tests/unit/document/test_summary.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 18576d9b881..34b0e01c2c6 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -76,6 +76,8 @@ def test_plot_embedding(): ) def test_plot_point_cloud(colors): point_cloud = np.random.randint(20, size=(100, 3)) + import pyglet + if colors is not None: d = Document( tensor=point_cloud, chunks=[Document(tensor=colors, name='point_colors')] From e22cda6f9fef095f49c4a4a17cf2e7f047397271 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 11:17:21 +0100 Subject: [PATCH 05/24] test: revert changes in test plot point cloud Signed-off-by: anna-charlotte --- tests/unit/document/test_summary.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 34b0e01c2c6..6173a2ca36d 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -76,7 +76,6 @@ def test_plot_embedding(): ) def test_plot_point_cloud(colors): point_cloud = np.random.randint(20, size=(100, 3)) - import pyglet if colors is not None: d = Document( From 7b1decaaee8889960a978535d03ca2ca301a6b86 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 11:17:42 +0100 Subject: [PATCH 06/24] chore: install trimesh easy to include pyglet for display Signed-off-by: anna-charlotte --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c1fc9e3662f..eca2650b774 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ 'requests', 'matplotlib', 'Pillow', - 'trimesh', + 'trimesh[easy]', 'scipy', 'av', 'fastapi', From 5c03bd7a32446768b59823806886f7731f30e564 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 11:30:14 +0100 Subject: [PATCH 07/24] test: remove display test Signed-off-by: anna-charlotte --- tests/unit/document/test_summary.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 6173a2ca36d..0db81cc01b3 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -69,19 +69,3 @@ def test_plot_embedding(): c = Document(embedding=[1, 2, 3], tensor=np.random.random(128)) d.chunks.append(c) d.summary() - - -@pytest.mark.parametrize( - 'colors', [None, np.random.rand(100, 3), np.random.rand(100, 4)] -) -def test_plot_point_cloud(colors): - point_cloud = np.random.randint(20, size=(100, 3)) - - if colors is not None: - d = Document( - tensor=point_cloud, chunks=[Document(tensor=colors, name='point_colors')] - ) - else: - d = Document(tensor=point_cloud) - - d.display() From 278e5db52eee343b88e912b27959ba07a90ccaa4 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 13:48:36 +0100 Subject: [PATCH 08/24] chore: revert trimesh easy import Signed-off-by: anna-charlotte --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index eca2650b774..c1fc9e3662f 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ 'requests', 'matplotlib', 'Pillow', - 'trimesh[easy]', + 'trimesh', 'scipy', 'av', 'fastapi', From 4c94bb9b172d185fc9957ea6b673eefdfb75ae42 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 16:22:24 +0100 Subject: [PATCH 09/24] test: add test plot point cloud Signed-off-by: anna-charlotte --- tests/unit/document/test_summary.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 0db81cc01b3..6173a2ca36d 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -69,3 +69,19 @@ def test_plot_embedding(): c = Document(embedding=[1, 2, 3], tensor=np.random.random(128)) d.chunks.append(c) d.summary() + + +@pytest.mark.parametrize( + 'colors', [None, np.random.rand(100, 3), np.random.rand(100, 4)] +) +def test_plot_point_cloud(colors): + point_cloud = np.random.randint(20, size=(100, 3)) + + if colors is not None: + d = Document( + tensor=point_cloud, chunks=[Document(tensor=colors, name='point_colors')] + ) + else: + d = Document(tensor=point_cloud) + + d.display() From 718d7bb7e603dbf5ed01b1bed608fd8675517402 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 27 Dec 2022 17:37:54 +0100 Subject: [PATCH 10/24] chore: install trimesh full Signed-off-by: anna-charlotte --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c1fc9e3662f..b9bab78653e 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ 'requests', 'matplotlib', 'Pillow', - 'trimesh', + 'trimesh[full]', 'scipy', 'av', 'fastapi', From e6fd10270db3c169dc00f36f5a38481c718f7f91 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Wed, 28 Dec 2022 15:50:24 +0100 Subject: [PATCH 11/24] refactor: introduce constant var for pc colors Signed-off-by: anna-charlotte --- docarray/document/mixins/mesh.py | 4 ++++ docarray/document/mixins/plot.py | 4 ++-- docs/datatypes/mesh/index.md | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docarray/document/mixins/mesh.py b/docarray/document/mixins/mesh.py index 3b26489f030..ec0bc68f3fe 100644 --- a/docarray/document/mixins/mesh.py +++ b/docarray/document/mixins/mesh.py @@ -17,6 +17,10 @@ class Mesh: FACES = 'faces' +class PointCloud: + COLORS = 'point_cloud_colors' + + class MeshDataMixin: """Provide helper functions for :class:`Document` to support 3D mesh data and point cloud.""" diff --git a/docarray/document/mixins/plot.py b/docarray/document/mixins/plot.py index b64ca189e42..9a4b5f51fa7 100644 --- a/docarray/document/mixins/plot.py +++ b/docarray/document/mixins/plot.py @@ -3,7 +3,7 @@ import numpy as np -from docarray.document.mixins.mesh import Mesh +from docarray.document.mixins.mesh import Mesh, PointCloud class PlotMixin: @@ -189,7 +189,7 @@ def display_point_cloud_tensor(self) -> None: for chunk in self.chunks: if ( 'name' in chunk.tags.keys() - and chunk.tags['name'] == 'point_colors' + and chunk.tags['name'] == PointCloud.COLORS and (chunk.tensor.shape[-1] == 3 or chunk.tensor.shape[-1] == 4) ): colors = chunk.tensor diff --git a/docs/datatypes/mesh/index.md b/docs/datatypes/mesh/index.md index 463eb3c4acb..f497651fc00 100644 --- a/docs/datatypes/mesh/index.md +++ b/docs/datatypes/mesh/index.md @@ -2576,13 +2576,13 @@ init(); " width="100%" height="500px" style="border:none;"> Date: Wed, 28 Dec 2022 20:21:14 +0100 Subject: [PATCH 12/24] chore: install trimesh easy Signed-off-by: anna-charlotte --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b9bab78653e..eca2650b774 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ 'requests', 'matplotlib', 'Pillow', - 'trimesh[full]', + 'trimesh[easy]', 'scipy', 'av', 'fastapi', From d860f0a6ef65eb8ce239d4da9479cea13979b69d Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Wed, 28 Dec 2022 20:50:54 +0100 Subject: [PATCH 13/24] ci: add install freeglut devel Signed-off-by: anna-charlotte --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63d6facd16a..fb96da76cd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -171,8 +171,9 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Prepare enviroment + - name: Prepare environment run: | + apt install freeglut-devel # https://stackoverflow.com/questions/50446867/importerror-library-glu-not-found python -m pip install --upgrade pip python -m pip install wheel # pip does not properly resolve dependency versions with syntax pip install --no-cache-dir ".[test,full]" From 2ee94c0ff76573543c3aa8746c9e8753825883fe Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Wed, 28 Dec 2022 20:58:06 +0100 Subject: [PATCH 14/24] ci: change to sudo apt-get Signed-off-by: anna-charlotte --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb96da76cd2..3fcd3c74fa4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -173,7 +173,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Prepare environment run: | - apt install freeglut-devel # https://stackoverflow.com/questions/50446867/importerror-library-glu-not-found + sudo apt-get install freeglut-devel # https://stackoverflow.com/questions/50446867/importerror-library-glu-not-found python -m pip install --upgrade pip python -m pip install wheel # pip does not properly resolve dependency versions with syntax pip install --no-cache-dir ".[test,full]" From db12f74b9ffad01e2dc93655e9e9448e018259cc Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Wed, 28 Dec 2022 21:01:16 +0100 Subject: [PATCH 15/24] ci: change to freeglut3-dev Signed-off-by: anna-charlotte --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fcd3c74fa4..ff5f408c179 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -173,7 +173,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Prepare environment run: | - sudo apt-get install freeglut-devel # https://stackoverflow.com/questions/50446867/importerror-library-glu-not-found + sudo apt-get install freeglut3-dev # https://stackoverflow.com/questions/50446867/importerror-library-glu-not-found python -m pip install --upgrade pip python -m pip install wheel # pip does not properly resolve dependency versions with syntax pip install --no-cache-dir ".[test,full]" From dc64615ff351f4ede825895d1f8dae559d5877c3 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Wed, 28 Dec 2022 21:13:01 +0100 Subject: [PATCH 16/24] fix: set display Signed-off-by: anna-charlotte --- tests/unit/document/test_summary.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 6173a2ca36d..58173a99226 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -75,6 +75,9 @@ def test_plot_embedding(): 'colors', [None, np.random.rand(100, 3), np.random.rand(100, 4)] ) def test_plot_point_cloud(colors): + import os + + os.environ['DISPLAY'] = ':1' point_cloud = np.random.randint(20, size=(100, 3)) if colors is not None: From 4a005e5637e6a7e351409c2995bc3227646aa129 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Thu, 29 Dec 2022 08:32:16 +0100 Subject: [PATCH 17/24] fix: remove env var Signed-off-by: anna-charlotte --- tests/unit/document/test_summary.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 58173a99226..6173a2ca36d 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -75,9 +75,6 @@ def test_plot_embedding(): 'colors', [None, np.random.rand(100, 3), np.random.rand(100, 4)] ) def test_plot_point_cloud(colors): - import os - - os.environ['DISPLAY'] = ':1' point_cloud = np.random.randint(20, size=(100, 3)) if colors is not None: From 8dafaa1a2ba0648bf4c32d0e72f24be3b788d648 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Thu, 29 Dec 2022 09:40:19 +0100 Subject: [PATCH 18/24] fix: remove test Signed-off-by: anna-charlotte --- .github/workflows/ci.yml | 1 - tests/unit/document/test_summary.py | 16 ---------------- 2 files changed, 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff5f408c179..eda1318e7b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -173,7 +173,6 @@ jobs: python-version: ${{ matrix.python-version }} - name: Prepare environment run: | - sudo apt-get install freeglut3-dev # https://stackoverflow.com/questions/50446867/importerror-library-glu-not-found python -m pip install --upgrade pip python -m pip install wheel # pip does not properly resolve dependency versions with syntax pip install --no-cache-dir ".[test,full]" diff --git a/tests/unit/document/test_summary.py b/tests/unit/document/test_summary.py index 6173a2ca36d..0db81cc01b3 100644 --- a/tests/unit/document/test_summary.py +++ b/tests/unit/document/test_summary.py @@ -69,19 +69,3 @@ def test_plot_embedding(): c = Document(embedding=[1, 2, 3], tensor=np.random.random(128)) d.chunks.append(c) d.summary() - - -@pytest.mark.parametrize( - 'colors', [None, np.random.rand(100, 3), np.random.rand(100, 4)] -) -def test_plot_point_cloud(colors): - point_cloud = np.random.randint(20, size=(100, 3)) - - if colors is not None: - d = Document( - tensor=point_cloud, chunks=[Document(tensor=colors, name='point_colors')] - ) - else: - d = Document(tensor=point_cloud) - - d.display() From cf7881d7aaa811316045a15450b63b149256a21b Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Mon, 2 Jan 2023 11:17:49 +0100 Subject: [PATCH 19/24] fix: add ipython and pyglet to setup py Signed-off-by: anna-charlotte --- setup.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index eca2650b774..4e95de78df0 100644 --- a/setup.py +++ b/setup.py @@ -60,11 +60,9 @@ 'requests', 'matplotlib', 'Pillow', - 'trimesh[easy]', - 'scipy', - 'av', - 'fastapi', - 'pydantic>=1.9.0', + 'trimesh', + 'ipython', + 'pyglet<=1.5.27', # requi 'uvicorn', 'strawberry-graphql', ], From a4cf9765acfdb27b2483815cb8288bf4334b72fd Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Mon, 2 Jan 2023 11:19:44 +0100 Subject: [PATCH 20/24] fix: add ipython and pyglet to setup py Signed-off-by: anna-charlotte --- setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4e95de78df0..dc819ac6439 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,11 @@ 'Pillow', 'trimesh', 'ipython', - 'pyglet<=1.5.27', # requi + 'pyglet<=1.5.27', # required by trimesh + 'scipy', + 'av', + 'fastapi', + 'pydantic>=1.9.0', 'uvicorn', 'strawberry-graphql', ], From a0444f700ee1a5fa90cd10edfae1f05dd98e8b6e Mon Sep 17 00:00:00 2001 From: Charlotte Gerhaher Date: Mon, 2 Jan 2023 11:24:00 +0100 Subject: [PATCH 21/24] fix: apply suggestion from code review Co-authored-by: samsja <55492238+samsja@users.noreply.github.com> Signed-off-by: Charlotte Gerhaher --- docarray/document/mixins/plot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docarray/document/mixins/plot.py b/docarray/document/mixins/plot.py index 9a4b5f51fa7..45ce6618340 100644 --- a/docarray/document/mixins/plot.py +++ b/docarray/document/mixins/plot.py @@ -190,7 +190,8 @@ def display_point_cloud_tensor(self) -> None: if ( 'name' in chunk.tags.keys() and chunk.tags['name'] == PointCloud.COLORS - and (chunk.tensor.shape[-1] == 3 or chunk.tensor.shape[-1] == 4) + and chunk.tensor.shape[-1] in [3, 4] + ): colors = chunk.tensor From e72e917b19ef69d923cfd7e2a775cdedbb5026cc Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Mon, 2 Jan 2023 11:29:31 +0100 Subject: [PATCH 22/24] refactor: meshenum and pointcloudenum Signed-off-by: anna-charlotte --- docarray/document/mixins/mesh.py | 13 +++++++------ docarray/document/mixins/plot.py | 13 +++++++------ tests/unit/document/test_converters.py | 6 +++--- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/docarray/document/mixins/mesh.py b/docarray/document/mixins/mesh.py index ec0bc68f3fe..8f5de66918b 100644 --- a/docarray/document/mixins/mesh.py +++ b/docarray/document/mixins/mesh.py @@ -1,3 +1,4 @@ +from enum import Enum from typing import TYPE_CHECKING, Union import numpy as np @@ -7,7 +8,7 @@ import trimesh -class Mesh: +class MeshEnum(Enum): FILE_EXTENSIONS = [ 'glb', 'obj', @@ -17,7 +18,7 @@ class Mesh: FACES = 'faces' -class PointCloud: +class PointCloudEnum(Enum): COLORS = 'point_cloud_colors' @@ -84,8 +85,8 @@ def load_uri_to_vertices_and_faces(self: 'T') -> 'T': faces = mesh.faces.view(np.ndarray) self.chunks = [ - Document(name=Mesh.VERTICES, tensor=vertices), - Document(name=Mesh.FACES, tensor=faces), + Document(name=MeshEnum.VERTICES, tensor=vertices), + Document(name=MeshEnum.FACES, tensor=faces), ] return self @@ -100,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'] == Mesh.VERTICES: + if chunk.tags['name'] == MeshEnum.VERTICES: vertices = chunk.tensor - if chunk.tags['name'] == Mesh.FACES: + if chunk.tags['name'] == MeshEnum.FACES: 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 45ce6618340..00f6570c6e0 100644 --- a/docarray/document/mixins/plot.py +++ b/docarray/document/mixins/plot.py @@ -3,7 +3,7 @@ import numpy as np -from docarray.document.mixins.mesh import Mesh, PointCloud +from docarray.document.mixins.mesh import MeshEnum, PointCloudEnum class PlotMixin: @@ -133,7 +133,7 @@ def _is_3d_vertices_and_faces(self): """ if self.chunks is not None: name_tags = [c.tags['name'] for c in self.chunks] - if Mesh.VERTICES in name_tags and Mesh.FACES in name_tags: + if MeshEnum.VERTICES in name_tags and MeshEnum.FACES in name_tags: return True else: return False @@ -173,9 +173,11 @@ def display_vertices_and_faces(self): import trimesh vertices = [ - c.tensor for c in self.chunks if c.tags['name'] == Mesh.VERTICES + c.tensor for c in self.chunks if c.tags['name'] == MeshEnum.VERTICES ][-1] - faces = [c.tensor for c in self.chunks if c.tags['name'] == Mesh.FACES][-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()) @@ -189,9 +191,8 @@ def display_point_cloud_tensor(self) -> None: for chunk in self.chunks: if ( 'name' in chunk.tags.keys() - and chunk.tags['name'] == PointCloud.COLORS + and chunk.tags['name'] == PointCloudEnum.COLORS and chunk.tensor.shape[-1] in [3, 4] - ): colors = chunk.tensor diff --git a/tests/unit/document/test_converters.py b/tests/unit/document/test_converters.py index 0a4f70e0785..9316c4a9b6f 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 Mesh +from docarray.document.mixins.mesh import MeshEnum __windows__ = sys.platform == 'win32' @@ -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'] == Mesh.VERTICES + assert doc.chunks[0].tags['name'] == MeshEnum.VERTICES assert doc.chunks[0].tensor.shape[1] == 3 - assert doc.chunks[1].tags['name'] == Mesh.FACES + assert doc.chunks[1].tags['name'] == MeshEnum.FACES assert doc.chunks[1].tensor.shape[1] == 3 From 97d4ba85ea25882ab0cb850d331fe6aa7e0cb5a0 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Mon, 2 Jan 2023 11:38:03 +0100 Subject: [PATCH 23/24] docs: change code snippet for colored point cloud display Signed-off-by: anna-charlotte --- docs/datatypes/mesh/index.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/datatypes/mesh/index.md b/docs/datatypes/mesh/index.md index f497651fc00..d6fdbb413db 100644 --- a/docs/datatypes/mesh/index.md +++ b/docs/datatypes/mesh/index.md @@ -2581,9 +2581,8 @@ To display a colored point cloud, store the corresponding colors in the `.tensor ```python n_samples = 1000 colors = np.random.rand(n_samples, 3) -doc = Document( - uri='mesh_man.glb', chunks=[Document(tensor=colors, name='point_cloud_colors')] -).load_uri_to_point_cloud_tensor(samples=n_samples) +doc = Document(uri='mesh_man.glb').load_uri_to_point_cloud_tensor(samples=n_samples) +doc.chunks = [Document(tensor=colors, name='point_cloud_colors')] ``` ## RGB-D image representation From e4096a3d7ce0b1905385548b900d872b90973e51 Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Tue, 3 Jan 2023 09:50:48 +0100 Subject: [PATCH 24/24] fix: trimesh easy import Signed-off-by: anna-charlotte --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index dc819ac6439..ef3ee210ad4 100644 --- a/setup.py +++ b/setup.py @@ -60,9 +60,8 @@ 'requests', 'matplotlib', 'Pillow', - 'trimesh', + 'trimesh[easy]', 'ipython', - 'pyglet<=1.5.27', # required by trimesh 'scipy', 'av', 'fastapi',