[vtkusers] KeyPress Events / Callbacks / User Interaction
Sebastian Gatzka
sebastian.gatzka at stud.tu-darmstadt.de
Fri Mar 12 05:38:07 EST 2010
Just great this worked!
But as I want to change the normal and center of the
vtkImplicitPlaneWidget2 I need to access its representation.
There I can set the things I want:
vtkImplicitPlaneRepresentation *iPlaneRepresentation =
vtkImplicitPlaneRepresentation::New();
iPlaneRepresentation->SetPlaceFactor(1.0); // This must be set prior to
placing the widget
iPlaneRepresentation->PlaceWidget(sGrid->GetBounds());
iPlaneRepresentation->SetNormal(0,0,1);
iPlaneRepresentation->SetOrigin(sGrid->GetCenter());
iPlaneRepresentation->SetOutlineTranslation(0);
iPlaneRepresentation->SetDrawPlane(0);
So how can I have access to the representation itself from withing the
class KeyPressInteractorStyle?
Am 10.03.2010 15:28, schrieb David Doria:
> On Wed, Mar 10, 2010 at 6:36 AM, Sebastian Gatzka
> <sebastian.gatzka at stud.tu-darmstadt.de
> <mailto: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/20100312/7addf046/attachment.htm>
More information about the vtkusers
mailing list