[vtkusers] KeyPress Events / Callbacks / User Interaction

David Doria daviddoria+vtk at gmail.com
Mon Mar 15 09:03:40 EDT 2010


On Mon, Mar 15, 2010 at 8:57 AM, Sebastian Gatzka <
sebastian.gatzka at stud.tu-darmstadt.de> wrote:

>  Somthing like this? I'm not getting it ...
>
> class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
> {
>   public:
>     static KeyPressInteractorStyle* New();
>
>     vtkImplicitPlaneWidget2 *planeWidget;
>
>
>     virtual void OnKeyPress()
>     {
>       //get the keypress
>       vtkRenderWindowInteractor *rwi = this->Interactor;
>       std::string key = rwi->GetKeySym();
>
>       if (key.compare("p") == 0)
>       {
>           vtkImplicitPlaneRepresentation* rep = *planeWidget*
> ->GetRepresentation();
>
>
>           rep->SetNormal(1,0,0);
>           planeWidget->SetRepresentation(rep);
>
>       }
>
>       //handle an arrow key
>       if(key.compare("Up") == 0)
>         {
>         cout << "The up arrow was pressed." << endl;
>         }
>
>       // forward events
>       vtkInteractorStyleTrackballCamera::OnKeyPress();
>     }
>
>
> };
>
> *This leads to problems: The planeWidget inside the {}-brackets is
> unknown.*
> *
> *
>


class KeyPressInteractorStyle : public vtkInteractorStyleTrackballCamera
{
  ...
    vtkImplicitPlaneWidget2 *planeWidget;


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

      if (key.compare("p") == 0)
      {
          vtkImplicitPlaneRepresentation* rep = *planeWidget*
->GetRepresentation();


          rep->SetNormal(1,0,0);
          //planeWidget->SetRepresentation(rep); you don't need this, it is
already set (since you just Got it)

      }
...


};


int main(int argc, char *argv[])
{
vtkSmartPointer<KeyPressInteractorStyle> style =
vtkSmartPointer<KeyPressInteractorStyle>::New();
 ...
  vtkSmartPointer<vtkImplicitPlaneWidget2> planeWidget =
      vtkSmartPointer<vtkImplicitPlaneWidget2>::New();
  planeWidget->SetInteractor(renderWindowInteractor);

style.planeWidget = planeWidget;
...


You're definitely right that we need a tutorial on callback and widgets and
interactor subclasses - I'll get to it soon.

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100315/1452909e/attachment.htm>


More information about the vtkusers mailing list