[vtkusers] Select 2D image region in QVTKWidget

Khue Le huudienkhue.le at gmail.com
Wed Mar 14 07:01:45 EDT 2012


Hello everybody,

I am writing a program using ImageViewer2 to display 2D images, in which I
have to be able to select regions (by clicking and dragging the left mouse
button). The image viewer should be embedded in a QVTKWidget.

The problem is that I cannot get the both (displaying the image and
selecting regions) working at the same time, but only one of them. Let me
detail.

1. If I use  ImageViewer2:
        vtkSmartPointer<vtkInteractorStyleRubberBand2D> style
= vtkSmartPointer<vtkInteractorStyleRubberBand2D>::New();
        style->AddObserver ( vtkCommand::SelectionChangedEvent,
selectionChangedCallback );

        vtkSmartPointer<vtkImageViewer2> imageViewer
= vtkSmartPointer<vtkImageViewer2>::New();
        vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor
= vtkSmartPointer<vtkRenderWindowInteractor>::New();

        renderWindowInteractor->SetInteractorStyle (style);
        imageViewer->SetInput(vtkImage);
imageViewer->SetupInteractor(renderWindowInteractor);

vtkRenderer* renderer = imageViewer->GetRenderer();
 renderer->ResetCamera();
imageViewer->SetSize(widget->geometry().width(),widget->geometry().height());
 imageViewer->SetRenderWindow(widget->GetRenderWindow());
imageViewer->Render();
        renderWindowInteractor->SetRenderWindow ( renderWindow );
        renderWindowInteractor->Initialize();

then the program can display the image, but it does not allow selecting
regions. I think what's wrong here is that the interactor style did not
change (am I right?). So to get the event handler working, we have to *change
the interactor style of the image viewer*. Is there any way to do it?

2. If I don't use ImageViewer2:

                // Create an actor
                vtkSmartPointer<vtkImageActor> actor
= vtkSmartPointer<vtkImageActor>::New();
                actor->SetInput( vtkImage);

                // Setup renderer
                vtkSmartPointer<vtkRenderer> renderer
= vtkSmartPointer<vtkRenderer>::New();
                renderer->AddActor ( actor );
                renderer->ResetCamera();

                vtkSmartPointer<vtkRenderWindow>
renderWindow=widget->GetRenderWindow();
                renderWindow->AddRenderer(renderer);
                vtkSmartPointer<vtkInteractorStyleRubberBand2D> style
= vtkSmartPointer<vtkInteractorStyleRubberBand2D>::New();
                style->AddObserver ( vtkCommand::SelectionChangedEvent,
selectionChangedCallback );

                // Setup render window interactor
                vtkSmartPointer<vtkRenderWindowInteractor>
renderWindowInteractor =
                vtkSmartPointer<vtkRenderWindowInteractor>::New();
                renderWindowInteractor->SetInteractorStyle ( style );
                renderWindowInteractor->SetRenderWindow ( renderWindow );
                renderWindowInteractor->Initialize();
                renderWindowInteractor->Start();

then I can very well select regions in the widget, but the image does not
show up.


I would really appreciate if someone can help.

Thank you for reading.
_____________________

*Huu Dien Khue LE*
- Automated Systems, Instrumentation and Computer Engineering student
  at l'Ecole Nationale d'Ingénieurs du Val de Loire (ENIVL), Blois, France;
- Master of Computer Science student at l'Ecole Polytechnique de
l'Université de Tours, France.
- Home: 10 rue Ronceraie, 41000 Blois, France
- Phone: +33 (0)9 82 50 90 09
- Mobile: +33 (0)6 66 67 84 70
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120314/ddc1cc0e/attachment.htm>


More information about the vtkusers mailing list