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[]) {

  QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
  // DOES NOT WORK WHEN INSTANTIATED HERE
  // QApplication app(argc, argv);
  // QVTKOpenGLNativeWidget widget;

  vtkNew<vtkDICOMImageReader> reader;
  vtkNew<vtkImageData> imageData;
  vtkNew<vtkSmartVolumeMapper> volumeMapper;
  vtkNew<vtkVolume> volume;
  vtkNew<vtkRenderer> renderer;
  vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
    
  reader->SetDirectoryName("/my/DICOM/images");
  reader->Update();
  imageData->ShallowCopy(reader->GetOutput());
    
  volumeMapper->SetInputData(imageData);
  volume->SetMapper(volumeMapper);
  volume->Update();

  renderer->AddVolume(volume);
  renderer->SetBackground(0.1, 0.2, 0.3);
  renderWindow->AddRenderer(renderer);

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

  widget.SetRenderWindow(renderWindow);
  widget.resize(500, 500);
  widget.show();
    
  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

I’m having the same problem, but not using vtkDICOMImageReader. I am using vtkMetaIOImageReader. When I use the same transfer functions, etc. in the example here

https://lorensen.github.io/VTKExamples/site/Cxx/Medical/MedicalDemo4/

I can render my volume in MedicalDemo4.

And, I can also render geometric primitives, e.g. cylinder in my QVTKOpenGLNativeWidget

But using vtkSmartVolumeMapper and vtkVolume I get nothing when using QVTKOpenGLNativeWidget to render a volume.

If anyone has a debugging tip, I could use it!

Rick

It’s a late, but I would bet inserting
vtkGenericOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples( 0 );
Before
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat()); will fix the issue …
In our experience, we need to disable MSAA with the QVTKOpenGLNativeWidget in order for volume rendering to work on intel card.
If you have a recent nvidia, then you dont need to disable it (ie your code should work just fine on a recent geforce)

I am running this on NVIDIA Quadro P5000 on desktop and M5000 on laptop
both high end cards

Rick Frank
Dominion Software, Inc.

825 Beacon Street

Newton, MA 02459

Medical, Scientific, and Industrial Software

Does adding the line fix the bug ?

It fixes it on my M5000 laptop , yes.

I will check the P5000 at the office later.

Is this a bug in NVIDIA driver?

Cool,
I have seen some similar code working on a Geforce and not on a quadro :slight_smile:
I don’t think it’s an nvidia bug, more a VTK bug that I would describe as :
QVTKOpenGLNativeWidget + Volume Rendering + MSAA = not working in most platform except some geforce (again from our experience)