Skip to content

Commit e0e8d1a

Browse files
author
anna-charlotte
committed
fix: apply samis suggestion
Signed-off-by: anna-charlotte <[email protected]>
1 parent 147b429 commit e0e8d1a

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

docarray/documents/point_cloud/points_and_colors.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import numpy as np
44

55
from docarray.base_document import BaseDocument
6+
from docarray.typing import AnyTensor
67
from docarray.typing.tensor.abstract_tensor import AbstractTensor
7-
from docarray.typing.tensor.tensor import AnyTensor
8-
from docarray.typing.url.url_3d.point_cloud_url import _display_point_cloud
9-
from docarray.utils.misc import is_tf_available, is_torch_available
8+
from docarray.utils.misc import is_notebook, is_tf_available, is_torch_available
109

1110
torch_available = is_torch_available()
1211
if torch_available:
@@ -49,8 +48,21 @@ def display(self) -> None:
4948
"""
5049
Plot point cloud consisting of points in 3D space and optionally colors.
5150
"""
52-
if self.points is None:
53-
raise ValueError(
54-
'Can\'t display point cloud from tensors when the points are None.'
51+
import trimesh
52+
from IPython.display import display
53+
54+
colors = (
55+
self.colors
56+
if self.colors is not None
57+
else np.tile(
58+
np.array([0, 0, 0]),
59+
(self.points.get_comp_backend().shape(self.points)[0], 1),
5560
)
56-
_display_point_cloud(points=self.points, colors=self.colors)
61+
)
62+
pc = trimesh.points.PointCloud(vertices=self.points, colors=colors)
63+
64+
if is_notebook():
65+
s = trimesh.Scene(geometry=pc)
66+
display(s.show())
67+
else:
68+
display(pc.show())

docarray/typing/url/url_3d/point_cloud_url.py

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
from typing import TYPE_CHECKING, Optional, TypeVar
1+
from typing import TYPE_CHECKING, TypeVar
22

33
import numpy as np
44
from pydantic import parse_obj_as
55

6-
from docarray.typing import AnyTensor
76
from docarray.typing.proto_register import _register_proto
8-
from docarray.typing.tensor.abstract_tensor import AbstractTensor
97
from docarray.typing.tensor.ndarray import NdArray
108
from docarray.typing.url.url_3d.url_3d import Url3D
11-
from docarray.utils.misc import is_notebook
129

1310
if TYPE_CHECKING:
1411
from docarray.documents.point_cloud.points_and_colors import PointsAndColors
1512

13+
1614
T = TypeVar('T', bound='PointCloud3DUrl')
1715

1816

@@ -78,30 +76,4 @@ def display(self, samples: int = 10000) -> None:
7876
Plot point cloud from url.
7977
:param samples: number of points to sample from the mesh.
8078
"""
81-
tensors = self.load(samples=samples)
82-
_display_point_cloud(points=tensors.points)
83-
84-
85-
def _display_point_cloud(
86-
points: AnyTensor, colors: Optional[AbstractTensor] = None
87-
) -> None:
88-
"""
89-
Plot point cloud from tensors.
90-
:param points: tensor representing the point in 3D space, shape (n_points, 3).
91-
:param colors: tensor representing the colors as RGB or RGB-A values,
92-
shape (n_points, 3) or (n_points, 4).
93-
"""
94-
import trimesh
95-
from IPython.display import display
96-
97-
if colors is None:
98-
colors = np.tile(
99-
np.array([0, 0, 0]), (points.get_comp_backend().shape(points)[0], 1)
100-
)
101-
pc = trimesh.points.PointCloud(vertices=points, colors=colors)
102-
103-
if is_notebook():
104-
s = trimesh.Scene(geometry=pc)
105-
display(s.show())
106-
else:
107-
display(pc.show())
79+
self.load(samples=samples).display()

0 commit comments

Comments
 (0)