[vtkusers] vtk keyboard keys

Cory Quammen cory.quammen at kitware.com
Thu Apr 7 09:51:16 EDT 2016


I don't see that you are setting the interactor style in the
vtkRenderWindowInteractor.

You should have code like this somewhere in your example:

KeyPressInteractorStyle *style = KeyPressInteractorStyle::New();
vtkRenderWindowInteractor* renderWindowInteractor =
renderWindow->GetInteractor();
renderWindowInteractor->SetInteractorStyle(style);

On Thu, Apr 7, 2016 at 9:39 AM, aria dob <minaninina1 at gmail.com> wrote:
> hi ,
> i try this programme wich is true i guess but it doesn't work ,i don't khnow
> why please help me
>
> #include "stdafx.h"
> #include <vtkPolyData.h>
> #include <vtkArrowSource.h>
> #include <vtkSmartPointer.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkActor.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkPolyDataReader.h>
> #include <vtkProperty.h>
> #include <vtkTextActor.h>
> #include <vtkTextProperty.h>
> #include <vtkTriangleFilter.h>
> #include <vtkTriangleFilter.h>
> #include <vtkOBBTree.h>
> #include <vtkCellArray.h>
> #include <vtkPoints.h>
> #include <vtkDataSet.h>
> #include <vtkInteractorStyleTrackballCamera.h>
> #include<vtkObjectFactory.h>
>
> vtkSmartPointer<vtkActor> act =vtkSmartPointer<vtkActor>::New();
>  vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();
>   vtkSmartPointer<vtkRenderWindow> renderWindow
> =vtkSmartPointer<vtkRenderWindow>::New();
>
>      vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor
> =vtkSmartPointer<vtkRenderWindowInteractor>::New();
>
> class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
> {
> public:
>         static KeyPressInteractorStyle* New();
>         vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);
>
>         virtual void OnKeyPress()
>         {    double handpos[3] = {0.7,-1.2,2.6};
>
>        // Get the keypress
>                 vtkRenderWindowInteractor *rwi = this->Interactor;
>                 std::string key = rwi->GetKeySym();
>
>                 // Output the key that was pressed
>                 std::cout << "Pressed " << key << std::endl;
>
>                 // Handle an arrow key
>                 if (key == "Up")
>                 {
>                         std::cout << "The up arrow was pressed." << std::endl;
>                         handpos[0]++;
>                         act->SetPosition(handpos[0], handpos[1], handpos[2]);
>                         renderer->Render();
>                         renderWindow->Render();
>                 }
>
>                 if (key == "a")
>                 {
>                         std::cout << "The up arrow was pressed." << std::endl;
>                         handpos[1]++;
>                         act->SetPosition(handpos[0], handpos[1], handpos[2]);
>                         renderer->Render();
>                         renderWindow->Render();
>                 }
>                 if (key == "h")
>                 {
>                         std::cout << "The up arrow was pressed." << std::endl;
>                         handpos[2]++;
>                         act->SetPosition(handpos[0], handpos[1], handpos[2]);
>                         renderer->Render();
>                         renderWindow->Render();
>                 }
>                 // Forward events
>                 vtkInteractorStyleTrackballCamera::OnKeyPress();
>         }
> };
> vtkStandardNewMacro(KeyPressInteractorStyle);
>
>
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/vtk-keyboard-keys-tp5737565p5737571.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at 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
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers



-- 
Cory Quammen
R&D Engineer
Kitware, Inc.


More information about the vtkusers mailing list