[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/insight-users/attachments/20160407/50db367d/attachment.html>


More information about the Insight-users mailing list