Skip to content
Snippets Groups Projects
Commit f6d99c28 authored by fima's avatar fima :beers:
Browse files

Changing var names

parent d58dc824
No related branches found
No related tags found
1 merge request!126Sphericity
This commit is part of merge request !126. Comments created here will be created in the context of that merge request.
import numpy as np
import qim3d.processing
from qim3d.utils.logger import log
import trimesh
import qim3d
def volume(obj, **mesh_kwargs) -> float:
"""
Compute the volume of a 3D volume or mesh.
......@@ -44,7 +46,8 @@ def volume(obj, **mesh_kwargs) -> float:
log.info("Converting volume to mesh.")
obj = qim3d.processing.create_mesh(obj, **mesh_kwargs)
return obj.volume
return abs(obj.volume)
def area(obj, **mesh_kwargs) -> float:
"""
......@@ -88,6 +91,7 @@ def area(obj, **mesh_kwargs) -> float:
return obj.area
def sphericity(obj, **mesh_kwargs) -> float:
"""
Compute the sphericity of a 3D volume or mesh.
......@@ -135,13 +139,13 @@ def sphericity(obj, **mesh_kwargs) -> float:
log.info("Converting volume to mesh.")
obj = qim3d.processing.create_mesh(obj, **mesh_kwargs)
V = volume(obj)
A = area(obj)
volume = qim3d.processing.volume(obj)
area = qim3d.processing.area(obj)
if A == 0:
if area == 0:
log.warning("Surface area is zero, sphericity is undefined.")
return np.nan
sphericity = (np.pi**(1/3) * (6 * V)**(2/3)) / A
sphericity = (np.pi ** (1 / 3) * (6 * volume) ** (2 / 3)) / area
log.info(f"Sphericity: {sphericity}")
return sphericity
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment