Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SoDualSceneCollider Class Reference

VSG extension Class to check for collisions between two scenes. More...

#include <Inventor/collision/SoDualSceneCollider.h>

Public Member Functions

 SoDualSceneCollider ()
 Default constructor.
 
virtual ~SoDualSceneCollider ()
 
void setMovingScene (SoPath *object, int max_triangles_per_leaf=0)
 Specifies the scene that will be moved or transformed.
 
void setStaticScene (SoPath *scene, int max_triangles_per_leaf=0)
 Specifies the scene the moving scene is interacting with.
 
void activate (SoTransform *transform)
 Specifies the transformation that will be watched.
 
virtual SbBool checkCollision () const
 Checks if the current moving scene collides with the static scene.
 
virtual SbBool searchNextIntersection () const
 Method called by checkCollision() for each pair of intersecting triangles found.
 
void setMinEdgeLength (double minEdgeLength)
 Specifies the minimum length of a triangle edge.
 
double getMinEdgeLength () const
 Returns the minimum length of a triangle edge.
 
void enableMultiThread (bool enable)
 Use multiple threads to compute intersections.
 
bool isMultiThreadEnabled () const
 Returns true if multithreaded computation is enabled.
 

Protected Member Functions

const SoPathgetCollidingStaticPath () const
 Returns the path in the static scene of the current colliding shape.
 
const SoPathgetCollidingMovingPath () const
 Returns the path in the moving scene of the current colliding shape.
 
void getCollidingStaticTriangle (SbVec3f &v0, SbVec3f &v1, SbVec3f &v2) const
 Returns the coordinates of the current colliding triangle in the static scene.
 
void getCollidingMovingTriangle (SbVec3f &v0, SbVec3f &v1, SbVec3f &v2) const
 Returns the coordinates of the current colliding triangle in the moving scene.
 
void getCommonPoints (SbVec3f &p0, SbVec3f &p1) const
 Returns the coordinates of the two common points of the current pair of intersecting triangles.
 
virtual SbBool isSensitiveStaticObject (const SoPath *object_path) const
 Tells if an object of the static scene is sensitive to collision detection or not.
 
virtual SbBool isSensitiveMovingObject (const SoPath *object_path) const
 Tells if an object of the moving scene is sensitive to collision detection or not.
 
virtual void staticTriangleListBuilt (int num_triangles) const
 Method called by setStaticScene() when the list of triangles in the static scene is built.
 
virtual void staticLeafBuilt (int num_triangles) const
 Method called by setStaticScene() when a new leaf is stored in the static tree.
 
virtual void movingTriangleListBuilt (int num_triangles) const
 Method called by setMovingScene() when the list of triangles in the moving scene is built.
 
virtual void movingLeafBuilt (int num_triangles) const
 Method called by setMovingScene() when a new leaf is stored in the moving tree.
 

Detailed Description

VSG extension Class to check for collisions between two scenes.

The SoDualSceneCollider class manages collisions, i.e., it checks the intersection of one scene with a second scene. Both scenes are tessellated into a list of triangles by using an SoCallbackAction and its addTriangleCallback method. An intersection occurs when a triangle of the first scene intersects a triangle of the second scene. For each pair of intersecting triangles some response methods are called. These response methods can be overridden, for instance,

  • to highlight the intersecting shape
  • to highlight the intersecting pair of triangles
  • to compute points common to the two scenes
  • to count the number of intersecting pairs of triangles
  • etc.

The SoDualSceneCollider references a static scene and a moving scene (with two SoPaths) and a transformation (with an SoTransform). The user scene graph must be organized such that the transformation will affect the moving scene during traversal. The static scene is specified by the method setStaticScene and the moving scene by the method setMovingScene.

The SoDualSceneCollider references a scene by storing its triangle list (see SoCallbackAction) and by building a database as a tree. This database spatially organizes the list of triangles in order to optimize the number of triangle intersection tests. Note that the SoDualSceneCollider does not monitor the scene graph. Any modifications to the Open Inventor nodes in the static scene or the moving scene are not reflected in the internal tree database unless setMovingScene or setStaticScene are called again by the application.

However SoDualSceneCollider watches for any modification to the given transformation. Each time the transformation changes, an intersection test is done between the two scenes by automatically calling checkCollision(). This method searches for pairs of intersecting triangles in an optimal way. For each pair of intersecting triangles found, the Boolean method searchNextIntersection() is called. By default this method returns FALSE, but in most cases, it will be overridden. If it returns FALSE, the process of searching intersecting triangles is stopped and checkCollision() returns TRUE. If searchNextIntersection returns TRUE, the process continues to search other pairs of intersecting triangles. If searchNextIntersection always returns TRUE, all pairs of intersecting triangles will be found. If the two scenes do not collide, searchNextIntersection is never called and checkCollision returns FALSE. When searchNextIntersection is overridden, some methods can be called to get information about the current pair of intersecting triangles:
getCollidingStaticPath(), getCollidingStaticTriangle(), getCollidingMovingPath(), getCollidingMovingTriangle(), and getCommonPoints().

