Skip to content

Commit

Permalink
added threshold option to marching cubes
Browse files Browse the repository at this point in the history
  • Loading branch information
bhacha committed Nov 5, 2024
1 parent 9dbb10c commit 794d44e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions trimesh/voxel/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,19 @@ def fill_base(sparse_indices):
fill_voxelization = fill_base


def matrix_to_marching_cubes(matrix, pitch=1.0):
def matrix_to_marching_cubes(matrix, pitch=1.0, threshold=None):
"""
Convert an (n, m, p) matrix into a mesh, using marching_cubes.
Parameters
-----------
matrix : (n, m, p) bool
Occupancy array
pitch : float or length-3 tuple of floats, optional
Voxel spacing in each dimension
threshold : float or None, optional
If specified, converts the input 'matrix' into a Boolean matrix by setting values above to 'threshold' to True and those below or equal to False
Returns
----------
Expand All @@ -114,7 +119,12 @@ def matrix_to_marching_cubes(matrix, pitch=1.0):

from ..base import Trimesh

matrix = np.asanyarray(matrix, dtype=bool)
if isinstance(threshold, float) or isinstance(threshold, int) :
matrix_as_array = np.asarray(matrix)
matrix = np.where(matrix_as_array > threshold, True, False)
print(matrix.shape)
else:
matrix = np.asanyarray(matrix, dtype=bool)

rev_matrix = np.logical_not(matrix) # Takes set about 0.
# Add in padding so marching cubes can function properly with
Expand Down

0 comments on commit 794d44e

Please sign in to comment.