[vtkusers] Interaction using vtkRenderWindowInteractor
Kjeld Vestberg Hansen
kjeld at aub.dk
Mon Apr 17 12:59:03 EDT 2006
Hi Ashley
You should use a vtkCommand instead of then you can get yours OnLeftButtonDown event to be excurse direct on an object. You use the method
AddObserver and RemoveObserver and you schall only implement execute in the class the inherent from vtkCommand.
Best regards Kjeld
>
> 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.
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list