<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><div class="">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 ?<br class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Thanks again</div><div class="">Olivier<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">Le 1 août 2017 à 20:04, Utkarsh Ayachit <<a href="mailto:utkarsh.ayachit@kitware.com" class="">utkarsh.ayachit@kitware.com</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I can see one thing missing, right of the bat. You need to do the following before QApplication in instantiated.<div class=""><br class=""></div><div class=""><div class="gmail-line" style="font-stretch: normal; font-size: 13px; line-height: 1; font-family: monospace, fixed; min-height: 13px; white-space: pre-wrap; word-wrap: break-word; padding-left: 53px; padding-bottom: 0px; margin: 0px;"><b class="">QSurfaceFormat::setDefaultFormat</b>(format);</div></div><div class=""><br class=""></div><div class="">Utkarsh</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Aug 1, 2017 at 1:49 PM, Olivier Commowick <span dir="ltr" class=""><<a href="mailto:olivier.commowick@inria.fr" target="_blank" class="">olivier.commowick@inria.fr</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class="">Hi everyone, <div class=""><br class=""></div><div class="">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. </div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Would anyone have any clue on what could make this work (i.e. actually render something and display it) ? </div><div class=""><br class=""></div><div class="">Thanks in advance</div><div class="">Olivier</div><div class=""><br class=""></div><div class="">——</div><div class=""><br class=""></div><div class="">Main.cxx code:</div><div class=""><br class=""></div><div class="">
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#000080" class="">#include</span><span style="color:#c0c0c0" class=""> </span><span style="color:#008000" class=""><QApplication></span></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#000080" class="">#include</span><span style="color:#c0c0c0" class=""> </span><span style="color:#008000" class="">"vtkImageViewer3.h"</span></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#000080" class="">#include</span><span style="color:#c0c0c0" class=""> </span><span style="color:#008000" class="">"vtkRenderWindowInteractor.h"</span></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#000080" class="">#include</span><span style="color:#c0c0c0" class=""> </span><span style="color:#008000" class="">"vtkRenderer.h"</span></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#000080" class="">#include</span><span style="color:#c0c0c0" class=""> </span><span style="color:#008000" class="">"vtkPNGReader.h"</span></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#000080" class="">#include</span><span style="color:#c0c0c0" class=""> </span><span style="color:#008000" class="">"QVTKOpenGLWidget.h"</span></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#000080" class="">#include</span><span style="color:#c0c0c0" class=""> </span><span style="color:#008000" class=""><QSurfaceFormat></span></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#808000" class="">int</span><span style="color:#c0c0c0" class=""> </span>main(<span style="color:#808000" class="">int</span><span style="color:#c0c0c0" class=""> </span>argc,<span style="color:#c0c0c0" class=""> </span><span style="color:#808000" class="">char</span>**<span style="color:#c0c0c0" class=""> </span>argv)</pre>
<pre style="margin-top:0px;margin-bottom:0px" class="">{</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span><span style="color:#800080" class="">QSurfaceFormat</span><span style="color:#c0c0c0" class=""> </span>format<span style="color:#c0c0c0" class=""> </span>=<span style="color:#c0c0c0" class=""> </span><span style="color:#800080" class="">QVTKOpenGLWidget</span>::<wbr class="">defaultFormat();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>format.setSamples(<span style="color:#000080" class="">0</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span><span style="color:#800080" class="">QApplication</span><span style="color:#c0c0c0" class=""> </span>app(argc,<span style="color:#c0c0c0" class=""> </span>argv);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span><span style="color:#800080" class="">QVTKOpenGLWidget</span><span style="color:#c0c0c0" class=""> </span>widget;</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>widget.setFormat(format);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>widget.<span style="font-style:italic" class="">setEnableHiDPI</span>(<span style="color:#808000" class="">true</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>widget.resize(<span style="color:#000080" class="">256</span>,<span style="color:#000080" class="">256</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span><span style="color:#800080" class="">vtkPNGReader</span>*<span style="color:#c0c0c0" class=""> </span>reader<span style="color:#c0c0c0" class=""> </span>=<span style="color:#c0c0c0" class=""> </span><span style="color:#800080" class="">vtkPNGReader</span>::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span><span style="color:#800080" class="">std</span>::<span style="color:#800080" class="">string</span><span style="color:#c0c0c0" class=""> </span>fname<span style="color:#c0c0c0" class=""> </span>=<span style="color:#c0c0c0" class=""> </span>argv[<span style="color:#000080" class="">1</span>];</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>reader-><span style="font-style:italic" class="">SetFileName</span>(fname.c_<wbr class="">str());</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span><span style="color:#800080" class="">vtkImageViewer3</span>*<span style="color:#c0c0c0" class=""> </span>image_view<span style="color:#c0c0c0" class=""> </span>=<span style="color:#c0c0c0" class=""> </span><span style="color:#800080" class="">vtkImageViewer3</span>::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>image_view-><span style="font-style:italic" class="">SetInputConnection</span><wbr class="">(reader->GetOutputPort());</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>widget.SetRenderWindow(image_<wbr class="">view-><span style="font-style:italic" class="">GetRenderWindow</span>());</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>image_view->SetupInteractor(<wbr class="">widget.<span style="font-style:italic" class="">GetRenderWindow</span>()-><span style="font-style:italic" class="">GetI<wbr class="">nteractor</span>());</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>image_view->SetColorLevel(<span style="color:#000080" class="">138.<wbr class="">5</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>image_view->SetColorWindow(<span style="color:#000080" class="">233</span><wbr class="">);</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>widget.show();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>app.exec();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>image_view-><span style="font-style:italic" class="">Delete</span>();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span>reader-><span style="font-style:italic" class="">Delete</span>();</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><span style="color:#c0c0c0" class="">    </span><span style="color:#808000" class="">return</span><span style="color:#c0c0c0" class=""> </span><span style="color:#000080" class="">0</span>;</pre>
<pre style="margin-top:0px;margin-bottom:0px" class="">}</pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre>
<pre style="margin-top:0px;margin-bottom:0px" class=""><br class=""></pre><div class=""><br class=""></div></div><div class=""><br class=""></div></div><br class="">______________________________<wbr class="">_________________<br class="">
Powered by <a href="http://www.kitware.com/" rel="noreferrer" target="_blank" class="">www.kitware.com</a><br class="">
<br class="">
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank" class="">http://www.kitware.com/<wbr class="">opensource/opensource.html</a><br class="">
<br class="">
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank" class="">http://www.vtk.org/Wiki/VTK_<wbr class="">FAQ</a><br class="">
<br class="">
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank" class="">http://markmail.org/search/?q=<wbr class="">vtkusers</a><br class="">
<br class="">
Follow this link to subscribe/unsubscribe:<br class="">
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank" class="">http://public.kitware.com/<wbr class="">mailman/listinfo/vtkusers</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></div></div><br class=""></body></html>