Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoGetBoundingBoxAction Class Reference

The SoGetBoundingBoxAction class calculates bounding boxes for nodes and subgraphs. More...

#include <Inventor/actions/SoGetBoundingBoxAction.h>

Inheritance diagram for SoGetBoundingBoxAction:
SoAction

Public Types

enum  ResetType { TRANSFORM = 0x1 , BBOX = 0x2 , ALL = TRANSFORM | BBOX }
 
- Public Types inherited from SoAction
enum  AppliedCode { NODE = 0 , PATH = 1 , PATH_LIST = 2 }
 
enum  PathCode { NO_PATH = 0 , IN_PATH = 1 , BELOW_PATH = 2 , OFF_PATH = 3 }
 

Public Member Functions

 SoGetBoundingBoxAction (const SbViewportRegion &vp)
 
virtual ~SoGetBoundingBoxAction (void)
 
void checkResetAfter (void)
 
void checkResetBefore (void)
 
void extendBy (const SbBox3f &box)
 
void extendBy (const SbXfBox3f &box)
 
SbBox3f getBoundingBox (void) const
 
const SbVec3fgetCenter (void) const
 
const SoPathgetResetPath (void) const
 
virtual SoType getTypeId (void) const
 
const SbViewportRegiongetViewportRegion (void) const
 
SoGetBoundingBoxAction::ResetType getWhatReset (void) const
 
SbXfBox3fgetXfBoundingBox (void)
 
SbBool isCenterSet (void) const
 
SbBool isInCameraSpace (void) const
 
SbBool isResetBefore (void) const
 
SbBool isResetPath (void) const
 
void resetCenter (void)
 
void setCenter (const SbVec3f &center, const SbBool transformcenter)
 
void setInCameraSpace (const SbBool flag)
 
void setResetPath (const SoPath *path, const SbBool resetbefore=TRUE, const ResetType what=ALL)
 
void setViewportRegion (const SbViewportRegion &newregion)
 
- Public Member Functions inherited from SoAction
virtual ~SoAction (void)
 
virtual void apply (const SoPathList &pathlist, SbBool obeysrules=FALSE)
 
void apply (SoAction *beingApplied)
 
virtual void apply (SoNode *root)
 
virtual void apply (SoPath *path)
 
const SoPathgetCurPath (void)
 
PathCode getCurPathCode (void) const
 
virtual SoNodegetCurPathTail (void)
 
SoNodegetNodeAppliedTo (void) const
 
const SoPathListgetOriginalPathListAppliedTo (void) const
 
SoPathgetPathAppliedTo (void) const
 
PathCode getPathCode (int &numindices, const int *&indices)
 
const SoPathListgetPathListAppliedTo (void) const
 
SoStategetState (void) const
 
AppliedCode getWhatAppliedTo (void) const
 
SbBool hasTerminated (void) const
 
virtual void invalidateState (void)
 
SbBool isLastPathListAppliedTo (void) const
 
virtual SbBool isOfType (SoType type) const
 
void popCurPath (const PathCode prevpathcode)
 
void popCurPath (void)
 
void popPushCurPath (const int childindex, SoNode *node=NULL)
 
void pushCurPath (const int childindex, SoNode *node=NULL)
 
void pushCurPath (void)
 
void switchToNodeTraversal (SoNode *node)
 
void switchToPathTraversal (SoPath *path)
 
void traverse (SoNode *const node)
 
void usePathCode (int &numindices, const int *&indices)
 

Static Public Member Functions

static void addMethod (const SoType type, SoActionMethod method)
 
static void enableElement (const SoType type, const int stackindex)
 
static SoType getClassTypeId (void)
 
static void initClass (void)
 
- Static Public Member Functions inherited from SoAction
static SoType getClassTypeId (void)
 
static void initClass (void)
 
static void initClasses (void)
 
static void nullAction (SoAction *action, SoNode *node)
 

Protected Member Functions

virtual void beginTraversal (SoNode *node)
 
virtual const SoEnabledElementsListgetEnabledElements (void) const
 
- Protected Member Functions inherited from SoAction
 SoAction (void)
 
virtual void endTraversal (SoNode *node)
 
void setTerminated (const SbBool flag)
 
virtual SbBool shouldCompactPathList (void) const
 

Static Protected Member Functions

static SoActionMethodListgetClassActionMethods (void)
 
static SoEnabledElementsListgetClassEnabledElements (void)
 
- Static Protected Member Functions inherited from SoAction
static SoActionMethodListgetClassActionMethods (void)
 
static SoEnabledElementsListgetClassEnabledElements (void)
 

Additional Inherited Members

- Protected Attributes inherited from SoAction
SoStatestate
 
SoActionMethodListtraversalMethods
 

