vtkVolume not rendering when using QVTKOpenGLNativeWidget

Hi all,

I’m currently experiencing a strange rendering issue where a vtkVolume is not rendered when displayed inside a QVTKOpenGLNativeWidget. It works fine when testing the same code/pipeline with a simple vtkSphere though.

What’s even more strange is that it seemingly depends on when an instance of QApplication get instantiated. For instance the rendering of the vtkVolume works, if QApplication is instantiated after building the pipeline, whereas if I’m moving the following code lines at the beginning of my program, it doesn’t work anymore:

#include <QApplication>
#include <QSurfaceFormat>
#include <QVTKOpenGLNativeWidget.h>

#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkDICOMImageReader.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkSmartVolumeMapper.h>

int main(int argc, char *argv[]) {

  // QApplication app(argc, argv);
  // QVTKOpenGLNativeWidget widget;

  vtkNew<vtkDICOMImageReader> reader;
  vtkNew<vtkImageData> imageData;
  vtkNew<vtkSmartVolumeMapper> volumeMapper;
  vtkNew<vtkVolume> volume;
  vtkNew<vtkRenderer> renderer;
  vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;

  renderer->SetBackground(0.1, 0.2, 0.3);

  QApplication app(argc, argv);
  QVTKOpenGLNativeWidget widget;

  widget.resize(500, 500);
  return app.exec();

I am trying this on macOS, using Qt 5.12.4 and VTK 8.2.0 with either a
Radeon Pro Vega 48 or Intel Iris Graphics 550.

Edit: It also does work if I’m using VTK only for rendering. It basically stops rendering as soon as I am adding QApplication to the sources.

Building multi-platform Qt applications with recent VTK and Qt versions is indeed very tricky. Unless you particularly enjoy exploring these low-level details, I would recommend to choose an application framework that takes care of such things so that you can focus on the actual problem that you want to solve.

For example, for general technical visualization you can build your application based on Paraview, for medical applications you can create custom applications based on 3D Slicer. They are both tested on Windows, Mac, and Linux and on a wide range of hardware configurations.

Hey Andras,

thanks for your reply. However, this is currently not an option, unfortunately.
It seems to me the problem is really with the vtkGenericOpenGLRenderWindow. All other example visualizations I’ve tried do work fine (in both vtkRenderWindow and with Qt). It just doesn’t seem to work when visualizing a vtkVolume and after studying the source code a bit, I still have no clue why that may by the case here.

So to answer my own question for any poor soul that might come across this post and experienced the same behavior:

The vtkDICOMImageReader has some problems reading meta data if the locale is different on the host then the one used to generate the metada. Hence, it may help to switch the locale (to english in my case) in order to parse the correct metadata.

1 Like