[vtkusers] Subclassing vtkInteractorStyle in FourPainView Example

Panayiotis Georgiou ps.georgiou at gmail.com
Mon Sep 9 19:53:51 EDT 2013


Thanks for your reply Alex.

I have tried what you have suggested but it sill doesn't work. I believe
the problem is on how I apply the new style on the three views. As I have
noted in my original post, when I apply the customised style on the 4th
view it works. The way I did that for the 4th view is:

vtkSmartPointer< vtkRenderer > ren = vtkSmartPointer< vtkRenderer >::New();

this->ui->view4->GetRenderWindow()->AddRenderer(ren);
vtkRenderWindowInteractor *iren = this->ui->view4->GetInteractor();
iren->SetInteractorStyle(style);
style->SetCurrentRenderer(ren);

Any other suggestions?

Thanks.


On Mon, Sep 9, 2013 at 9:25 PM, Alex Malyushytskyy <alexmalvtk at gmail.com>wrote:

> 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/20130910/42b03641/attachment.htm>


More information about the vtkusers mailing list