[vtkusers] vtk keyboard keys

aria dob minaninina1 at gmail.com
Thu Apr 7 11:07:06 EDT 2016


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.


More information about the vtkusers mailing list