Fvtk module implements simple visualization functions using VTK.
The main idea is the following: A window can have one or more renderers. A renderer can have none, one or more actors. Examples of actors are a sphere, line, point etc. You basically add actors in a renderer and in that way you can visualize the forementioned objects e.g. sphere, line ...
>>> from dipy.viz import fvtk
>>> r=fvtk.ren()
>>> a=fvtk.axes()
>>> fvtk.add(r,a)
>>> #fvtk.show(r)
Add a specific actor
Create a Python function to create the text for the text mapper used to display the results of picking.
Create an actor with the coordinate system axes where red = x, green = y, blue =z.
Remove all actors from the renderer
Take a volume and draw surface contours for any any number of thresholds (levels) where every contour has its own color and opacity
Parameters : | vol : (N, M, K) ndarray
voxsz : (3,) array_like
affine : None
levels : array_like
colors : (N, 3) ndarray
opacities : array_like
|
---|---|
Returns : | ass : assembly of actors
|
Examples
>>> import numpy as np
>>> from dipy.viz import fvtk
>>> A=np.zeros((10,10,10))
>>> A[3:-3,3:-3,3:-3]=1
>>> r=fvtk.ren()
>>> fvtk.add(r,fvtk.contour(A,levels=[1]))
>>> #fvtk.show(r)
Create colors from a specific colormap and return it as an array of shape (N,3) where every row gives the corresponding r,g,b value. The colormaps we use are similar with those of pylab.
Parameters : | v : (N,) array
name : str. ‘jet’, ‘blues’, ‘blue_red’, ‘accent’
auto : bool,
|
---|
Notes
If you want to add more colormaps here is what you could do. Go to this website http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps see which colormap you need and then get in pylab using the cm.datad dictionary.
e.g.:
cm.datad['jet']
{'blue': ((0.0, 0.5, 0.5),
(0.11, 1, 1),
(0.34000000000000002, 1, 1),
(0.65000000000000002, 0, 0),
(1, 0, 0)),
'green': ((0.0, 0, 0),
(0.125, 0, 0),
(0.375, 1, 1),
(0.64000000000000001, 1, 1),
(0.91000000000000003, 0, 0),
(1, 0, 0)),
'red': ((0.0, 0, 0),
(0.34999999999999998, 0, 0),
(0.66000000000000003, 1, 1),
(0.89000000000000001, 1, 1),
(1, 0.5, 0.5))}
visualize a volume of crossings
Examples
See ‘dipy/doc/examples/visualize_crossings.py’ at Examples
Create one or more 3d dots(points) returns one actor handling all the points
Create a ellipsoid actor.
Stretch a unit sphere to make it an ellipsoid under a 3x3 translation matrix R.
Create a label actor.
This actor will always face the camera
Parameters : | ren : vtkRenderer() object
text : str
pos : (3,) array_like, optional
scale : (3,) array_like
color : (3,) array_like
|
---|---|
Returns : | l : vtkActor object
|
Examples
>>> from dipy.viz import fvtk
>>> r=fvtk.ren()
>>> l=fvtk.label(r)
>>> fvtk.add(r,l)
>>> #fvtk.show(r)
Create an actor for one or more lines.
Parameters : | lines : list of arrays representing lines as 3d points for example
colors : array, shape (N,3)
opacity : float, optional
linewidth : float, optional
|
---|---|
Returns : | v : vtkActor object
|
Examples
>>> from dipy.viz import fvtk
>>> r=fvtk.ren()
>>> lines=[np.random.rand(10,3),np.random.rand(20,3)]
>>> colors=np.random.rand(2,3)
>>> c=fvtk.line(lines,colors)
>>> fvtk.add(r,c)
>>> #fvtk.show(r)
This will record a video of your scene
Records a video as a series of .png files of your scene by rotating the azimuth angle az_angle in every frame.
Parameters : | ren : vtkRenderer() object
cam_pos : None or sequence (3,), optional
cam_focal : None or sequence (3,), optional
cam_view : None or sequence (3,), optional
out_path : str, optional
path_numbering : bool
n_frames : int, optional
az_ang : float, optional
magnification : int, optional
|
---|
Examples
>>> from dipy.viz import fvtk
>>> r=fvtk.ren()
>>> a=fvtk.axes()
>>> fvtk.add(r,a)
>>> #uncomment below to record
>>> #fvtk.record(r)
>>> #check for new images in current directory
Create a renderer.
Returns : | v : vtkRenderer() object
|
---|
Examples
>>> from dipy.viz import fvtk
>>> import numpy as np
>>> r=fvtk.ren()
>>> lines=[np.random.rand(10,3)]
>>> c=fvtk.line(lines,fvtk.red)
>>> fvtk.add(r,c)
>>> #fvtk.show(r)
Remove a specific actor
Remove all actors from the renderer
Show window
Parameters : | ren : vtkRenderer() object
title : string
size : (int, int)
png_magnify : int
|
---|
See also
Notes
If you want to:
Examples
>>> import numpy as np
>>> from dipy.viz import fvtk
>>> r=fvtk.ren()
>>> lines=[np.random.rand(10,3),np.random.rand(20,3)]
>>> colors=np.array([[0.2,0.2,0.2],[0.8,0.8,0.8]])
>>> c=fvtk.line(lines,colors)
>>> fvtk.add(r,c)
>>> l=fvtk.label(r)
>>> fvtk.add(r,l)
>>> #fvtk.show(r)
Slicer and contour rendering of 3d volumes
Parameters : | vol : array, shape (N, M, K), dtype uint8
voxsz : sequence of 3 floats
affine : array, shape (4,4), default None
contours : bool 1 to show contours
planes : boolean 1 show planes
levels : sequence
opacities : sequence
colors : None or sequence of 3-tuples
planesx : (2,) array_like
planesy : (2,) array_like
planesz : :
|
---|
Examples
>>> import numpy as np
>>> from dipy.viz import fvtk
>>> x, y, z = np.ogrid[-10:10:80j, -10:10:80j, -10:10:80j]
>>> s = np.sin(x*y*z)/(x*y*z)
>>> r=fvtk.ren()
>>> #fvtk.slicer(r,s) #does showing too
Create a sphere actor
Plot many morphed spheres simultaneously.
Parameters : | sphere_values : (M,) or (X, M) or (X, Y, M) or (X, Y, Z, M) ndarray
sphere : Sphere image : None,
colormap : None or ‘jet’
scale : float,
norm : bool,
radial_scale : bool,
|
---|---|
Returns : | actor : vtkActor
|
Examples
>>> from dipy.viz import fvtk
>>> r = fvtk.ren()
>>> odfs = np.ones((5, 5, 724))
>>> odfs[..., 0] = 2.
>>> from dipy.data import get_sphere
>>> sphere = get_sphere('symmetric724')
>>> fvtk.add(r, fvtk.sphere_funcs(odfs, sphere))
>>> #fvtk.show(r)
Deprecated
Wrap a tube around a line connecting point1 with point2 with a specific radius.
Create a volume and return a volumetric actor using volumetric rendering.
This function has many different interesting capabilities. The maptype, opacitymap and colormap are the most crucial parameters here.
Parameters : | vol : array, shape (N, M, K), dtype uint8
voxsz : (3,) array_like
affine : (4, 4) ndarray
center_origin : int {0,1}
info : int {0,1}
trilinear : int {0,1}
maptype : int {0,1}
iso : int {0,1}
iso_thr : int
opacitymap : (2, 2) ndarray
colormap : (4, 4) ndarray
|
---|---|
Returns : | v : vtkVolume
|
Notes
What is the difference between TextureMapper2D and RayCastFunction? Coming soon... See VTK user’s guide [book] & The Visualization Toolkit [book] and VTK’s online documentation & online docs.
What is the difference between RayCastIsosurfaceFunction and RayCastCompositeFunction? Coming soon... See VTK user’s guide [book] & The Visualization Toolkit [book] and VTK’s online documentation & online docs.
What about trilinear interpolation? Coming soon... well when time permits really ... :-)
Examples
First example random points.
>>> from dipy.viz import fvtk
>>> import numpy as np
>>> vol=100*np.random.rand(100,100,100)
>>> vol=vol.astype('uint8')
>>> print vol.min(), vol.max()
0 99
>>> r = fvtk.ren()
>>> v = fvtk.volume(vol)
>>> fvtk.add(r,v)
>>> #fvtk.show(r)
Second example with a more complicated function
>>> from dipy.viz import fvtk
>>> import numpy as np
>>> x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
>>> s = np.sin(x*y*z)/(x*y*z)
>>> r = fvtk.ren()
>>> v = fvtk.volume(s)
>>> fvtk.add(r,v)
>>> #fvtk.show(r)
If you find this function too complicated you can always use mayavi. Please do not forget to use the -wthread switch in ipython if you are running mayavi.
from enthought.mayavi import mlab import numpy as np x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j] s = np.sin(x*y*z)/(x*y*z) mlab.pipeline.volume(mlab.pipeline.scalar_field(s)) mlab.show()
More mayavi demos are available here:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html