[vtkusers] vtkExtractVOI and volume raycast

Richard Layman mdl_126 at hotmail.com
Wed Dec 21 13:14:07 EST 2005


Can someone run the code and confirm the result for linux?

Thanks.

>From: "Richard Layman" <mdl_126 at hotmail.com>
>To: vtkusers at vtk.org
>Subject: [vtkusers] vtkExtractVOI and volume raycast
>Date: Tue, 20 Dec 2005 14:01:37 -0500
>
>Hope I get responses this time.  Sorry for no subject. I am also attaching 
>the screen shot for the two cases.
>
>>From: "Richard Layman" <mdl_126 at hotmail.com>
>>To: vtkusers at vtk.org
>>Subject: [vtkusers] (no subject)
>>Date: Mon, 19 Dec 2005 14:38:04 -0500
>>
>>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/
>>
>>_______________________________________________
>>This is the private VTK discussion list. Please keep messages on-topic. 
>>Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>Follow this link to subscribe/unsubscribe:
>>http://www.vtk.org/mailman/listinfo/vtkusers
>
>_________________________________________________________________
>Don’t just search. Find. Check out the new MSN Search! 
>http://search.msn.click-url.com/go/onm00200636ave/direct/01/


><< linux.png >>


><< windows.png >>


>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at: 
>http://www.vtk.org/Wiki/VTK_FAQ
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/




More information about the vtkusers mailing list