I'm playing a bit with scikit-image marching cubes algorithm. Here is a simplified version of the example given in the docs.
from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from skimage import measure
x = np.linspace(-1, 1, 11)
X, Y, Z = np.meshgrid(x, x, x, indexing = 'ij')
def f(x, y, z):
return x
verts, faces = measure.marching_cubes(f(X, Y, Z), 0.6)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
mesh = Poly3DCollection(verts[faces])
ax.add_collection3d(mesh)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_zlim(0, 10)
plt.show()
Here is the resulting surface:
It appears that coordinates of vertices are given in terms of array index rather than coordinates of the meshgrid. How can I transform the coordinates of vertices so that they map to the meshgrid, like in the image below?
I can do that by hand:
mesh = Poly3DCollection((verts[faces] / 5) - 1)
but there must be some numpy magic here.
Thanks.


