[vtkusers] vtkImageViewer2 picking

Mark Wyszomierski markww at gmail.com
Mon May 2 09:56:54 EDT 2005


Hi Nik,

You just want to pick the actual pixel right? All I did was create a
vtkPointPicker, and then set it as the picker of my
vtkWin32RenderWindowInteractor:

vtkWin32RenderWindowInteractor *iren = vtkWin32RenderWindowInteractor::New();
iren->SetPicker(picker);

Then I added a simple mouse move observer to the ImageViewer2 object
itself. In the handler for the mouse move, I pass a pointer to the
picker and the ImageViewer2 object, and manually call a pick everytime
the mouse move event is triggered:

virtual void execute(...) {

    double *ptActual, *ptMapped;

    // picker and viewer are pointers to the actual picker/viewer objects.
    picker->Pick(viewer->GetInteractor()->GetEventPosition()[0], 
                        viewer->GetInteractor()->GetEventPosition()[1], 
                        viewer->GetZSlice(), 
                        viewer->GetRenderer());
    picker->GetSelectionPoint(ptActual);
    picker->GetMapperPosition(ptMapped);
}

Then ptActual will be filled with the window coordinates of the mouse,
and ptMapped will be filled with the image coordinates of the mouse,
taking into account zooming etc. It works really well.

Mark






On 5/2/05, nikolaus heger <nikolaus.heger at gmail.com> wrote:
> How do i pick points on a vtkImageViewer2?
> 
> I added a vtkPointPicker, but with no success. It never picks anything. So far,
> the problem seems to be that there are no actors in the renderer...
> 
> # this code snippet (Python):
>         self.imageViewer2 = vtk.vtkImageViewer2()
>         self.imageViewer2.SetInput(reader.GetOutput())
>         print "DEBUG ", self.imageViewer2.GetRenderer().GetActors()
> 
> prints out this:
> DEBUG  vtkActorCollection (068C55A0)
>   Debug: Off
>   Modified Time: 894
>   Reference Count: 3
>   Registered Events: (none)
>   Number Of Items: 0
> 
> I don't understand why there are 0 actors, but it would certainly explain that
> the picker doesn't pick anything. I also check the same thing further down the
> road, e.g. after rendering. Always the same problem: The renderer contains no
> actors.
> At the same time, the image seems to render just fine, and i can zoom and pan!
> 
> Please help if you have any ideas! Thanks!
> 
>        Nik
> 
> Mark Wyszomierski wrote:
> > Hi,
> >
> > I am displaying a 2D image using vtkImageViewer2. I want to set a
> > pixel that the user clicks on to a certain color. What function can I
> > use to get the coordinates of the pixel the user clicked on.
> >
> > Secondly, after I know the coordinates, should I just set the voxel in
> > the underlying volume to my color, then call viewer2->Render() to
> > update the image. I am trying to implement some fast drawing and am
> > worried that calling Render() after each time I set a voxel color may
> > be too slow? Thanks for any ideas.
> >
> > Mark
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
> 
>



More information about the vtkusers mailing list