[vtkusers] Is it possible to render two intersected ImageData as Volume?
Jordi Campos i Miralles
jcampos at maia.ub.es
Mon Jul 2 13:43:36 EDT 2007
Hi,
When I load 2 intersected ImageData files and try to render them as
Volume, the last one is always rendered over the first one.
Is there any way to avoid this behaviour?
I also tried to make and assembly of both volumes before adding them to
the renderer, but I obtain the same result.
I first "detected the problem" in Paraview, but I also tested it in
"plain VTK" with the same behavior.
What am I doing wrong?
Thanks,
jor;)i
Listings:
- 15-VolumesIntersected-2Volumes.py
- 15-VolumesIntersected-Assembly.py
#!/usr/bin/python
# 15-VolumesIntersected-2Volumes.py
import vtk
from vtk import *
def main():
alphaTF = vtkPiecewiseFunction() # Opacity (A-TF)
alphaTF.AddPoint( 0.0, 1.0) ; alphaTF.AddPoint( 42.0, 1.0)
colorTF = vtkColorTransferFunction() # Color (RGB-TF)
colorTF.AddRGBPoint( 0, 0, 1, 0) ; colorTF.AddRGBPoint( 42, 1, 0, 0)
volProp = vtkVolumeProperty() # VolumeProperty
volProp.SetColor(colorTF) ; volProp.SetScalarOpacity(alphaTF)
volProp.SetInterpolationTypeToLinear()
ren = vtkRenderer() # Renderer
createMapperAndVtkVolume( "teddy-64-body.vti", volProp, ren )
createMapperAndVtkVolume( "teddy-64-armR.vti", volProp, ren )
ren.ResetCamera()
renwin = vtkRenderWindow() # Window
renwin.AddRenderer(ren)
renwin.SetSize(300, 300)
iren = vtkRenderWindowInteractor() # Interactor
iren.SetRenderWindow(renwin)
iren.Start()
def createMapperAndVtkVolume( fileName, volProp, renderer ):
source = vtkXMLImageDataReader() # Read: Body
source.SetFileName( fileName )
volumeMapper = vtkVolumeRayCastMapper() # Mapper
cast = vtkImageCast() # - uchar conversion
cast.SetInput( source.GetOutput() ) # (required by VRayCast)
cast.SetOutputScalarTypeToUnsignedChar()
volumeMapper.SetInput( cast.GetOutput() )
compositeFunc = vtkVolumeRayCastCompositeFunction() # - composite
volumeMapper.SetVolumeRayCastFunction(compositeFunc)
volume = vtkVolume() # Volume=Mapper+Property
volume.SetMapper(volumeMapper)
volume.SetProperty(volProp)
renderer.AddVolume(volume)
main()
#!/usr/bin/python
# 15-VolumesIntersected-Assembly.py
import vtk
from vtk import *
def main():
alphaTF = vtkPiecewiseFunction() # Opacity (A-TF)
alphaTF.AddPoint( 0.0, 1.0) ; alphaTF.AddPoint( 42.0, 1.0)
colorTF = vtkColorTransferFunction() # Color (RGB-TF)
colorTF.AddRGBPoint( 0, 0, 1, 0) ; colorTF.AddRGBPoint( 42, 1, 0, 0)
volProp = vtkVolumeProperty() # VolumeProperty
volProp.SetColor(colorTF) ; volProp.SetScalarOpacity(alphaTF)
volProp.SetInterpolationTypeToLinear()
ren = vtkRenderer() # Renderer
assembly = vtk.vtkAssembly() # Assembly
createMapperAndVtkVolume( "teddy-64-body.vti", volProp, assembly )
createMapperAndVtkVolume( "teddy-64-armR.vti", volProp, assembly )
ren.AddVolume( assembly )
ren.ResetCamera()
renwin = vtkRenderWindow() # Window
renwin.AddRenderer(ren)
renwin.SetSize(300, 300)
iren = vtkRenderWindowInteractor() # Interactor
iren.SetRenderWindow(renwin)
iren.Start()
def createMapperAndVtkVolume( fileName, volProp, assembly ):
source = vtkXMLImageDataReader() # Read: Body
source.SetFileName( fileName )
volumeMapper = vtkVolumeRayCastMapper() # Mapper
cast = vtkImageCast() # - uchar conversion
cast.SetInput( source.GetOutput() ) # (required by VRayCast)
cast.SetOutputScalarTypeToUnsignedChar()
volumeMapper.SetInput( cast.GetOutput() )
compositeFunc = vtkVolumeRayCastCompositeFunction() # - composite
volumeMapper.SetVolumeRayCastFunction(compositeFunc)
volume = vtkVolume() # Volume=Mapper+Property
volume.SetMapper(volumeMapper)
volume.SetProperty(volProp)
assembly.AddPart( volume )
main()
--
Jordi Campos i Miralles
Departament de Matemàtica Aplicada i Anàlisi, MAiA
Facultat de Matemàtiques, Universitat de Barcelona
Gran Via de les Corts Catalanes, 585
08007 Barcelona
Telf : +34 93 403 93 72
More information about the vtkusers
mailing list