Detailed Description

The SoGetBoundingBoxAction class calculates bounding boxes for nodes and subgraphs.

If this action is applied to a path or scene graph root, it will calculate the bounding box and the center point of the geometry contained within the scene.

You don't have to apply an SoGetBoundingBoxAction to the root of a scene. When using the action, you will get the bounding box of the node you are applying it to and that node's subtree in the scene graph (if any).

The calculated bounding box will be in the local coordinates of that subtree. If applying it to a scene graph root node, the calculated bounding box will be in global coordinates.

The use of bounding boxes is ubiquitous within the Coin library. It is needed for the correct execution of and for performance enhancements during rendering, picking, caching, culling, etc.

SoSeparator nodes are aggressively caching the results of bounding box calculations, so that they are really only recalculated whenever the scene graph rooted below any SoSeparator node has been modified. This means that applying this action to scene graphs, or parts of scene graphs, should be very quick on successive runs for "static" parts of the scene.

Note that the algorithm used is not guaranteed to always give an exact bounding box: it combines bounding boxes in pairs and extends one of them to contain the other. Since the boxes need not be parallel to the principal axes the new box might not be a perfect fit for the box not extended (its coordinate system has been changed).

Note also that what is returned from getBoundingBox() will be projected so as to be oriented along the principal axes, which can often cause it to become quite a lot larger than what it was before projection. For client code to obtain the best bounding box that Coin can calculate (and which will usually be exact), you need to use the getXfBoundingBox() method after having applied the SoGetBoundingBoxAction.

See also
SoSeparator::boundingBoxCaching

Member Enumeration Documentation

◆ ResetType

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Constructor & Destructor Documentation

◆ SoGetBoundingBoxAction()

SoGetBoundingBoxAction::SoGetBoundingBoxAction ( const SbViewportRegion & vp)

Constructor.

It might seem unnecessary to have to pass in a viewport region argument to calculate bounding boxes, but there is a good reason for this: a few shape nodes needs to know the viewport region to calculate their bounding box – these include SoText2 and SoImage, among others.

