Skip to content

Commit 1868f43

Browse files
Expose the get_plotly_fig function, return fig from draw_plotly and draw_plotly_server (#7258)
Co-authored-by: Sameer Sheorey <[email protected]>
1 parent 997f04e commit 1868f43

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
- Add optional indices arg for fast computation of a small subset of FPFH features (PR #7118).
6060
- Fix CMake configuration summary incorrectly reporting `no` for system BLAS. (PR #7230)
6161
- Add error handling for insufficient correspondences in AdvancedMatching (PR #7234)
62+
- Exposed `get_plotly_fig` and modified `draw_plotly` to return the `Figure` it creates. (PR #7258)
6263

6364
## 0.13
6465

python/open3d/visualization/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from open3d.cpu.pybind.visualization import *
1717

1818
from ._external_visualizer import *
19+
from .draw_plotly import get_plotly_fig
1920
from .draw_plotly import draw_plotly
2021
from .draw_plotly import draw_plotly_server
2122
from .to_mitsuba import to_mitsuba

python/open3d/visualization/draw_plotly.py

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,39 @@ def get_plotly_fig(geometry_list,
144144
lookat=None,
145145
up=None,
146146
zoom=1.0):
147+
"""Generates a Plotly Figure object for a list of Open3D geometries.
148+
149+
Args:
150+
geometry_list (List[open3d.geometry.Geometry]): A list of Open3D
151+
geometry objects (e.g., PointCloud, TriangleMesh, LineSet) to be
152+
visualized.
153+
width (int, optional): The width of the Plotly figure in pixels.
154+
Defaults to 600.
155+
height (int, optional): The height of the Plotly figure in pixels.
156+
Defaults to 400.
157+
mesh_show_wireframe (bool, optional): If True, a wireframe will be
158+
rendered for TriangleMesh geometries in addition to the mesh
159+
itself. Defaults to False.
160+
point_sample_factor (float, optional): A factor between 0.0 and 1.0
161+
that determines the fraction of points to sample from PointCloud
162+
geometries. A value of 1.0 means all points are used.
163+
Defaults to 1.0.
164+
front (list of float, optional): A list of 3 floats representing the
165+
camera's front vector (e.g., [x, y, z]). If None, a default
166+
orientation is used. Defaults to None.
167+
lookat (list of float, optional): A list of 3 floats representing the
168+
point the camera is looking at (e.g., [x, y, z]). If None, the
169+
camera looks at the center of the combined geometries.
170+
Defaults to None.
171+
up (list of float, optional): A list of 3 floats representing the
172+
camera's up vector (e.g., [x, y, z]). Defaults to Plotly's default
173+
(0,0,1) if None.
174+
zoom (float, optional): The zoom level of the camera. Affects the
175+
distance of the eye position from the center. Defaults to 1.0.
176+
177+
Returns:
178+
plotly.graph_objects.Figure: The generated Plotly figure object.
179+
"""
147180
graph_objects = get_graph_objects(geometry_list, mesh_show_wireframe,
148181
point_sample_factor)
149182
geometry_center = get_geometry_center(geometry_list)
@@ -198,10 +231,37 @@ def draw_plotly(geometry_list,
198231
lookat=None,
199232
up=None,
200233
zoom=1.0):
201-
234+
"""Draws Open3D geometries using Plotly and displays them.
235+
236+
This function creates a Plotly figure from the provided geometries and
237+
then calls `show()` to render it.
238+
239+
Args:
240+
geometry_list (List[open3d.geometry.Geometry]): A list of Open3D
241+
geometry objects.
242+
window_name (str, optional): The title of the window where the figure is
243+
displayed.
244+
width (int, optional): The width of the Plotly figure in pixels.
245+
Defaults to 600.
246+
height (int, optional): The height of the Plotly figure in pixels.
247+
Defaults to 400.
248+
mesh_show_wireframe (bool, optional): If True, renders a wireframe for
249+
TriangleMesh geometries. Defaults to False.
250+
point_sample_factor (float, optional): Sampling factor for point clouds
251+
(0.0 to 1.0). Defaults to 1.0.
252+
front (list of float, optional): Camera's front vector. Defaults to None.
253+
lookat (list of float, optional): Point camera is looking at.
254+
Defaults to None.
255+
up (list of float, optional): Camera's up vector. Defaults to None.
256+
zoom (float, optional): Camera zoom level. Defaults to 1.0.
257+
258+
Returns:
259+
plotly.graph_objects.Figure: The generated and displayed Plotly figure.
260+
"""
202261
fig = get_plotly_fig(geometry_list, width, height, mesh_show_wireframe,
203262
point_sample_factor, front, lookat, up, zoom)
204263
fig.show()
264+
return fig
205265

206266

207267
def draw_plotly_server(geometry_list,
@@ -215,7 +275,38 @@ def draw_plotly_server(geometry_list,
215275
up=None,
216276
zoom=1.0,
217277
port=8050):
218-
278+
"""Serves Open3D geometries via a Dash web application using Plotly.
279+
280+
This function creates a Plotly figure and embeds it within a Dash web
281+
application. The application is then run on a local development server,
282+
making the visualization accessible through a web browser at the
283+
specified port.
284+
285+
Args:
286+
geometry_list (List[open3d.geometry.Geometry]): A list of Open3D
287+
geometry objects.
288+
window_name (str, optional): The title for the Dash application,
289+
which also appears as the browser tab title. Defaults to 'Open3D'.
290+
width (int, optional): The width of the Plotly figure in pixels.
291+
Defaults to 1080.
292+
height (int, optional): The height of the Plotly figure in pixels.
293+
Defaults to 960.
294+
mesh_show_wireframe (bool, optional): If True, renders a wireframe for
295+
TriangleMesh geometries. Defaults to False.
296+
point_sample_factor (float, optional): Sampling factor for point clouds
297+
(0.0 to 1.0). Defaults to 1.0.
298+
front (list of float, optional): Camera's front vector. Defaults to None.
299+
lookat (list of float, optional): Point camera is looking at.
300+
Defaults to None.
301+
up (list of float, optional): Camera's up vector. Defaults to None.
302+
zoom (float, optional): Camera zoom level. Defaults to 1.0.
303+
port (int, optional): The port number on which the Dash application
304+
will be served. Defaults to 8050.
305+
306+
Returns:
307+
tuple[dash.Dash, plotly.graph_objects.Figure]: A tuple containing the
308+
Dash application instance and the Plotly figure object.
309+
"""
219310
fig = get_plotly_fig(geometry_list, width, height, mesh_show_wireframe,
220311
point_sample_factor, front, lookat, up, zoom)
221312
app = Dash(window_name)
@@ -232,4 +323,5 @@ def draw_plotly_server(geometry_list,
232323
},
233324
),
234325
])
235-
app.run_server(debug=False, port=port)
326+
app.run_server(debug=False, port=port)
327+
return (app, fig)

0 commit comments

Comments
 (0)