Fvtk module implements simple visualization functions using VTK. Fos means light in Greek.
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
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 that of pylab.
Current options for colormaps are ‘jet’,’blues’,’blue_red’, ‘accent’
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))}
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 : array, shape (N, M, K)
voxsz : sequence of 3 floats
affine : not used here levels : sequence of thresholds for the contours taken from image values
colors : array, shape (N,3) with the rgb values in where r,g,b belong to [0,1] opacities : sequence of floats [0,1] |
---|---|
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)
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 as returned from ren() text : a text for the label pos : left down position of the label scale : change the size of the label color : (r,g,b) and RGB tuple |
---|---|
Returns : | 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, default 1
linewidth : float, default is 1
|
---|---|
Returns : | 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
n_frames : int, optional
az_ang : float, optional
magnification : int, optional
|
---|
Examples
>>> from dipy.viz import fvtk
>>> r=fvtk.ren()
>>> a=fvtk.axes()
>>> from dipy.viz import fvtk
>>> r=fvtk.ren()
>>> fvtk.add(r,fvtk.axes())
>>> #uncomment below to record
>>> #fvtk.record(r,cam_pos=(0,0,-10))
Create a renderer
Returns : | a 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 : contour levels opacities : opacity for every contour level colors : None or planesx : saggital planesy : coronal planesz : axial |
---|
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
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 : sequence of 3 floats
affine : array, shape (4,4), default None
center_origin : int {0,1}, default 1
info : int {0,1}, default 1
trilinear: int {0,1}, default 1 :
maptype : int {0,1}, default 0,
iso : int {0,1} default 0,
iso_thr : int, default 100,
opacitymap : array, shape (N,2), default None.
colormap : array, shape (N,4), default None.
|
---|---|
Returns : | 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