[vtkusers] QVTKOpenGLWidget and vtkImageViewer

Olivier Commowick olivier.commowick at inria.fr
Tue Aug 1 14:12:46 EDT 2017


Thanks for the answer, it actually solves the problem, but I do not get completely why. In my code I had set the format of the widget to the right one. Would you have an explanation of that difference ? Basically why putting it before the QApplication instanciation is important ?

Thanks again
Olivier

> Le 1 août 2017 à 20:04, Utkarsh Ayachit <utkarsh.ayachit at kitware.com <mailto:utkarsh.ayachit at kitware.com>> a écrit :
> 
> I can see one thing missing, right of the bat. You need to do the following before QApplication in instantiated.
> 
> QSurfaceFormat::setDefaultFormat(format);
> 
> Utkarsh
> 
> On Tue, Aug 1, 2017 at 1:49 PM, Olivier Commowick <olivier.commowick at inria.fr <mailto:olivier.commowick at inria.fr>> wrote:
> 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;
> }
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Powered by www.kitware.com <http://www.kitware.com/>
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html <http://www.kitware.com/opensource/opensource.html>
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ <http://www.vtk.org/Wiki/VTK_FAQ>
> 
> Search the list archives at: http://markmail.org/search/?q=vtkusers <http://markmail.org/search/?q=vtkusers>
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers <http://public.kitware.com/mailman/listinfo/vtkusers>
> 
> 


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


More information about the vtkusers mailing list