[vtkusers] Pass value from vtkInteractorStyle to local variable?
DVigneault
davis.vigneault at gmail.com
Fri Jul 11 09:38:29 EDT 2014
All--
I'd like to understand the best practice for passing a variable obtained in
an interactor to a local variable, such that it can be used after the render
window is closed (in my case: open a window, obtain pixel coordinates from
mouse click, close window, then use the pixel coordinates later on in the
program). I can get the functionality I want by creating a InteractorStyle
class (inheriting from vtkInteractorStyleImage, pasted at the bottom of this
e-mail) that saves the pixel coordinates to a global variable pointPosition
OnLeftButtonUp, then closes the window OnRightButtonUp. However, I'm
nervous that coding a global variable name into a class is not very
maintainable, and thought there was likely a better way to do it. What is
the best practice in this case?
Sorry if this is more of a c++ question and less of a VTK question--I've
been learning c++/vtk/itk in tandem with one another, and am sometimes
unclear when one ends and the other begins.
Best, and thanks,
--Davis
// Create a class inheriting from vtkInteractorStyleImage
class dvInteractorStyleSelectPoint : public vtkInteractorStyleImage
{
public:
static dvInteractorStyleSelectPoint* New();
vtkTypeMacro(dvInteractorStyleSelectPoint, vtkInteractorStyleImage);
// OnLeftButtonUp, save the pixel coordinates to the global
variable pointPosition
virtual void OnLeftButtonUp() {
std::cout << "Picking pixel: " <<
this->Interactor->GetEventPosition()[0] << " " <<
this->Interactor->GetEventPosition()[1] << std::endl;
this->Interactor->GetPicker()->Pick(this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1],
0, // always zero.
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
this->Interactor->GetPicker()->GetPickPosition(pointPosition);
std::cout << "Picked value: " << pointPosition[0] << " " <<
pointPosition[1] << std::endl;
vtkInteractorStyleImage::OnLeftButtonUp();
}
// OnRightButtonUp, close the window
virtual void OnRightButtonUp() {
this->GetInteractor()->GetRenderWindow()->Finalize();
std::cout << "Closing window..." << std::endl;
vtkInteractorStyleImage::OnRightButtonUp();
}
};
--
View this message in context: http://vtk.1045678.n5.nabble.com/Pass-value-from-vtkInteractorStyle-to-local-variable-tp5727826.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list