[ITK] [ITK-users] Interaction of keyboard
Abdelkhalek Bakkari
bakkari.abdelkhalek at hotmail.fr
Thu Apr 7 16:34:38 EDT 2016
Hi !
I would like to interact the button of my keyboard in order to modify the position of a 3D object (translation) using up or down or left or right buttons.
I created the following piece of code but it does not give results :------------------------------------------------------------------------------------------------------------class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static KeyPressInteractorStyle* New();
vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyleTrackballCamera);
virtual void OnKeyPress()
{
double handpos[3]={8.0,2.0, 0.0};
// Get the keypress
vtkRenderWindowInteractor *rwi = this->Interactor;
// vtkRenderer *rend=new(vtkRenderer);
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;
// act->SetPosition(handpos[0]+1, handpos[1], handpos[2]);
myTrans->Translate(handpos[0]+1, handpos[1], handpos[2]);
handpos[0]++;
act->SetPosition(handpos[0], handpos[1], handpos[2]);
renderer->Render();
renderWindow->Render();
}
// Handle a "normal" key
if(key == "Down")
{
std::cout << "The a key was pressed." << std::endl;
handpos[0]++;
act->SetPosition(handpos[0], handpos[1], handpos[2]);
renderer->Render();
renderWindow->Render();
}
// Handle a "normal" key
if(key == "Right")
{
std::cout << "The Right key was pressed." << std::endl;
handpos[2]++;
act->SetPosition(handpos[0], handpos[1], handpos[2]);
renderer->Render();
renderWindow->Render();
}
if(key== "Left")
{
std::cout << "The left key was pressed." << std::endl;
handpos[2]++;
act->SetPosition(handpos[0], handpos[1], handpos[2]);
renderer->Render();
renderWindow->Render();
}
// Forward events
vtkInteractorStyleTrackballCamera::OnKeyPress();
}
};
------------------------------------------------------------------------------------------------------------------
Best regards,
Abdelkhalek BakkariPh.D candidate in Computer ScienceInstitute of Applied Computer ScienceLodz University of Technology, Poland
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160407/50db367d/attachment-0001.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
More information about the Community
mailing list