[vtkusers] seeking for help on volume rendering

Jian Wu eewujian at gmail.com
Wed Aug 23 13:43:19 EDT 2006


Hi, everyone,
I'm a new VTK user. I was failed to produced the similar results for a
sample code I came upon with in the book "The VTK User's Guide (VTK4.4)".
Page 122. Here is the code that I used. I made a few modification 'cause it
is incomplete and has a few obvious errors for the original one. It is
supposed to display two similar spheres. But I found the one given by
ray-casting was incorrect. It displayed as a dark cube. Is there anyone know
the reason? Thanks!

Jian Wu

######################################################################
package require vtk
package require vtkinteraction

# Create the standard renderer, render window
# and interactor
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# Create a geometric sphere
vtkSphereSource sphere
    sphere SetRadius 20
    sphere SetCenter 70 25 25
    sphere SetThetaResolution 50
    sphere SetPhiResolution 50

vtkPolyDataMapper mapper
    mapper SetInput [sphere GetOutput]

vtkActor actor
    actor SetMapper mapper
    [actor GetProperty] SetColor 1 1 1
    [actor GetProperty] SetAmbient 0.01
    [actor GetProperty] SetDiffuse 0.7
    [actor GetProperty] SetSpecular 0.5
    [actor GetProperty] SetSpecularPower 70.0

# Read in a volumetric sphere
vtkSLCReader reader
    reader SetFileName "$VTK_DATA_ROOT/Data/sphere.slc"

# Use this tfun for both opacity and color
vtkPiecewiseFunction tfun
    tfun AddSegment 0 1.0 255 1.0

# Make the volume property match the geometric one
vtkVolumeProperty volumeProperty
    volumeProperty SetColor tfun
    volumeProperty SetScalarOpacity tfun
    volumeProperty ShadeOn
    volumeProperty SetInterpolationTypeToLinear
    volumeProperty SetDiffuse 0.7
    volumeProperty SetAmbient 0.01
    volumeProperty SetSpecular 0.5
    volumeProperty SetSpecularPower 70.0

vtkVolumeRayCastCompositeFunction  compositeFunction
vtkVolumeRayCastMapper volumeMapper
    volumeMapper SetInputConnection [reader GetOutputPort]
    volumeMapper SetVolumeRayCastFunction compositeFunction

vtkVolume volume
    volume SetMapper volumeMapper
    volume SetProperty volumeProperty

# Add both the geometric and volumetric spheres to the renderer
ren1 AddViewProp volume
ren1 AddViewProp actor

# Create a red, green, and blue light
vtkLight redlight
    redlight SetColor 1 0 0
    redlight SetPosition 1000 25 25
    redlight SetFocalPoint 25 25 25
    redlight SetIntensity 0.5

vtkLight greenlight
    greenlight SetColor 0 1 0
    greenlight SetPosition 25 1000 25
    greenlight SetFocalPoint 25 25 25
    greenlight SetIntensity 0.5

vtkLight bluelight
    bluelight SetColor 0 0 1
    bluelight SetPosition 25 25 1000
    bluelight SetFocalPoint 25 25 25
    bluelight SetIntensity 0.5

# Add the light to the renderer
ren1 AddLight redlight
ren1 AddLight greenlight
ren1 AddLight bluelight
ren1 SetBackground 0.1 0.1 0.2

# Render it!
renWin Render

proc TkCheckAbort {} {
  set foo [renWin GetEventPending]
  if {$foo != 0} {renWin SetAbortRender 1}
}
renWin AddObserver AbortCheckEvent {TkCheckAbort}

iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize

wm withdraw .

######################################################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060823/b103bf09/attachment.htm>


More information about the vtkusers mailing list