Render window output is black when I use vtkGPUVolumeRayCastMapper python

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.:pray:

Here is my code : = vtk.vtkRenderer()
    self.vtkWidget = QVTKRenderWindowInteractor()

    self.reader = vtk.vtkDICOMImageReader()

    interactor = self.vtkWidget.GetRenderWindow().GetInteractor()

    volume = vtk.vtkVolume()
    # Ray cast function know how to render the data
    # volumeMapper = vtk.vtkOpenGLGPUVolumeRayCastMapper()
    volumeMapper = vtk.vtkGPUVolumeRayCastMapper()


    # 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
    # To add black as background of Volume



    self.vtkWidget.GetRenderWindow().AddRenderer(, 0, 0)
    # interactor.Initialize()


Probably your hardware does not meet GPU volume raycast mapper minimum requirements. What CPU and graphics card do you have?

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.


Which CPU generation? Which NVidia GTX model? What operating system?

Default Qt surface format of VTK needs modifications depending on your hardware and operating system. See for example how it is set up in 3D Slicer: Intel UHD 620 + VTK + Qt bug with new drivers on windows

Here is my HW detail :
Intel® Core™ i7-6700HQ CPU @ 2.60GHz × 8
Intel® HD Graphics 530 (Skylake GT2) 64bit

CPU chipset is recent enough. Intel graphics cards require using QSurfaceFormat::CompatibilityProfile when you set up your surface format.

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.

beside ctk I have to use slicer library?

CTK does not use or require 3D Slicer.

Instead, a number of image computing applications, such as 3D Slicer and MITK, use CTK.

My problem just solved by set QVTKRWIBase to “QGLWidget” :

vtk.qt.QVTKRWIBase = "QGLWidget"