[vtkusers] help on how to get the pixel position.

Obada Mahdi omahdi at gmx.de
Tue Jan 17 17:50:30 EST 2006


Hi Dongquing,

I am not sure what exactly you are looking for, so I am just going to
blurt out whatever I know about "pickers" in vtk.
@all: Please correct me if I am providing erroneous information.

On Tue, 17 Jan 2006, dqchen wrote:
>   I am not very familar with VTK Programming. Now I want to get the
>   position of any pixel on which I click using mouse. I think that it
>   should just be some built-in commands?

If I got your question right, you want to determine world coordinates of
a spot pointed to by the mouse.  Retrieving such information from a
rendered scene in VTK is done by a "picker".  There are several types of
pickers available in VTK; which one to choose depends on what has to be
picked.  For example, there are

- vtkWorldPointPicker
  Determines (x, y, z) coordinates in world space.  This picker uses
  hardware acceleration on most (?) systems, exploiting depth buffer
  information.
    This is most probably what you want.  However, there is no control
  over which objects are included in the picking process and which are
  not; e.g., if for some reason you have a translucent object in a scene
  and need to pick "through" it (like the patient's skin in a 3D
  reconstruction of medical image data), you would have to use a
  software picker like the one below.
- vtkCellPicker
  Also determines cell IDs.  This picker sends a ray from the camera
  position through a point on the viewport, given by display
  coordinates, and intersects this ray with geometry in the scene.  Like
  its superclass, vtkPicker, the vtkCellPicker actually determines a
  list of geometric objects which intersect with the ray (or are close
  enough, see the SetTolerance() method).  The GetCellId() method just
  returns the ID of the intersected cell of the closest actor.
    Note that vtkPicker and its subclasses only consider for
  intersection the geometry of actors that have been marked "pickable",
  which is not the default; see the SetPickable(int) method of vtkProp
  and descendants.
    Note also that this picker can be quite slow, especially if complex
  geometry is involved.

You would use a picker like this:
1. Get mouse coordinates using the API that connects to your windowing
   system.
2. Maybe adjust the tolerance for vtkPicker-compatible pickers.
3. Call the picker's Pick(x, y, z, renderer) method , with "x" and "y"
   being the mouse coordinates relative to the render window, "z"
   usually set to 0 and "renderer" being the corresponding renderer.

Example:
{
	vtkWorldPointPicker* picker = vtkWorldPointPicker::New();
	double pickCoords[3];

	...
	picker->Pick(mouseX, mouseY, 0.0, myRenderer);
	picker->GetPickPosition(pickCoords);
	...
}

You might want to refer to the class documentation for a more detailed
description of available methods at
http://www.vtk.org/doc/nightly/html/classvtkAbstractPropPicker.html
and related pages.


Regards

Obada



More information about the vtkusers mailing list