Skip to content
Snippets Groups Projects

Docstrings

1 file
+ 14
2
Compare changes
  • Side-by-side
  • Inline
@@ -12,11 +12,11 @@ def volume(obj: np.ndarray|trimesh.Trimesh,
Compute the volume of a 3D volume or mesh.
Args:
obj: Either a np.ndarray volume or a mesh object of type trimesh.Trimesh.
**mesh_kwargs: Additional arguments for mesh creation if the input is a volume.
obj (np.ndarray or trimesh.Trimesh): Either a np.ndarray volume or a mesh object of type trimesh.Trimesh.
**mesh_kwargs (Any): Additional arguments for mesh creation if the input is a volume.
Returns:
volume: The volume of the object.
volume (float): The volume of the object.
Example:
Compute volume from a mesh:
@@ -27,8 +27,8 @@ def volume(obj: np.ndarray|trimesh.Trimesh,
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the volume of the mesh
volume = qim3d.processing.volume(mesh)
print('Volume:', volume)
vol = qim3d.features.volume(mesh)
print('Volume:', vol)
```
Compute volume from a np.ndarray:
@@ -36,10 +36,12 @@ def volume(obj: np.ndarray|trimesh.Trimesh,
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the volume of the blob
volume = qim3d.processing.volume(synthetic_blob, level=0.5)
volume = qim3d.features.volume(synthetic_blob, level=0.5)
volume = qim3d.features.volume(synthetic_blob, level=0.5)
print('Volume:', volume)
```
@@ -58,11 +60,11 @@ def area(obj: np.ndarray|trimesh.Trimesh,
Compute the surface area of a 3D volume or mesh.
Args:
obj: Either a np.ndarray volume or a mesh object of type trimesh.Trimesh.
**mesh_kwargs: Additional arguments for mesh creation if the input is a volume.
obj (np.ndarray or trimesh.Trimesh): Either a np.ndarray volume or a mesh object of type trimesh.Trimesh.
**mesh_kwargs (Any): Additional arguments for mesh creation if the input is a volume.
Returns:
area: The surface area of the object.
area (float): The surface area of the object.
Example:
Compute area from a mesh:
@@ -73,7 +75,8 @@ def area(obj: np.ndarray|trimesh.Trimesh,
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the surface area of the mesh
area = qim3d.processing.area(mesh)
area = qim3d.features.area(mesh)
area = qim3d.features.area(mesh)
print(f"Area: {area}")
```
@@ -82,16 +85,19 @@ def area(obj: np.ndarray|trimesh.Trimesh,
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the surface area of the blob
volume = qim3d.processing.area(synthetic_blob, level=0.5)
volume = qim3d.features.area(synthetic_blob, level=0.5)
volume = qim3d.features.area(synthetic_blob, level=0.5)
print('Area:', volume)
```
"""
if isinstance(obj, np.ndarray):
log.info("Converting volume to mesh.")
obj = qim3d.processing.create_mesh(obj, **mesh_kwargs)
obj = qim3d.mesh.from_volume(obj, **mesh_kwargs)
obj = qim3d.mesh.from_volume(obj, **mesh_kwargs)
return obj.area
@@ -107,11 +113,11 @@ def sphericity(obj: np.ndarray|trimesh.Trimesh,
actual surface area.
Args:
obj: Either a np.ndarray volume or a mesh object of type trimesh.Trimesh.
**mesh_kwargs: Additional arguments for mesh creation if the input is a volume.
obj (np.ndarray or trimesh.Trimesh): Either a np.ndarray volume or a mesh object of type trimesh.Trimesh.
**mesh_kwargs (Any): Additional arguments for mesh creation if the input is a volume.
Returns:
sphericity: A float value representing the sphericity of the object.
sphericity (float): A float value representing the sphericity of the object.
Example:
Compute sphericity from a mesh:
@@ -122,7 +128,8 @@ def sphericity(obj: np.ndarray|trimesh.Trimesh,
mesh = qim3d.io.load_mesh('path/to/mesh.obj')
# Compute the sphericity of the mesh
sphericity = qim3d.processing.sphericity(mesh)
sphericity = qim3d.features.sphericity(mesh)
sphericity = qim3d.features.sphericity(mesh)
```
Compute sphericity from a np.ndarray:
@@ -130,10 +137,12 @@ def sphericity(obj: np.ndarray|trimesh.Trimesh,
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.blob(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
synthetic_blob = qim3d.generate.noise_object(noise_scale = 0.015)
# Compute the sphericity of the blob
sphericity = qim3d.processing.sphericity(synthetic_blob, level=0.5)
sphericity = qim3d.features.sphericity(synthetic_blob, level=0.5)
sphericity = qim3d.features.sphericity(synthetic_blob, level=0.5)
```
!!! info "Limitations due to pixelation"
@@ -143,10 +152,13 @@ def sphericity(obj: np.ndarray|trimesh.Trimesh,
"""
if isinstance(obj, np.ndarray):
log.info("Converting volume to mesh.")
obj = qim3d.processing.create_mesh(obj, **mesh_kwargs)
obj = qim3d.mesh.from_volume(obj, **mesh_kwargs)
obj = qim3d.mesh.from_volume(obj, **mesh_kwargs)
volume = qim3d.processing.volume(obj)
area = qim3d.processing.area(obj)
volume = qim3d.features.volume(obj)
area = qim3d.features.area(obj)
volume = qim3d.features.volume(obj)
area = qim3d.features.area(obj)
if area == 0:
log.warning("Surface area is zero, sphericity is undefined.")
Loading