Hi
I use vtkGPUVolumeRayCastMapper to render a DICOM volume. The output window is black but when I use vtkFixedPointVolumeRayCastMapper it works and volume will be displayed.
I also use QVTKRenderWindowInteractor widget to display it ( pyqt5 ).
I want to use GPUVolumeRayCast or OpenGLGPUVolumeRayCast mapper for rendering.
would you please help me with that.
Here is my code :
self.ren = vtk.vtkRenderer()
self.vtkWidget = QVTKRenderWindowInteractor()
self.reader = vtk.vtkDICOMImageReader()
self.reader.SetDirectoryName(folder)
self.reader.Update()
interactor = self.vtkWidget.GetRenderWindow().GetInteractor()
volume = vtk.vtkVolume()
# Ray cast function know how to render the data
# volumeMapper = vtk.vtkOpenGLGPUVolumeRayCastMapper()
volumeMapper = vtk.vtkGPUVolumeRayCastMapper()
volumeMapper.SetInputConnection(self.reader.GetOutputPort())
volumeMapper.SetBlendModeToMaximumIntensity()
# 2. Filter --> Setting the color mapper, Opacity for VolumeProperty
s0, sf = self.reader.GetOutput().GetScalarRange()
colorFunc = vtk.vtkColorTransferFunction()
colorFunc.AddRGBPoint(s0, 1, 0, 0)
colorFunc.AddRGBPoint(sf, 0, 1, 0)
volumeProperty = vtk.vtkVolumeProperty()
# The opacity transfer function is used to control the opacity
# of different tissue types.
# Create transfer mapping scalar value to opacity
volumeScalarOpacity = vtk.vtkPiecewiseFunction()
volumeScalarOpacity.AddPoint(0, 0.00)
volumeScalarOpacity.AddPoint(500, 0.55)
volumeScalarOpacity.AddPoint(800, 0.75)
volumeScalarOpacity.AddPoint(1000, 0.75)
volumeScalarOpacity.AddPoint(1150, 0.85)
# set the color for volumes
volumeProperty.SetColor(colorFunc)
# To add black as background of Volume
volumeProperty.SetScalarOpacity(volumeScalarOpacity)
volumeProperty.SetInterpolationTypeToLinear()
volumeProperty.SetIndependentComponents(2)
volumeProperty.ShadeOn()
volumeProperty.SetAmbient(0.4)
volumeProperty.SetDiffuse(0.6)
volumeProperty.SetSpecular(0.2)
volume.SetMapper(volumeMapper)
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.ren.SetBackground(0., 0, 0)
self.ren.AddActor(volume)
# interactor.Initialize()
self.ren.ResetCamera()
self.vtkWidget.GetRenderWindow().Render()
interactor.Start()
I can display the volume with âvtkGPUVolumeRayCastMapperâ in vtkâs own vtkRenderWindow and vtkRenderWindowInteractor .it means my hardware support it but I cannot display it in âQVTKRenderWindowInteractorâ of qt widget.
could you please help me with that?
I donât know really what should I do.
as I understand I have to add âQSurfaceFormat.setDefaultFormat(QSurfaceFormat.CompatibilityProfile)â in to my code but ,I got this error :
TypeError: setDefaultFormat(QSurfaceFormat): argument 1 has unexpected type âOpenGLContextProfileâ
I also add this " QSurfaceFormat.defaultFormat().setProfile(QSurfaceFormat.CompatibilityProfile)" and run with out error but nothing changed and is still black scene.
Do views in 3D Slicer show volume rendering correctly on your computer? If they do, then you may consider using CTK libraryâs Qt VTK render window (ctkVTKRenderView). If you use it from Python then you can use the Python interpreter embedded in 3D Slicer (which by the way provides many other features for visualizing DICOM volumes).
Is there another solution without using ctk?
I want to render with vtk library.
one thing is better to know is when i execute âvolumeMapper.IsRenderSupported(self.vtkWidget.GetRenderWindow(), volumeProperty)â command the output is 1 means it supports the gpu ray cast mapper.
CTK just adds many features to VTK (DICOM browser, GUI widgets for medical image visualization, helper classes for Qt-VTK integration, etc) does not replace VTK. So, if rendering works in 3D Slicer then you can surely make things work by using CTK only or even just using VTK. You just need to figure out what pieces you need to port from there. Or, you can take ideas from how Paraview creates its rendering widgets.