Bullet Collision Detection & Physics Library
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
btQuantizedBvh Class Reference

The btQuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU. More...

#include <btQuantizedBvh.h>

Inheritance diagram for btQuantizedBvh:
Inheritance graph
[legend]
Collaboration diagram for btQuantizedBvh:
Collaboration graph
[legend]

Public Types

enum  btTraversalMode {
  TRAVERSAL_STACKLESS = 0,
  TRAVERSAL_STACKLESS_CACHE_FRIENDLY,
  TRAVERSAL_RECURSIVE
}
 

Public Member Functions

 BT_DECLARE_ALIGNED_ALLOCATOR ()
 
 btQuantizedBvh ()
 
virtual ~btQuantizedBvh ()
 
void setQuantizationValues (const btVector3 &bvhAabbMin, const btVector3 &bvhAabbMax, btScalar quantizationMargin=btScalar(1.0))
 ***************************************** expert/internal use only ************************* More...
 
QuantizedNodeArraygetLeafNodeArray ()
 
void buildInternal ()
 buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized More...
 
void reportAabbOverlappingNodex (btNodeOverlapCallback *nodeCallback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
 ***************************************** expert/internal use only ************************* More...
 
void reportRayOverlappingNodex (btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget) const
 
void reportBoxCastOverlappingNodex (btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget, const btVector3 &aabbMin, const btVector3 &aabbMax) const
 
void quantize (unsigned short *out, const btVector3 &point, int isMax) const
 
void quantizeWithClamp (unsigned short *out, const btVector3 &point2, int isMax) const
 
btVector3 unQuantize (const unsigned short *vecIn) const
 
void setTraversalMode (btTraversalMode traversalMode)
 setTraversalMode let's you choose between stackless, recursive or stackless cache friendly tree traversal. Note this is only implemented for quantized trees. More...
 
QuantizedNodeArraygetQuantizedNodeArray ()
 
BvhSubtreeInfoArraygetSubtreeInfoArray ()
 
unsigned calculateSerializeBufferSize () const
 
virtual bool serialize (void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const
 Data buffer MUST be 16 byte aligned. More...
 
virtual int calculateSerializeBufferSizeNew () const
 
virtual const char * serialize (void *dataBuffer, btSerializer *serializer) const
 fills the dataBuffer and returns the struct name (and 0 on failure) More...
 
virtual void deSerializeFloat (struct btQuantizedBvhFloatData &quantizedBvhFloatData)
 
virtual void deSerializeDouble (struct btQuantizedBvhDoubleData &quantizedBvhDoubleData)
 
bool isQuantized ()
 

Static Public Member Functions

static btQuantizedBvhdeSerializeInPlace (void *i_alignedDataBuffer, unsigned int i_dataBufferSize, bool i_swapEndian)
 deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place' More...
 
static unsigned int getAlignmentSerializationPadding ()
 

Protected Member Functions

void setInternalNodeAabbMin (int nodeIndex, const btVector3 &aabbMin)
 two versions, one for quantized and normal nodes. More...
 
void setInternalNodeAabbMax (int nodeIndex, const btVector3 &aabbMax)
 
btVector3 getAabbMin (int nodeIndex) const
 
btVector3 getAabbMax (int nodeIndex) const
 
void setInternalNodeEscapeIndex (int nodeIndex, int escapeIndex)
 
void mergeInternalNodeAabb (int nodeIndex, const btVector3 &newAabbMin, const btVector3 &newAabbMax)
 
void swapLeafNodes (int firstIndex, int secondIndex)
 
void assignInternalNodeFromLeafNode (int internalNode, int leafNodeIndex)
 
void buildTree (int startIndex, int endIndex)
 
int calcSplittingAxis (int startIndex, int endIndex)
 
int sortAndCalcSplittingIndex (int startIndex, int endIndex, int splitAxis)
 
void walkStacklessTree (btNodeOverlapCallback *nodeCallback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
 
void walkStacklessQuantizedTreeAgainstRay (btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget, const btVector3 &aabbMin, const btVector3 &aabbMax, int startNodeIndex, int endNodeIndex) const
 
void walkStacklessQuantizedTree (btNodeOverlapCallback *nodeCallback, unsigned short int *quantizedQueryAabbMin, unsigned short int *quantizedQueryAabbMax, int startNodeIndex, int endNodeIndex) const
 
void walkStacklessTreeAgainstRay (btNodeOverlapCallback *nodeCallback, const btVector3 &raySource, const btVector3 &rayTarget, const btVector3 &aabbMin, const btVector3 &aabbMax, int startNodeIndex, int endNodeIndex) const
 
void walkStacklessQuantizedTreeCacheFriendly (btNodeOverlapCallback *nodeCallback, unsigned short int *quantizedQueryAabbMin, unsigned short int *quantizedQueryAabbMax) const
 tree traversal designed for small-memory processors like PS3 SPU More...
 
void walkRecursiveQuantizedTreeAgainstQueryAabb (const btQuantizedBvhNode *currentNode, btNodeOverlapCallback *nodeCallback, unsigned short int *quantizedQueryAabbMin, unsigned short int *quantizedQueryAabbMax) const
 use the 16-byte stackless 'skipindex' node tree to do a recursive traversal More...
 
void walkRecursiveQuantizedTreeAgainstQuantizedTree (const btQuantizedBvhNode *treeNodeA, const btQuantizedBvhNode *treeNodeB, btNodeOverlapCallback *nodeCallback) const
 use the 16-byte stackless 'skipindex' node tree to do a recursive traversal More...
 
void updateSubtreeHeaders (int leftChildNodexIndex, int rightChildNodexIndex)
 

Protected Attributes

btVector3 m_bvhAabbMin
 
btVector3 m_bvhAabbMax
 
btVector3 m_bvhQuantization
 
int m_bulletVersion
 
int m_curNodeIndex
 
bool m_useQuantization
 
NodeArray m_leafNodes
 
NodeArray m_contiguousNodes
 
QuantizedNodeArray m_quantizedLeafNodes
 
QuantizedNodeArray m_quantizedContiguousNodes
 
btTraversalMode m_traversalMode
 
BvhSubtreeInfoArray m_SubtreeHeaders
 
int m_subtreeHeaderCount
 

Private Member Functions

 btQuantizedBvh (btQuantizedBvh &other, bool ownsMemory)
 

Detailed Description

The btQuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU.

It is used by the btBvhTriangleMeshShape as midphase, and by the btMultiSapBroadphase. It is recommended to use quantization for better performance and lower memory requirements.

Definition at line 174 of file btQuantizedBvh.h.

Member Enumeration Documentation

Enumerator
TRAVERSAL_STACKLESS 
TRAVERSAL_STACKLESS_CACHE_FRIENDLY 
TRAVERSAL_RECURSIVE 

Definition at line 177 of file btQuantizedBvh.h.

Constructor & Destructor Documentation

btQuantizedBvh::btQuantizedBvh ( )

Definition at line 24 of file btQuantizedBvh.cpp.

btQuantizedBvh::~btQuantizedBvh ( )
virtual

Definition at line 123 of file btQuantizedBvh.cpp.

btQuantizedBvh::btQuantizedBvh ( btQuantizedBvh other,
bool  ownsMemory 
)
private

Definition at line 1156 of file btQuantizedBvh.cpp.

Member Function Documentation

void btQuantizedBvh::assignInternalNodeFromLeafNode ( int  internalNode,
int  leafNodeIndex 
)
protected

Definition at line 823 of file btQuantizedBvh.cpp.

btQuantizedBvh::BT_DECLARE_ALIGNED_ALLOCATOR ( )
void btQuantizedBvh::buildInternal ( )

buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized

assumes that caller filled in the m_quantizedLeafNodes

if the entire tree is small then subtree size, we need to create a header info for the tree

Definition at line 40 of file btQuantizedBvh.cpp.

void btQuantizedBvh::buildTree ( int  startIndex,
int  endIndex 
)
protected

Definition at line 132 of file btQuantizedBvh.cpp.

int btQuantizedBvh::calcSplittingAxis ( int  startIndex,
int  endIndex 
)
protected

Definition at line 302 of file btQuantizedBvh.cpp.

unsigned btQuantizedBvh::calculateSerializeBufferSize ( ) const

Definition at line 852 of file btQuantizedBvh.cpp.

int btQuantizedBvh::calculateSerializeBufferSizeNew ( ) const
inlinevirtual

Definition at line 574 of file btQuantizedBvh.h.

void btQuantizedBvh::deSerializeDouble ( struct btQuantizedBvhDoubleData quantizedBvhDoubleData)
virtual

Definition at line 1236 of file btQuantizedBvh.cpp.

void btQuantizedBvh::deSerializeFloat ( struct btQuantizedBvhFloatData quantizedBvhFloatData)
virtual

Definition at line 1165 of file btQuantizedBvh.cpp.

btQuantizedBvh * btQuantizedBvh::deSerializeInPlace ( void *  i_alignedDataBuffer,
unsigned int  i_dataBufferSize,
bool  i_swapEndian 
)
static

deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place'

Definition at line 1049 of file btQuantizedBvh.cpp.

btVector3 btQuantizedBvh::getAabbMax ( int  nodeIndex) const
inlineprotected

Definition at line 248 of file btQuantizedBvh.h.

btVector3 btQuantizedBvh::getAabbMin ( int  nodeIndex) const
inlineprotected

Definition at line 238 of file btQuantizedBvh.h.

unsigned int btQuantizedBvh::getAlignmentSerializationPadding ( )
static

Definition at line 846 of file btQuantizedBvh.cpp.

QuantizedNodeArray& btQuantizedBvh::getLeafNodeArray ( )
inline

Definition at line 343 of file btQuantizedBvh.h.

QuantizedNodeArray& btQuantizedBvh::getQuantizedNodeArray ( )
inline

Definition at line 450 of file btQuantizedBvh.h.

BvhSubtreeInfoArray& btQuantizedBvh::getSubtreeInfoArray ( )
inline

Definition at line 456 of file btQuantizedBvh.h.

bool btQuantizedBvh::isQuantized ( )
inline

Definition at line 488 of file btQuantizedBvh.h.

void btQuantizedBvh::mergeInternalNodeAabb ( int  nodeIndex,
const btVector3 newAabbMin,
const btVector3 newAabbMax 
)
inlineprotected

Definition at line 273 of file btQuantizedBvh.h.

void btQuantizedBvh::quantize ( unsigned short *  out,
const btVector3 point,
int  isMax 
) const
inline

Make sure rounding is done in a way that unQuantize(quantizeWithClamp(...)) is conservative end-points always set the first bit, so that they are sorted properly (so that neighbouring AABBs overlap properly)

Definition at line 352 of file btQuantizedBvh.h.

void btQuantizedBvh::quantizeWithClamp ( unsigned short *  out,
const btVector3 point2,
int  isMax 
) const
inline

Definition at line 419 of file btQuantizedBvh.h.

void btQuantizedBvh::reportAabbOverlappingNodex ( btNodeOverlapCallback nodeCallback,
const btVector3 aabbMin,
const btVector3 aabbMax 
) const

***************************************** expert/internal use only *************************

quantize query AABB

Definition at line 331 of file btQuantizedBvh.cpp.

void btQuantizedBvh::reportBoxCastOverlappingNodex ( btNodeOverlapCallback nodeCallback,
const btVector3 raySource,
const btVector3 rayTarget,
const btVector3 aabbMin,
const btVector3 aabbMax 
) const

Definition at line 780 of file btQuantizedBvh.cpp.

void btQuantizedBvh::reportRayOverlappingNodex ( btNodeOverlapCallback nodeCallback,
const btVector3 raySource,
const btVector3 rayTarget 
) const

Definition at line 774 of file btQuantizedBvh.cpp.

bool btQuantizedBvh::serialize ( void *  o_alignedDataBuffer,
unsigned  i_dataBufferSize,
bool  i_swapEndian 
) const
virtual

Data buffer MUST be 16 byte aligned.

Definition at line 863 of file btQuantizedBvh.cpp.

const char * btQuantizedBvh::serialize ( void *  dataBuffer,
btSerializer serializer 
) const
virtual

fills the dataBuffer and returns the struct name (and 0 on failure)

Definition at line 1311 of file btQuantizedBvh.cpp.

void btQuantizedBvh::setInternalNodeAabbMax ( int  nodeIndex,
const btVector3 aabbMax 
)
inlineprotected

Definition at line 227 of file btQuantizedBvh.h.

void btQuantizedBvh::setInternalNodeAabbMin ( int  nodeIndex,
const btVector3 aabbMin 
)
inlineprotected

two versions, one for quantized and normal nodes.

This allows code-reuse while maintaining readability (no template/macro!) this might be refactored into a virtual, it is usually not calculated at run-time

Definition at line 216 of file btQuantizedBvh.h.

void btQuantizedBvh::setInternalNodeEscapeIndex ( int  nodeIndex,
int  escapeIndex 
)
inlineprotected

Definition at line 260 of file btQuantizedBvh.h.

void btQuantizedBvh::setQuantizationValues ( const btVector3 bvhAabbMin,
const btVector3 bvhAabbMax,
btScalar  quantizationMargin = btScalar(1.0) 
)

***************************************** expert/internal use only *************************

just for debugging, to visualize the individual patches/subtrees

Definition at line 91 of file btQuantizedBvh.cpp.

void btQuantizedBvh::setTraversalMode ( btTraversalMode  traversalMode)
inline

setTraversalMode let's you choose between stackless, recursive or stackless cache friendly tree traversal. Note this is only implemented for quantized trees.

Definition at line 444 of file btQuantizedBvh.h.

int btQuantizedBvh::sortAndCalcSplittingIndex ( int  startIndex,
int  endIndex,
int  splitAxis 
)
protected

Definition at line 248 of file btQuantizedBvh.cpp.

void btQuantizedBvh::swapLeafNodes ( int  firstIndex,
int  secondIndex 
)
protected

Definition at line 808 of file btQuantizedBvh.cpp.

btVector3 btQuantizedBvh::unQuantize ( const unsigned short *  vecIn) const
inline

Definition at line 432 of file btQuantizedBvh.h.

void btQuantizedBvh::updateSubtreeHeaders ( int  leftChildNodexIndex,
int  rightChildNodexIndex 
)
protected

Definition at line 215 of file btQuantizedBvh.cpp.

void btQuantizedBvh::walkRecursiveQuantizedTreeAgainstQuantizedTree ( const btQuantizedBvhNode treeNodeA,
const btQuantizedBvhNode treeNodeB,
btNodeOverlapCallback nodeCallback 
) const
protected

use the 16-byte stackless 'skipindex' node tree to do a recursive traversal

void btQuantizedBvh::walkRecursiveQuantizedTreeAgainstQueryAabb ( const btQuantizedBvhNode currentNode,
btNodeOverlapCallback nodeCallback,
unsigned short int *  quantizedQueryAabbMin,
unsigned short int *  quantizedQueryAabbMax 
) const
protected

use the 16-byte stackless 'skipindex' node tree to do a recursive traversal

Definition at line 435 of file btQuantizedBvh.cpp.

void btQuantizedBvh::walkStacklessQuantizedTree ( btNodeOverlapCallback nodeCallback,
unsigned short int *  quantizedQueryAabbMin,
unsigned short int *  quantizedQueryAabbMax,
int  startNodeIndex,
int  endNodeIndex 
) const
protected

Definition at line 685 of file btQuantizedBvh.cpp.

void btQuantizedBvh::walkStacklessQuantizedTreeAgainstRay ( btNodeOverlapCallback nodeCallback,
const btVector3 raySource,
const btVector3 rayTarget,
const btVector3 aabbMin,
const btVector3 aabbMax,
int  startNodeIndex,
int  endNodeIndex 
) const
protected

what about division by zero? –> just set rayDirection[i] to 1.0

careful with this check: need to check division by zero (above) and fix the unQuantize method thanks Joerg/hiker for the reproduction case! http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858

Definition at line 559 of file btQuantizedBvh.cpp.

void btQuantizedBvh::walkStacklessQuantizedTreeCacheFriendly ( btNodeOverlapCallback nodeCallback,
unsigned short int *  quantizedQueryAabbMin,
unsigned short int *  quantizedQueryAabbMax 
) const
protected

tree traversal designed for small-memory processors like PS3 SPU

Definition at line 751 of file btQuantizedBvh.cpp.

void btQuantizedBvh::walkStacklessTree ( btNodeOverlapCallback nodeCallback,
const btVector3 aabbMin,
const btVector3 aabbMax 
) const
protected

Definition at line 371 of file btQuantizedBvh.cpp.

void btQuantizedBvh::walkStacklessTreeAgainstRay ( btNodeOverlapCallback nodeCallback,
const btVector3 raySource,
const btVector3 rayTarget,
const btVector3 aabbMin,
const btVector3 aabbMax,
int  startNodeIndex,
int  endNodeIndex 
) const
protected

what about division by zero? –> just set rayDirection[i] to 1.0

careful with this check: need to check division by zero (above) and fix the unQuantize method thanks Joerg/hiker for the reproduction case! http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858

Definition at line 467 of file btQuantizedBvh.cpp.

Member Data Documentation

int btQuantizedBvh::m_bulletVersion
protected

Definition at line 191 of file btQuantizedBvh.h.

btVector3 btQuantizedBvh::m_bvhAabbMax
protected

Definition at line 188 of file btQuantizedBvh.h.

btVector3 btQuantizedBvh::m_bvhAabbMin
protected

Definition at line 187 of file btQuantizedBvh.h.

btVector3 btQuantizedBvh::m_bvhQuantization
protected

Definition at line 189 of file btQuantizedBvh.h.

NodeArray btQuantizedBvh::m_contiguousNodes
protected

Definition at line 200 of file btQuantizedBvh.h.

int btQuantizedBvh::m_curNodeIndex
protected

Definition at line 193 of file btQuantizedBvh.h.

NodeArray btQuantizedBvh::m_leafNodes
protected

Definition at line 199 of file btQuantizedBvh.h.

QuantizedNodeArray btQuantizedBvh::m_quantizedContiguousNodes
protected

Definition at line 202 of file btQuantizedBvh.h.

QuantizedNodeArray btQuantizedBvh::m_quantizedLeafNodes
protected

Definition at line 201 of file btQuantizedBvh.h.

int btQuantizedBvh::m_subtreeHeaderCount
mutableprotected

Definition at line 208 of file btQuantizedBvh.h.

BvhSubtreeInfoArray btQuantizedBvh::m_SubtreeHeaders
protected

Definition at line 205 of file btQuantizedBvh.h.

btTraversalMode btQuantizedBvh::m_traversalMode
protected

Definition at line 204 of file btQuantizedBvh.h.

bool btQuantizedBvh::m_useQuantization
protected

Definition at line 195 of file btQuantizedBvh.h.


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