alvin-yang68 / Marching-Cubes

Implementation of the Marching Cubes algorithm on Python.
11 stars 7 forks source link

code produce weird results #2

Open derrick-xwp opened 1 year ago

derrick-xwp commented 1 year ago

Hi,

I tried to visualize the extracted mesh from your code in the notebook, but I got the below figure.

截屏2023-02-02 下午7 21 31
derrick-xwp commented 1 year ago

if name == "main":


cache={}

badset=set()

x, y, z = pi*np.mgrid[-1:1:31j, -1:1:31j, -1:1:31j]

vol = cos(x) + cos(y) + cos(z)

iso_val=-2.0

verts,faces=getContourSegments(iso_val,vol)



vol


celltypes = np.empty(faces.shape[0], dtype=np.uint8)

celltypes[:] = vtk.VTK_TRIANGLE

grid = pv.UnstructuredGrid(faces.ravel(), celltypes, verts)
 # call itkwidget

view(geometries=grid)



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()