I have a view with a vtkInteractorStyleTrackballCamera interactor. When you drag the mouse (left click and drag) it rotates the object. This is good. Now I want to return the mouse coordinates when the user does a single left button click and release.
At the moment, when I add a vtkCallbackCommand with the vtkCommand::KeyPressEvent the rotational ability of the object gets disabled. Any thoughts?
Do you extend vtkInteractorStyleTrackballCamera? If so, you need to forward the event to the superclass: vtkInteractorStyleTrackballCamera::OnLeftButtonDown(); in your class if you wish to maintain the original behavior in addition to the one of your code.
Thanks for your response. I have managed to find a solution to my problem. Not sure if it is the best one but it works.
I prefer to use observers then I do not have to do the whole inheritance thing. I added a callback method to my vtkInteractorStyleTrackballCamera object using the vtkCommand::LeftButtonPressEvent and the vtkCommand::LeftButtonReleaseEvent (on the same method).
I then record the mouse pointer location on the LeftButtonPressEvent and compare it to when the mouse button is released (LeftButtonReleaseEvent). If they match I then do my stuff. That is it.
Hi, Paulo.I have a question. I Do not extend vtkInteractorStyleTrackballCamera,because I use C# program Kitware.VTK.When I drag the mouse (left click and drag) it rotates the object,but the event function: renWinInteractor.LeftButtonReleaseEvt+=LeftButtonReleaseEvt can not capture Button Release at once , As you say,in C++ program ,just need to forward the event to the superclass: vtkInteractorStyleTrackballCamera::OnLeftButtonDown(),I want to know how to realize this in Kitware.VTK using event function
regards
Not sure about what’s available from Kitware’s C# VTK. If you’re doing it without extending the interactor style, it is best to listen to the interactor for events and then forward the event to the interactor style.
Here’s an example in C++, it should apply to Python and C# assuming VTK C# exposes the enums from vtkCommand and functions from interactor style.
void OnLeftButtonDown(....)
{
// ...
// switch style could be a special case, so just to be safe, let's handle it.
auto* style = vtkInteractorStyle::SafeDownCast(interactor->GetInteractorStyle());
if (auto* switchableStyle = vtkInteractorStyleSwitch::SafeDownCast(style))
{
switchableStyle->GetCurrentStyle()->OnLeftButtonDown();
}
else
{
style->OnLeftButtonDown();
}
}
void OnLeftButtonUp(....)
{
// ...
// switch style could be a special case, so just to be safe, let's handle it.
auto* style = vtkInteractorStyle::SafeDownCast(interactor->GetInteractorStyle());
if (auto* switchableStyle = vtkInteractorStyleSwitch::SafeDownCast(style))
{
switchableStyle->GetCurrentStyle()->OnLeftButtonUp();
}
else
{
style->OnLeftButtonUp();
}
}
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, OnLeftButtonDown);
interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, OnLeftButtonUp);
class MyInteractor : public vtkInteractorStyleTrackballCamera {
public:
...
void OnLeftButtonDown() override {
do_my_stuff();
// Forward the event to the base class to keep current behavior.
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
...
private:
...
protected:
...
};
I think translating this to C# is straightforward.