From cb5324b81aad13f74b5b1e3623ee5fab60b16f5f Mon Sep 17 00:00:00 2001 From: Alessia Saccardo <s212246@dtu.dk> Date: Tue, 18 Feb 2025 10:12:02 +0100 Subject: [PATCH] Fix minor errors in documentation --- docs/doc/cli/cli.md | 2 +- docs/doc/gui/gui.md | 2 +- docs/doc/releases/releases.md | 2 +- qim3d/features/_common_features_methods.py | 18 ++++---- qim3d/filters/_common_filter_methods.py | 1 - qim3d/io/_loading.py | 12 +++++- qim3d/io/_saving.py | 21 ++++------ qim3d/mesh/_common_mesh_methods.py | 2 +- qim3d/viz/_k3d.py | 48 ++++++++++------------ 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/docs/doc/cli/cli.md b/docs/doc/cli/cli.md index 58fae7e2..123fee26 100644 --- a/docs/doc/cli/cli.md +++ b/docs/doc/cli/cli.md @@ -44,7 +44,7 @@ The command line interface allows you to run graphical user interfaces directly !!! Example - Here's an example of how to open the [Data Explorer](gui.md#qim3d.gui.data_explorer) + Here's an example of how to open the [Data Explorer](../gui/gui.md#qim3d.gui.data_explorer) ``` title="Command" qim3d gui --data-explorer diff --git a/docs/doc/gui/gui.md b/docs/doc/gui/gui.md index 681041fc..4bc2de99 100644 --- a/docs/doc/gui/gui.md +++ b/docs/doc/gui/gui.md @@ -21,7 +21,7 @@ The `qim3d` library provides a set of custom made GUIs that ease the interaction ``` In general, the GUIs can be launched directly from the command line. -For details see [here](cli.md#qim3d-gui). +For details see [here](../cli/cli.md#qim3d-gui). ::: qim3d.gui.data_explorer options: diff --git a/docs/doc/releases/releases.md b/docs/doc/releases/releases.md index 8174ea97..bdb5c2a8 100644 --- a/docs/doc/releases/releases.md +++ b/docs/doc/releases/releases.md @@ -11,7 +11,7 @@ hide: Below, you'll find details about the version history of `qim3d`. -Remember to keep your pip installation [up to date](index.md/#get-the-latest-version) so that you have the latest features! +Remember to keep your pip installation [up to date](../../index.md/#get-the-latest-version) so that you have the latest features! ### v1.0.0 (21/01/2025) diff --git a/qim3d/features/_common_features_methods.py b/qim3d/features/_common_features_methods.py index ca782336..a2c41d57 100644 --- a/qim3d/features/_common_features_methods.py +++ b/qim3d/features/_common_features_methods.py @@ -9,7 +9,7 @@ def volume(obj: np.ndarray|hmesh.Manifold) -> float: Compute the volume of a 3D mesh using the Pygel3D library. Args: - obj: Either a np.ndarray volume or a mesh object of type hmesh.Manifold. + obj (numpy.ndarray or pygel3d.hmesh.Manifold): Either a np.ndarray volume or a mesh object of type pygel3d.hmesh.Manifold. Returns: volume (float): The volume of the object. @@ -24,7 +24,7 @@ def volume(obj: np.ndarray|hmesh.Manifold) -> float: # Compute the volume of the mesh volume = qim3d.features.volume(mesh) - print('Volume:', volume) + print(f'Volume: {volume}') ``` Compute volume from a np.ndarray: @@ -36,7 +36,7 @@ def volume(obj: np.ndarray|hmesh.Manifold) -> float: # Compute the volume of the blob volume = qim3d.features.volume(synthetic_blob) - print('Volume:', volume) + print(f'Volume: {volume}') ``` """ @@ -52,7 +52,7 @@ def area(obj: np.ndarray|hmesh.Manifold) -> float: Compute the surface area of a 3D mesh using the Pygel3D library. Args: - obj: Either a np.ndarray volume or a mesh object of type hmesh.Manifold. + obj (numpy.ndarray or pygel3d.hmesh.Manifold): Either a np.ndarray volume or a mesh object of type pygel3d.hmesh.Manifold. Returns: area (float): The surface area of the object. @@ -67,7 +67,7 @@ def area(obj: np.ndarray|hmesh.Manifold) -> float: # Compute the surface area of the mesh area = qim3d.features.area(mesh) - print(f"Area: {area}") + print(f'Area: {area}') ``` Compute area from a np.ndarray: @@ -79,7 +79,7 @@ def area(obj: np.ndarray|hmesh.Manifold) -> float: # Compute the surface area of the blob area = qim3d.features.area(synthetic_blob) - print(f"Area: {area}") + print(f'Area: {area}') ``` """ @@ -95,7 +95,7 @@ def sphericity(obj: np.ndarray|hmesh.Manifold) -> float: Compute the sphericity of a 3D mesh using the Pygel3D library. Args: - obj: Either a np.ndarray volume or a mesh object of type hmesh.Manifold. + obj (numpy.ndarray or pygel3d.hmesh.Manifold): Either a np.ndarray volume or a mesh object of type pygel3d.hmesh.Manifold. Returns: sphericity (float): The sphericity of the object. @@ -110,6 +110,7 @@ def sphericity(obj: np.ndarray|hmesh.Manifold) -> float: # Compute the sphericity of the mesh sphericity = qim3d.features.sphericity(mesh) + print(f'Sphericity: {sphericity}') ``` Compute sphericity from a np.ndarray: @@ -121,6 +122,7 @@ def sphericity(obj: np.ndarray|hmesh.Manifold) -> float: # Compute the sphericity of the blob sphericity = qim3d.features.sphericity(synthetic_blob) + print(f'Sphericity: {sphericity}') ``` """ @@ -137,5 +139,5 @@ def sphericity(obj: np.ndarray|hmesh.Manifold) -> float: return np.nan sphericity = (np.pi ** (1 / 3) * (6 * volume) ** (2 / 3)) / area - log.info(f"Sphericity: {sphericity}") + # log.info(f"Sphericity: {sphericity}") return sphericity \ No newline at end of file diff --git a/qim3d/filters/_common_filter_methods.py b/qim3d/filters/_common_filter_methods.py index 3b6ded27..6ce9d334 100644 --- a/qim3d/filters/_common_filter_methods.py +++ b/qim3d/filters/_common_filter_methods.py @@ -295,7 +295,6 @@ def gaussian( sigma (float or sequence of floats): The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes. dask (bool, optional): Whether to use Dask for the Gaussian filter. chunks (int or tuple or "'auto'", optional): Defines how to divide the array into blocks when using Dask. Can be an integer, tuple, size in bytes, or "auto" for automatic sizing. - *args (Any): Additional positional arguments for the Gaussian filter. **kwargs (Any): Additional keyword arguments for the Gaussian filter. Returns: diff --git a/qim3d/io/_loading.py b/qim3d/io/_loading.py index 0ed9ae83..f718741d 100644 --- a/qim3d/io/_loading.py +++ b/qim3d/io/_loading.py @@ -868,10 +868,18 @@ def load( def load_mesh(filename: str) -> hmesh.Manifold: """ - Load a mesh from an an X3D/OBJ/OFF/PLY file. + Load a mesh from a specific file. + This function is based on the [PyGEL3D library's loading function implementation](https://www2.compute.dtu.dk/projects/GEL/PyGEL/pygel3d/hmesh.html#load). + + Supported formats: + + - `X3D` + - `OBJ` + - `OFF` + - `PLY` Args: - filename (str or os.PathLike): The path to the .obj file. + filename (str or os.PathLike): The path to the file. Returns: mesh (hmesh.Manifold or None): A hmesh object containing the mesh data or None if loading failed. diff --git a/qim3d/io/_saving.py b/qim3d/io/_saving.py index 6dd770b5..aa69fb9d 100644 --- a/qim3d/io/_saving.py +++ b/qim3d/io/_saving.py @@ -494,25 +494,22 @@ def save( # mesh.export(filename) def save_mesh(filename: str, mesh: hmesh.Manifold) -> None: - """Save a mesh object to an X3D/OBJ/OFF file. The file format is determined by the file extension. + """ + Save a mesh object to a specific file. + This function is based on the [PyGEL3D library's saving function implementation](https://www2.compute.dtu.dk/projects/GEL/PyGEL/pygel3d/hmesh.html#save). + Args: - filename (str or os.PathLike): The name of the file to save the mesh. - mesh (hmesh.Manifold): A hmesh.Manifold object representing the mesh. + filename (str or os.PathLike): The path to save file to. File format is chosen based on the extension. Supported extensions are: '.x3d', '.obj', '.off'. + mesh (pygel3d.hmesh.Manifold): A hmesh.Manifold object representing the mesh. Example: ```python import qim3d - vol = qim3d.generate.noise_object(base_shape=(32, 32, 32), - final_shape=(32, 32, 32), - noise_scale=0.05,mesh.export(filename) - order=1, - gamma=1.0, - max_value=255, - threshold=0.5) - mesh = qim3d.mesh.from_volume(vol) - qim3d.io.save_mesh("mesh.obj", mesh) + synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015) + mesh = qim3d.mesh.from_volume(synthetic_blob) + qim3d.io.save_mesh("mesh.obj", mesh) ``` """ # Export the mesh to the specified filename diff --git a/qim3d/mesh/_common_mesh_methods.py b/qim3d/mesh/_common_mesh_methods.py index 7ff2dbe8..317affbd 100644 --- a/qim3d/mesh/_common_mesh_methods.py +++ b/qim3d/mesh/_common_mesh_methods.py @@ -7,7 +7,7 @@ from qim3d.utils._logger import log def from_volume( volume: np.ndarray, - **kwargs + **kwargs: any ) -> 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. diff --git a/qim3d/viz/_k3d.py b/qim3d/viz/_k3d.py index 2bfe1273..1e22339a 100644 --- a/qim3d/viz/_k3d.py +++ b/qim3d/viz/_k3d.py @@ -15,6 +15,7 @@ from qim3d.utils._misc import downscale_img, scale_to_float16 from pygel3d import hmesh from pygel3d import jupyter_display as jd import k3d +from typing import Optional def volumetric( img: np.ndarray, @@ -182,54 +183,47 @@ def mesh( show: bool = True, save: bool = False, **kwargs, -): +)-> Optional[k3d.Plot]: """Visualize a 3D mesh using `k3d` or `pygel3d`. Args: - mesh (pygel3d.hmesh.HMesh): The input mesh object. + mesh (pygel3d.hmesh.Manifold): The input mesh object. backend (str, optional): The visualization backend to use. - Choose between `"k3d"` (default) and `"pygel3d"`. + Choose between `k3d` (default) and `pygel3d`. wireframe (bool, optional): If True, displays the mesh as a wireframe. - Works both with `"k3d"` and `"pygel3d"`. Defaults to True. + Works both with `k3d` and `pygel3d`. Defaults to True. flat_shading (bool, optional): If True, applies flat shading to the mesh. - Works only with `"k3d"`. Defaults to True. + Works only with `k3d`. Defaults to True. grid_visible (bool, optional): If True, shows a grid in the visualization. - Works only with `"k3d"`. Defaults to False. + Works only with `k3d`. Defaults to False. show (bool, optional): If True, displays the visualization inline. - Works for both `"k3d"` and `"pygel3d"`. Defaults to True. + Works only with `k3d`. Defaults to True. save (bool or str, optional): If True, saves the visualization as an HTML file. If a string is provided, it's interpreted as the file path where the HTML - file will be saved. Works only with `"k3d"`. Defaults to False. + file will be saved. Works only with `k3d`. Defaults to False. **kwargs (Any): Additional keyword arguments specific to the chosen backend: - - `k3d.plot` kwargs: Arguments that customize the `k3d.plot` visualization. - See full reference: https://k3d-jupyter.org/reference/factory.plot.html + - `k3d.plot` kwargs: Arguments that customize the [`k3d.plot`](https://k3d-jupyter.org/reference/factory.plot.html) visualization. - - `pygel3d.display` kwargs: Arguments for `pygel3d` visualization, such as: - - `smooth` (bool, default=True): Enables smooth shading. - - `data` (optional): Allows embedding custom data in the visualization. - See full reference: https://www2.compute.dtu.dk/projects/GEL/PyGEL/pygel3d/jupyter_display.html#display - + - `pygel3d.display` kwargs: Arguments that customize the [`pygel3d.display`](https://www2.compute.dtu.dk/projects/GEL/PyGEL/pygel3d/jupyter_display.html#display) visualization. + Returns: 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. + + Raises: + ValueError: If `backend` is not `'k3d'` or `'pygel3d'`. + Example: ```python import qim3d - vol = qim3d.generate.noise_object(base_shape=(128,128,128), - final_shape=(128,128,128), - noise_scale=0.03, - order=1, - gamma=1, - max_value=255, - threshold=0.5, - dtype='uint8' - ) - mesh = qim3d.mesh.from_volume(vol) - qim3d.viz.mesh(mesh) + synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015) + mesh = qim3d.mesh.from_volume(synthetic_blob) + qim3d.viz.mesh(mesh, backend="k3d") # or qim3d.viz.mesh(mesh, backend="pygel3d") ``` + """ @@ -282,4 +276,4 @@ def mesh( elif backend == "pygel3d": jd.set_export_mode(True) - return jd.display(mesh, **valid_pygel_kwargs) + return jd.display(mesh, wireframe=wireframe, **valid_pygel_kwargs) -- GitLab