Matt Hancock
Matt Hancock

Reputation: 4039

Wireframe isosurface with Mayavi

The mesh function in Mayavi accepts a representation keyword that allows the surface to be viewed as the triangulated wireframe mesh. How can achieve a similar result for an iso surface using mlab.pipeline.iso_surface or mlab.contour3d?

For example, I'd like to achieve something to the effect:

import numpy as np
from mayavi import mlab

# Create image volume with sphere as zero level surface.
x,y,z = np.mgrid[-20:21, -20:21, -20:21].astype(np.float)
vol = np.sqrt(x**2 + y**2 + z**2) - 7

# Visualize the level surface.
sf = mlab.pipeline.scalar_field(vol)
mlab.pipeline.iso_surface(sf, contours=[0.0],
                          representation='wireframe')
mlab.show()

Of course, this code doesn't run because the representation keyword argument doesn't exist for the iso_surface function.

Upvotes: 0

Views: 1189

Answers (1)

Matt Hancock
Matt Hancock

Reputation: 4039

I've figured it out by using the mlab.view_pipeline() command and using the GUI to explore the properties of the pipeline created.

The wireframe can be achieved by:

sf = mlab.pipeline.scalar_field(vol)
iso = mlab.pipeline.iso_surface(sf, contours=[0.0])

# Added line.
iso.actor.property.representation = 'wireframe'

mlab.show()

which results in

enter image description here

Upvotes: 1

Related Questions