[vtkusers] Interaction using vtkRenderWindowInteractor

Ashley Sher tany0029 at ntu.edu.sg
Mon Apr 17 02:29:04 EDT 2006


Hi all,

I want to use vtkRenderWindowInteractor to interact with the vtk window. I
searched through the history and found some useful information about it.
However, when i implement it, there're some problems. I'm not too sure if i
understand the steps correctly. 

Here's the steps i referred to:
(1) Create an instance of vtkRenderWindowInteractor, say
myRenderWindowInteractor 
(2) Create an instance of vtkRenderWindow, say myRenderWindow
(3) Link myRenderWindowInteractor and myRenderWindow together by
    myRenderWindowInteractor->SetRenderWindow(myRenderWindow);
(4) Derive a class from one of the subclasses of vtkInteractorStyle, say
myInteractorStyleClass
(5) Implement your own functions, such as OnLeftButtonDown(), in
MyInteractorStyleClass.

(6) Create an instance of myInteractorStyleClass, say MyInteractorStyle.
(7) Assign the interactor style to the render window interactor by
    myRenderWindowInteractor->SetInteractorStyle(MyInteractorStyle); 

Can anyone offer some advice? Thx for reading this long post! 

PS: Below is what i've implemented. 

vtkRenderer *ren = vtkRenderer::New();

vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);    

vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow (renWin);

vtkCubeSource *cube = vtkCubeSource::New();
cube->SetXLength(0.05);
cube->SetYLength(0.05);
cube->SetZLength(0.05);
	
vtkPolyDataMapper *mapCubes = vtkPolyDataMapper::New();
mapCubes->SetInputConnection(cube->GetOutputPort());

vtkActor *cubeActor = vtkActor::New();
cubeActor->SetMapper(mapCubes);		
ren->AddActor(cubeActor);    
ren->SetBackground(1, 1, 1);
	
myInteractorStyle myIren;
iren->SetInteractorStyle (myIren);
iren->ReInitialize ();
iren->Start ();

vtkCamera *cam = ren->GetActiveCamera();
renWin->Render();

cube->Delete();
mapCubes->Delete();
cubeActor->Delete();
ren->Delete();
renWin->Delete();
iren->Delete();

//myInteractorStyle header file
#pragma once
#include "C:\packages\vtk\rendering\vtkinteractorstyle.h"

class myInteractorStyle : public vtkInteractorStyle
{
public:
	myInteractorStyle();
	~myInteractorStyle();
	virtual void OnLeftButtonDown();
};

//myInteractorStyle.cxx file
#include "StdAfx.h"
#include ".\myinteractorstyle.h"
myInteractorStyle::myInteractorStyle()
{
}

myInteractorStyle::~myInteractorStyle()
{
}

void myInteractorStyle::OnLeftButtonDown()
{
	AfxMessageBox("left button down");
}
--
View this message in context: http://www.nabble.com/Interaction-using-vtkRenderWindowInteractor-t1460285.html#a3946511
Sent from the VTK - Users forum at Nabble.com.




More information about the vtkusers mailing list