[vtkusers] KeyPress Events / Callbacks / User Interaction
David Doria
daviddoria+vtk at gmail.com
Wed Mar 10 09:28:49 EST 2010
On Wed, Mar 10, 2010 at 6:36 AM, Sebastian Gatzka <
sebastian.gatzka at stud.tu-darmstadt.de> wrote:
> Hello world.
>
> I have found the example for the catching of keys:
> http://vtk.org/Wiki/VTK/Examples/Interaction/KeypressEvents
> This is great news to me, but I want to link different things:
>
> - Wait for a key to be pressed
> - On one special key press change the normal direction of a
> vtkImplicitPlaneWidget2 representation
> - On a different special key press change the center point of a
> vtkImplicitPlaneWidget2 representation
> - Write the new normal direction and center point of the
> vtkImplicitPlaneWidget2 representation to a textActor to display the new
> values
>
> So I think I will have to link key press events and callbacks?
> I'm really not sure how to handle this on my own
>
> You will notice that my previous posts are somhow related to the topic.
> This here is the final requirement to the code and include the steps I have
> asked before.
>
> Sebastian
>
>
You need to create a member variable of type vtkImplicitPlaneWidget2* in the
interactor style subclass:
class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static KeyPressInteractorStyle* New();
virtual void OnKeyPress()
{
//get the keypress
vtkRenderWindowInteractor *rwi = this->Interactor;
std::string key = rwi->GetKeySym();
//handle a "normal" key
if(key.compare("a") == 0)
{
cout << "The a key was pressed." << endl;
}
// forward events
vtkInteractorStyleTrackballCamera::OnKeyPress();
}
vtkImplicitPlaneWidget2* PlaneWidget;
};
Then from main:
vtkImplicitPlaneWidget2* planeWidget = vtkImplicitPlaneWidget2::New();
KeyPressInteractorStyle* style = KeyPressInteractorStyle::New();
style.PlaneWidget = planeWidget;
Then you can do whatever you want to the PlaneWidget from inside
if(key.compare("a") == 0)
{
//do something to the PlaneWidget when 'a' is pressed
}
Thanks,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100310/0db93cea/attachment.htm>
More information about the vtkusers
mailing list