What is particular about these shapes is that they are fundamentally 2D shapes, but they are being rendered on the screen "surface" as if they were in a 3D scene. (This is possible because we can match each pixel's depth value against the 3D shapes in the scene.)

To compute an accurate 3D bounding box of a shape rendered in 2D on the screen "surface", you need to "de-project" the screen space area it occupies to a 2D rectangle placed at some depth in the scene. This "de-projecting" operation needs to know about the dimensions of the viewport.

Also, some 3D shapes like for instance SoNurbsSurface, get slightly distorted if there's an SoComplexity node in the scene graph with the SoComplexity::value field set to SCREEN_SPACE. Then it is also necessary to know the viewport region to find out how to accurately calculate the bounding box of those shapes.

You would usually want to pass in a viewport region equal to the layout of the current render area canvas. If you have a viewer or So@Gui@RenderArea available, you can get hold of the viewport region data simply by doing

const SbViewportRegion & vpreg = viewer->getViewportRegion();
The SbList class is a template container class for lists.
Definition SbList.h:70
The SbViewportRegion class is a viewport within a full window.
Definition SbViewportRegion.h:40

(If you don't have a viewer or render area available in your application at the point where you want to get the bounding box, it probably doesn't matter much what you set it to. The accuracy of the bounding box calculation might be slightly wrong versus the actual rendered appearance of the scene, but this is usually not noticeable.)

◆ ~SoGetBoundingBoxAction()

SoGetBoundingBoxAction::~SoGetBoundingBoxAction ( void )
virtual

Destructor.

Member Function Documentation

◆ addMethod()

void SoGetBoundingBoxAction::addMethod ( const SoType type,
SoActionMethod method )
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ beginTraversal()

void SoGetBoundingBoxAction::beginTraversal ( SoNode * node)
protectedvirtual

This virtual method is called from SoAction::apply(), and is the entry point for the actual scene graph traversal.

It can be overridden to initialize the action at traversal start, for specific initializations in the action subclasses inheriting SoAction.

Default method just calls traverse(), which any overridden implementation of the method must do too (or call SoAction::beginTraversal()) to trigger the scene graph traversal.

Reimplemented from SoAction.

◆ checkResetAfter()

void SoGetBoundingBoxAction::checkResetAfter ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Called after node traversal of each node (from SoNode action method).

◆ checkResetBefore()

void SoGetBoundingBoxAction::checkResetBefore ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Called before node traversal of each node (from SoNode action method).

◆ enableElement()

void SoGetBoundingBoxAction::enableElement ( const SoType type,
const int stackindex )
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ extendBy() [1/2]

void SoGetBoundingBoxAction::extendBy ( const SbBox3f & box)

Extend bounding box by the given box. Called from nodes during traversal.

Should usually not be of interest to application programmers, unless you're extending Coin with your own shapenode extension classes.

◆ extendBy() [2/2]

void SoGetBoundingBoxAction::extendBy ( const SbXfBox3f & box)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getBoundingBox()

SbBox3f SoGetBoundingBoxAction::getBoundingBox ( void ) const

Returns the projected bounding box after (or during) traversal.

◆ getCenter()

const SbVec3f & SoGetBoundingBoxAction::getCenter ( void ) const

Returns center point of scene after the action has been applied.

This might differ from the geometric center of the bounding box, as shape nodes may "weight" the center point according to various criteria (i.e. a faceset could for instance weight the center point according to the area within its bounding box where there are more polygons).

◆ getClassActionMethods()

SoActionMethodList * SoGetBoundingBoxAction::getClassActionMethods ( void )
staticprotected

Returns list of action methods for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.

◆ getClassEnabledElements()

SoEnabledElementsList * SoGetBoundingBoxAction::getClassEnabledElements ( void )
staticprotected

Returns list of enabled elements for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.

◆ getClassTypeId()

SoType SoGetBoundingBoxAction::getClassTypeId ( void )
static

This static method returns the SoType object associated with objects of this class.

◆ getEnabledElements()

const SoEnabledElementsList & SoGetBoundingBoxAction::getEnabledElements ( void ) const
protectedvirtual

Returns list of enabled elements.

Reimplemented from SoAction.

◆ getResetPath()

const SoPath * SoGetBoundingBoxAction::getResetPath ( void ) const

Returns the reset path (or NULL).

See also
setResetPath(), isResetPath(), isResetBefore(), getWhatReset()

◆ getTypeId()

SoType SoGetBoundingBoxAction::getTypeId ( void ) const
virtual

Returns the type identification of an object derived from a class inheriting SoAction. This is used for runtime type checking and "downward" casting.

Implements SoAction.

◆ getViewportRegion()

const SbViewportRegion & SoGetBoundingBoxAction::getViewportRegion ( void ) const

Returns the viewport region used by the action instance.

◆ getWhatReset()

SoGetBoundingBoxAction::ResetType SoGetBoundingBoxAction::getWhatReset ( void ) const

Returns what type of reset has been specified for the reset path.

See also
setResetPath(), getResetPath(), isResetPath(), isResetBefore()

◆ getXfBoundingBox()

SbXfBox3f & SoGetBoundingBoxAction::getXfBoundingBox ( void )

Returns the bounding box and transformation matrix to global coordinates. Use after (or during) traversal.

◆ initClass()

void SoGetBoundingBoxAction::initClass ( void )
static

Initializes the runtime type system for this class, and sets up the enabled elements and action method list.

◆ isCenterSet()

SbBool SoGetBoundingBoxAction::isCenterSet ( void ) const

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Query about the center point during traversal.

◆ isInCameraSpace()

SbBool SoGetBoundingBoxAction::isInCameraSpace ( void ) const

Returns whether the bounding box returned is to be in camera space.

◆ isResetBefore()

SbBool SoGetBoundingBoxAction::isResetBefore ( void ) const

Returns whether the bounding box and transformation is reset before or after the tail node of the reset path.

See also
setResetPath(), getResetPath(), isResetPath(), getWhatReset()

◆ isResetPath()

SbBool SoGetBoundingBoxAction::isResetPath ( void ) const

Returns whether a reset path is set or not.

See also
setResetPath(), getResetPath(), isResetBefore(), getWhatReset()

◆ resetCenter()

void SoGetBoundingBoxAction::resetCenter ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Reset the scene center point during traversal.

◆ setCenter()

void SoGetBoundingBoxAction::setCenter ( const SbVec3f & centerarg,
const SbBool transformcenter )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Set a new center point during traversal.

◆ setInCameraSpace()

void SoGetBoundingBoxAction::setInCameraSpace ( const SbBool on)

Sets whether the returned bounding box should be calculated in the coordinate system of the camera space or not.

◆ setResetPath()

void SoGetBoundingBoxAction::setResetPath ( const SoPath * path,
const SbBool resetbefore = TRUE,
const ResetType what = ALL )

Forces the computed bounding box to be reset and the transformation to be identity before or after the tail node of path, depending on the resetbefore argument. NULL can be specified for the path argument to disable this behavior.

See also
getResetPath(), isResetPath(), isResetBefore(), getWhatReset()

◆ setViewportRegion()

void SoGetBoundingBoxAction::setViewportRegion ( const SbViewportRegion & newregion)

Set a new viewport region with this method, if it has changed from the one passed in with the constructor.


The documentation for this class was generated from the following files: