[vtkusers] Rotate actor programmatically while vtkRenderWindowInteractor is active

Pablo Rubi pabloarubi at gmail.com
Fri Jun 26 10:25:08 EDT 2015


(This message was also posted in StackOverflow, those who want to start
using it as a platform for help, can answer in this link
<http://stackoverflow.com/questions/31075569/vtk-rotate-actor-programmatically-while-vtkrenderwindowinteractor-is-active>
)

Hi all,

I'm trying to rotate a vtkActor using vtkActor::RotateZ and then calling
vtkRenderWindow::Render. It works fine (it rotates the actor) but I can't
move, resize, or even focus the window.

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

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

renderWindowInteractor->Start();

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

Thanks for your help!

-------------------------------

constexpr float planeWidth = 200.0f;constexpr float planeHeight = 100.0f;
int main(){
    auto renderer = vtkRenderer::New();

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

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

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

    renderer->AddActor(texturedPlane);
    renderer->ResetCamera();

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

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

        renWin->Render();
    }}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150626/4d5804a3/attachment.html>


More information about the vtkusers mailing list