[vtkusers] QVTKOpenGLWidget and vtkImageViewer

Olivier Commowick olivier.commowick at inria.fr
Tue Aug 1 13:49:31 EDT 2017


Hi everyone, 

I have been struggling with using QVTKOpenGLWidget to display an image with the vtkImageViewer. My problem is basically that the image is loaded and everything created but it seems the rendering is never triggered and thus the display is black. 

To summarize what I’ve done, I’ve created a vtkImageViewer3 which is the same as vtkImageViewer from VTK, only changing the vtkRenderWindow to be a vtkGenericOpenGLRenderWindow (required by the QVTKOpenGLWidget). I have then modified the ImageViewer example from VTK to match these new classes which gives the following code (see at the end). Oh, and I am using Qt5.7, and VTK 8.0 release.

Would anyone have any clue on what could make this work (i.e. actually render something and display it) ? 

Thanks in advance
Olivier

——

Main.cxx code:

#include <QApplication>

#include "vtkImageViewer3.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkPNGReader.h"

#include "QVTKOpenGLWidget.h"
#include <QSurfaceFormat>

int main(int argc, char** argv)
{
    QSurfaceFormat format = QVTKOpenGLWidget::defaultFormat();
    format.setSamples(0);

    QApplication app(argc, argv);

    QVTKOpenGLWidget widget;
    widget.setFormat(format);
    widget.setEnableHiDPI(true);
    widget.resize(256,256);

    vtkPNGReader* reader = vtkPNGReader::New();
    std::string fname = argv[1];
    reader->SetFileName(fname.c_str());

    vtkImageViewer3* image_view = vtkImageViewer3::New();
    image_view->SetInputConnection(reader->GetOutputPort());

    widget.SetRenderWindow(image_view->GetRenderWindow());
    image_view->SetupInteractor(widget.GetRenderWindow()->GetInteractor());

    image_view->SetColorLevel(138.5);
    image_view->SetColorWindow(233);

    widget.show();

    app.exec();

    image_view->Delete();
    reader->Delete();

    return 0;
}





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170801/69746af0/attachment.html>


More information about the vtkusers mailing list