<div dir="ltr">Solved in: <a href="http://stackoverflow.com/questions/31075569/vtk-rotate-actor-programmatically-while-vtkrenderwindowinteractor-is-active">http://stackoverflow.com/questions/31075569/vtk-rotate-actor-programmatically-while-vtkrenderwindowinteractor-is-active</a><br><br>-------------------------<br><pre style class=""><code><span class="">constexpr</span><span class=""> </span><span class="">float</span><span class=""> planeWidth </span><span class="">=</span><span class=""> </span><span class="">200.0f</span><span class="">;</span><span class="">
</span><span class="">constexpr</span><span class=""> </span><span class="">float</span><span class=""> planeHeight </span><span class="">=</span><span class=""> </span><span class="">100.0f</span><span class="">;</span><span class="">
vtkActor </span><span class="">*</span><span class=""> texturedPlane</span><span class="">;</span><span class="">
vtkRenderWindowInteractor </span><span class="">*</span><span class=""> renderWindowInteractor</span><span class="">;</span><span class="">
vtkRenderWindow </span><span class="">*</span><span class=""> renWin</span><span class="">;</span><span class="">
</span><span class="">float</span><span class=""> rot </span><span class="">=</span><span class=""> </span><span class="">0.0f</span><span class="">;</span><span class="">

</span><span class="">class</span><span class=""> </span><span class="">RotateCommand</span><span class=""> </span><span class="">:</span><span class=""> </span><span class="">public</span><span class=""> vtkCommand
</span><span class="">{</span><span class="">
</span><span class="">public</span><span class="">:</span><span class="">
    vtkTypeMacro</span><span class="">(</span><span class="">RotateCommand</span><span class="">,</span><span class=""> vtkCommand</span><span class="">);</span><span class="">

    </span><span class="">static</span><span class=""> </span><span class="">RotateCommand</span><span class=""> </span><span class="">*</span><span class=""> </span><span class="">New</span><span class="">()</span><span class="">
    </span><span class="">{</span><span class="">
        </span><span class="">return</span><span class=""> </span><span class="">new</span><span class=""> </span><span class="">RotateCommand</span><span class="">;</span><span class="">
    </span><span class="">}</span><span class="">

    </span><span class="">void</span><span class=""> </span><span class="">Execute</span><span class="">(</span><span class="">vtkObject </span><span class="">*</span><span class=""> vtkNotUsed</span><span class="">(</span><span class="">caller</span><span class="">),</span><span class="">
                 </span><span class="">unsigned</span><span class=""> </span><span class="">long</span><span class=""> vtkNotUsed</span><span class="">(</span><span class="">eventId</span><span class="">),</span><span class=""> 
                 </span><span class="">void</span><span class=""> </span><span class="">*</span><span class=""> vtkNotUsed</span><span class="">(</span><span class="">callData</span><span class="">))</span><span class="">
    </span><span class="">{</span><span class="">
        texturedPlane</span><span class="">-></span><span class="">SetOrientation</span><span class="">(</span><span class="">0</span><span class="">,</span><span class="">0</span><span class="">,</span><span class="">0</span><span class="">);</span><span class="">
        texturedPlane</span><span class="">-></span><span class="">RotateZ</span><span class="">(</span><span class="">rot</span><span class="">++);</span><span class="">

        renWin</span><span class="">-></span><span class="">Render</span><span class="">();</span><span class="">
    </span><span class="">}</span><span class="">
</span><span class="">};</span><span class="">

