How to threshold out small elements in python marching cubes

284 views Asked by At

I am using the python scikit-image marching cubes implementation to create real time moving surface meshes. I am running into a problem where sometimes I get really small surface elements, or else really narrow / high aspect ratio triangles. You can see some of these in the example code here:

https://scikit-image.org/docs/stable/auto_examples/edges/plot_marching_cubes.html?highlight=marching%20cubes

arrow points to problem elements

Is there a way to threshold these out? For example, is there any way that I can say "if a point lies less than X% away from a node, then just put it on the node?" I see that there is a flag to smooth out 0 area elements as well. Is there a way to smooth out area < X?

Thanks!

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection

from skimage import measure
from skimage.draw import ellipsoid


# Generate a level set about zero of two identical ellipsoids in 3D
ellip_base = ellipsoid(6, 10, 16, levelset=True)
ellip_double = np.concatenate((ellip_base[:-1, ...],
                               ellip_base[2:, ...]), axis=0)

# Use marching cubes to obtain the surface mesh of these ellipsoids
verts, faces, normals, values = measure.marching_cubes(ellip_double, 0)

# Display resulting triangular mesh using Matplotlib. This can also be done
# with mayavi (see skimage.measure.marching_cubes_lewiner docstring).
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')

# Fancy indexing: `verts[faces]` to generate a collection of triangles
mesh = Poly3DCollection(verts[faces])
mesh.set_edgecolor('k')
ax.add_collection3d(mesh)

ax.set_xlabel("x-axis: a = 6 per ellipsoid")
ax.set_ylabel("y-axis: b = 10")
ax.set_zlabel("z-axis: c = 16")

ax.set_xlim(0, 24)  # a = 6 (times two for 2nd ellipsoid)
ax.set_ylim(0, 20)  # b = 10
ax.set_zlim(0, 32)  # c = 16

plt.tight_layout()
plt.show()
0

There are 0 answers