Hello again,
After one more hour of ducktyping I eventually managed to fetch what I want
from the object returned by mlab.pipeline.iso_surface. Here is the code if
it can help someone:
# image being some 3D array
from mayavi import mlab
fld = mlab.pipeline.scalar_field(image)
ctr = mlab.pipeline.iso_surface(fld, contours=[.5])
nodes = ctr.contour.contour_filter.output.points.to_array() # This is an
array containing the nodes of the meshed surface contour
faces = ctr.contour.contour_filter.output.polys.to_array() # This is an
array containing the connectivity for the triangular mesh
faces = np.reshape(faces, (faces.size / 4., 4))[:, 1:] # Reshape
accordingly to ctr.contour.contour_filter 's docstring
Now I have another question. I would also need to fetch the normals of the
surface at the nodes... I saw that iso_surface does compute normals, so I
tried to fetch them using :
normals = ctr.normals.filter.output.points.to_array()
However, the shape of normals does not match that of nodes neither that of
faces... Do you have any idea what normals actually is?!!
normals.shape is (2999, 3)
faces.shape is (4096, 3)
nodes.shape is (2079, 3)
Thanks,
Vincent
2012/9/12 Vincent Dubourg <vincent.dubo...@gmail.com>
> Hi list,
>
> I have a 3 dimensional numpy array describing a sort of MRI image.
> I woud like to fetch the vertices and faces of an iso_surface plot for
> some contour as numpy arrays? Is it possible?
>
> I've been ducktyping for a while trying to understand the structure of the
> object returned by mlab.pipeline.iso_surface and ended up in some VTK
> structures that are somewhat hard to understand without any docstring!
>
> Is there any other python alternative to mayavi for this task?
>
> Thank you!
> Vincent
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
MayaVi-users mailing list
MayaVi-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mayavi-users