</span><span class="">int</span><span class=""> main</span><span class="">()</span><span class="">
</span><span class="">{</span><span class="">
    </span><span class="">auto</span><span class=""> renderer </span><span class="">=</span><span class=""> vtkRenderer</span><span class="">::</span><span class="">New</span><span class="">();</span><span class="">

    </span><span class="">// Create render window</span><span class="">
    renWin </span><span class="">=</span><span class=""> vtkRenderWindow</span><span class="">::</span><span class="">New</span><span class="">();</span><span class="">
    renWin</span><span class="">-></span><span class="">AddRenderer</span><span class="">(</span><span class="">renderer</span><span class="">);</span><span class="">
    renWin</span><span class="">-></span><span class="">SetSize</span><span class="">(</span><span class="">600</span><span class="">,</span><span class="">600</span><span class="">);</span><span class="">

    </span><span class="">// Create a plane</span><span class="">
    texturedPlane </span><span class="">=</span><span class=""> vtkActor</span><span class="">::</span><span class="">New</span><span class="">();</span><span class="">
    </span><span class="">auto</span><span class=""> plane </span><span class="">=</span><span class=""> vtkPlaneSource</span><span class="">::</span><span class="">New</span><span class="">();</span><span class="">
    plane</span><span class="">-></span><span class="">SetOrigin</span><span class="">(</span><span class="">0</span><span class="">,</span><span class=""> planeHeight</span><span class="">,</span><span class=""> </span><span class="">0</span><span class="">);</span><span class="">
    plane</span><span class="">-></span><span class="">SetPoint1</span><span class="">(</span><span class="">planeWidth</span><span class="">,</span><span class=""> planeHeight</span><span class="">,</span><span class=""> </span><span class="">0</span><span class="">);</span><span class="">
    plane</span><span class="">-></span><span class="">SetPoint2</span><span class="">(</span><span class="">0</span><span class="">,</span><span class=""> </span><span class="">0</span><span class="">,</span><span class=""> </span><span class="">0</span><span class="">);</span><span class="">

    </span><span class="">auto</span><span class=""> planeMapper </span><span class="">=</span><span class=""> vtkPolyDataMapper</span><span class="">::</span><span class="">New</span><span class="">();</span><span class="">
    planeMapper</span><span class="">-></span><span class="">SetInputConnection</span><span class="">(</span><span class="">plane</span><span class="">-></span><span class="">GetOutputPort</span><span class="">());</span><span class="">
    texturedPlane</span><span class="">-></span><span class="">SetMapper</span><span class="">(</span><span class="">planeMapper</span><span class="">);</span><span class="">
    texturedPlane</span><span class="">-></span><span class="">SetOrigin</span><span class="">(</span><span class="">planeWidth </span><span class="">/</span><span class=""> </span><span class="">2</span><span class="">,</span><span class=""> planeHeight</span><span class="">,</span><span class=""> </span><span class="">0</span><span class="">);</span><span class="">

    renderer</span><span class="">-></span><span class="">AddActor</span><span class="">(</span><span class="">texturedPlane</span><span class="">);</span><span class="">

    renderer</span><span class="">-></span><span class="">ResetCamera</span><span class="">();</span><span class="">

    </span><span class="">// Create a RenderWindowInteractor</span><span class="">
    renderWindowInteractor </span><span class="">=</span><span class=""> vtkRenderWindowInteractor</span><span class="">::</span><span class="">New</span><span class="">();</span><span class="">
    renderWindowInteractor</span><span class="">-></span><span class="">SetRenderWindow</span><span class="">(</span><span class="">renWin</span><span class="">);</span><span class="">
    renderWindowInteractor</span><span class="">-></span><span class="">Initialize</span><span class="">();</span><span class="">
    renderWindowInteractor</span><span class="">-></span><span class="">CreateRepeatingTimer</span><span class="">(</span><span class="">1</span><span class="">);</span><span class="">
    </span><span class="">RotateCommand</span><span class=""> </span><span class="">*</span><span class=""> rotateCallback </span><span class="">=</span><span class="">  </span><span class="">RotateCommand</span><span class="">::</span><span class="">New</span><span class="">();</span><span class="">
    renderWindowInteractor</span><span class="">-></span><span class="">AddObserver</span><span class="">(</span><span class="">vtkCommand</span><span class="">::</span><span class="">TimerEvent</span><span class="">,</span><span class=""> rotateCallback </span><span class="">);</span><span class="">

    renderWindowInteractor</span><span class="">-></span><span class="">Start</span><span class="">();</span><span class="">
</span><span class="">}</span></code></pre><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-26 11:25 GMT-03:00 Pablo Rubi <span dir="ltr"><<a href="mailto:pabloarubi@gmail.com" target="_blank">pabloarubi@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p><font size="1">(This message was also posted in StackOverflow, those who want to start using it as a platform for help, can answer in <a href="http://stackoverflow.com/questions/31075569/vtk-rotate-actor-programmatically-while-vtkrenderwindowinteractor-is-active" target="_blank">this link</a>)</font><br></p><p>Hi all,<br></p><p>I'm trying to rotate a <code>vtkActor</code> using <code>vtkActor::RotateZ</code> and then calling <code>vtkRenderWindow::Render</code>. It works fine (it rotates the actor) but I can't move, resize, or even focus the window.</p>

<p>I suspected this was caused due to something not catching operating system events, so I added a <code>vtkRenderWindowInteractor</code> to the mix. Now I can move, resize and focus the window, but the actor is not rotating anymore.</p>

<p>I've isolated the code in the snippet below, comment line 43 to see both effects:</p>

<pre><code><span>renderWindowInteractor</span><span>-></span><span>Start</span><span>();</span></code></pre>

