[vtkusers] (no subject)

Richard Layman mdl_126 at hotmail.com
Mon Dec 19 14:38:04 EST 2005


Hi everyone,

I made some changes to the VolumeRendering/SimpleRayCast example. Basically 
what I wanted to do is to dynamically select a subvolume within a given data 
volume to render. I use vtkExtractVOI to get the subvolume I want and feed 
this to the rendering pipeline. An outline is added for reference.

As program starts it displays the whole extent. At the press of a key, the 
vtkExtractVOI is given a new extent. And I was hoping to see the rendering 
of the subvolume. This indeed works on Windows. However on my Linux system 
the raycast rendering was shifted relative to the new outline.

My modified code is shown below. Could anyone tell me if this is the right 
way to do this or what I need to do to make it work? I am using vtk 4.2 if 
it's relevant.

Thanks.


#!/usr/bin/env python

# This is a simple volume rendering example that uses a
# vtkVolumeRayCast mapper

import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Create the standard renderer, render window and interactor
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Create the reader for the data
reader = vtk.vtkStructuredPointsReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/ironProt.vtk")

#*** voi ***
reader.Update()
extent = reader.GetOutput().GetWholeExtent()
print 'extent:', extent
voi = vtk.vtkExtractVOI()
voi.SetInput(reader.GetOutput())
reader = voi

# Create transfer mapping scalar value to opacity
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(20, 0.0)
opacityTransferFunction.AddPoint(255, 0.2)

# Create transfer mapping scalar value to color
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0)
colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0)
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0)

# The property describes how the data will look
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOn()
volumeProperty.SetInterpolationTypeToLinear()

# The mapper / ray cast function know how to render the data
compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
volumeMapper = vtk.vtkVolumeRayCastMapper()
volumeMapper.SetVolumeRayCastFunction(compositeFunction)
volumeMapper.SetInput(reader.GetOutput())

# The volume holds the mapper and the property and
# can be used to position/orient the volume
volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)

#*** outline ***
outline = vtk.vtkOutlineFilter()
outline.SetInput(reader.GetOutput())
olmapper = vtk.vtkPolyDataMapper()
olmapper.SetInput(outline.GetOutput())
olactor = vtk.vtkActor()
olactor.SetMapper(olmapper)
olactor.GetProperty().SetColor(0,0,0)
ren.AddActor(olactor)

ren.AddVolume(volume)
ren.SetBackground(1, 1, 1)
renWin.SetSize(600, 600)
renWin.Render()

def CheckAbort(obj, event):
    if obj.GetEventPending() != 0:
        obj.SetAbortRender(1)

def keypress(obj, event):
    print 'key pressed'
    newext = list(extent)
    for i in range(0, 6, 2):
        newext[i] = (newext[i] + newext[i+1]) / 2
    print 'new extent:', newext
    voi.SetVOI(*newext)
    #ren.ResetCamera()
    #ren.ResetCameraClippingRange()
    renWin.Render()

renWin.AddObserver("AbortCheckEvent", CheckAbort)
iren.AddObserver("KeyPressEvent", keypress)

iren.Initialize()
renWin.Render()
iren.Start()

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/




More information about the vtkusers mailing list