Skip to content
Snippets Groups Projects
Commit cb5324b8 authored by Alessia Saccardo's avatar Alessia Saccardo
Browse files

Fix minor errors in documentation

parent 68519332
No related branches found
No related tags found
1 merge request!156Mesh pygel3d
......@@ -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
......
......@@ -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:
......
......@@ -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)
......
......@@ -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
......@@ -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:
......
......@@ -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.
......
......@@ -494,24 +494,21 @@ 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)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
mesh = qim3d.mesh.from_volume(synthetic_blob)
qim3d.io.save_mesh("mesh.obj", mesh)
```
"""
......
......@@ -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.
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment