[vtkusers] Re: Picking points from multiple surfaces.

安 继业 an_jiye at hotmail.com
Tue Feb 17 21:11:38 EST 2004


Hi.

I have understood why the picking results are not as expected. Here are the 
explanations.

There is a section in the vtk textbook introducing the picking functions of 
vtk. Unfortunately, I only have the 2nd edition for vtk 2.0. But I think 
the principle should be the same. Here I quote some contents from it.

"The Visualization Toolkit provides four classes to perform actor, point, 
cell and world point picking. These are the classes vtkPicker, 
vtkPointPicker, vtkCellPicker and vtkWorldPointPicker. These pickers vary 
in speed and functionality as described in the following."

"The object vtkPicker intersects a ray defined from camera position to a 
screen (i.e., pixel coordinate) against the bounding box of all pickable 
and nontransparent actors. (An actor is pickable if its Pickable instance 
variable is true.) The result of the vtkPicker pick operation is to return 
a list of the actors whose bounding box is intersected. The actor closest 
to the camera position is also returned."

"The object vtkPointPicker intersects the ray against the points defining 
each actor, and returns the point coordinate closest to the camera 
position, as well as the actor that the point belongs to. Since screen 
resolution prevents precise selection of a point, a tolerance around the 
ray must be specified. The tolerance is expressed as a fraction of the 
rendering window size. (Rendering window size is measured across the window 
diagonal) Points must lie within this tolerance to be picked."

==========================================================================================

According to the above introduction to vtkPointPicker, my problems can be 
easily explained.

First, the returning points y coordinate is not necessarily one of the 1, 
20, 39 and 49. This is because I set the camera position to (0, 0, 0). So 
when I perform a picking, the ray is from origin to the cursor position. It 
doesn't run parallel with the y-axis.

Second, I will get one or two points as a result. This is because the 
vtkPointPicker will return both the point coordinate closest to the camera 
position, and the actor that the point belongs to. When these two points 
are actually the same, one point is returned.

Third, the points from the back surface are picked sometimes. This is 
because the vtkPointPicker only pick the points defining each actor. So the 
ray will traverse all the surfaces, no matter it is front or back. If it 
doesn't intersect any points on the front surface, a back surface point 
will be returned of course. And do not forget that the ray comes from the 
origin (0, 0, 0).

Combining the second and third situation, you will probably get two points. 
And neither of them is on the front surface.
==========================================================================================


Let's go on with other vtk pickers.

"The object vtkCellPicker intersects the ray with the cells defining each 
actor, and returns the point of intersection, as well as the actor that the 
cell belongs to. If you are trying to select a unique actor, vtkCellPicker 
is the object to use because it performs surface (or cell) intersection. 
Picking actors using vtkPicker can yield undesirable results because of the 
overlap of bounding boxes; the same is true of vtkPointPicker because of 
tolerance problems. Unfortunately, vtkCellPicker is the slowest object of 
the three because of greater computational requirements."

==========================================================================================

So I decided to use vtkCellPicker for my picking application. Since the 
camera affects the picking results directly. Remember to manipulate it 
carefully. In my application, I set its position to ahead of the screen, 
and at the middle of the z-axis, (32, -1, 46.5). Also I set the focal point 
to (32, 63, 46.5), which lies in the center of the back most surfaces in my 
former example. It works well for picking if user does not change the 
camera or actor positions by vtkRenderWindowInteractor. But if this 
happens, I still don't know how to deal with it.
==========================================================================================


For completeness, please allow me to introduce vtkWorldPointPicker at last.

"The calss vtkWorldPointPicker returns the (x,y,z) coordinate value of a 
pick in the rendering window. To determine this information, it combines 
the display (x,y) values with the z-buffer depth values. Of all the pickers 
it is the fastest, but it cannot determine the actual cell, point or actor 
that is selected. (Note: on some system z-buffer operations are inoperative 
and this object will not function properly)"


Hope this will help some newbie who are performing picking in vtk, just 
like me.

Best Regards,
Jiye An

_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger:  http://messenger.msn.com/cn  




More information about the vtkusers mailing list