mayavi contour_surface issues

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

mayavi contour_surface issues

Cris Lanting
Dear all,

I've got a question with regards to plotting isocontours with
mlab.pipeline.contour_surface. I've got a surface-rendering with
mlab.triangular_mesh and have added an overlay. Based on this overlay I want
to display isocontours at specific values, rather than choosing the number
of contours. According to the help, I should be able to specify a list with
the iso-values (e.g., contours = [2,4] to display the contours at the values
2 and 4). Regardless of this I get a whole bunch of isocontours...

Any help or pointers?

--- relevant code: ---

#display background (gray)
mesh_curv =
mlab.triangular_mesh(x,y,z,faces,scalars=bck_data,vmin=0,vmax=1,colormap='gray')

maxval = np.max(cf2)
mesh_overlay = mlab.triangular_mesh(x,y,z,faces,scalars=cf2_data,vmin=0.01,
vmax=maxval,colormap='spectral')

#adjust colorbar to 'mask' all zero-valued data
lut = mesh_overlay.module_manager.scalar_lut_manager.lut.table.to_array()
ilut = lut[::-1]   #reverse lut -> red: low frequency / blue: high frequency
ilut[0, :] = 0 #reset value of '[0,0,0]' to transparent
mesh_overlay.module_manager.scalar_lut_manager.lut.table = ilut

#contours
contour_vals = [2,4]
contour_mesh =
mlab.pipeline.triangular_mesh_source(x,y,z,faces,scalars=cf2_data)
surf = mlab.pipeline.contour_surface(contour_mesh,contours=contour_vals,
colormap='spectral')

--- end ---

Cheers,
Cris




_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: mayavi contour_surface issues

Cris Lanting
Cris Lanting <c.lanting@...> writes:

>
> Dear all,
>
> I've got a question with regards to plotting isocontours with
> mlab.pipeline.contour_surface. I've got a surface-rendering with
> mlab.triangular_mesh and have added an overlay. Based on this overlay I want
> to display isocontours at specific values, rather than choosing the number
> of contours. According to the help, I should be able to specify a list with
> the iso-values (e.g., contours = [2,4] to display the contours at the values
> 2 and 4). Regardless of this I get a whole bunch of isocontours...
>
> Any help or pointers?
>
> --- relevant code: ---
>
> #display background (gray)
> mesh_curv =
>
mlab.triangular_mesh(x,y,z,faces,scalars=bck_data,vmin=0,vmax=1,colormap='gray')

>
> maxval = np.max(cf2)
> mesh_overlay = mlab.triangular_mesh(x,y,z,faces,scalars=cf2_data,vmin=0.01,
> vmax=maxval,colormap='spectral')
>
> #adjust colorbar to 'mask' all zero-valued data
> lut = mesh_overlay.module_manager.scalar_lut_manager.lut.table.to_array()
> ilut = lut[::-1]   #reverse lut -> red: low frequency / blue: high frequency
> ilut[0, :] = 0 #reset value of '[0,0,0]' to transparent
> mesh_overlay.module_manager.scalar_lut_manager.lut.table = ilut
>
> #contours
> contour_vals = [2,4]
> contour_mesh =
> mlab.pipeline.triangular_mesh_source(x,y,z,faces,scalars=cf2_data)
> surf = mlab.pipeline.contour_surface(contour_mesh,contours=contour_vals,
> colormap='spectral')
>
> --- end ---
>
> Cheers,
> Cris
>

In the meantime I've found a solution that I'd like to share:

Rather than using mlab.pipeline.contour_surface directly, you can also use
mlab.pipeline.triangular_mesh_source in combination with
mlab.pipeline.iso_surface. This seems to be working fine!

In addition, there's also a thresholding function (mlab.pipeline.threshold)
in which you can mask out a subset of vertices. This is quite useful when
using overlays where only certain bits of the surface are visualized as an
overlay in a different colormap than the original surface (think fMRI data
where the cortex is visualized (gray) with a statistical map on top (jet)).

Here's the relevant bit:

#display background (gray)
mesh_curv =
mlab.triangular_mesh(x,y,z,faces,scalars=bck_data,vmin=0,vmax=1,
colormap='gray')

#display functional overlay (with inverted jet colormap)
mesh_overlay =
mlab.pipeline.triangular_mesh_source(x,y,z,faces,scalars=cf2_data)
overlay_thr = mlab.pipeline.threshold(mesh_overlay, low = 0.1)
overlay_surf = mlab.pipeline.surface(overlay_thr,colormap='jet',vmin=1,vmax=7)
lut = overlay_surf.module_manager.scalar_lut_manager.lut.table.to_array()
ilut = lut[::-1]  #reverse lut -> red: low frequency / blue: high frequency
overlay_surf.module_manager.scalar_lut_manager.lut.table = ilut


#display contours
contour_vals = [1,2,3]
contour_mesh =
mlab.pipeline.triangular_mesh_source(x,y,z,faces,scalars=cf2_data)
contour_mesh_thr = mlab.pipeline.threshold(contour_mesh,low=0.1)
surf =
mlab.pipeline.iso_surface(contour_mesh_thr,contours=contour_vals,
colormap='Reds',vmin=1,vmax=4)


Cheers.
Cris




_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev