[vtkusers] Subclassing vtkInteractorStyle in FourPainView Example

Panayiotis Georgiou ps.georgiou at gmail.com
Mon Sep 9 12:37:56 EDT 2013


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,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130909/593994d7/attachment.htm>


More information about the vtkusers mailing list