[vtkusers] vtkSelection

David E DeMarle dave.demarle at kitware.com
Thu Nov 13 10:50:47 EST 2008

On 11/13/08, Bryn Lloyd <blloyd at vision.ee.ethz.ch> wrote:
> Hi,
> I am trying to use the selection mechanism. Somethings are a bit unclear to
> me:
> I would like to do something like is implemented in Paraview. In Point
> selection mode I would like to select all points in a rectangular area. In
> cell selection I would like to select all cells.

Do you want to select the points/cells on the near (visible) surface
only? Or those and all the ones that are behind too?

>  1. I have figured out that I need to use the vtkAreaPicker and the
> vtkInteractorStyleRubberBandPick classes.

You might not need to use AreaPicker. It's job is to pick entire
Props, you seem more interested in cells and points on a particular
prop. VisibleCellSelector can determine props on its own if you want
it to, and the FrustumExtractor could be reapplied to all the props in
the scene if you don't end up using AreaPicker to narrow down the

The InteractorStyle is useful for giving the user a rubber band to
draw on the screen with, so you might as well use that part.
Converting that 2D rectangle into a 3D rectangle is only needed if you
are selecting through. The AreaPicker can help with that if you need

>  2. It seems I then need to extract cells AND points with the
> vtkExtractSelectedFrustum object (vtkAreaPicker::GetFrustum()).

That should work, assuming you are interested in selecting through.

>  3. Finally, I would need to either pass the points or the cells, depending
> on the mode. It seems vtkSelection can help at this stage. I still need to
> figure out how.
> Is this approach correct? Is the main importance of vtkSelection to select
> cells or points in a unified generic way? Or is there another use for it?
> The description is quite difficult to understand.

Sorry about the description. Suggestions for improvement are always
welcome. You can also log in and edit the wiki page.

This is how I describe it:

vtkSelection is a way of generically identifying a subset of something else.
vtkExtractSelection is a filter that takes in a vtkDataSet and a
vtkSelection and produces the a new vtkDataSet containing only the
particular parts of the original dataset that correspond to the

Selecting through is easy, just make up a vtkSelection that knows the
frustum in 3D space you are interested in, and run it and the input
dataset through the extraction filter.

Selecting on is similar, you make up a vtkSelection that contains a
list of the cells or points you want taken out, and then run it and
the dataset through the extraction filter. The hard part about
selecting on is making up the list. That is where the
vtkVisibleCellSelector (and Utkarsh's new and improved class) helps.
They create the list by running the RenderWindow through a couple of
specialized render passes in the back buffer, and using the rendered
pixel colors to figure out that cells/points were drawn inside the
"selected" 2D rectangle on the window.

Take a look at TestExtraction first to investigate what Selections and
Extraction are and how to use them,

Then take a look at TestAreaSelections to see how to use them to grab
things that the user identifies behind the rubber band.

David E DeMarle
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x109

More information about the vtkusers mailing list