From 6851933277c6cc6ce5dd536487efe8a23fba1652 Mon Sep 17 00:00:00 2001 From: Alessia Saccardo <s212246@dtu.dk> Date: Tue, 18 Feb 2025 08:58:35 +0100 Subject: [PATCH] fix descriptions and examples --- docs/doc/data_handling/io.md | 4 ++-- qim3d/mesh/_common_mesh_methods.py | 28 ++++++++++++++++++++++++++-- qim3d/viz/_k3d.py | 3 ++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/docs/doc/data_handling/io.md b/docs/doc/data_handling/io.md index 82c984bb..607d81ed 100644 --- a/docs/doc/data_handling/io.md +++ b/docs/doc/data_handling/io.md @@ -8,5 +8,5 @@ - Downloader - export_ome_zarr - import_ome_zarr - - save_mesh - - load_mesh \ No newline at end of file + - load_mesh + - save_mesh \ No newline at end of file diff --git a/qim3d/mesh/_common_mesh_methods.py b/qim3d/mesh/_common_mesh_methods.py index ace4749a..7ff2dbe8 100644 --- a/qim3d/mesh/_common_mesh_methods.py +++ b/qim3d/mesh/_common_mesh_methods.py @@ -7,11 +7,35 @@ from qim3d.utils._logger import log def from_volume( volume: np.ndarray, - **Kwargs + **kwargs ) -> hmesh.Manifold: + """ Convert a 3D numpy array to a mesh object using the [volumetric_isocontour](https://www2.compute.dtu.dk/projects/GEL/PyGEL/pygel3d/hmesh.html#volumetric_isocontour) function from Pygel3D. + + Args: + volume (np.ndarray): A 3D numpy array representing a volume. + **kwargs: Additional arguments to pass to the Pygel3D volumetric_isocontour function. + + Raises: + ValueError: If the input volume is not a 3D numpy array. + + Returns: + hmesh.Manifold: A Pygel3D mesh object representing the input volume. + + Example: + Convert a 3D numpy array to a Pygel3D mesh object: + ```python + import qim3d + + # Generate a 3D blob + synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015) + + # Convert the 3D numpy array to a Pygel3D mesh object + mesh = qim3d.mesh.from_volume(synthetic_blob) + ``` + """ if volume.ndim != 3: raise ValueError("The input volume must be a 3D numpy array.") - mesh = hmesh.volumetric_isocontour(volume) + mesh = hmesh.volumetric_isocontour(volume, **kwargs) return mesh \ No newline at end of file diff --git a/qim3d/viz/_k3d.py b/qim3d/viz/_k3d.py index aab60d40..2bfe1273 100644 --- a/qim3d/viz/_k3d.py +++ b/qim3d/viz/_k3d.py @@ -211,7 +211,8 @@ def mesh( See full reference: https://www2.compute.dtu.dk/projects/GEL/PyGEL/pygel3d/jupyter_display.html#display Returns: - k3d.Plot or None: + k3d.Plot or None: + - If `backend="k3d"`, returns a `k3d.Plot` object. - If `backend="pygel3d"`, the function displays the mesh but does not return a plot object. Example: -- GitLab