[vtkusers] help for visualize image data from vti file

何学俭 hexuejian_2003 at hotmail.com
Tue Jul 25 04:50:43 EDT 2006


Dear vtk users,

I get a vti file from volview and I want to use ray-casting method to visualize it.
This file contains an anotomical data, hip data. But it seems that I cannot get the 
right result. The problem maybe is I don't know how to set the opacity transfer and color 
transfer function. The following is the tcl code:

#####################code begin####################
package require vtk
package require vtkinteraction
package require vtktesting

vtkXMLImageDataReader reader  
  reader SetFileName "$VTK_DATA_ROOT/data/hip.vti"
  reader Update

  set image [reader GetOutput]  
  $image SetScalarTypeToUnsignedChar
  $image Update

vtkImageShiftScale shiftScale
shiftScale SetInput $image
shiftScale SetShift 0
shiftScale SetScale 1
shiftScale SetOutputScalarTypeToUnsignedChar
shiftScale Update

vtkPiecewiseFunction tfun
  tfun AddPoint    0  0.0
  tfun AddPoint   30  0.1
  tfun AddPoint   80  0.2
  tfun AddPoint  255  0.5

vtkColorTransferFunction ctfun
  ctfun AddRGBPoint      0 0.2 0.0 0.0
   ctfun AddRGBPoint    30 0.0 0.3 0.0
  ctfun AddRGBPoint    80 0.0 0.0 0.4
  ctfun AddRGBPoint    255 0.5 0.2 0.6
  
vtkVolumeRayCastCompositeFunction  compositeFunction

vtkVolumeRayCastMapper volumeMapper
  volumeMapper SetInput [shiftScale GetOutput]
  volumeMapper SetVolumeRayCastFunction compositeFunction

vtkVolumeProperty volumeProperty
  volumeProperty SetColor ctfun
  volumeProperty SetScalarOpacity tfun
  volumeProperty SetInterpolationTypeToLinear
  volumeProperty ShadeOn

vtkVolume newvol
  newvol SetMapper volumeMapper
  newvol SetProperty volumeProperty

vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

ren1 AddVolume newvol

ren1 SetBackground 0 0 0
renWin SetSize 300 300

#####################code end##################
The result appeared in my window is only a dark box. Does anyone have any idea of rendering image data from vti?


_________________________________________________________________
率先尝试 Windows Live Mail。
http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d



More information about the vtkusers mailing list