[vtkusers] KeyPress Events / Callbacks / User Interaction

David Doria daviddoria+vtk at gmail.com
Fri Mar 12 10:04:02 EST 2010


On Fri, Mar 12, 2010 at 6:58 AM, Sebastian Gatzka
<sebastian.gatzka at stud.tu-darmstadt.de> wrote:
>
> 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.
>

You didn't show how you set the planeRepresentation member variable. I
wouldn't do it like this, I would simply set the planeWidget member
variable and then use:

vtkImplicitPlaneRepresentation* rep = planeWidget->GetRepresentation();

to do things to the representation.

Thanks,

David



More information about the vtkusers mailing list