[vtkusers] Overriding vtkInteractorStyleImage

Scott Johnson Scott.Johnson at neuwave.com
Wed Mar 31 13:07:03 EDT 2010


Hi Folks,

 

I am trying to override the behavior of vtkInteractorStyleImage.  I want
the mouse wheel to page through slices of the volume, and not zoom, but
I want to preserve the window/level functionality on the left mouse
move.

 

I created a subclass and overrode OnMouseWheelForward and
OnMouseWheelBackward, then set the style on a vtkRenderWindowInteractor.
The mouse wheel works, but the window/level functionality is gone.  Any
ideas as to why?

 

My class is:

class ResliceInteractorStyle : public vtkInteractorStyleImage

{

  public:

    static ResliceInteractorStyle* New();

 

    virtual void OnMouseWheelForward()

    {

        int slice=_reslice->GetSlice();

 

        _reslice->SetSlice(slice + 1);

    }

 

    virtual void OnMouseWheelBackward()

    {

        int slice=_reslice->GetSlice();

 

        _reslice->SetSlice(slice - 1);

    }

 

    void SetCallbackData(ResliceRender* reslice)

    {

        _reslice=reslice;

    }

 

protected:

    ResliceRender* _reslice;

};

 

The Pipeline is created with:

void ResliceRender::CreatePipeline(vtkAlgorithmOutput* input)

{

    vtkSmartPointer<ResliceInteractorStyle> style = 

        vtkSmartPointer<ResliceInteractorStyle>::New();

    style->SetCallbackData(this);

 

    _transform = vtkTransform::New();

 

    _reslice = vtkImageReslice::New();

    _reslice->SetInputConnection(input);

    _reslice->SetResliceTransform(_transform);

 

    _interactor = vtkRenderWindowInteractor::New();

 

    _imageViewer = vtkImageViewer2::New();

    _imageViewer->SetupInteractor(_interactor);

    _imageViewer->SetInputConnection(_reslice->GetOutputPort());

    _imageViewer->SetSize(400, 400);

    _imageViewer->SetColorWindow(2048);

    _imageViewer->SetColorLevel(1024);

 

    _imageViewer->Render();

 

    _interactor->Initialize();

    // This has to happen here or the new style isn't called.

    _interactor->SetInteractorStyle(style);

}

 

I also tried to create an empty subclass of vtkInteractorStyleImage,
with no overridden methods, and still didn't get the window/level
functionality.  If I don't set a new interactor style the original
interaction works as expected.  If I instantiate a raw
vtkInteractorStyleImage and Set it as the style, it works too.

 

If I subclass vtkCommand for the mouse wheel events and assign them to
the default interactor style, the mouse wheel changes the image slice
while zooming.  I couldn't get the event removed to make it do just one.

 

It also worked in python.

 

Thanks

 

                                -- Scott

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100331/741aedb5/attachment.htm>


More information about the vtkusers mailing list