# vtkVolume not rendering when using QVTKOpenGLNativeWidget

**URL:** https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547
**Category:** Support
**Created:** [August 10, 2019, 2:35pm UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547 "2019-08-10T14:35:37Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![NewProggie](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newproggie/32/739_2.png) [@NewProggie](https://discourse.vtk.org/u/NewProggie)
#### Post date: [August 10, 2019, 2:35pm UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/1 "2019-08-10T14:35:37Z")

</div>

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:

```auto
#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.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [August 10, 2019, 6:28pm UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/2 "2019-08-10T18:28:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![NewProggie](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newproggie/32/739_2.png) [@NewProggie](https://discourse.vtk.org/u/NewProggie)
#### Post date: [August 12, 2019, 8:58am UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/3 "2019-08-12T08:58:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![NewProggie](https://discourse.vtk.org/user_avatar/discourse.vtk.org/newproggie/32/739_2.png) [@NewProggie](https://discourse.vtk.org/u/NewProggie)
#### Post date: [August 12, 2019, 7:54pm UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/4 "2019-08-12T19:54:21Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DominionSoftware](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dominionsoftware/32/1064_2.png) [@DominionSoftware](https://discourse.vtk.org/u/DominionSoftware)
#### Post date: [November 12, 2019, 2:45am UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/5 "2019-11-12T02:45:22Z")

</div>

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/](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

---

<div class="post-metadata">

### Author: ![simonesneault](https://discourse.vtk.org/user_avatar/discourse.vtk.org/simonesneault/32/67_2.png) [@simonesneault](https://discourse.vtk.org/u/simonesneault)
#### Post date: [November 13, 2019, 8:57am UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/6 "2019-11-13T08:57:35Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![DominionSoftware](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dominionsoftware/32/1064_2.png) [@DominionSoftware](https://discourse.vtk.org/u/DominionSoftware)
#### Post date: [November 13, 2019, 9:45am UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/7 "2019-11-13T09:45:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![simonesneault](https://discourse.vtk.org/user_avatar/discourse.vtk.org/simonesneault/32/67_2.png) [@simonesneault](https://discourse.vtk.org/u/simonesneault)
#### Post date: [November 13, 2019, 9:51am UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/8 "2019-11-13T09:51:49Z")

</div>

Does adding the line fix the bug ?

---

<div class="post-metadata">

### Author: ![DominionSoftware](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dominionsoftware/32/1064_2.png) [@DominionSoftware](https://discourse.vtk.org/u/DominionSoftware)
#### Post date: [November 13, 2019, 9:58am UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/9 "2019-11-13T09:58:26Z")

</div>

It fixes it on my M5000 laptop , yes.

I will check the P5000 at the office later.

Is this a bug in NVIDIA driver?

---

<div class="post-metadata">

### Author: ![simonesneault](https://discourse.vtk.org/user_avatar/discourse.vtk.org/simonesneault/32/67_2.png) [@simonesneault](https://discourse.vtk.org/u/simonesneault)
#### Post date: [November 13, 2019, 10:07am UTC](https://discourse.vtk.org/t/vtkvolume-not-rendering-when-using-qvtkopenglnativewidget/1547/10 "2019-11-13T10:07:14Z")

</div>

Cool,  
I have seen some similar code working on a Geforce and not on a quadro 🙂  
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)