In the static or moving scene, each internal node of the tree contains a bounding box while the leaf nodes contain triangles of the tessellation. The maximum number of triangles per leaf (max_triangles_per_leaf) is given as the second argument of the method setMovingScene and setStaticScene. Note how max_triangles_per_leaf affects the computation:

  • the smaller max_triangles_per_leaf, the deeper the tree.
  • the smaller max_triangles_per_leaf, the more memory the tree needs
  • the smaller max_triangles_per_leaf, the quicker the checkCollision() function becomes
  • the smaller max_triangles_per_leaf, the slower the setMovingScene/setStaticScene() functions become

A compromise must be chosen between the initial time to build the tree (setMovingScene/setStaticScene) and the time to check the collisions.

Depending on the total number of triangles and the value of max_triangles_per_leaf, the execution of setMovingScene/setStaticScene can take several seconds. The methods staticTriangleListBuilt/movingTriangleListBuilt and staticLeafBuilt/movingLeafBuilt have been defined and can be overridden to implement, for instance, a progress bar. However, note that the methods staticLeafBuilt/movingLeafBuilt are not called in linear time.

Collision checking will be faster using multiple threads. See the enableMultiThread() method.

Definition at line 112 of file SoDualSceneCollider.h.

Constructor & Destructor Documentation

◆ SoDualSceneCollider()

SoDualSceneCollider::SoDualSceneCollider ( )

Default constructor.

◆ ~SoDualSceneCollider()

virtual SoDualSceneCollider::~SoDualSceneCollider ( )
virtual

Member Function Documentation

◆ activate()

void SoDualSceneCollider::activate ( SoTransform transform)

Specifies the transformation that will be watched.

When the transformation changes, collision detection computations are started. transform is the transformation node to watch. If NULL, the collision are not checked.

◆ checkCollision()

virtual SbBool SoDualSceneCollider::checkCollision ( ) const
virtual

Checks if the current moving scene collides with the static scene.

This method is automatically called when the transform node given to activate() is updated (or touched). Returns TRUE if the two scenes collide, FALSE otherwise.

◆ enableMultiThread()

void SoDualSceneCollider::enableMultiThread ( bool  enable)

Use multiple threads to compute intersections.

This is faster when testing for collision against a large number of triangles. The computation will use the maximum number of threads supported on the processor.

IMPORTANT: When multithreaded computation is enabled, the searchNextIntersection(), is not necessarily called from the main thread. Therefore the code in searchNextIntersection() (and any methods called from it) must be thread-safe. As an example, GUI update calls outside the main thread are often not allowed.

Default is FALSE.

Since Open Inventor 9.6

◆ getCollidingMovingPath()

const SoPath * SoDualSceneCollider::getCollidingMovingPath ( ) const
protected

Returns the path in the moving scene of the current colliding shape.

This method could be called, for instance, by an overridden version of searchNextIntersection().

◆ getCollidingMovingTriangle()

void SoDualSceneCollider::getCollidingMovingTriangle ( SbVec3f v0,
SbVec3f v1,
SbVec3f v2 
) const
protected

Returns the coordinates of the current colliding triangle in the moving scene.

This method could be called, for instance, by an overridden version of searchNextIntersection().

◆ getCollidingStaticPath()

const SoPath * SoDualSceneCollider::getCollidingStaticPath ( ) const
protected

Returns the path in the static scene of the current colliding shape.

This method could be called, for instance, by an overridden version of searchNextIntersection().

◆ getCollidingStaticTriangle()

void SoDualSceneCollider::getCollidingStaticTriangle ( SbVec3f v0,
SbVec3f v1,
SbVec3f v2 
) const
protected

Returns the coordinates of the current colliding triangle in the static scene.

This method could be called, for instance, by an overridden version of searchNextIntersection().

◆ getCommonPoints()

void SoDualSceneCollider::getCommonPoints ( SbVec3f p0,
SbVec3f p1 
) const
protected

Returns the coordinates of the two common points of the current pair of intersecting triangles.

This method could be called, for instance, by an overridden version of searchNextIntersection().

◆ getMinEdgeLength()

double SoDualSceneCollider::getMinEdgeLength ( ) const

Returns the minimum length of a triangle edge.

See also
setMinEdgeLength().

