Class SoDualSceneCollider
 java.lang.Object

 com.openinventor.inventor.Inventor

 com.openinventor.inventor.collision.SoDualSceneCollider

public class SoDualSceneCollider extends Inventor
Class to check for collisions between two scenes. TheSoDualSceneCollider
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 anSoCallbackAction
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 anSoTransform
). 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 methodsetStaticScene
and the moving scene by the methodsetMovingScene
.The
SoDualSceneCollider
references a scene by storing its triangle list (seeSoCallbackAction
) 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 theSoDualSceneCollider
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 unlesssetMovingScene
orsetStaticScene
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 callingcheckCollision()
. This method searches for pairs of intersecting triangles in an optimal way. For each pair of intersecting triangles found, the Boolean methodsearchNextIntersection()
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 andcheckCollision()
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()
, andgetCommonPoints()
.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
andstaticLeafBuilt
/movingLeafBuilt
have been defined and can be overridden to implement, for instance, a progress bar. However, note that the methodsstaticLeafBuilt
/movingLeafBuilt
are not called in linear time.Collision checking will be faster using multiple threads. See the
enableMultiThread()
method.


Nested Class Summary

Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand


Field Summary

Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle


Constructor Summary
Constructors Constructor Description SoDualSceneCollider()
Default constructor.

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activate(SoTransform transform)
Specifies the transformation that will be watched.boolean
checkCollision()
Checks if the current moving scene collides with the static scene.void
enableMultiThread(boolean enable)
Use multiple threads to compute intersections.double
getMinEdgeLength()
Returns the minimum length of a triangle edge.boolean
isMultiThreadEnabled()
Returns true if multithreaded computation is enabled.boolean
searchNextIntersection()
Method called bycheckCollision()
for each pair of intersecting triangles found.void
setMinEdgeLength(double minEdgeLength)
Specifies the minimum length of a triangle edge.void
setMovingScene(SoPath object)
Calls setMovingScene(object, (int)0).void
setMovingScene(SoPath object, int max_triangles_per_leaf)
Specifies the scene that will be moved or transformed.void
setStaticScene(SoPath scene)
Calls setStaticScene(scene, (int)0).void
setStaticScene(SoPath scene, int max_triangles_per_leaf)
Specifies the scene the moving scene is interacting with.
Methods inherited from class com.openinventor.inventor.Inventor
dispose, getNativeResourceHandle




Method Detail

setMovingScene
public void setMovingScene(SoPath object)
Calls setMovingScene(object, (int)0).

setStaticScene
public void setStaticScene(SoPath scene)
Calls setStaticScene(scene, (int)0).

setStaticScene
public void setStaticScene(SoPath scene, int max_triangles_per_leaf)
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.

enableMultiThread
public void enableMultiThread(boolean 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 insearchNextIntersection()
(and any methods called from it) must be threadsafe. As an example, GUI update calls outside the main thread are often not allowed.Default is false.
 Since:
 Open Inventor 9.6

isMultiThreadEnabled
public boolean isMultiThreadEnabled()
Returns true if multithreaded computation is enabled. Since:
 Open Inventor 9.6

searchNextIntersection
public boolean searchNextIntersection()
Method called bycheckCollision()
for each pair of intersecting triangles found. The method returns false by default and may be overridden.

checkCollision
public boolean checkCollision()
Checks if the current moving scene collides with the static scene. This method is automatically called when the transform node given toactivate()
is updated (or touched). Returns true if the two scenes collide, false otherwise.

setMovingScene
public void setMovingScene(SoPath object, int max_triangles_per_leaf)
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.

getMinEdgeLength
public double getMinEdgeLength()
Returns the minimum length of a triangle edge. See Also:
setMinEdgeLength()

activate
public void 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.

setMinEdgeLength
public void 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:
minEdgeLength
 if < 0, no edges are checked and all triangles of the scene are registered. Default value is 1E8.

