Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/machinevisiontoolbox/PointCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ def _show_in_notebook(
# get_plotly_fig rather than draw_plotly, which shows the figure and also returns
# it, so that a cell ending in the call shows it twice
fig = o3d.visualization.get_plotly_fig([geometry], **kwargs)
fig.update_layout(title=dict(text=title), margin=dict(t=40))
# the three axes have the same scale, so shapes have their true proportions as
# in the Open3D window. Plotly's default, "auto", does that unless one axis is
# more than four times longer than the other two, when it draws a cube instead
# and squashes a long or flat scene
fig.update_layout(
title=dict(text=title), margin=dict(t=40), scene_aspectmode="data"
)
fig.show()


Expand Down Expand Up @@ -419,7 +425,8 @@ def disp(
besides the view options above, ``width``, ``height`` and
``point_sample_factor`` (the fraction of the points drawn, 0 to 1, which
keeps a large cloud responsive) are passed to
:func:`open3d.visualization.draw_plotly`.
:func:`open3d.visualization.draw_plotly`. The three axes have the same
scale, so shapes have their true proportions, as in the Open3D window.

.. versionchanged:: 2.5.0
Added the ``notebook`` option.
Expand Down Expand Up @@ -831,8 +838,9 @@ def disp(

With ``notebook=True`` the voxels are drawn in the output of the notebook
cell, as a Plotly figure that can be rotated and zoomed, in the same way as
:meth:`PointCloud.disp`, which describes the options. Each voxel is drawn
as a cube of 12 triangles, so a grid of many thousands of voxels is slow.
:meth:`PointCloud.disp`, which describes the options, and with the same
scale on the three axes. Each voxel is drawn as a cube of 12 triangles, so a
grid of many thousands of voxels is slow.

.. versionchanged:: 2.5.0
Added the ``notebook`` option.
Expand Down
28 changes: 28 additions & 0 deletions tests/test_pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ def test_shown_once_as_a_figure_with_points(self):
# nothing is returned, or a cell ending in the call would show it again
self.assertIsNone(result)

@unittest.skipUnless(plotly_available, "plotly not installed")
def test_axes_have_the_same_scale(self):
from unittest.mock import patch

# a long thin cloud, for which Plotly's default would draw a cube
pc = PointCloud(np.random.rand(3, 500) * np.array([[10.0], [0.5], [0.5]]))
shown = []
with patch(
"plotly.graph_objects.Figure.show",
autospec=True,
side_effect=lambda fig, *a, **k: shown.append(fig),
):
pc.disp(notebook=True)
self.assertEqual(shown[0].layout.scene.aspectmode, "data")

@unittest.skipUnless(plotly_available, "plotly not installed")
def test_figure_has_the_points_and_title(self):
from unittest.mock import patch
Expand Down Expand Up @@ -161,6 +176,19 @@ def test_shown_once_with_a_mesh_of_the_voxels(self):
self.assertEqual(len(shown[0].data), 1)
self.assertEqual(len(shown[0].data[0].x), len(self.vg._cubes().vertices))

@unittest.skipUnless(plotly_available, "plotly not installed")
def test_axes_have_the_same_scale(self):
from unittest.mock import patch

shown = []
with patch(
"plotly.graph_objects.Figure.show",
autospec=True,
side_effect=lambda fig, *a, **k: shown.append(fig),
):
self.vg.disp(notebook=True)
self.assertEqual(shown[0].layout.scene.aspectmode, "data")

def test_plotly_missing_says_how_to_install_it(self):
from unittest.mock import patch

Expand Down
Loading