[vtkusers] vtk keyboard keys

Cory Quammen cory.quammen at kitware.com
Thu Apr 14 11:37:14 EDT 2016


I think you are missing the setting of the interactor in the render window,
e.g.,

renderWindow->SetInteractor(renderWindowInteractor);

On Thu, Apr 7, 2016 at 11:07 AM, aria dob <minaninina1 at gmail.com> wrote:

> this is my program
>
>
> #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);
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> // ajouter la main
> vtkPolyDataReader *read= vtkPolyDataReader::New ();
> read->SetFileName("C:/hand.vtk");
> read->Update();
> // Create a mapper and actor(la main)
> vtkSmartPointer<vtkPolyDataMapper> map
> =vtkSmartPointer<vtkPolyDataMapper>::New();
> map->SetInputConnection(read->GetOutputPort());
> //act->GetProperty()->SetColor(1.0,0.49,0.25);
> act->SetMapper(map);
> act->SetPosition(0.7,-1.2,2.6);
> act->SetScale(0.09);
> act->RotateX(0);
> act->GetProperty()->SetColor(1.0,0.49,0.25);
>  // act->GetProperty()->SetEdgeColor(0,0,0);
> act->GetProperty()->EdgeVisibilityOn();
> renderWindow->AddRenderer(renderer);
>   renderWindowInteractor->SetRenderWindow(renderWindow);
>
>     vtkSmartPointer<KeyPressInteractorStyle> style =
> vtkSmartPointer<KeyPressInteractorStyle>::New();
>   renderWindowInteractor->SetInteractorStyle(style);
>   style->SetCurrentRenderer(renderer);
>
>  renderer->AddActor(act);
>   renderer->SetBackground(.1, .2, .3); // Background color dark blue
>
>   renderWindow->SetSize(1300,700);
>
>          renderWindow->Render();
>   renderWindowInteractor->Start();
>
>
>         return(0)}
>
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/vtk-keyboard-keys-tp5737565p5737577.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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160414/53e007cb/attachment-0001.html>


More information about the vtkusers mailing list