Friday 14 December 2007

Showing an Image in VTK

Oh, at last I did it. I don't know why people say who an image can be shown in VTK straight forward. But here it is at last.

The piece of code is written by TCL , using vtk. The brain.tif is in the same directory as the tcl file.


 

# create image reader

#source object for reading tiff files

vtkTIFFReader tiffR

tiffR SetFileName brain.tif


 

#tiffR Update

#vtkImageViewer is a convenience class for displaying a 2d image.

#It packages up the functionality found in vtkRenderWindow, vtkRenderer, vtkActor2D and vtkImageMapper into a single easy to use class.

#Behind the scenes these four classes are actually used to to provide the required functionality. vtkImageViewer is simply a wrapper around them.

vtkImageViewer vw

vw SetInput [ tiffR GetOutput ]

#set the slice to be viewed

vw SetZSlice 0

vw SetColorLevel 128

vw SetColorWindow 255

vw Render


 

wm withdraw .

vwait forever


 

No comments: