[vtkusers] Subclassing vtkInteractorStyle in FourPainView Example

Alex Malyushytskyy alexmalvtk at gmail.com
Mon Sep 9 16:25:03 EDT 2013


Override  vtkInteractorStyle::OnChar ( )

Make it do nothing.

Alex



On Mon, Sep 9, 2013 at 9:37 AM, Panayiotis Georgiou
<ps.georgiou at gmail.com>wrote:

> Dear vtk users,
>
> I am trying to customize the FourPaneViewer example from the provided VTK
> examples. The full code of the example can be found in
> VTK_DIR/Examples/GUI/Qt/FourPaneViewer.
>
> The example embeds in Qt 4 QVTKWidget views and performs reslicing. One of
> the views renders (3) vtkImagePlaneWidgets and each of the other 3 views
> renders a vtkResliceImageViewer.
>
> What I am trying to achieve is disable in the 3 vtkResliceImageViewers any
> events triggered by pressing keys on the keyboard, i.e. I want to restrict
> the user and allow him to interact with these widgets using only the mouse.
>
> The way I have tried to do this is by subclassing the vtkInteractorStyle
> class as follows:
>
>     // Define interaction style
>     class KeyPressInteractorStyle : public vtkInteractorStyle
>     {
>     public:
>     static KeyPressInteractorStyle* New();
>     vtkTypeMacro(KeyPressInteractorStyle, vtkInteractorStyle);
>
>     virtual void OnKeyPress()
>     {
>     // Get the keypress
>     vtkRenderWindowInteractor *rwi = this->Interactor;
>     std::string key = rwi->GetKeySym();
>
>     // Output the key that was pressed
>     std::cout << "Pressed " << key << std::endl;
>     qDebug()<< "Pressed " << rwi->GetKeySym();
>
>     // Forward events
>     vtkInteractorStyle::OnKeyPress();
>     }
>
>     };
>     vtkStandardNewMacro(KeyPressInteractorStyle);
>
> and then for each of the 3 views, the customised interaction style is
> applied as follows:
>
>         vtkSmartPointer<KeyPressInteractorStyle> style =
>     vtkSmartPointer<KeyPressInteractorStyle>::New();
>
>
> this->ui->view1->GetRenderWindow()->GetInteractor()->SetInteractorStyle(style);
>         style->SetCurrentRenderer(riw[0]->GetRenderer());
>
>         this->ui->view1->SetRenderWindow(riw[0]->GetRenderWindow());
>
> riw[0]->SetupInteractor(this->ui->view1->GetRenderWindow()->GetInteractor());
>
> where view1 is of type QVTKWidget  and riw[i] of type
> vtkResliceImageViewer.
>
> Unfortunately the approach I am using has no effect. The keyboard events
> are not captured at all by the interaction style. Nothing is printed in the
> console. It should be noted that if I apply the customised style on the 4th
> view for vtkImagePlaneWidgets, then it works.
>
> Can someone help me to fix this? I am new to VTK and any help will be much
> appreciated.
>
> Thanks for your help,
>
> _______________________________________________
> 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/20130909/bf30769b/attachment.htm>


More information about the vtkusers mailing list