[vtkusers] KeyPress Events / Callbacks / User Interaction

Sebastian Gatzka sebastian.gatzka at stud.tu-darmstadt.de
Fri Mar 12 06:58:55 EST 2010


Ok some updates: This is what I tried to change the widgets normal:

// Define interaction style
class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
   public:
     static KeyPressInteractorStyle* New();

     virtual void OnKeyPress()
     {
       //get the keypress
       vtkRenderWindowInteractor *rwi = this->Interactor;
       std::string key = rwi->GetKeySym();

       if (key.compare("p") == 0)
       {
           planeRepresentation->SetNormal(1,0,0);
           planeWidget->SetRepresentation(planeRepresentation);
       }

       //handle an arrow key
       if(key.compare("Up") == 0)
         {
         cout << "The up arrow was pressed." << endl;
         }

       // forward events
       vtkInteractorStyleTrackballCamera::OnKeyPress();
     }
      vtkImplicitPlaneWidget2 *planeWidget;
     vtkImplicitPlaneRepresentation *planeRepresentation;
};

Results in a crash when setting the normal.

Am 12.03.2010 11:38, schrieb Sebastian Gatzka:
> 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
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100312/c18684ca/attachment.htm>


More information about the vtkusers mailing list