Difference between revisions of "Selection Implementation in VTK and ParaView III"

From KitwarePublic
Jump to: navigation, search
 
(Test case and example)
Line 49: Line 49:
  
 
The new VTK level ctest located at '''VTK/Rendering/Testing/Cxx/TestAreaSelections.cxx''' demonstrates the use of both the vtkFrustumExtractor and the vtkVisibleCellSelector. In the test two datasets are drawn, one a vtkStructuredGrid, the other a vtkPolyData. When a rubber band selection happens, the portions of the two datasets that lie behind the screen rectangle are extracted and reproduced offset to the right (+X) of the original input datasets.
 
The new VTK level ctest located at '''VTK/Rendering/Testing/Cxx/TestAreaSelections.cxx''' demonstrates the use of both the vtkFrustumExtractor and the vtkVisibleCellSelector. In the test two datasets are drawn, one a vtkStructuredGrid, the other a vtkPolyData. When a rubber band selection happens, the portions of the two datasets that lie behind the screen rectangle are extracted and reproduced offset to the right (+X) of the original input datasets.
 +
 +
[[Image:TestAreaSelections.png]]

Revision as of 08:32, 18 August 2006

Overview

We have added rubber band selection to VTK. This new feature of VTK allows end users to draw a rubber band selection rectangle with the mouse and obtain the portion of the visualization data that lies behind the selected area of the screen. Three different algorithms have been implemented that allow the application developer to support three different types of selection. The AreaPicker allows selection of objects at the vtkProp level. The selection is made using software bounding box tests with an additional optional pass in rendering hardware (aka OpenGL selection). The next two selection algorithms select primarily at the vtkCell level. The frustum extraction algorithm (aka Pure Geometry) allows the selection of 3D cells behind the selection rectangle. The color buffer selection algorithm (aka G Buffer) allows the selection of only the front or visible 2D polygonal cells.

New classes added to VTK

vtkInteractorStyleRubberBandPick - This new interactor style draws a selection rectangle on the screen. It acts like the TrackballCamera interactor style, until the 'r' key is pressed. Once this happens, and until 'r' is pressed again, it creates a rubber band with each left button drag operation. On each drag release, it passes the screen start and end positions to a vtkPicker. The pre-existing vtkPicker classes get only the center of the selection area to maintain backward compatibility.

vtkAreaPicker - This new vtkPicker class takes a screen rectangle and does a software bounding box intersection test with the pickable vtkProps in the scene. Internally the vtkAreaPicker uses the new vtkFrustumExtractor test to do a fast intersection test on each vtkProp's boundaries.

vtkRenderedAreaPicker - This is a child of the vtkAreaPicker class. It is more selective than its parent because in addition to the bounding box test above it also determines if the vtkProp has some visible contents within the selection area. vtkRenderedAreaPicker, like vtkPropPicker does uses OpenGL's GL_SELECT mode, aka hardware picking.

vtkFrustumExtractor - This vtkDataSetAlgorithm runs a software frustum intersection algorithm to determine which cells of its input vtkDataSet lie within a frustum defined by a rectangular region of the screen.

vtkFrustumExtractor contains two intersection algorithms, the first produces a conservative estimate of insidedness which can be incorrect with a thin selection area, the second algorithm is inclusive producing all cells that at least partially intersect the frustum. The ExactTest flag controls which is run. With ExactTest off, each point is simply evaluated against the six plane equations that define the frustum. Cells are inside if all of their points are inside. If the ExactTest flag is on, a fast cell frustum intersection algorithm is used instead (see Ned Greene, Graphics Gems IV, 1994, p 74-82). The algorithm can quickly accept or reject most cells by testing only the two points that are nearest to and farthest from each of the six plane equations. Only those few cells that are neither trivially accepted nor rejected are then run though a full polygon clipping algorithm.

The PassThrough flag controls whether the output of the algorithm is a shallow copy of the input vtkDataSet with two new "vtkInsidedness" field data arrays, or is an entirely new vtkUnstructuredGrid output that contains only the inside cells and points.

vtkVisibleCellSelector - Rather than operating in world space, this class operates in screen space using the rendering hardware. This class operates by putting vtkRenderer into new selection modes and telling it to render. When the render happens, each visible cell or data set is rendered with the color of each cell chosen to encode a unique identifier. After one or more selection render passes, the contents of the color buffer are read back, and each pixel is examined to identify which cell was frontmost in the scene behind it. Because color buffer resolution in VTK is limited to 24 bits, up to five passes may be required to obtain a complete result. Up to three passes are used to find the visible cells within the rendered datasets. One pass selects between actors, and another pass is used in parallel composite rendering to determine which processor is responsible for each visible cell.

vtkIdentColoredPainter - This class is a new vtkPainter that the vtkRender uses to render each cell in the color coded mode. This Painter temporarily turns off lighting and shading and sets the background to black to do its job. In selection mode, vtkRendered tries to swap in a vtkIdentColoredPainter for each prop. If the Prop is not rendering polygons or is not pickable, the prop is ignored (not drawn.)

Comparison of vtkFrustumExtractor and vtkVisibleCellSelector

vtkFrustumExtractor.

Advantages:

  • Exactness - no cell that partially covers the selection area can be missed.
  • Ability to pick through the front layer of cells.
  • Data type insensitive - can operate on and produce and vtkDataSet type.

Disadvantages:

  • Slow: it must iterate over (at least) every cell and examine it in the CPU.
  • Can not pick only the front layer of cells.

vtkVisibleCellSelector.

Advantages:

  • Fast - uses the rendering hardware. Selection time is roughly 1 to 5x render time.
  • Picks front layer of polygons only.

Disadvantages:

  • Will omit cells when sub pixel sized polygons are drawn.
  • Like compositing it will not work properly when GPU antialising is on.
  • Limited to operating on opaque polygonal data only.
  • Can not pick cells behind the front shell.

The last two disadvantages are mitigated by the new passthrough feature of vtkDataSetSurfaceFilter and its kin. This preserves the input cell id of all of cells that produce surface polygons in the output. Using this feature, one can recover the front layer of any cell type that constitutes a dataset.

Test case and example

The new VTK level ctest located at VTK/Rendering/Testing/Cxx/TestAreaSelections.cxx demonstrates the use of both the vtkFrustumExtractor and the vtkVisibleCellSelector. In the test two datasets are drawn, one a vtkStructuredGrid, the other a vtkPolyData. When a rubber band selection happens, the portions of the two datasets that lie behind the screen rectangle are extracted and reproduced offset to the right (+X) of the original input datasets.

TestAreaSelections.png