[vtkusers] point picking problem.

Obada Mahdi omahdi at gmx.de
Mon Nov 27 17:46:42 EST 2006


Hi Peter!

On 11/24/06, Peter  Spring <meancity at gmail.com> wrote:
> the things i want to do is picking up some point in a medical iso
> surface, display is generated from CT DICOM data.

> however i also want to put an actual point on the surface, so what
> shall i do in this case?  do i need use vtk point widget (maybe some
> example code)?

That probably depends on whether or not you want to further interact
with that point once it is set.  If you just want to mark its
position, it would be enough to place an actor at the picked position,
using e.g. a sphere as geometrical representation.  For a small
picking example, have a look at
Examples/Annotation/Tcl/annotatePick.tcl
in the VTK source tree.  When pressing 'p' it will display a text
actor showing the picked position.  You can easily replace that code
(in the "annotatePick" handler) to put a sphere at the picked position
instead:

# Somewhere in the initialization code:
# Create a polydata source for point markers
vtkSphereSource annotationSphereSource
    annotationSphereSource SetRadius 0.01
# ...
# Within the annotatePick handler:
# Place a red sphere at the picked world coordinates.
	set sphereMapper [vtkPolyDataMapper New]
	$sphereMapper SetInputConnection [annotationSphereSource GetOutputPort]
	set sphereActor [vtkActor New]
	set sphereProperty [$sphereActor GetProperty]
	$sphereActor SetMapper $sphereMapper
	$sphereProperty SetColor 1.0 0.0 0.0
	$sphereActor SetPosition $xp $yp $zp
	ren1 AddActor $sphereActor

(You probably want to keep a reference to those sphere actors and
mappers in a list somewhere.)

> and also,
> i hope some one can explain to me a bit about the difference between
> cell picker and point picker.

Both cell and point pickers shoot a ray into the scene and try to find
intersections with cell geometry and points (within a certain
tolerance), respectively.  They are specialized versions of vtkPicker,
which means that they iterate over all props in a scene and check for
intersection with their bounding boxes.  vtkCellPicker and
vtkPointPicker then go a step further and, for every prop hit by the
ray, try to find the closest cell or point that lies within a certain
tolerance of the ray, which is then reported.

The difference between them is just the type of geometry that is
picked (cells or points), and consequently a point picker can only
return pick coordinates that correspond to an existing point position
in a data set, whereas a cell picker can calculate an exact
intersection point and return it in both world coordinates and
parametric coordinates, as well as the intersected cell (their parent
class, vtkPicker, just returns the center of the picked actor's
bounding box).

These pickers are implemented in software and iterate over all cells
or points, respectively, of any prop that is hit by the ray, which can
make picking quite slow for large data sets.  They are, however, a bit
more accurate than hardware pickers, which are limited by Z-buffer
precision and also cannot handle translucent geometry.

For picking points on an isosurface, it is probably enough to just use
a vtkPropPicker to fetch the world coordinates of a picked point [1].
It is still possible then to determine cell or point IDs if needed, by
using a locator (vtkCellLocator); intersection tests via
IntersectWithLine() or FindClosestPoint() also perform better than the
algorithm used by software pickers.  Note, however, that a
vtkWorldPointPicker cannot pick on translucent surfaces, and there is
no direct way of telling whether the pick hit a surface or not.

Some of these properties are easily verified by replacing
"vtkCellPicker" with "vtkPointPicker" or "vtkPropPicker" in the
modified "annotatePick.tcl" example mentioned above.  Note, for
example, how the point picker always returns positions that correspond
to points in the input data set (press 'w' for wireframe), or how
vtkCellPicker succeeds in picking on a translucent sphere, but
vtkPropPicker does not (try "[sphereActor GetProperty] SetOpacity
0.8").


HTH,

Obada

----
[1] Actually using a vtkWorldPointPicker would be enough for this, but
pickers used in conjunction with a renderWindowInteractor need to be
able to pick props.



More information about the vtkusers mailing list