[vtkusers] The Visible Human project Display Script

Nathaniel Gonzalez ngonzalez at rcm.upr.edu
Tue Oct 26 14:47:17 EDT 2004


I'm trying to display the anatomy images of the Human Visible Project.
I'm able to see the images using vtk, but I'm unable to load the images
in a 3d volume form. If anyone has a simple script to do this I will
greatly appreciate your help. I'm also looking for a way to remove the
blue gel from the anatomy images. I think that I have to use the
vtkColorTransferFunction any hint on how to do this will be great.

This is what I have managed to do so far using examples, but I only get
a white outline in a volume form, the images are in ppm format:

package require vtk
package require vtkinteraction


vtkPNMReader part
     part SetFilePrefix"/VTK/VTKData/Male/Fullcolor/head/ppm/a_vm"
     part SetFilePattern %s%d.ppm
     part SetDataSpacing 0.33 0.33 1.0
     part SetDataExtent 0 2047 0 1215 1001 1050
     part SetDataByteOrderToBigEndian


#vtkVolume16Reader v16
#  v16 SetDataDimensions 2048 1216
#  [v16 GetOutput] SetOrigin 0.0 0.0 0.0
# v16 SetDataByteOrderToLittleEndian
#  v16 SetDataByteOrderToBigEndian
#  v16 SetFilePrefix "/home/VTK/VTKData/Male/Fullcolor/head/ppm/a_vm"
#  v16 SetFilePattern %s%d.ppm
#  v16 SetImageRange 1001 1050
# v16 SetImageRange 1 93
#  v16 SetDataSpacing .33 .33 1

vtkPiecewiseFunction tfun
  tfun AddPoint  0.0  0.0
  tfun AddPoint  127.5 0.8
  tfun AddPoint  255 0.0

vtkPiecewiseFunction white_tfun
  tfun AddPoint  0.0  1.0
  tfun AddPoint  255  1.0 
 

vtkVolumeProperty volumeProperty
  volumeProperty SetColor white_tfun
  volumeProperty SetScalarOpacity tfun
  volumeProperty SetInterpolationTypeToLinear
  volumeProperty ShadeOn


vtkVolumeRayCastCompositeFunction  compositeFunction

vtkVolumeRayCastMapper volumeMapper
  volumeMapper SetVolumeRayCastFunction compositeFunction
  volumeMapper SetInput [part GetOutput] 
  volumeMapper SetSampleDistance 1.0

vtkVolume newvol
  newvol SetMapper volumeMapper
  newvol SetProperty volumeProperty

 
vtkOutlineFilter outline
    outline SetInput [part GetOutput]
vtkPolyDataMapper outlineMapper
    outlineMapper SetInput [outline GetOutput]
vtkActor outlineActor
    outlineActor SetMapper outlineMapper



# Create the RenderWindow, Renderer and both Actors
#
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# The SetInteractor method is how 3D widgets are associated with the
render
# window interactor. Internally, SetInteractor sets up a bunch of
callbacks
# using the Command/Observer mechanism (AddObserver()).
vtkBoxWidget boxWidget
    boxWidget SetInteractor iren
    boxWidget SetPlaceFactor 1.0

# Add the actors to the renderer, set the background and size
#
ren1 AddActor outlineActor
ren1 AddVolume newvol

ren1 SetBackground 0 0 0
renWin SetSize 300 300

# Place the interactor initially. The output of the reader is used to
place
# the box widget.
#boxWidget SetInput [v16 GetOutput]
boxWidget SetInput [part GetOutput]
boxWidget PlaceWidget
boxWidget InsideOutOn
boxWidget AddObserver StartInteractionEvent StartInteraction
boxWidget AddObserver InteractionEvent ClipVolumeRender
boxWidget AddObserver EndInteractionEvent EndInteraction
set outlineProperty [boxWidget GetOutlineProperty]
    $outlineProperty SetRepresentationToWireframe
    $outlineProperty SetAmbient 1.0
    $outlineProperty SetAmbientColor 1 1 1
    $outlineProperty SetLineWidth 3
set selectedOutlineProperty [boxWidget GetSelectedOutlineProperty]
    $selectedOutlineProperty SetRepresentationToWireframe
    $selectedOutlineProperty SetAmbient 1.0
    $selectedOutlineProperty SetAmbientColor 1 0 0
    $selectedOutlineProperty SetLineWidth 3

# This adds the "u" keypress event...it pops up a Tcl interpreter.
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize

# Prevent the tk window from showing up then start the event loop.
wm withdraw .

# When interaction starts, the requested frame rate is increased.
proc StartInteraction {} {
   renWin SetDesiredUpdateRate 10
}

# When interaction ends, the requested frame rate is decreased to
# normal levels. This causes a full resolution render to occur.
proc EndInteraction {} {
   renWin SetDesiredUpdateRate 0.001
}

# The implicit function vtkPlanes is used in conjunction with the
# volume ray cast mapper to limit which portion of the volume is
# volume rendered.
vtkPlanes planes
proc ClipVolumeRender {} {
   boxWidget GetPlanes planes
   volumeMapper SetClippingPlanes planes
}


Thanks.


Nathaniel Gonzalez
RCMI-CIAR
Medical Science Campus
University of Puerto Rico  




More information about the vtkusers mailing list