<p>I'm compiling VTK 6.2 with mingw-w64 (GCC 4.9.1), running in Windows 8.1. I've uploaded the code in <a href="https://github.com/Blito/VTK-SFML/tree/stackoverflow-question" rel="nofollow" target="_blank">this repo</a> with a small CMake setup so you can test it easily.</p>

<p>Thanks for your help!</p><p>-------------------------------<br></p><pre><code><span>constexpr</span><span> </span><span>float</span><span> planeWidth </span><span>=</span><span> </span><span>200.0f</span><span>;</span><span>
</span><span>constexpr</span><span> </span><span>float</span><span> planeHeight </span><span>=</span><span> </span><span>100.0f</span><span>;</span><span>

</span><span>int</span><span> main</span><span>()</span><span>
</span><span>{</span><span>
    </span><span>auto</span><span> renderer </span><span>=</span><span> vtkRenderer</span><span>::</span><span>New</span><span>();</span><span>

    </span><span>// Create render window</span><span>
    </span><span>auto</span><span> renWin </span><span>=</span><span> vtkRenderWindow</span><span>::</span><span>New</span><span>();</span><span>
    renWin</span><span>-></span><span>AddRenderer</span><span>(</span><span>renderer</span><span>);</span><span>
    renWin</span><span>-></span><span>SetSize</span><span>(</span><span>600</span><span>,</span><span>600</span><span>);</span><span>

    </span><span>// Create a plane</span><span>
    </span><span>auto</span><span> texturedPlane </span><span>=</span><span> vtkActor</span><span>::</span><span>New</span><span>();</span><span>
    </span><span>auto</span><span> plane </span><span>=</span><span> vtkPlaneSource</span><span>::</span><span>New</span><span>();</span><span>
    plane</span><span>-></span><span>SetOrigin</span><span>(</span><span>0</span><span>,</span><span> planeHeight</span><span>,</span><span> </span><span>0</span><span>);</span><span>
    plane</span><span>-></span><span>SetPoint1</span><span>(</span><span>planeWidth</span><span>,</span><span> planeHeight</span><span>,</span><span> </span><span>0</span><span>);</span><span>
    plane</span><span>-></span><span>SetPoint2</span><span>(</span><span>0</span><span>,</span><span> </span><span>0</span><span>,</span><span> </span><span>0</span><span>);</span><span>

    </span><span>auto</span><span> planeMapper </span><span>=</span><span> vtkPolyDataMapper</span><span>::</span><span>New</span><span>();</span><span>
    planeMapper</span><span>-></span><span>SetInputConnection</span><span>(</span><span>plane</span><span>-></span><span>GetOutputPort</span><span>());</span><span>
    texturedPlane</span><span>-></span><span>SetMapper</span><span>(</span><span>planeMapper</span><span>);</span><span>
    texturedPlane</span><span>-></span><span>SetOrigin</span><span>(</span><span>planeWidth </span><span>/</span><span> </span><span>2</span><span>,</span><span> planeHeight</span><span>,</span><span> </span><span>0</span><span>);</span><span>

    renderer</span><span>-></span><span>AddActor</span><span>(</span><span>texturedPlane</span><span>);</span><span>
    renderer</span><span>-></span><span>ResetCamera</span><span>();</span><span>

    </span><span>// Create a RenderWindowInteractor</span><span>
    </span><span>auto</span><span> renderWindowInteractor </span><span>=</span><span> vtkRenderWindowInteractor</span><span>::</span><span>New</span><span>();</span><span>
    renderWindowInteractor</span><span>-></span><span>SetRenderWindow</span><span>(</span><span>renWin</span><span>);</span><span>
    renderWindowInteractor</span><span>-></span><span>Start</span><span>();</span><span> </span><span>// <-- Comment this line!</span><span>

    </span><span>// Render</span><span>
    </span><span>float</span><span> rot </span><span>=</span><span> </span><span>0.0f</span><span>;</span><span>
    </span><span>while</span><span>(</span><span>true</span><span>)</span><span>
    </span><span>{</span><span>
        texturedPlane</span><span>-></span><span>SetOrientation</span><span>(</span><span>0</span><span>,</span><span>0</span><span>,</span><span>0</span><span>);</span><span>
        texturedPlane</span><span>-></span><span>RotateZ</span><span>(</span><span>rot</span><span>++);</span><span>

        renWin</span><span>-></span><span>Render</span><span>();</span><span>
    </span><span>}</span><span>
</span><span>}</span></code></pre></div>
</blockquote></div><br></div>