[vtkusers] adjust the transparency/opacity
付文宇
fuwenyu at emails.bjut.edu.cn
Tue Feb 27 04:57:05 EST 2007
hi everyone:
I want to modify an example to fade out the outer layer of the brain. The
previous script code is :
#--------------------------------------------------------------------------------
lappend auto_path [ file dirname [ info script ]]
package require vtk
wm geometry . 200x200
# This is a simple volume rendering example that
# uses a vtkVolumeRayCast mapper
# Create the standard renderer, render window
# and interactor
# Create the reader for the data
# First Load the Image
set reader [ vtkStructuredPointsReader vobject1]
$reader SetFileName brain.vt
$reader Update
# Convert image to unsigned char (volume rendering requires unsigned char/short)
set cast [ vtkImageCast vobject2]
$cast SetInput [ $reader GetOutput ]
$cast SetOutputScalarTypeToUnsignedChar
# Create transfer mapping scalar value to opacity
set opacityTransferFunction [ vtkPiecewiseFunction vobject3]
$opacityTransferFunction AddPoint 40 0.0
$opacityTransferFunction AddPoint 255 1.0
# Create transfer mapping scalar value to color
set colorTransferFunction [ vtkColorTransferFunction vobject4]
$colorTransferFunction AddRGBPoint 0.0 0.0 0.0 0.0
$colorTransferFunction AddRGBPoint 255.0 1.0 1.0 1.0
# The property describes how the data will look
set volumeProperty [ vtkVolumeProperty vobject5]
$volumeProperty SetColor $colorTransferFunction
$volumeProperty SetScalarOpacity $opacityTransferFunction
$volumeProperty SetInterpolationTypeToLinear
# The mapper
# THIS IS THE ONLY CHANGE FROM script12-3.tcl !!
set volumeMapper [ vtkVolumeTextureMapper2D vobject6]
$volumeMapper SetInput [ $cast GetOutput]
# END OF CHANGE
# The volume holds the mapper and the property and
# can be used to position/orient the volume
set volume [ vtkVolume vobject7]
$volume SetMapper $volumeMapper
$volume SetProperty $volumeProperty
set ren [ vtkRenderer vobject8]
$ren AddVolume $volume
set renwin [ vtkRenderWindow vobject9 ]
$renwin AddRenderer $ren
$renwin SetSize 300 300
$ren ResetCamera
$renwin Render
$renwin SetDesiredUpdateRate 1.0
set iren [ vtkRenderWindowInteractor vobject10 ]
$iren SetRenderWindow $renwin
$iren Initialize
$iren AddObserver SetExitMethod { exit }
wm withdraw .; vwait forever
#-------------------------------------------------------------------------------
But I do not know how to achieve that. Anyone who can give some advices or example
is welcome. Thanks in advace.
Fu wenyu
2007.02.27
More information about the vtkusers
mailing list