<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="">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=""><!--StartFragment--><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>::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_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>(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_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(widget.<span style="font-style: italic;" class="">GetRenderWindow</span>()-><span style="font-style: italic;" class="">GetInteractor</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.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>);</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=""><!--EndFragment--></pre><div class=""><br class=""></div></div><div class=""><br class=""></div></body></html>