Computes bounding box of a scene. More...
#include <Inventor/actions/SoGetBoundingBoxAction.h>
Public Types | |
enum | ResetType { TRANSFORM = 0x01, BBOX = 0x02, ALL = 0x03 } |
Public Member Functions | |
virtual SoType | getTypeId () const |
SoGetBoundingBoxAction (const SbViewportRegion &viewportRegion) | |
void | setViewportRegion (const SbViewportRegion &newRegion) |
const SbViewportRegion & | getViewportRegion () const |
SbBox3f | getBoundingBox () const |
SbXfBox3f & | getXfBoundingBox () |
const SbVec3f & | getCenter () const |
void | setInCameraSpace (SbBool flag) |
SbBool | isInCameraSpace () const |
void | setResetPath (const SoPath *path, SbBool resetBefore=TRUE, ResetType what=ALL) |
const SoPath * | getResetPath () const |
SbBool | isResetPath () const |
SbBool | isResetBefore () const |
SoGetBoundingBoxAction::ResetType | getWhatReset () const |
Static Public Member Functions | |
static SoType | getClassTypeId () |
Computes bounding box of a scene.
This class is used to compute a 3D bounding box enclosing objects defined by a scene graph. The box is a rectangular prism. The action also computes the center point, which is defined differently for different objects. (For example, the center of an SoFaceSet is the average of its vertices' coordinates.) For a group, the center point is defined as the average of the centers of all shapes in it.
Each bounding box is calculated as an SbXfBox3f, where the transformation matrix is defined so that the bounding box can be stored in the object space of the SoShape. When two bounding boxes are combined by a group node, the combination is performed so as to produce the smaller object-space box. Note that this does not necessarily yield the smallest world-space-aligned box, especially in the case of few SoShape nodes. The application can accomodate this by using SoBBox nodes.
The result of the calculation by the action can be returned as an SbXfBox3f or as a world-space-aligned SbBox3f.
To calculate the bounding box of a subgraph bounded by two paths, specify the left edge of the subgraph with setResetPath(), and apply the action to the path that defines the right edge of the subgraph. The accumulated bounding box and transformation will be reset when the tail of the reset path is traversed.
If the subgraph being traversed does not contain any shapes, the returned bounding box will be empty (that is, SbBox3f::isEmpty() will return TRUE).
The SoBBox node can be used to specify the bounding box for a shape or portion of the scene graph. This is useful, for example, to avoid the cost of computing the bounding box of a large (or frequently changing) geometry. The SoBBox node can also be used to specify that a shape or portion of the scene graph should not be included in the bounding box calculation. This is useful, for example, to avoid considering screen aligned "annotation" graphics like legends.
Bounding boxes are used internally by Open Inventor to optimize rendering, picking, culling and other operations. For example, the standard viewer classes apply an SoGetBoundingBoxAction to the scene graph when automatic adjustment of the near and far clipping planes is enabled (which is the default).
Bounding boxes are cached by some grouping nodes, primarily SoSeparator. When this action is applied to a scene graph, it will use the cached bounding box whenever possible. So querying the bounding box of a (relatively) static scene graph is normally very fast. Open Inventor automatically detects when bounding caches become invalid and they are re-computed the next time an SoGetBoundingBoxAction is applied.
NOTES:
Sets: SoViewportRegionElement
// Get bounding box using current viewport on screen SoGetBoundingBoxAction gba( viewer->getViewportRegion() ); gba.apply( root ); SbBox3f bbox = gba.getBoundingBox();
SbBox3f, SbXfBox3f, SoGetMatrixAction, SoBBox
SoGetBoundingBoxAction::SoGetBoundingBoxAction | ( | const SbViewportRegion & | viewportRegion | ) |
Constructor.
Even though the bounding box computation may not involve a window per se, some nodes need the size of the viewport to determine their size in 3D coordinates. For example the size of an SoText2 is a fixed value in device coordinates, but the corresponding size in 3D depends on the current camera.
Usually it is convenient to get the actual viewport region from the viewer as shown in the example above. However if the scene graph does not contain any viewport dependent nodes then any values can be used.
SbBox3f SoGetBoundingBoxAction::getBoundingBox | ( | ) | const |
Returns computed bounding box in world space.
const SbVec3f& SoGetBoundingBoxAction::getCenter | ( | ) | const |
Returns computed center point in world space.
static SoType SoGetBoundingBoxAction::getClassTypeId | ( | ) | [static] |
Returns the type identifier for this class.
Reimplemented from SoAction.
const SoPath* SoGetBoundingBoxAction::getResetPath | ( | ) | const |
Returns the current reset path, or NULL.
virtual SoType SoGetBoundingBoxAction::getTypeId | ( | ) | const [virtual] |
Returns the type identifier for this specific instance.
Implements SoTypedObject.
const SbViewportRegion& SoGetBoundingBoxAction::getViewportRegion | ( | ) | const |
Returns current viewport region to use for action.
SoGetBoundingBoxAction::ResetType SoGetBoundingBoxAction::getWhatReset | ( | ) | const |
Returns what flags were specified to be reset for the reset path.
SbXfBox3f& SoGetBoundingBoxAction::getXfBoundingBox | ( | ) |
Returns computed bounding box before transformation into world space.
SbBool SoGetBoundingBoxAction::isInCameraSpace | ( | ) | const |
Returns camera space flag.
SbBool SoGetBoundingBoxAction::isResetBefore | ( | ) | const |
Returns TRUE if the resetBefore flag was specified for the reset path.
SbBool SoGetBoundingBoxAction::isResetPath | ( | ) | const |
Returns TRUE if the current reset path is not NULL.
void SoGetBoundingBoxAction::setInCameraSpace | ( | SbBool | flag | ) |
Set this flag to TRUE if you want the returned bounding box to be in the space of whatever camera is in the graph.
Camera space is defined to have the viewpoint at the origin, with the direction of view along the negative z axis. This space can be used to determine distances of objects from the camera.
void SoGetBoundingBoxAction::setResetPath | ( | const SoPath * | path, | |
SbBool | resetBefore = TRUE , |
|||
ResetType | what = ALL | |||
) |
If a non-NULL path is specified, the action will reset the computed bounding box to be empty and/or the current transformation to identity.
The resetBefore flag indicates whether to perform the reset before or after the tail node of the path is traversed.
void SoGetBoundingBoxAction::setViewportRegion | ( | const SbViewportRegion & | newRegion | ) |
Sets current viewport region to use for action.