◆ isMultiThreadEnabled()

bool SoDualSceneCollider::isMultiThreadEnabled ( ) const
inline

Returns true if multithreaded computation is enabled.

Since Open Inventor 9.6

Definition at line 202 of file SoDualSceneCollider.h.

◆ isSensitiveMovingObject()

SbBool SoDualSceneCollider::isSensitiveMovingObject ( const SoPath object_path) const
inlineprotectedvirtual

Tells if an object of the moving scene is sensitive to collision detection or not.

This method is called by setMovingScene() for each node found during the traversal. If it returns FALSE, the node is not inserted in the moving scene. By default it returns always TRUE and can be overridden by the application.

Definition at line 342 of file SoDualSceneCollider.h.

◆ isSensitiveStaticObject()

SbBool SoDualSceneCollider::isSensitiveStaticObject ( const SoPath object_path) const
inlineprotectedvirtual

Tells if an object of the static scene is sensitive to collision detection or not.

This method is called by setStaticScene() for each node found during the traversal. If it returns FALSE, the node is not inserted in the static scene. By default it returns always TRUE and can be overridden by the application.

Definition at line 338 of file SoDualSceneCollider.h.

◆ movingLeafBuilt()

void SoDualSceneCollider::movingLeafBuilt ( int  num_triangles) const
inlineprotectedvirtual

Method called by setMovingScene() when a new leaf is stored in the moving tree.

By default this method does nothing. But when it is overridden in a subclass, an application can use it, for instance, to modify the state of a progress bar. num_triangles is the number of triangles stored in the leaf. See movingTriangleListBuilt.

Definition at line 358 of file SoDualSceneCollider.h.

◆ movingTriangleListBuilt()

void SoDualSceneCollider::movingTriangleListBuilt ( int  num_triangles) const
inlineprotectedvirtual

Method called by setMovingScene() when the list of triangles in the moving scene is built.

By default this method does nothing. But when it is overridden in a subclass, an application can use it, for instance, to start a progress bar. num_triangles is the total number of triangles found in the moving scene. See movingLeafBuilt.

Definition at line 354 of file SoDualSceneCollider.h.

◆ searchNextIntersection()

virtual SbBool SoDualSceneCollider::searchNextIntersection ( ) const
inlinevirtual

Method called by checkCollision() for each pair of intersecting triangles found.

The method returns FALSE by default and may be overridden.

Definition at line 162 of file SoDualSceneCollider.h.

◆ setMinEdgeLength()

void SoDualSceneCollider::setMinEdgeLength ( double  minEdgeLength)

Specifies the minimum length of a triangle edge.

Any triangle having an edge smaller than this minimum is not registered in the static and moving scene. This minimum length prevents the collider from having floating point precision errors which could lead to invalid detection of intersections.

Parameters
minEdgeLengthif < 0, no edges are checked and all triangles of the scene are registered. Default value is 1E-8.

◆ setMovingScene()

void SoDualSceneCollider::setMovingScene ( SoPath object,
int  max_triangles_per_leaf = 0 
)

Specifies the scene that will be moved or transformed.

max_triangles_per_leaf is the maximum number of triangles stored in each leaf of the internal tree database representing the moving scene. If max_triangles_per_leaf is 0, a default maximum number is computed based on the total number of triangles in the moving scene.

◆ setStaticScene()

void SoDualSceneCollider::setStaticScene ( SoPath scene,
int  max_triangles_per_leaf = 0 
)

Specifies the scene the moving scene is interacting with.

max_triangles_per_leaf is the maximum number of triangles stored in each leaf of the internal tree database representing the static scene If max_triangles_per_leaf is 0, a default maximum number is computed based on the total number of triangles in the static scene.

◆ staticLeafBuilt()

void SoDualSceneCollider::staticLeafBuilt ( int  num_triangles) const
inlineprotectedvirtual

Method called by setStaticScene() when a new leaf is stored in the static tree.

By default this method does nothing. But when it is overridden in a subclass, an application can use it, for instance, to modify the state of a progress bar. num_triangles is the number of triangles stored in the leaf. See staticTriangleListBuilt.

Definition at line 350 of file SoDualSceneCollider.h.

◆ staticTriangleListBuilt()

void SoDualSceneCollider::staticTriangleListBuilt ( int  num_triangles) const
inlineprotectedvirtual

Method called by setStaticScene() when the list of triangles in the static scene is built.

By default this method does nothing. But when it is overridden in a subclass, an application can use it, for instance, to start a progress bar. num_triangles is the total number of triangles found in the static scene. See staticLeafBuilt.

Definition at line 346 of file SoDualSceneCollider.h.


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