BVHTree_BinarySphere< T > Class Template Reference

BVHTree_BinarySphere class is a class for Binary Sphere Boundary Volume Hierarchy Tree. More...

#include <TAPsBVHTree_BinarySphere.hpp>

Inheritance diagram for BVHTree_BinarySphere< T >:

Inheritance graph
[legend]
Collaboration diagram for BVHTree_BinarySphere< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 BVHTree_BinarySphere (TransformationSupport< T > &transform, HEFaceList< T > *heFaceList)
 BVHTree_BinarySphere (TransformationSupport< T > &transform, Enum::CD type=Enum::UNDEFINED_TREE, int numOfNodes=0, BVHNode< T > *rootNode=NULL)
virtual bool TestIntersectionWithLineSegmentTillLeafNodes (Vector3< T > const *const ptA, Vector3< T > const *const ptB)
virtual bool TestOverlapWith (BoundingVolume< T > const *const pBV)
virtual bool TestOverlapWith (MultiBoundingVolume< T > const *const pMBV)
virtual bool TestOverlapWith (BVHNode< T > const *const node)
virtual bool TestOverlapWith (BVHTree< T > const *const that)
virtual bool TestOverlapWithTillLeafNodes (BoundingVolume< T > const *const pBV)
virtual bool TestOverlapWithTillLeafNodes (MultiBoundingVolume< T > const *const pMBV)
virtual bool TestOverlapWithTillLeafNodes (BVHNode< T > const *const node)
virtual bool TestOverlapWithTillLeafNodes (BVHTree< T > const *const that)
virtual ~BVHTree_BinarySphere ()

Static Public Member Functions

static BVHTree< T > * Build (TransformationSupport< T > &transform, std::list< HEFace< T > * > const *const heFaceList, Enum::CD treeType, BVHTree< T > *cdtree)
 O/P: pointer to BVHTree.

Protected Member Functions

void ForBVCylinderTransformations (Matrix4x4< T > const &nodeTransform_IP, BoundingVolume< T > const *const pBV, Matrix4x4< T > const &bvTransformation, Matrix4x4< T > &nodeTransform_OP)
void ForBVCylinderTransformations (Matrix4x4< T > const &nodeTransform_IP, BoundingVolume< T > const *const pBV, Matrix4x4< T > &nodeTransform_OP)
void ForBVCylinderTransformations (BoundingVolume< T > const *const pBV, Matrix4x4< T > const &bvTransformation, Matrix4x4< T > &nodeTransform_OP)
void ForBVCylinderTransformations (BoundingVolume< T > const *const pBV, Matrix4x4< T > &nodeTransform_OP)
void ForBVSphereTransformations (BoundingVolume< T > const *const pBV, Matrix4x4< T > const &bvTransformation, Vector3< T > &sphereCenter, T &sphereRadius)
 Transform BV sphere's center and radius.
bool TestIntersectionWithLineSegmentTillLeafNodesRecursive (BVHNode< T > const *const node, Vector3< T > const *const ptA, Vector3< T > const *const ptB)
virtual bool TestOverlap_vs_BinarySphere (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BVHNode< T > const *const nodeB, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BinarySphere (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BVHNode< T > const *const nodeB)
virtual bool TestOverlap_vs_BinarySphere (BVHNode< T > const *const nodeA, BVHNode< T > const *const nodeB, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BinarySphere (BVHNode< T > const *const nodeA, BVHNode< T > const *const nodeB)
virtual bool TestOverlap_vs_BinarySphere_TillLeafNodes (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BVHNode< T > const *const nodeB, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BinarySphere_TillLeafNodes (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BVHNode< T > const *const nodeB)
virtual bool TestOverlap_vs_BinarySphere_TillLeafNodes (BVHNode< T > const *const nodeA, BVHNode< T > const *const nodeB, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BinarySphere_TillLeafNodes (BVHNode< T > const *const nodeA, BVHNode< T > const *const nodeB)
virtual bool TestOverlap_vs_BV (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BoundingVolume< T > const *const pBV, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BV (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BoundingVolume< T > const *const pBV)
virtual bool TestOverlap_vs_BV (BVHNode< T > const *const nodeA, BoundingVolume< T > const *const pBV, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BV (BVHNode< T > const *const nodeA, BoundingVolume< T > const *const pBV)
bool TestOverlap_vs_BV_Cylinder_AtOrigin (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, T cylinderRadius, T cylinderHeight)
bool TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, T cylinderRadius, T cylinderHeight)
bool TestOverlap_vs_BV_Sphere (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, Vector3< T > const &sphereCenter, T sphereRadius)
bool TestOverlap_vs_BV_Sphere (BVHNode< T > const *const nodeA, Vector3< T > const &sphereCenter, T sphereRadius)
 Remark: existing transformB is already applied to sphereCenter and sphereRadius.
bool TestOverlap_vs_BV_Sphere_TillLeafNodes (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, Vector3< T > const &sphereCenter, T sphereRadius)
bool TestOverlap_vs_BV_Sphere_TillLeafNodes (BVHNode< T > const *const nodeA, Vector3< T > const &sphereCenter, T sphereRadius)
 Remark: existing transformB is already applied to sphereCenter and sphereRadius.
virtual bool TestOverlap_vs_BV_TillLeafNodes (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BoundingVolume< T > const *const pBV, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BV_TillLeafNodes (BVHNode< T > const *const nodeA, Matrix4x4< T > const &transformA, BoundingVolume< T > const *const pBV)
virtual bool TestOverlap_vs_BV_TillLeafNodes (BVHNode< T > const *const nodeA, BoundingVolume< T > const *const pBV, Matrix4x4< T > const &transformB)
virtual bool TestOverlap_vs_BV_TillLeafNodes (BVHNode< T > const *const nodeA, BoundingVolume< T > const *const pBV)

Static Private Member Functions

static BVHTree< T > * BSphereBuild (TransformationSupport< T > &transform, const std::list< HEFace< T > * > &heFaceList, BVHTree< T > *cdtree)
 O/P: pointer to BVHTree.
static void BSphereBuildChildren (BVHNode< T > *pParentNode, const std::list< HEFace< T > * > &heFaceList, Vector3< T > const &principleVector)
static int BSphereDetermineFaceGroup (HEFace< T > *face, const Vector3< T > &center, const Vector3< T > &direction)
static void BSphereDivideToFaceGroups (const std::list< HEFace< T > * > &faces, std::list< HEFace< T > * > &group1, std::list< HEFace< T > * > &group2, const Vector3< T > &center, const Vector3< T > &direction)
static BVHNode< T > * CreateBVHNodeBSphere (BVHNode< T > *pParentNode, const std::list< HEFace< T > * > &heFaceList)

Friends

std::ostream & operator<< (std::ostream &output, BVHTree_BinarySphere< T > const &obj)


Detailed Description

template<typename T>
class BVHTree_BinarySphere< T >

BVHTree_BinarySphere class is a class for Binary Sphere Boundary Volume Hierarchy Tree.

See also:
TAPsCDLib.hpp for details about Collision Detection implemented in TAPs.

Definition at line 25 of file TAPsBVHTree_BinarySphere.hpp.


Constructor & Destructor Documentation

template<typename T>
BEGIN_NAMESPACE_TAPs BVHTree_BinarySphere< T >::BVHTree_BinarySphere ( TransformationSupport< T > &  transform,
Enum::CD  type = Enum::UNDEFINED_TREE,
int  numOfNodes = 0,
BVHNode< T > *  rootNode = NULL 
) [inline]

Definition at line 18 of file TAPsBVHTree_BinarySphere.cpp.

00023     : BVHTree<T>( transform, type, numOfNodes, rootNode )
00024 {}

template<typename T>
BVHTree_BinarySphere< T >::BVHTree_BinarySphere ( TransformationSupport< T > &  transform,
HEFaceList< T > *  heFaceList 
) [inline]

Parameters:
transform  I/O: Transform
heFaceList  I/P: half-edge face list

Definition at line 27 of file TAPsBVHTree_BinarySphere.cpp.

00028                                                     : Transform
00029     HEFaceList<T> * heFaceList              
00030 )
00031     : BVHTree<T>( transform )
00032 {
00033     //-----------------------------------------------------
00034     // Copy original face list (heFaceList) to a list 
00035     // of face (faceList)
00036     std::list< HEFace<T> * > faceList;
00037     HEFace<T> * face = heFaceList->Head();
00038     while ( face ) {
00039         faceList.push_back( face );
00040         face = face->Next();
00041     }
00042 
00043     m_eType = Enum::BVH_TREE_BINARY_SPHERE;
00044     m_iTotalNodes = 1;
00045     m_Transform = transform;
00046     m_pRoot = CreateBVHNodeBSphere( NULL, faceList );
00047 
00048     Vector3<T> U, V, W;
00049     FindOBBOfFaceList( faceList, m_pRoot->GetCenter(), U, V, W );
00050     if ( m_pRoot )  BSphereBuildChildren( m_pRoot, faceList, U );
00051 
00052     FindListOfLeafNodes();
00053 
00054     SetNumOfNodes( CountNodes() );
00055 }

template<typename T>
BVHTree_BinarySphere< T >::~BVHTree_BinarySphere (  )  [inline, virtual]

Definition at line 58 of file TAPsBVHTree_BinarySphere.cpp.

00059 {}


Member Function Documentation

template<typename T>
BVHTree< T > * BVHTree_BinarySphere< T >::BSphereBuild ( TransformationSupport< T > &  transform,
const std::list< HEFace< T > * > &  heFaceList,
BVHTree< T > *  cdtree 
) [inline, static, private]

O/P: pointer to BVHTree.

Parameters:
transform  I/O: Transform
heFaceList  I/P: half-edge face list

Definition at line 1816 of file TAPsBVHTree_BinarySphere.cpp.

01817                                                           : Transform
01818         const std::list< HEFace<T>* > & heFaceList, // I/P half-edge face list
01819         BVHTree<T> * cdtree )                       // O/P pointer to BVHTree
01820 {
01821     //std::cout << "BSphereBuild (before): " << cdtree << std::endl;
01822     BVHNode<T> *node = CreateBVHNodeBSphere( NULL, heFaceList );
01823 //  node->listHEFace  = heFaceList;         // DEBUG
01824     cdtree = new BVHTree<T>( transform, Enum::BVH_TREE_BINARY_SPHERE, 1, node );
01825     //FindOBBOfFaceList( heFaceList, node );
01826     Vector3<T> U, V, W;
01827     FindOBBOfFaceList( heFaceList, node->GetCenter(), U, V, W );
01828     if ( node ) BSphereBuildChildren( node, heFaceList, U );
01829     //std::cout << "BSphereBuild (after): " << cdtree << std::endl;
01830 
01831     SetNumOfNodes( CountNodes() );
01832     return cdtree;
01833 }

template<typename T>
void BVHTree_BinarySphere< T >::BSphereBuildChildren ( BVHNode< T > *  pParentNode,
const std::list< HEFace< T > * > &  heFaceList,
Vector3< T > const &  principleVector 
) [inline, static, private]

Definition at line 1837 of file TAPsBVHTree_BinarySphere.cpp.

01841 {
01842     int size = static_cast<int>( heFaceList.size() );
01843     std::list< HEFace<T> * > leftGroup, rightGroup;
01844     //---------------------------------------------------------------
01845     // CASE: one face
01846     // This is a leaf node.
01847     assert( size > 0 );         // ASSERT
01848     if ( 1 == size ) {
01849         return;
01850     }
01851     //---------------------------------------------------------------
01852     assert( pParentNode );          // ASSERT
01853     BVHNode<T> * leftChild  = NULL;
01854     BVHNode<T> * rightChild = NULL;
01855     //---------------------------------------------------------------
01856     // CASE: two faces
01857     // Create Two Leaf Nodes
01858     if ( 2 == size ) {
01859         //-------------------------------------------------
01860         // Separate two faces into left and right groups
01861         std::list< HEFace<T> * >::const_iterator face = heFaceList.begin();
01862         leftGroup.push_back( *face );
01863         ++face;
01864         rightGroup.push_back( *face );
01865         //-------------------------------------------------
01866         // Create Left Leaf Node
01867         leftChild  = CreateBVHNodeBSphere( pParentNode, leftGroup );
01868 //      leftChild->listHEFace  = leftGroup;         // DEBUG
01869         pParentNode->Child( 0, leftChild );
01870         //-------------------------------------------------
01871         // Create Right Leaf Node
01872         rightChild = CreateBVHNodeBSphere( pParentNode, rightGroup );
01873 //      rightChild->listHEFace = rightGroup;        // DEBUG
01874         pParentNode->Child( 1, rightChild );
01875         return;
01876     }
01877     //---------------------------------------------------------------
01878     // CASE: more than two faces
01879     // Didive into two groups
01880     BSphereDivideToFaceGroups(  heFaceList, leftGroup, rightGroup, 
01881                                 pParentNode->GetCenter(), 
01882                                 principleVector );
01883     //---------------------------------------------------------------
01884     // CASE: more than two faces and the divider failed to divide the face list
01885     if (   static_cast<int>( leftGroup.size() )  == size 
01886         || static_cast<int>( rightGroup.size() ) == size ) {
01887         //std::cout << "Total    : " << size;
01888         //std::cout << "; Left  Grp: " << leftGroup.size();
01889         //std::cout << "; Right Grp: " << rightGroup.size() << std::endl;
01890         leftGroup.clear();
01891         rightGroup.clear();
01892         std::list< HEFace<T> * >::const_iterator face = heFaceList.begin();
01893         int i = 0;
01894         for ( ; i < size/2; ++i ) {
01895             leftGroup.push_back( *face );
01896             ++face;
01897         }
01898         for ( ; i < size; ++i ) {
01899             rightGroup.push_back( *face );
01900             ++face;
01901         }
01902     }
01903     Vector3<T> U, V, W;
01904     //---------------------------------------------------------------
01905     // Create Left Child Node
01906     leftChild  = CreateBVHNodeBSphere( pParentNode, leftGroup );
01907     FindOBBOfFaceList( leftGroup, leftChild->GetCenter(), U, V, W );
01908 //  leftChild->listHEFace  = leftGroup;         // DEBUG
01909     pParentNode->Child( 0, leftChild );
01910     BSphereBuildChildren( leftChild, leftGroup, U );
01911     //---------------------------------------------------------------
01912     // Create Right Child Node
01913     rightChild = CreateBVHNodeBSphere( pParentNode, rightGroup );
01914     FindOBBOfFaceList( rightGroup, rightChild->GetCenter(), U, V, W );
01915 //  rightChild->listHEFace = rightGroup;        // DEBUG
01916     pParentNode->Child( 1, rightChild );
01917     BSphereBuildChildren( rightChild, rightGroup, U );
01918 }

template<typename T>
int BVHTree_BinarySphere< T >::BSphereDetermineFaceGroup ( HEFace< T > *  face,
const Vector3< T > &  center,
const Vector3< T > &  direction 
) [inline, static, private]

Definition at line 1922 of file TAPsBVHTree_BinarySphere.cpp.

01925 {
01926     //-------------------------------------------------------------------------
01927     // Divided into an axis positive and negative
01928     //---------------------------------------------------------------
01929     // REMARK:
01930     //   To speed thing up, we can evaluate only the first vertex of the polygon.
01931     //---------------------------------------------------------------
01932     // Determine from all vertices
01933     int value = 0;
01934     HEHalfEdge<T> * firstHalfEdge = face->IncidentHalfEdge();
01935     HEHalfEdge<T> * halfEdge = firstHalfEdge;
01936     Vector3<T> vertex;
01937     do {
01938         /*
01939         vertex = halfEdge->Vertex()->GetPosition() - center;
01940         if ( vertex.GetY() >= 0 )   ++value;
01941         else                        --value;
01942         //*/
01943         //*
01944         if ( (halfEdge->Vertex()->GetPosition() - center) * direction >= 0 )
01945             ++value;
01946         else
01947             --value;
01948         //*/
01949         
01950         halfEdge = halfEdge->Next();
01951     } while ( halfEdge != firstHalfEdge );
01952     //---------------------------------------------------------------
01953     // Determine the group (left or right)
01954     return  value >= 0 ? 1 : 0;
01955 }

template<typename T>
void BVHTree_BinarySphere< T >::BSphereDivideToFaceGroups ( const std::list< HEFace< T > * > &  faces,
std::list< HEFace< T > * > &  group1,
std::list< HEFace< T > * > &  group2,
const Vector3< T > &  center,
const Vector3< T > &  direction 
) [inline, static, private]

Definition at line 1958 of file TAPsBVHTree_BinarySphere.cpp.

01964 {
01965     std::list< HEFace<T> * >::const_iterator face;
01966     for ( face = inputFaces.begin(); face != inputFaces.end(); ++face ) {
01967         if ( BSphereDetermineFaceGroup( *face, center, direction ) == 1 )
01968             group1.push_back( *face );
01969         else
01970             group2.push_back( *face );
01971     }
01972 }

template<typename T>
static BVHTree<T>* BVHTree_BinarySphere< T >::Build ( TransformationSupport< T > &  transform,
std::list< HEFace< T > * > const *const   heFaceList,
Enum::CD  treeType,
BVHTree< T > *  cdtree 
) [static]

O/P: pointer to BVHTree.

Parameters:
transform  I/O: Transform
heFaceList  I/P: half-edge face list
treeType  I/P: BVHTree type

template<typename T>
BVHNode< T > * BVHTree_BinarySphere< T >::CreateBVHNodeBSphere ( BVHNode< T > *  pParentNode,
const std::list< HEFace< T > * > &  heFaceList 
) [inline, static, private]

Definition at line 1978 of file TAPsBVHTree_BinarySphere.cpp.

01981 {
01982     //---------------------------------------------------------------
01983     Vector3<T> AABB[2];
01984     //HEVertex<T> * vertex = m_listVertex->Head();
01985     std::list< HEFace<T> * >::const_iterator face = heFaceList.begin();
01986     HEHalfEdge<T> * firstHalfEdge = (*face)->IncidentHalfEdge();
01987     HEHalfEdge<T> * halfEdge = firstHalfEdge;
01988     Vector3<T> vertex = halfEdge->Vertex()->GetPosition();
01989     AABB[0] = AABB[1] = vertex;
01990     //---------------------------------------------------------------
01991     // For Each Face
01992     for ( ; face != heFaceList.end(); ++face ) {
01993         halfEdge = firstHalfEdge = (*face)->IncidentHalfEdge();
01994         //-------------------------------------------------
01995         // For Each Vertex
01996         do {
01997             vertex = halfEdge->Vertex()->GetPosition();
01998             // Find the lowest an the highest of x, y, and z
01999             // AABB[0] is min and AABB[1] is max
02000             if      ( AABB[0][0] > vertex[0] )  AABB[0][0] = vertex[0];
02001             else if ( AABB[1][0] < vertex[0] )  AABB[1][0] = vertex[0];
02002             if      ( AABB[0][1] > vertex[1] )  AABB[0][1] = vertex[1];
02003             else if ( AABB[1][1] < vertex[1] )  AABB[1][1] = vertex[1];
02004             if      ( AABB[0][2] > vertex[2] )  AABB[0][2] = vertex[2];
02005             else if ( AABB[1][2] < vertex[2] )  AABB[1][2] = vertex[2];
02006             // Next vertex
02007             halfEdge = halfEdge->Next();
02008         } while ( halfEdge != firstHalfEdge );
02009     }
02010     //---------------------------------------------------------------
02011     // Find the bounding volume center from the AABB
02012     Vector3<T> vCenter( ( AABB[0][0] + AABB[1][0] ) / 2.0,
02013                         ( AABB[0][1] + AABB[1][1] ) / 2.0,
02014                         ( AABB[0][2] + AABB[1][2] ) / 2.0 );
02015     //---------------------------------------------------------------
02016     // Find the Sphere Bounding Volume
02017     T radius = 0, squaredLength;
02018     for ( face = heFaceList.begin(); face != heFaceList.end(); ++face ) {
02019         halfEdge = firstHalfEdge = (*face)->IncidentHalfEdge();
02020         //-------------------------------------------------
02021         do {
02022             vertex = halfEdge->Vertex()->GetPosition();
02023             //squaredLength = (vertex - vCenter).SquaredLength();
02024             squaredLength = (vertex - vCenter).Length();
02025             if ( squaredLength > radius )   radius = squaredLength;
02026             halfEdge = halfEdge->Next();
02027         } while ( halfEdge != firstHalfEdge );
02028     }
02029     //radius = sqrt( radius );
02030     //---------------------------------------------------------------
02031     // Make the root node
02032     //-------------------------------------------
02033     // BVHNode Constructor
02034     //   BVHNode<T>(    Enum::CD type,
02035     //                  int id, 
02036     //                  BVHNode<T> * parent, 
02037     //                  BVHNode<T> ** children )
02038     //-------------------------------------------
02039     //BVHNode<T> * node;
02040     if ( 1 == static_cast<int>( heFaceList.size() ) ) {
02041         /*
02042         node = new BVHNode<T>( Enum::BVH_NODE_BINARY_SPHERE, 
02043                                 -1, pParentNode, NULL );
02044         //*/
02045         //*
02046         BVHNodeLeafHalfEdgeAPrim<T> * node = new BVHNodeLeafHalfEdgeAPrim<T>( 
02047                 Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM, 
02048                 -1, pParentNode );
02049         node->m_primHEFace = heFaceList.front();
02050 //      BVHNodeLeafHalfEdgePrims<T> * node = new BVHNodeLeafHalfEdgePrims<T>( 
02051 //              Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS, 
02052 //              -1, pParentNode );
02053         //node->listHEFace = heFaceList;
02054         node->SetCenter( vCenter );
02055         node->SetRadius( radius );
02056         return node;
02057         //*/
02058     }
02059     else {
02060         BVHNode<T> * node = new BVHNode<T>( Enum::BVH_NODE_BINARY_SPHERE, 
02061                                             -1, pParentNode, NULL );
02062         node->SetCenter( vCenter );
02063         node->SetRadius( radius );
02064         return node;
02065     }
02066 }

template<typename T>
void BVHTree_BinarySphere< T >::ForBVCylinderTransformations ( Matrix4x4< T > const &  nodeTransform_IP,
BoundingVolume< T > const *const   pBV,
Matrix4x4< T > const &  bvTransformation,
Matrix4x4< T > &  nodeTransform_OP 
) [inline, protected]

Transform BV cylinder's center, radius, and height. Also find the transformation for the node.

Parameters:
nodeTransform_IP  I/P: node's transformation
pBV  I/P: cylinder bounding volume
bvTransformation  I/P: cylinder bounding volume's transformation
nodeTransform_OP  O/P: node's transformation

Definition at line 1079 of file TAPsBVHTree_BinarySphere.cpp.

01080                                                         : node's transformation
01081         BoundingVolume<T> const * const pBV,    //!< I/P: cylinder bounding volume
01082         Matrix4x4<T> const & bvTransformation,  //!< I/P: cylinder bounding volume's transformation
01083         Matrix4x4<T> & nodeTransform_OP         
01084 )
01085 {
01086     nodeTransform_OP = bvTransformation * Matrix4x4<T>( 1, 0, 0, pBV->GetCenter()[0], 
01087                                                         0, 1, 0, pBV->GetCenter()[1], 
01088                                                         0, 0, 1, pBV->GetCenter()[2], 
01089                                                         0, 0, 0, 1
01090                                                     );
01091     nodeTransform_OP = nodeTransform_OP.Inversed() * nodeTransform_IP;
01092 }

template<typename T>
void BVHTree_BinarySphere< T >::ForBVCylinderTransformations ( Matrix4x4< T > const &  nodeTransform_IP,
BoundingVolume< T > const *const   pBV,
Matrix4x4< T > &  nodeTransform_OP 
) [inline, protected]

Transform BV cylinder's center, radius, and height. Also find the transformation for the node.

Parameters:
nodeTransform_IP  I/P: node's transformation
pBV  I/P: cylinder bounding volume
nodeTransform_OP  O/P: node's transformation

Definition at line 1063 of file TAPsBVHTree_BinarySphere.cpp.

01064                                                         : node's transformation
01065         BoundingVolume<T> const * const pBV,    //!< I/P: cylinder bounding volume
01066         Matrix4x4<T> & nodeTransform_OP         //!< O/P: node's transformation
01067 )
01068 {
01069     nodeTransform_OP = Matrix4x4<T>(    1, 0, 0, -pBV->GetCenter()[0], 
01070                                         0, 1, 0, -pBV->GetCenter()[1], 
01071                                         0, 0, 1, -pBV->GetCenter()[2], 
01072                                         0, 0, 0, 1
01073                                     )
01074                     * nodeTransform_IP;
01075 }

template<typename T>
void BVHTree_BinarySphere< T >::ForBVCylinderTransformations ( BoundingVolume< T > const *const   pBV,
Matrix4x4< T > const &  bvTransformation,
Matrix4x4< T > &  nodeTransform_OP 
) [inline, protected]

Transform BV cylinder's center, radius, and height. Also find the transformation for the node.

Parameters:
pBV  I/P: cylinder bounding volume
bvTransformation  I/P: cylinder bounding volume's transformation
nodeTransform_OP  O/P: node's transformation

Definition at line 1047 of file TAPsBVHTree_BinarySphere.cpp.

01048                                                         : cylinder bounding volume
01049         Matrix4x4<T> const & bvTransformation,  
01050         Matrix4x4<T> & nodeTransform_OP         
01051 )
01052 {
01053     nodeTransform_OP = bvTransformation * Matrix4x4<T>( 1, 0, 0, pBV->GetCenter()[0], 
01054                                                         0, 1, 0, pBV->GetCenter()[1], 
01055                                                         0, 0, 1, pBV->GetCenter()[2], 
01056                                                         0, 0, 0, 1
01057                                                     );
01058     nodeTransform_OP.Inversed();
01059 }

template<typename T>
void BVHTree_BinarySphere< T >::ForBVCylinderTransformations ( BoundingVolume< T > const *const   pBV,
Matrix4x4< T > &  nodeTransform_OP 
) [inline, protected]

Transform BV cylinder's center, radius, and height. Also find the transformation for the node.

Parameters:
pBV  I/P: cylinder bounding volume
nodeTransform_OP  O/P: node's transformation

Definition at line 1033 of file TAPsBVHTree_BinarySphere.cpp.

01034                                                         : cylinder bounding volume
01035         Matrix4x4<T> & nodeTransform_OP         
01036 )
01037 {
01038     nodeTransform_OP = Matrix4x4<T>(    1, 0, 0, -pBV->GetCenter()[0], 
01039                                         0, 1, 0, -pBV->GetCenter()[1], 
01040                                         0, 0, 1, -pBV->GetCenter()[2], 
01041                                         0, 0, 0, 1
01042                                     );
01043 }

template<typename T>
void BVHTree_BinarySphere< T >::ForBVSphereTransformations ( BoundingVolume< T > const *const   pBV,
Matrix4x4< T > const &  bvTransformation,
Vector3< T > &  sphereCenter,
T &  sphereRadius 
) [inline, protected]

Transform BV sphere's center and radius.

Parameters:
pBV  I/P: sphere bounding volume
bvTransformation  I/P: sphere bounding volume's transformation
sphereCenter  O/P: sphere center
sphereRadius  O/P: sphere radius

Definition at line 995 of file TAPsBVHTree_BinarySphere.cpp.

00996                                                         : sphere bounding volume
00997         Matrix4x4<T> const & bvTransformation,  
00998         Vector3<T> & sphereCenter,              
00999         T & sphereRadius                        
01000 )
01001 {
01002     // Transform the pBV due to its transformation, center, and radius
01003     Vector3<T> C( pBV->GetCenter() );
01004     Matrix4x4<T> translation( 1, 0, 0, C[0], 
01005                               0, 1, 0, C[1],
01006                               0, 0, 1, C[2],
01007                               0, 0, 0, 1 );
01008     Vector3<T> S( pBV->GetRadius(), pBV->GetRadius(), pBV->GetRadius() );
01009     Matrix4x4<T> scale( S[0], 0,    0,    0, 
01010                         0,    S[1], 0,    0,
01011                         0,    0,    S[2], 0,
01012                         0,    0,    0,    1 );
01013     Matrix4x4<T> trx = bvTransformation * translation * scale;
01014 
01015     // Sphere's center and radius after the transformation
01016     sphereCenter = (trx * Vector4<T>(0,0,0,1)).GetVector3();
01017     sphereRadius = ( (trx * Vector4<T>(1,0,0,1)) - sphereCenter ).Length();
01018 
01019     /*
01020     // DEBUG
01021     std::cout << "(trx * Vector4<T>(S[0],0,0,1)): " << (trx * Vector4<T>(S[0],0,0,1)) << "\n";
01022 
01023     std::cout << "transformB: " << transformB;
01024     std::cout << "transformB * translation: " << transformB * translation;
01025     std::cout << "transformB * translation * scale: " << transformB * translation * scale;
01026     std::cout << "pBV: " << *pBV << "\n";
01027     std::cout << "Sphere: center " <<  sphereCenter << "; radius " << sphereRadius << "\n";
01028     //*/
01029 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestIntersectionWithLineSegmentTillLeafNodes ( Vector3< T > const *const   ptA,
Vector3< T > const *const   ptB 
) [inline, virtual]

Test intersection with a line segment (without primitive tests) The collided nodes of this BVH tree are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree.

Implements BVHTree< T >.

Definition at line 540 of file TAPsBVHTree_BinarySphere.cpp.

00542 {
00543     m_svCollidedNode.clear();
00544     return TestIntersectionWithLineSegmentTillLeafNodesRecursive( Root(), ptA, ptB );
00545 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestIntersectionWithLineSegmentTillLeafNodesRecursive ( BVHNode< T > const *const   node,
Vector3< T > const *const   ptA,
Vector3< T > const *const   ptB 
) [inline, protected]

< I/P: a point

< I/P: a line (start point)

< I/P: a line (end point)

< O/P: ratio

< O/P: q = p1 + ratio*(p1-p2)

< O/P: distance = |p - q|

Definition at line 548 of file TAPsBVHTree_BinarySphere.cpp.

00552 {
00553     // Need to add transformation of the node into the computation !!!
00554 
00555     T ratio, distance;
00556     Vector3<T> projPt;
00557     CGMath<T>::FindProjectedPointOnALine ( 
00558             node->GetCenter(),  
00559             *ptA,   
00560             *ptB,   
00561             ratio,      
00562             projPt,     
00563             distance    
00564     );
00565     //---------------------------------------------------------------
00566     // Test overlapping
00567     if ( distance > node->GetRadius() || ratio < 0 || 1 < ratio ) {
00568         return false;
00569     }
00570     //---------------------------------------------------------------
00571     // If node A is leaf
00572     else if ( node->IsLeaf() ) {
00573         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( node ) );
00574         return true;
00575     }
00576     //---------------------------------------------------------------
00577     // If node A is not leaf
00578     else {
00579         bool overlap1 = false, overlap2 = false;
00580         if ( node->Child(0) ) {
00581             overlap1 = TestIntersectionWithLineSegmentTillLeafNodesRecursive( node->Child(0), ptA, ptB );
00582         }
00583         if ( node->Child(1) ) {
00584             overlap2 = TestIntersectionWithLineSegmentTillLeafNodesRecursive( node->Child(1), ptA, ptB );
00585         }
00586         if ( overlap1 || overlap2 ) {
00587             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
00588                 const_cast< BVHNode<T> * >( node )->flag = true;
00589             #endif//TAPs_DEBUG_COLLISION_DETECTION
00590             return true;
00591         }
00592         else {
00593             return false;
00594         }
00595     }
00596 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BVHNode< T > const *const   nodeB,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 1415 of file TAPsBVHTree_BinarySphere.cpp.

01420 {
01421     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01422     std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BinarySphere( BVHNode<T>, Matrix4x4<T>, BVHNode<T>, Matrix4x4<T> )\n";
01423     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01424     std::cout << "\tCurrently call TestOverlap_vs_BinarySphere_TillLeafNodes( ... ) instead\n";
01425 
01426     bool bResult = TestOverlap_vs_BinarySphere_TillLeafNodes( nodeA, transformA, nodeB, transformB );
01427     if ( bResult ) {
01428         //-----------------------------------
01429         // Do Low-level Intersection Test HERE!
01430         //std::cout << "// Do Low-level Intersection Test HERE!\n";
01431         // E.g., Triangle-triangle intersection test
01432         //bResult = leaf node from nodeA->TestOverlapPrimitiveWithPrimitive( transformA, leaf node from nodeB, transformB );
01433     }
01434     return bResult;
01435 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BVHNode< T > const *const   nodeB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 1392 of file TAPsBVHTree_BinarySphere.cpp.

01396 {
01397     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01398     std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BinarySphere( BVHNode<T>, Matrix4x4<T>, BVHNode<T> )\n";
01399     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01400     std::cout << "\tCurrently call TestOverlap_vs_BinarySphere_TillLeafNodes( ... ) instead\n";
01401 
01402     bool bResult = TestOverlap_vs_BinarySphere_TillLeafNodes( nodeA, transformA, nodeB );
01403     if ( bResult ) {
01404         //-----------------------------------
01405         // Do Low-level Intersection Test HERE!
01406         //std::cout << "// Do Low-level Intersection Test HERE!\n";
01407         // E.g., Triangle-triangle intersection test
01408         //bResult = leaf node from nodeA->TestOverlapPrimitiveWithPrimitive( transformA, leaf node from nodeB );
01409     }
01410     return bResult;
01411 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere ( BVHNode< T > const *const   nodeA,
BVHNode< T > const *const   nodeB,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 1369 of file TAPsBVHTree_BinarySphere.cpp.

01373 {
01374     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01375     std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BinarySphere( BVHNode<T>, BVHNode<T>, Matrix4x4<T> )\n";
01376     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01377     std::cout << "\tCurrently call TestOverlap_vs_BinarySphere_TillLeafNodes( ... ) instead\n";
01378 
01379     bool bResult = TestOverlap_vs_BinarySphere_TillLeafNodes( nodeA, nodeB, transformB );
01380     if ( bResult ) {
01381         //-----------------------------------
01382         // Do Low-level Intersection Test HERE!
01383         //std::cout << "// Do Low-level Intersection Test HERE!\n";
01384         // E.g., Triangle-triangle intersection test
01385         //bResult = leaf node from nodeA->TestOverlapPrimitiveWithPrimitive( leaf node from nodeB, transformB );
01386     }
01387     return bResult;
01388 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere ( BVHNode< T > const *const   nodeA,
BVHNode< T > const *const   nodeB 
) [inline, protected, virtual]

Currently Both TestOverlap_vs_BinarySphere is the same as TestOverlap_vs_BinarySphere_TillLeafNodes. So TestOverlap_vs_BinarySphere need to be complete!!!

Test overlap of a BVH tree with another binary sphere tree with primitive-primitive intersection test.

Implements BVHTree< T >.

Definition at line 1347 of file TAPsBVHTree_BinarySphere.cpp.

01350 {
01351     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01352     std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BinarySphere( BVHNode<T>, BVHNode<T> )\n";
01353     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01354     std::cout << "\tCurrently call TestOverlap_vs_BinarySphere_TillLeafNodes( ... ) instead\n";
01355 
01356     bool bResult = TestOverlap_vs_BinarySphere_TillLeafNodes( nodeA, nodeB );
01357     if ( bResult ) {
01358         //-----------------------------------
01359         // Do Low-level Intersection Test HERE!
01360         //std::cout << "// Do Low-level Intersection Test HERE!\n";
01361         // E.g., Triangle-triangle intersection test
01362         //bResult = leaf node from nodeA->TestOverlapPrimitiveWithPrimitive( leaf node from nodeB );
01363     }
01364     return bResult;
01365 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere_TillLeafNodes ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BVHNode< T > const *const   nodeB,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 1715 of file TAPsBVHTree_BinarySphere.cpp.

01720 {
01721     //---------------------------------------------------------------
01722     // Test overlapping
01723     if ( nodeA->TestOverlapSphereWithSphere_TillLeafNodes( transformA, nodeB, transformB ) > Math<T>::ZERO ) {
01724         return false;
01725     }
01726     //---------------------------------------------------------------
01727     // If node A is leaf
01728     else if ( nodeA->IsLeaf() ) {
01729         //-------------------------------------------------
01730         // Both node A and node B are leaves
01731         if ( nodeB->IsLeaf() ) {
01732             //-----------------------------------
01733             // Do Low-level Intersection Test HERE!
01734             //std::cout << "// Do Low-level Intersection Test HERE!\n";
01735             //-----------------------------------
01736             //std::cout << "Distance (" << nodeA << "," << nodeB << "): " 
01737             //      << nodeA->TestOverlapSphereWithSphere_TillLeafNodes( nodeB ) << "\n";
01738             BVHNode<T> * nA = const_cast< BVHNode<T> * >( nodeA );
01739             BVHNode<T> * nB = const_cast< BVHNode<T> * >( nodeB );
01740             m_svCollidedNode.push_back( nA );
01741             m_svCollidedNodeThat.push_back( nB );
01742             //-----------------------------------
01743             return true;
01744         }
01745         //-------------------------------------------------
01746         // Node A is leaf, but node B is not
01747         else {
01748             bool overlap1 = false, overlap2 = false;
01749             if ( nodeB->Child(0) ) {
01750                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01751                                 nodeA, transformA, nodeB->Child(0), transformB );
01752             }
01753             if ( nodeB->Child(1) ) {
01754                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01755                                 nodeA, transformA, nodeB->Child(1), transformB );
01756             }
01757             if ( overlap1 || overlap2 ) return true;
01758             else                        return false;
01759         }
01760     }
01761     //---------------------------------------------------------------
01762     // If node A is not leaf
01763     else {
01764         //-------------------------------------------------
01765         // Node A is not leaf, but node B is
01766         if ( nodeB->IsLeaf() ) {
01767             bool overlap1 = false, overlap2 = false;
01768             if ( nodeA->Child(0) ) {
01769                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01770                                 nodeA->Child(0), transformA, nodeB, transformB );
01771             }
01772             if ( nodeA->Child(1) ) {
01773                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01774                                 nodeA->Child(1), transformA, nodeB, transformB );
01775             }
01776             if ( overlap1 || overlap2 ) return true;
01777             else                        return false;
01778         }
01779         //-------------------------------------------------
01780         // Both node A and node B are not leaves
01781         else {
01782             bool overlap1 = false, overlap2 = false, overlap3 = false, overlap4 = false;
01783             if ( nodeA->Child(0) && nodeB->Child(0) ) {
01784                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01785                                 nodeA->Child(0), transformA, nodeB->Child(0), transformB );
01786             }
01787             if ( nodeA->Child(0) && nodeB->Child(1) ) {
01788                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01789                                 nodeA->Child(0), transformA, nodeB->Child(1), transformB );
01790             }
01791             if ( nodeA->Child(1) && nodeB->Child(0) ) {
01792                 overlap3 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01793                                 nodeA->Child(1), transformA, nodeB->Child(0), transformB );
01794             }
01795             if ( nodeA->Child(1) && nodeB->Child(1) ) {
01796                 overlap4 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01797                                 nodeA->Child(1), transformA, nodeB->Child(1), transformB );
01798             }
01799             if ( overlap1 || overlap2 || overlap3 || overlap4 )
01800                 return true;
01801             else
01802                 return false;
01803         }
01804     }
01805     //---------------------------------------------------------------
01806 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere_TillLeafNodes ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BVHNode< T > const *const   nodeB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 1621 of file TAPsBVHTree_BinarySphere.cpp.

01625 {
01626     //---------------------------------------------------------------
01627     // Test overlapping
01628     if ( nodeA->TestOverlapSphereWithSphere_TillLeafNodes( transformA, nodeB ) > Math<T>::ZERO ) {
01629         return false;
01630     }
01631     //---------------------------------------------------------------
01632     // If node A is leaf
01633     else if ( nodeA->IsLeaf() ) {
01634         //-------------------------------------------------
01635         // Both node A and node B are leaves
01636         if ( nodeB->IsLeaf() ) {
01637             //-----------------------------------
01638             // Do Low-level Intersection Test HERE!
01639             //std::cout << "// Do Low-level Intersection Test HERE!\n";
01640             //-----------------------------------
01641             //std::cout << "Distance (" << nodeA << "," << nodeB << "): " 
01642             //      << nodeA->TestOverlapSphereWithSphere_TillLeafNodes( nodeB ) << "\n";
01643             BVHNode<T> * nA = const_cast< BVHNode<T> * >( nodeA );
01644             BVHNode<T> * nB = const_cast< BVHNode<T> * >( nodeB );
01645             m_svCollidedNode.push_back( nA );
01646             m_svCollidedNodeThat.push_back( nB );
01647             //-----------------------------------
01648             return true;
01649         }
01650         //-------------------------------------------------
01651         // Node A is leaf, but node B is not
01652         else {
01653             bool overlap1 = false, overlap2 = false;
01654             if ( nodeB->Child(0) ) {
01655                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01656                                 nodeA, transformA, nodeB->Child(0) );
01657             }
01658             if ( nodeB->Child(1) ) {
01659                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01660                                 nodeA, transformA, nodeB->Child(1) );
01661             }
01662             if ( overlap1 || overlap2 ) return true;
01663             else                        return false;
01664         }
01665     }
01666     //---------------------------------------------------------------
01667     // If node A is not leaf
01668     else {
01669         //-------------------------------------------------
01670         // Node A is not leaf, but node B is
01671         if ( nodeB->IsLeaf() ) {
01672             bool overlap1 = false, overlap2 = false;
01673             if ( nodeA->Child(0) ) {
01674                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01675                                 nodeA->Child(0), transformA, nodeB );
01676             }
01677             if ( nodeA->Child(1) ) {
01678                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01679                                 nodeA->Child(1), transformA, nodeB );
01680             }
01681             if ( overlap1 || overlap2 ) return true;
01682             else                        return false;
01683         }
01684         //-------------------------------------------------
01685         // Both node A and node B are not leaves
01686         else {
01687             bool overlap1 = false, overlap2 = false, overlap3 = false, overlap4 = false;
01688             if ( nodeA->Child(0) && nodeB->Child(0) ) {
01689                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01690                                 nodeA->Child(0), transformA, nodeB->Child(0) );
01691             }
01692             if ( nodeA->Child(0) && nodeB->Child(1) ) {
01693                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01694                                 nodeA->Child(0), transformA, nodeB->Child(1) );
01695             }
01696             if ( nodeA->Child(1) && nodeB->Child(0) ) {
01697                 overlap3 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01698                                 nodeA->Child(1), transformA, nodeB->Child(0) );
01699             }
01700             if ( nodeA->Child(1) && nodeB->Child(1) ) {
01701                 overlap4 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01702                                 nodeA->Child(1), transformA, nodeB->Child(1) );
01703             }
01704             if ( overlap1 || overlap2 || overlap3 || overlap4 )
01705                 return true;
01706             else
01707                 return false;
01708         }
01709     }
01710     //---------------------------------------------------------------
01711 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere_TillLeafNodes ( BVHNode< T > const *const   nodeA,
BVHNode< T > const *const   nodeB,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 1530 of file TAPsBVHTree_BinarySphere.cpp.

01534 {
01535     //---------------------------------------------------------------
01536     // Test overlapping
01537     if ( nodeA->TestOverlapSphereWithSphere_TillLeafNodes( nodeB, transformB ) > Math<T>::ZERO ) {
01538         return false;
01539     }
01540     //---------------------------------------------------------------
01541     // If node A is leaf
01542     else if ( nodeA->IsLeaf() ) {
01543         //-------------------------------------------------
01544         // Both node A and node B are leaves
01545         if ( nodeB->IsLeaf() ) {
01546             //-----------------------------------
01547             //std::cout << "Distance (" << nodeA << "," << nodeB << "): " 
01548             //      << nodeA->TestOverlapSphereWithSphere_TillLeafNodes( nodeB ) << "\n";
01549             BVHNode<T> * nA = const_cast< BVHNode<T> * >( nodeA );
01550             BVHNode<T> * nB = const_cast< BVHNode<T> * >( nodeB );
01551             m_svCollidedNode.push_back( nA );
01552             m_svCollidedNodeThat.push_back( nB );
01553             //-----------------------------------
01554             return true;
01555         }
01556         //-------------------------------------------------
01557         // Node A is leaf, but node B is not
01558         else {
01559             bool overlap1 = false, overlap2 = false;
01560             if ( nodeB->Child(0) ) {
01561                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01562                                 nodeA, nodeB->Child(0), transformB );
01563             }
01564             if ( nodeB->Child(1) ) {
01565                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01566                                 nodeA, nodeB->Child(1), transformB );
01567             }
01568             if ( overlap1 || overlap2 ) return true;
01569             else                        return false;
01570         }
01571     }
01572     //------------------------------------------------------------------
01573     // If node A is not leaf
01574     else {
01575         //-------------------------------------------------
01576         // Node A is not leaf, but node B is
01577         if ( nodeB->IsLeaf() ) {
01578             bool overlap1 = false, overlap2 = false;
01579             if ( nodeA->Child(0) ) {
01580                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01581                                 nodeA->Child(0), nodeB, transformB );
01582             }
01583             if ( nodeA->Child(1) ) {
01584                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01585                                 nodeA->Child(1), nodeB, transformB );
01586             }
01587             if ( overlap1 || overlap2 ) return true;
01588             else                        return false;
01589         }
01590         //-------------------------------------------------
01591         // Both node A and node B are not leaves
01592         else {
01593             bool overlap1 = false, overlap2 = false, overlap3 = false, overlap4 = false;
01594             if ( nodeA->Child(0) && nodeB->Child(0) ) {
01595                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01596                                 nodeA->Child(0), nodeB->Child(0), transformB );
01597             }
01598             if ( nodeA->Child(0) && nodeB->Child(1) ) {
01599                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01600                                 nodeA->Child(0), nodeB->Child(1), transformB );
01601             }
01602             if ( nodeA->Child(1) && nodeB->Child(0) ) {
01603                 overlap3 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01604                                 nodeA->Child(1), nodeB->Child(0), transformB );
01605             }
01606             if ( nodeA->Child(1) && nodeB->Child(1) ) {
01607                 overlap4 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01608                                 nodeA->Child(1), nodeB->Child(1), transformB );
01609             }
01610             if ( overlap1 || overlap2 || overlap3 || overlap4 )
01611                 return true;
01612             else
01613                 return false;
01614         }
01615     }
01616     //---------------------------------------------------------------
01617 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BinarySphere_TillLeafNodes ( BVHNode< T > const *const   nodeA,
BVHNode< T > const *const   nodeB 
) [inline, protected, virtual]

Test overlap of a BVH tree with another binary sphere tree without primitive-primitive intersection test. I.e., stop at leaf-leaf-node intersection test.

Implements BVHTree< T >.

Definition at line 1440 of file TAPsBVHTree_BinarySphere.cpp.

01443 {
01444     //---------------------------------------------------------------
01445     // Test overlapping
01446     if ( nodeA->TestOverlapSphereWithSphere_TillLeafNodes( nodeB ) > Math<T>::ZERO ) {
01447         return false;
01448     }
01449     //---------------------------------------------------------------
01450     // If node A is leaf
01451     else if ( nodeA->IsLeaf() ) {
01452         //-------------------------------------------------
01453         // Both node A and node B are leaves
01454         if ( nodeB->IsLeaf() ) {
01455             //-----------------------------------
01456             //std::cout << "Distance (" << nodeA << "," << nodeB << "): " 
01457             //      << nodeA->TestOverlapSphereWithSphere_TillLeafNodes( nodeB ) << "\n";
01458             BVHNode<T> * nA = const_cast< BVHNode<T> * >( nodeA );
01459             BVHNode<T> * nB = const_cast< BVHNode<T> * >( nodeB );
01460             m_svCollidedNode.push_back( nA );
01461             m_svCollidedNodeThat.push_back( nB );
01462             //-----------------------------------
01463             return true;
01464         }
01465         //-------------------------------------------------
01466         // Node A is leaf, but node B is not
01467         else {
01468             bool overlap1 = false, overlap2 = false;
01469             if ( nodeB->Child(0) ) {
01470                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01471                                 nodeA, nodeB->Child(0) );
01472             }
01473             if ( nodeB->Child(1) ) {
01474                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01475                                 nodeA, nodeB->Child(1) );
01476             }
01477             if ( overlap1 || overlap2 ) return true;
01478             else                        return false;
01479         }
01480     }
01481     //---------------------------------------------------------------
01482     // If node A is not leaf
01483     else {
01484         //-------------------------------------------------
01485         // Node A is not leaf, but node B is
01486         if ( nodeB->IsLeaf() ) {
01487             bool overlap1 = false, overlap2 = false;
01488             if ( nodeA->Child(0) ) {
01489                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01490                                 nodeA->Child(0), nodeB );
01491             }
01492             if ( nodeA->Child(1) ) {
01493                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01494                                 nodeA->Child(1), nodeB );
01495             }
01496             if ( overlap1 || overlap2 ) return true;
01497             else                        return false;
01498         }
01499         //-------------------------------------------------
01500         // Both node A and node B are not leaves
01501         else {
01502             bool overlap1 = false, overlap2 = false, overlap3 = false, overlap4 = false;
01503             if ( nodeA->Child(0) && nodeB->Child(0) ) {
01504                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01505                                 nodeA->Child(0), nodeB->Child(0) );
01506             }
01507             if ( nodeA->Child(0) && nodeB->Child(1) ) {
01508                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01509                                 nodeA->Child(0), nodeB->Child(1) );
01510             }
01511             if ( nodeA->Child(1) && nodeB->Child(0) ) {
01512                 overlap3 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01513                                 nodeA->Child(1), nodeB->Child(0) );
01514             }
01515             if ( nodeA->Child(1) && nodeB->Child(1) ) {
01516                 overlap4 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01517                                 nodeA->Child(1), nodeB->Child(1) );
01518             }
01519             if ( overlap1 || overlap2 || overlap3 || overlap4 )
01520                 return true;
01521             else
01522                 return false;
01523         }
01524     }
01525     //---------------------------------------------------------------
01526 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BoundingVolume< T > const *const   pBV,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 746 of file TAPsBVHTree_BinarySphere.cpp.

00751 {
00752     std::cout << "#4 BVHTree_BinarySphere<T>::TestOverlap_vs_BV( BVHNode<T>, Matrix4x4<T>, BoundingVolume<T>, Matrix4x4<T> )\n";
00753 
00754     //---------------------------------------------------------------
00755     switch ( pBV->GetType() ) {
00756         case Enum::BOUNDING_SPHERE:
00757             {
00758                 Vector3<T>  sphereCenter;
00759                 T           sphereRadius;
00760                 ForBVSphereTransformations( pBV, transformB, sphereCenter, sphereRadius );
00761 
00762                 // Collision Detection -- With Primitive-Primitive Test
00763                 return TestOverlap_vs_BV_Sphere( nodeA, transformA, sphereCenter, sphereRadius );
00764             }
00765             break;
00766         case Enum::BOUNDING_CYLINDER:
00767             {
00768                 Matrix4x4<T> nodeTransformation;
00769                 ForBVCylinderTransformations( transformA, pBV, transformB, nodeTransformation );
00770 
00771                 // Collision Detection -- With Primitive-Primitive Test
00772                 return TestOverlap_vs_BV_Cylinder_AtOrigin( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight()  );
00773             }
00774             break;
00775         case Enum::BOUNDING_BOX:
00776         case Enum::BOUNDING_ELLIPSOID:
00777         case Enum::BOUNDING_HALF_SPHERE:
00778         case Enum::BOUNDING_HALF_ELLIPSOID:
00779         case Enum::BOUNDING_CONE:
00780         case Enum::BOUNDING_CAPSULE:
00781         case Enum::BOUNDING_POLYTOPE:
00782             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 104)" << std::endl;
00783             break;
00784         default:
00785             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV Fn!" << std::endl;
00786             assert( false );
00787             break;
00788     }
00789     //---------------------------------------------------------------
00790     return false;
00791 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BoundingVolume< T > const *const   pBV 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 705 of file TAPsBVHTree_BinarySphere.cpp.

00709 {
00710     std::cout << "#3 BVHTree_BinarySphere<T>::TestOverlap_vs_BV( BVHNode<T>, Matrix4x4<T>, BoundingVolume<T> )\n";
00711 
00712     //---------------------------------------------------------------
00713     switch ( pBV->GetType() ) {
00714         case Enum::BOUNDING_SPHERE:
00715             return TestOverlap_vs_BV_Sphere( nodeA, transformA, pBV->GetCenter(), pBV->GetRadius() );
00716             break;
00717         case Enum::BOUNDING_CYLINDER:
00718             {
00719                 Matrix4x4<T> nodeTransformation;
00720                 ForBVCylinderTransformations( transformA, pBV, nodeTransformation );
00721 
00722                 // Collision Detection -- With Primitive-Primitive Test
00723                 return TestOverlap_vs_BV_Cylinder_AtOrigin( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00724             }
00725             break;
00726         case Enum::BOUNDING_BOX:
00727         case Enum::BOUNDING_ELLIPSOID:
00728         case Enum::BOUNDING_HALF_SPHERE:
00729         case Enum::BOUNDING_HALF_ELLIPSOID:
00730         case Enum::BOUNDING_CONE:
00731         case Enum::BOUNDING_CAPSULE:
00732         case Enum::BOUNDING_POLYTOPE:
00733             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 103)" << std::endl;
00734             break;
00735         default:
00736             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV Fn!" << std::endl;
00737             assert( false );
00738             break;
00739     }
00740     //---------------------------------------------------------------
00741     return false;
00742 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV ( BVHNode< T > const *const   nodeA,
BoundingVolume< T > const *const   pBV,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 657 of file TAPsBVHTree_BinarySphere.cpp.

00661 {
00662     std::cout << "#2 BVHTree_BinarySphere<T>::TestOverlap_vs_BV( BVHNode<T>, BoundingVolume<T>, Matrix4x4<T> )\n";
00663 
00664     //---------------------------------------------------------------
00665     switch ( pBV->GetType() ) {
00666         case Enum::BOUNDING_SPHERE:
00667             {
00668                 Vector3<T>  sphereCenter;
00669                 T           sphereRadius;
00670                 ForBVSphereTransformations( pBV, transformB, sphereCenter, sphereRadius );
00671 
00672                 // Collision Detection -- With Primitive-Primitive Test
00673                 return TestOverlap_vs_BV_Sphere( nodeA, sphereCenter, sphereRadius );
00674             }
00675             break;
00676         case Enum::BOUNDING_CYLINDER:
00677             {
00678                 Matrix4x4<T> nodeTransformation;
00679                 ForBVCylinderTransformations( pBV, transformB, nodeTransformation );
00680 
00681                 // Collision Detection -- With Primitive-Primitive Test
00682                 return TestOverlap_vs_BV_Cylinder_AtOrigin( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00683             }
00684             break;
00685         case Enum::BOUNDING_BOX:
00686         case Enum::BOUNDING_ELLIPSOID:
00687         case Enum::BOUNDING_HALF_SPHERE:
00688         case Enum::BOUNDING_HALF_ELLIPSOID:
00689         case Enum::BOUNDING_CONE:
00690         case Enum::BOUNDING_CAPSULE:
00691         case Enum::BOUNDING_POLYTOPE:
00692             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 102)" << std::endl;
00693             break;
00694         default:
00695             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV Fn!" << std::endl;
00696             assert( false );
00697             break;
00698     }
00699     //---------------------------------------------------------------
00700     return false;
00701 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV ( BVHNode< T > const *const   nodeA,
BoundingVolume< T > const *const   pBV 
) [inline, protected, virtual]

Currently Both TestOverlap_vs_BV is the same as TestOverlap_vs_BV_TillLeafNodes. So TestOverlap_vs_BV need to be complete!!!

Test overlap of a binary sphere tree with a bounding volume with primitive-primitive intersection test.

Implements BVHTree< T >.

Definition at line 617 of file TAPsBVHTree_BinarySphere.cpp.

00620 {
00621     std::cout << "#1 BVHTree_BinarySphere<T>::TestOverlap_vs_BV( BVHNode<T>, BoundingVolume<T> )\n";
00622 
00623     //---------------------------------------------------------------
00624     switch ( pBV->GetType() ) {
00625         case Enum::BOUNDING_SPHERE:
00626             return TestOverlap_vs_BV_Sphere( nodeA, pBV->GetCenter(), pBV->GetRadius() );
00627             break;
00628         case Enum::BOUNDING_CYLINDER:
00629             {
00630                 Matrix4x4<T> nodeTransformation;
00631                 ForBVCylinderTransformations( pBV, nodeTransformation );
00632 
00633                 // Collision Detection -- With Primitive-Primitive Test
00634                 return TestOverlap_vs_BV_Cylinder_AtOrigin( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00635             }
00636             break;
00637         case Enum::BOUNDING_BOX:
00638         case Enum::BOUNDING_ELLIPSOID:
00639         case Enum::BOUNDING_HALF_SPHERE:
00640         case Enum::BOUNDING_HALF_ELLIPSOID:
00641         case Enum::BOUNDING_CONE:
00642         case Enum::BOUNDING_CAPSULE:
00643         case Enum::BOUNDING_POLYTOPE:
00644             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 101)" << std::endl;
00645             break;
00646         default:
00647             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV Fn!" << std::endl;
00648             assert( false );
00649             break;
00650     }
00651     //---------------------------------------------------------------
00652     return false;
00653 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_Cylinder_AtOrigin ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
cylinderRadius,
cylinderHeight 
) [inline, protected]

Remark:
Assume an existing transformB is already applied to cylinderCenter, cylinderRadius, and cylinderHeight

Definition at line 1257 of file TAPsBVHTree_BinarySphere.cpp.

01262 {
01263     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01264     std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Cylinder_AtOrigin( BVHNode<T>, Matrix4x4<T>, cylinderRadius, cylinderHeight )\n";
01265     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01266     std::cout << "\tCurrently call TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( ... ) instead\n";
01267 
01268     return TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, transformA, cylinderRadius, cylinderHeight );
01269 
01270     //---------------------------------------------------------------
01271     // Do low level here!!!
01272     //---------------------------------------------------------------
01273 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
cylinderRadius,
cylinderHeight 
) [inline, protected]

Remark:
Assume an existing transformB is already applied to cylinderCenter, cylinderRadius, and cylinderHeight

Definition at line 1286 of file TAPsBVHTree_BinarySphere.cpp.

01291 {
01292     //std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Cylinder_TillLeafNodes( BVHNode<T>, Matrix4x4<T>, cylinderRadius, cylinderHeight )\n";
01293 
01294     //---------------------------------------------------------------
01295     // Test overlapping
01296     if ( nodeA->TestOverlapSphereWithBVCylinder_AtOrigin_TillLeafNodes( transformA, cylinderRadius, cylinderHeight ) == false ) {
01297         return false;
01298     }
01299     //---------------------------------------------------------------
01300     // If node A is leaf
01301     else if ( nodeA->IsLeaf() ) {
01302         #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01303             const_cast< BVHNode<T> * >( nodeA )->flag = true;
01304         #endif//TAPs_DEBUG_COLLISION_DETECTION
01305         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( nodeA ) );
01306         //std::cout << "\tTRUE -- nodeA: " << nodeA << "\n";
01307         return true;
01308     }
01309     //---------------------------------------------------------------
01310     // If node A is not leaf
01311     else {
01312         bool overlap1 = false, overlap2 = false;
01313         if ( nodeA->Child(0) ) {
01314             overlap1 = TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA->Child(0), transformA, cylinderRadius, cylinderHeight );
01315         }
01316         if ( nodeA->Child(1) ) {
01317             overlap2 = TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA->Child(1), transformA, cylinderRadius, cylinderHeight );
01318         }
01319         if ( overlap1 || overlap2 ) {
01320             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01321                 const_cast< BVHNode<T> * >( nodeA )->flag = true;
01322             #endif//TAPs_DEBUG_COLLISION_DETECTION
01323             return true;
01324         }
01325         else {
01326             return false;
01327         }
01328     }
01329     //---------------------------------------------------------------
01330 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_Sphere ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
Vector3< T > const &  sphereCenter,
sphereRadius 
) [inline, protected]

Definition at line 1124 of file TAPsBVHTree_BinarySphere.cpp.

01129 {
01130     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01131     std::cout << "#2 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere( BVHNode<T>, Matrix4x4<T>, Vector3<T>, sphereCenter, sphereRadius )\n";
01132     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01133     std::cout << "\tCurrently call TestOverlap_vs_BV_Sphere_TillLeafNodes( ... ) instead\n";
01134 
01135     return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, transformA, sphereCenter, sphereRadius );
01136 
01137     //---------------------------------------------------------------
01138     // Do low level here!!!
01139     //---------------------------------------------------------------
01140 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_Sphere ( BVHNode< T > const *const   nodeA,
Vector3< T > const &  sphereCenter,
sphereRadius 
) [inline, protected]

Remark: existing transformB is already applied to sphereCenter and sphereRadius.

Definition at line 1105 of file TAPsBVHTree_BinarySphere.cpp.

01109 {
01110     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01111     std::cout << "#1 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere( BVHNode<T>, Vector3<T>, T )\n";
01112     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01113     std::cout << "\tCurrently call TestOverlap_vs_BV_Sphere_TillLeafNodes( ... ) instead\n";
01114 
01115     return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, sphereCenter, sphereRadius );
01116 
01117     //---------------------------------------------------------------
01118     // Do low level here!!!
01119     //---------------------------------------------------------------
01120 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_Sphere_TillLeafNodes ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
Vector3< T > const &  sphereCenter,
sphereRadius 
) [inline, protected]

Definition at line 1200 of file TAPsBVHTree_BinarySphere.cpp.

01205 {
01206     //std::cout << "#2 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere_TillLeafNodes( BVHNode<T>, Matrix4x4<T>, Vector3<T>, T )\n";
01207     //---------------------------------------------------------------
01208     // Test overlapping
01209     if ( nodeA->TestOverlapSphereWithBVSphere_TillLeafNodes( transformA, sphereCenter, sphereRadius ) > Math<T>::ZERO ) {
01210         return false;
01211     }
01212     //---------------------------------------------------------------
01213     // If node A is leaf
01214     else if ( nodeA->IsLeaf() ) {
01215         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( nodeA ) );
01216         //std::cout << "\tTRUE -- nodeA: " << nodeA << "\n";
01217         #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01218             const_cast< BVHNode<T> * >( nodeA )->flag = true;
01219         #endif//TAPs_DEBUG_COLLISION_DETECTION
01220         return true;
01221     }
01222     //---------------------------------------------------------------
01223     // If node A is not leaf
01224     else {
01225         bool overlap1 = false, overlap2 = false;
01226         if ( nodeA->Child(0) ) {
01227             overlap1 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(0), transformA, sphereCenter, sphereRadius );
01228         }
01229         if ( nodeA->Child(1) ) {
01230             overlap2 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(1), transformA, sphereCenter, sphereRadius );
01231         }
01232         if ( overlap1 || overlap2 ) {
01233             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01234                 const_cast< BVHNode<T> * >( nodeA )->flag = true;
01235             #endif//TAPs_DEBUG_COLLISION_DETECTION
01236             return true;
01237         }
01238         else {
01239             return false;
01240         }
01241     }
01242     //---------------------------------------------------------------
01243 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_Sphere_TillLeafNodes ( BVHNode< T > const *const   nodeA,
Vector3< T > const &  sphereCenter,
sphereRadius 
) [inline, protected]

Remark: existing transformB is already applied to sphereCenter and sphereRadius.

Definition at line 1153 of file TAPsBVHTree_BinarySphere.cpp.

01157 {
01158     //std::cout << "#1 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere_TillLeafNodes( BVHNode<T>, Vector3<T>, T )\n";
01159 
01160     //---------------------------------------------------------------
01161     // Test overlapping
01162     if ( nodeA->TestOverlapSphereWithBVSphere_TillLeafNodes( sphereCenter, sphereRadius ) > Math<T>::ZERO ) {
01163         return false;
01164     }
01165     //---------------------------------------------------------------
01166     // If node A is leaf
01167     if ( nodeA->IsLeaf() ) {
01168         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( nodeA ) );
01169         //std::cout << "\tTRUE -- nodeA: " << nodeA << "\n";
01170         #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01171             const_cast< BVHNode<T> * >( nodeA )->flag = true;
01172         #endif//TAPs_DEBUG_COLLISION_DETECTION
01173         return true;
01174     }
01175     //---------------------------------------------------------------
01176     // If node A is not leaf
01177     else {
01178         bool overlap1 = false, overlap2 = false;
01179         if ( nodeA->Child(0) ) {
01180             overlap1 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(0), sphereCenter, sphereRadius );
01181         }
01182         if ( nodeA->Child(1) ) {
01183             overlap2 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(1), sphereCenter, sphereRadius );
01184         }
01185         if ( overlap1 || overlap2 ) {
01186             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01187                 const_cast< BVHNode<T> * >( nodeA )->flag = true;
01188             #endif//TAPs_DEBUG_COLLISION_DETECTION
01189             return true;
01190         }
01191         else {
01192             return false;
01193         }
01194     }
01195     //---------------------------------------------------------------
01196 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_TillLeafNodes ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BoundingVolume< T > const *const   pBV,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 939 of file TAPsBVHTree_BinarySphere.cpp.

00944 {
00945     // TEST PASSED
00946     //std::cout << "#4 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes( BVHNode<T>, Matrix4x4<T>, BoundingVolume<T>, Matrix4x4<T> )\n";
00947 
00948     //---------------------------------------------------------------
00949     switch ( pBV->GetType() ) {
00950         case Enum::BOUNDING_SPHERE:
00951             {
00952                 Vector3<T>  sphereCenter;
00953                 T           sphereRadius;
00954                 ForBVSphereTransformations( pBV, transformB, sphereCenter, sphereRadius );
00955 
00956                 // Collision Detection -- W/O Primitive-Primitive Test
00957                 return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, transformA, sphereCenter, sphereRadius );
00958             }
00959             break;
00960         case Enum::BOUNDING_CYLINDER:
00961             {
00962                 Matrix4x4<T> nodeTransformation;
00963                 ForBVCylinderTransformations( transformA, pBV, transformB, nodeTransformation );
00964 
00965                 // Collision Detection -- W/O Primitive-Primitive Test
00966                 return TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00967             }
00968             break;
00969         case Enum::BOUNDING_BOX:
00970         case Enum::BOUNDING_ELLIPSOID:
00971         case Enum::BOUNDING_HALF_SPHERE:
00972         case Enum::BOUNDING_HALF_ELLIPSOID:
00973         case Enum::BOUNDING_CONE:
00974         case Enum::BOUNDING_CAPSULE:
00975         case Enum::BOUNDING_POLYTOPE:
00976             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 204)" << std::endl;
00977             break;
00978         default:
00979             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes Fn!" << std::endl;
00980             assert( false );
00981             break;
00982     }
00983     //---------------------------------------------------------------
00984     return false;
00985 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_TillLeafNodes ( BVHNode< T > const *const   nodeA,
Matrix4x4< T > const &  transformA,
BoundingVolume< T > const *const   pBV 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 898 of file TAPsBVHTree_BinarySphere.cpp.

00902 {
00903     std::cout << "#3 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes( BVHNode<T>, Matrix4x4<T>, BoundingVolume<T> )\n";
00904 
00905     //---------------------------------------------------------------
00906     switch ( pBV->GetType() ) {
00907         case Enum::BOUNDING_SPHERE:
00908             return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, transformA, pBV->GetCenter(), pBV->GetRadius() );
00909             break;
00910         case Enum::BOUNDING_CYLINDER:
00911             {
00912                 Matrix4x4<T> nodeTransformation;
00913                 ForBVCylinderTransformations( transformA, pBV, nodeTransformation );
00914 
00915                 // Collision Detection -- W/O Primitive-Primitive Test
00916                 return TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00917             }
00918             break;
00919         case Enum::BOUNDING_BOX:
00920         case Enum::BOUNDING_ELLIPSOID:
00921         case Enum::BOUNDING_HALF_SPHERE:
00922         case Enum::BOUNDING_HALF_ELLIPSOID:
00923         case Enum::BOUNDING_CONE:
00924         case Enum::BOUNDING_CAPSULE:
00925         case Enum::BOUNDING_POLYTOPE:
00926             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 203)" << std::endl;
00927             break;
00928         default:
00929             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes Fn!" << std::endl;
00930             assert( false );
00931             break;
00932     }
00933     //---------------------------------------------------------------
00934     return false;
00935 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_TillLeafNodes ( BVHNode< T > const *const   nodeA,
BoundingVolume< T > const *const   pBV,
Matrix4x4< T > const &  transformB 
) [inline, protected, virtual]

Implements BVHTree< T >.

Definition at line 840 of file TAPsBVHTree_BinarySphere.cpp.

00844 {
00845     //std::cout << "#2 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes( BVHNode<T>, BoundingVolume<T>, Matrix4x4<T> )\n";
00846 
00847     //std::cout << "Matrix4x4<T>: " << transformB;
00848 
00849     //---------------------------------------------------------------
00850     switch ( pBV->GetType() ) {
00851         case Enum::BOUNDING_SPHERE:
00852             {
00853                 Vector3<T>  sphereCenter;
00854                 T           sphereRadius;
00855                 ForBVSphereTransformations( pBV, transformB, sphereCenter, sphereRadius );
00856 
00857                 //std::cout << "\tCall TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, sphereCenter, sphereRadius );\n";
00858 
00859                 // Collision Detection -- W/O Primitive-Primitive Test
00860                 return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, sphereCenter, sphereRadius );
00861             }
00862             break;
00863         case Enum::BOUNDING_CYLINDER:
00864             {
00865                 Matrix4x4<T> nodeTransformation;
00866                 ForBVCylinderTransformations( pBV, transformB, nodeTransformation );
00867 
00868                 //std::cout << "Inv: " << nodeTransformation;
00869 
00870                 //std::cout << "\tCall TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );\n";
00871                 //std::cout << "pBV->GetName(): " << pBV->GetName() << "\n";
00872 
00873                 // Collision Detection -- W/O Primitive-Primitive Test
00874                 return TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00875 
00876             }
00877             break;
00878         case Enum::BOUNDING_BOX:
00879         case Enum::BOUNDING_ELLIPSOID:
00880         case Enum::BOUNDING_HALF_SPHERE:
00881         case Enum::BOUNDING_HALF_ELLIPSOID:
00882         case Enum::BOUNDING_CONE:
00883         case Enum::BOUNDING_CAPSULE:
00884         case Enum::BOUNDING_POLYTOPE:
00885             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 202)" << std::endl;
00886             break;
00887         default:
00888             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes Fn!" << std::endl;
00889             assert( false );
00890             break;
00891     }
00892     //---------------------------------------------------------------
00893     return false;
00894 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlap_vs_BV_TillLeafNodes ( BVHNode< T > const *const   nodeA,
BoundingVolume< T > const *const   pBV 
) [inline, protected, virtual]

Test overlap of a binary sphere tree with a bounding volume without primitive-primitive intersection test. I.e., stop at leaf-leaf-node intersection test.

Implements BVHTree< T >.

Definition at line 800 of file TAPsBVHTree_BinarySphere.cpp.

00803 {
00804     std::cout << "#1 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes( BVHNode<T>, BoundingVolume<T> )\n";
00805 
00806     //---------------------------------------------------------------
00807     switch ( pBV->GetType() ) {
00808         case Enum::BOUNDING_SPHERE:
00809             return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, pBV->GetCenter(), pBV->GetRadius() );
00810             break;
00811         case Enum::BOUNDING_CYLINDER:
00812             {
00813                 Matrix4x4<T> nodeTransformation;
00814                 ForBVCylinderTransformations( pBV, nodeTransformation );
00815 
00816                 // Collision Detection -- W/O Primitive-Primitive Test
00817                 return TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00818             }
00819             break;
00820         case Enum::BOUNDING_BOX:
00821         case Enum::BOUNDING_ELLIPSOID:
00822         case Enum::BOUNDING_HALF_SPHERE:
00823         case Enum::BOUNDING_HALF_ELLIPSOID:
00824         case Enum::BOUNDING_CONE:
00825         case Enum::BOUNDING_CAPSULE:
00826         case Enum::BOUNDING_POLYTOPE:
00827             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 201)" << std::endl;
00828             break;
00829         default:
00830             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes Fn!" << std::endl;
00831             assert( false );
00832             break;
00833     }
00834     //---------------------------------------------------------------
00835     return false;
00836 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWith ( BoundingVolume< T > const *const   pBV  )  [inline, virtual]

Test overlap with a Bounding Volume object (with primitive tests) The collided nodes of this BVH tree are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree.

Implements BVHTree< T >.

Definition at line 249 of file TAPsBVHTree_BinarySphere.cpp.

00250 {
00251     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00252     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWith( BoundingVolume<T> const * const " << pBV << " )\n";
00253     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00254 
00255     // After finish the content in m_svCollidedNodeThat will be moved into m_svCollidedNode.
00256     // m_svCollidedNode must be priorly cleared by a caller function.
00257 
00258     m_svCollidedNode.clear();
00259     //m_svCollidedNodeThat.clear();
00260     // m_svCollidedBVAndNodeList is not cleared, so that this fn can be used for overlap test with MBV.
00261 
00262     int val = pBV->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00263     val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00264     bool bResult = false;
00265     switch ( val ) {
00266         case 0:
00267             bResult = TestOverlap_vs_BV( m_pRoot, pBV );
00268             break;
00269         case 1:
00270             bResult = TestOverlap_vs_BV( m_pRoot, pBV, pBV->GetTransform().GetMatrixTransform() );
00271             break;
00272         case 2:
00273             bResult = TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), pBV );
00274             break;
00275         case 3:
00276             bResult = TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), pBV, pBV->GetTransform().GetMatrixTransform() );
00277             break;
00278     }
00279     //---------------------------------------------------------------
00280     //if ( bResult ) {
00281     //  m_svCollidedNode = m_svCollidedNodeThat;
00282     //}
00283     //---------------------------------------------------------------
00284     return bResult;
00285 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWith ( MultiBoundingVolume< T > const *const   pMBV  )  [inline, virtual]

Test overlap with a Multi Bounding Volume object (with primitive tests) The collided nodes of this BVH tree and the collided bounding volume of the multi bounding volume are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree. Call GetListOfCollidedBoundingVolume() to get the collided bounding volumes of the MultiBoundingVolume object.

Implements BVHTree< T >.

Definition at line 149 of file TAPsBVHTree_BinarySphere.cpp.

00150 {
00151     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00152     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWith( MultiBoundingVolume<T> const * const " << pMBV << " )\n";
00153     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00154 
00155     m_svCollidedNode.clear();
00156     //m_svCollidedNodeThat.clear();
00157     m_svCollidedBVAndNodeList.clear();
00158 
00159     bool bResult = false;
00160     //---------------------------------------------------------------
00161     // Traverse the list of bounding volumes
00162     std::vector< BoundingVolume<T> * >::iterator pos = const_cast< MultiBoundingVolume<T> * >( pMBV )->GetBoundingVolumeList().begin();
00163     if ( pMBV->GetTransform().GetStatusApplyTransformation() ) {
00164         // The multi bounding volume's transformation is on.
00165         while ( pos != pMBV->GetBoundingVolumeList().end() ) {
00166             assert( *pos != NULL );
00167             // Store the transformation of the bounding volume
00168             TransformationSupport<T> trx = (*pos)->GetTransform();
00169             (*pos)->GetTransform().EnableStatusApplyTransformation();
00170             (*pos)->GetTransform().SetMatrixTransform( pMBV->GetTransform().GetMatrixTransform() * trx.GetMatrixTransform() );
00171             // Collision Detection
00172             int val = (*pos)->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00173             val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00174             bool result = false;
00175             switch ( val ) {
00176                 case 0:
00177                     result = TestOverlap_vs_BV( m_pRoot, *pos );
00178                     break;
00179                 case 1:
00180                     result = TestOverlap_vs_BV( m_pRoot, *pos, (*pos)->GetTransform().GetMatrixTransform() );
00181                     break;
00182                 case 2:
00183                     result = TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), *pos );
00184                     break;
00185                 case 3:
00186                     result = TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), *pos, (*pos)->GetTransform().GetMatrixTransform() );
00187                     break;
00188             }
00189             // Restore the transformation of the bounding volume
00190             (*pos)->GetTransform().SetMatrixTransform( trx.GetMatrixTransform() );
00191             // Set result and keep records
00192             if ( result ) {
00193                 bResult = true;
00194                 //for ( int i = 0; i < static_cast<int>( m_svCollidedNodeThat.size() ); ++i ) {
00195                 //  m_svCollidedNode.push_back( m_svCollidedNodeThat[i] );
00196                 //  m_svCollidedBVList.push_back( *pos );
00197                 //}
00198                 m_svCollidedBVAndNodeList.push_back( BVsAndNodesList<T>( *pos, m_svCollidedNode ) );
00199             }
00200             // Next Bounding Volume
00201             ++pos;
00202 
00203             //pos = const_cast< MultiBoundingVolume<T> * >( pMBV )->GetBoundingVolumeList().end();
00204         }
00205     }
00206     else {
00207         // The multi bounding volume's transformation is off.
00208         while ( pos != pMBV->GetBoundingVolumeList().end() ) {
00209             assert( *pos != NULL );
00210             // Collision Detection
00211             int val = (*pos)->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00212             val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00213             bool result = false;
00214             switch ( val ) {
00215                 case 0:
00216                     result = TestOverlap_vs_BV( m_pRoot, *pos );
00217                     break;
00218                 case 1:
00219                     result = TestOverlap_vs_BV( m_pRoot, *pos, (*pos)->GetTransform().GetMatrixTransform() );
00220                     break;
00221                 case 2:
00222                     result = TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), *pos );
00223                     break;
00224                 case 3:
00225                     result = TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), *pos, (*pos)->GetTransform().GetMatrixTransform() );
00226                     break;
00227             }
00228             // Set result and keep records
00229             if ( result ) {
00230                 bResult = true;
00231                 //for ( int i = 0; i < static_cast<int>( m_svCollidedNodeThat.size() ); ++i ) {
00232                 //  m_svCollidedNode.push_back( m_svCollidedNodeThat[i] );
00233                 //  m_svCollidedBVList.push_back( *pos );
00234                 //}
00235                 m_svCollidedBVAndNodeList.push_back( BVsAndNodesList<T>( *pos, m_svCollidedNode ) );
00236             }
00237             // Next Bounding Volume
00238             ++pos;
00239 
00240             //pos = const_cast< MultiBoundingVolume<T> * >( pMBV )->GetBoundingVolumeList().end();
00241         }
00242     }
00243     //---------------------------------------------------------------
00244     return bResult;
00245 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWith ( BVHNode< T > const *const   node  )  [inline, virtual]

Test overlap with a BVH node (with primitive tests) The collided nodes of this BVH tree are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree.

Implements BVHTree< T >.

Definition at line 121 of file TAPsBVHTree_BinarySphere.cpp.

00122 {
00123     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00124     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWith( BVHNode<T> const * const " << node << " )\n";
00125     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00126     std::cout << "\tNOT IMPLEMENTED YET!\n";
00127 
00128     m_svCollidedNode.clear();
00129     m_svCollidedNodeThat.clear();
00130     //---------------------------------------------------------------
00131     switch ( node->GetType() ) {
00132         case Enum::BVH_NODE_BINARY_SPHERE:
00133         case Enum::BVH_NODE_QUAD_SPHERE:
00134         case Enum::BVH_NODE_OCTANT_SPHERE:
00135         case Enum::BVH_NODE_GENERIC_SPHERE:
00136             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 004)" << std::endl;
00137             break;
00138         default:
00139             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlapWith Fn!" << std::endl;
00140             assert( false );
00141             break;
00142     }
00143     //---------------------------------------------------------------
00144     return false;
00145 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWith ( BVHTree< T > const *const   that  )  [inline, virtual]

Test overlap with another BVH tree (with primitive tests) The collided nodes of both BVH trees are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree. Call GetListOfCollidedNodesThat() to get the collided nodes of the other BVH tree.

Implements BVHTree< T >.

Definition at line 65 of file TAPsBVHTree_BinarySphere.cpp.

00066 {
00067     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00068     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWith( BVHTree<T> const * const " << that << " )\n";
00069     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00070 
00071     m_svCollidedNode.clear();
00072     m_svCollidedNodeThat.clear();
00073 
00074     int val = that->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00075     val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00076 
00077     //---------------------------------------------------------------
00078     switch ( that->GetType() ) {
00079         case Enum::BVH_TREE_BINARY_SPHERE:
00080             switch ( val ) {
00081                 case 0:
00082                     return TestOverlap_vs_BinarySphere( 
00083                                 m_pRoot, 
00084                                 that->Root() );
00085                     break;
00086                 case 1:
00087                     return TestOverlap_vs_BinarySphere( 
00088                                 m_pRoot, 
00089                                 that->Root(), that->GetTransform().GetMatrixTransform() );
00090                     break;
00091                 case 2:
00092                     return TestOverlap_vs_BinarySphere( 
00093                                 m_pRoot, GetTransform().GetMatrixTransform(), 
00094                                 that->Root() );
00095                     break;
00096                 case 3:
00097                     return TestOverlap_vs_BinarySphere( 
00098                                 m_pRoot, GetTransform().GetMatrixTransform(), 
00099                                 that->Root(), that->GetTransform().GetMatrixTransform() );
00100                     break;
00101             }
00102             break;
00103 
00104         case Enum::BVH_TREE_QUAD_SPHERE:
00105         case Enum::BVH_TREE_OCTANT_SPHERE:
00106         case Enum::BVH_TREE_GENERIC_SPHERE:
00107             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 002)" << std::endl;
00108             break;
00109 
00110         default:
00111             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlapWith Fn!" << std::endl;
00112             assert( false );
00113             break;
00114     }
00115     //---------------------------------------------------------------
00116     return false;
00117 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWithTillLeafNodes ( BoundingVolume< T > const *const   pBV  )  [inline, virtual]

Test overlap with a Bounding Volume object (without primitive tests) The collided nodes of this BVH tree are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree.

Implements BVHTree< T >.

Definition at line 494 of file TAPsBVHTree_BinarySphere.cpp.

00495 {
00496     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00497     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( BoundingVolume<T> const * const " << pBV << " )\n";
00498     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00499 
00500     // After finish the content in m_svCollidedNodeThat will be moved into m_svCollidedNode.
00501     // m_svCollidedNode must be priorly cleared by a caller function.
00502 
00503     m_svCollidedNode.clear();
00504     //m_svCollidedNodeThat.clear();
00505     // m_svCollidedBVAndNodeList is not cleared, so that this fn can be used for overlap test with MBV.
00506 
00507     int val = pBV->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00508     val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00509     bool bResult = false;
00510     switch ( val ) {
00511         case 0:
00512             bResult = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, pBV );
00513             break;
00514         case 1:
00515             bResult = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, pBV, pBV->GetTransform().GetMatrixTransform() );
00516             break;
00517         case 2:
00518             bResult = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), pBV );
00519             break;
00520         case 3:
00521             bResult = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), pBV, pBV->GetTransform().GetMatrixTransform() );
00522             break;
00523     }
00524     //---------------------------------------------------------------
00525     //if ( bResult ) {
00526     //  m_svCollidedNode = m_svCollidedNodeThat;
00527     //}
00528     //---------------------------------------------------------------
00529     return bResult;
00530 
00531 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWithTillLeafNodes ( MultiBoundingVolume< T > const *const   pMBV  )  [inline, virtual]

Test overlap with a Multi Bounding Volume object (without primitive tests) The collided nodes of this BVH tree and the collided bounding volume of the multi bounding volume are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree. Call GetListOfCollidedBoundingVolume() to get the collided bounding volumes of the MultiBoundingVolume object.

Implements BVHTree< T >.

Definition at line 376 of file TAPsBVHTree_BinarySphere.cpp.

00377 {
00378     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00379     //std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( MultiBoundingVolume<T> const * const " << pMBV << " )\n";
00380     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00381 
00382     // After finish the content in m_svCollidedNodeThat will be moved into m_svCollidedNode.
00383     // m_svCollidedNode must be priorly cleared by a caller function.
00384 
00385     m_svCollidedNode.clear();
00386     //m_svCollidedNodeThat.clear();
00387     m_svCollidedBVAndNodeList.clear();
00388 
00389     bool bResult = false;
00390     //---------------------------------------------------------------
00391     // Traverse the list of bounding volumes
00392     std::vector< BoundingVolume<T> * >::iterator pos = const_cast< MultiBoundingVolume<T> * >( pMBV )->GetBoundingVolumeList().begin();
00393 
00394     // MBV is transformed
00395     if ( pMBV->GetTransform().GetStatusApplyTransformation() ) {
00396 
00397         //std::cout << "From BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes ( MultiBoundingVolume<T> const * const pMBV )\n";
00398         //std::cout << "\tpMBV->GetTransform().GetStatusApplyTransformation() is TRUE\n";
00399 
00400         // The multi bounding volume's transformation is on.
00401         while ( pos != pMBV->GetBoundingVolumeList().end() ) {
00402             assert( *pos != NULL );
00403             // Store the transformation of the bounding volume
00404             TransformationSupport<T> trx = (*pos)->GetTransform();
00405             (*pos)->GetTransform().EnableStatusApplyTransformation();
00406             (*pos)->GetTransform().SetMatrixTransform( pMBV->GetTransform().GetMatrixTransform() * trx.GetMatrixTransform() );
00407             // Collision Detection
00408             int val = (*pos)->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00409             val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00410             bool result = false;
00411             switch ( val ) {
00412                 case 0:
00413                     std::cout << "CASE 0-0\n";  // WILL NEVER REACHED, BECUASE OF (*pos)->GetTransform().EnableStatusApplyTransformation(); ABOVE
00414                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, *pos );
00415                     break;
00416                 case 1:
00417                     //std::cout << "CASE 0-1\n";    // TEST PASSED
00418                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, *pos, (*pos)->GetTransform().GetMatrixTransform() );
00419                     break;
00420                 case 2:
00421                     std::cout << "CASE 0-2\n";  // WILL NEVER REACHED, BECUASE OF (*pos)->GetTransform().EnableStatusApplyTransformation(); ABOVE
00422                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), *pos );
00423                     break;
00424                 case 3:
00425                     //std::cout << "CASE 0-3\n";    // TEST PASSED
00426                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), *pos, (*pos)->GetTransform().GetMatrixTransform() );
00427                     break;
00428             }
00429             // Restore the transformation of the bounding volume
00430             (*pos)->GetTransform().SetMatrixTransform( trx.GetMatrixTransform() );
00431             // Set result and keep records
00432             if ( result ) {
00433                 bResult = true;
00434                 //for ( int i = 0; i < static_cast<int>( m_svCollidedNodeThat.size() ); ++i ) {
00435                 //  m_svCollidedNode.push_back( m_svCollidedNodeThat[i] );
00436                 //  m_svCollidedBVList.push_back( *pos );
00437                 //}
00438                 m_svCollidedBVAndNodeList.push_back( BVsAndNodesList<T>( *pos, m_svCollidedNode ) );
00439             }
00440             // Next Bounding Volume
00441             ++pos;
00442         }
00443     }
00444     // MBV is NOT transformed
00445     else {
00446 
00447         std::cout << "From BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes ( MultiBoundingVolume<T> const * const pMBV )\n";
00448         std::cout << "\tpMBV->GetTransform().GetStatusApplyTransformation() is FALSE\n";
00449 
00450         // The multi bounding volume's transformation is off.
00451         while ( pos != pMBV->GetBoundingVolumeList().end() ) {
00452             assert( *pos != NULL );
00453             // Collision Detection
00454             int val = (*pos)->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00455             val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00456             bool result = false;
00457             switch ( val ) {
00458                 case 0:
00459                     std::cout << "CASE 1-0\n";
00460                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, *pos );
00461                     break;
00462                 case 1:
00463                     std::cout << "CASE 1-1\n";
00464                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, *pos, (*pos)->GetTransform().GetMatrixTransform() );
00465                     break;
00466                 case 2:
00467                     std::cout << "CASE 1-2\n";
00468                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), *pos );
00469                     break;
00470                 case 3:
00471                     std::cout << "CASE 1-3\n";
00472                     result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), *pos, (*pos)->GetTransform().GetMatrixTransform() );
00473                     break;
00474             }
00475             // Set result and keep records
00476             if ( result ) {
00477                 bResult = true;
00478                 //for ( int i = 0; i < static_cast<int>( m_svCollidedNodeThat.size() ); ++i ) {
00479                 //  m_svCollidedNode.push_back( m_svCollidedNodeThat[i] );
00480                 //  m_svCollidedBVList.push_back( *pos );
00481                 //}
00482                 m_svCollidedBVAndNodeList.push_back( BVsAndNodesList<T>( *pos, m_svCollidedNode ) );
00483             }
00484             // Next Bounding Volume
00485             ++pos;
00486         }
00487     }
00488     //---------------------------------------------------------------
00489     return bResult;
00490 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWithTillLeafNodes ( BVHNode< T > const *const   node  )  [inline, virtual]

Test overlap with a BVH node (without primitive tests) The collided nodes of this BVH tree are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree.

Implements BVHTree< T >.

Definition at line 348 of file TAPsBVHTree_BinarySphere.cpp.

00349 {
00350     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00351     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( BVHNode<T> const * const " << node << " )\n";
00352     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00353     std::cout << "\tNOT IMPLEMENTED YET!\n";
00354 
00355     m_svCollidedNode.clear();
00356     m_svCollidedNodeThat.clear();
00357     //---------------------------------------------------------------
00358     switch ( node->GetType() ) {
00359         case Enum::BVH_NODE_BINARY_SPHERE:
00360         case Enum::BVH_NODE_QUAD_SPHERE:
00361         case Enum::BVH_NODE_OCTANT_SPHERE:
00362         case Enum::BVH_NODE_GENERIC_SPHERE:
00363             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree<T> 012)" << std::endl;
00364             break;
00365         default:
00366             std::cout << "Error: BVHNode<T>::TestOverlapWithTillLeafNodes Fn!" << std::endl;
00367             assert( false );
00368             break;
00369     }
00370     //---------------------------------------------------------------
00371     return false;
00372 }

template<typename T>
bool BVHTree_BinarySphere< T >::TestOverlapWithTillLeafNodes ( BVHTree< T > const *const   that  )  [inline, virtual]

Test overlap with another BVH tree (without primitive tests) The collided nodes of both BVH trees are stored. Call GetListOfCollidedNodes() to get the collided nodes of this BVH tree. Call GetListOfCollidedNodesThat() to get the collided nodes of the other BVH tree.

Implements BVHTree< T >.

Definition at line 292 of file TAPsBVHTree_BinarySphere.cpp.

00293 {
00294     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00295     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( BVHTree<T> const * const " << that << " )\n";
00296     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00297 
00298     m_svCollidedNode.clear();
00299     m_svCollidedNodeThat.clear();
00300 
00301     int val = that->GetTransform().GetStatusApplyTransformation() ? 1 : 0;
00302     val += this->GetTransform().GetStatusApplyTransformation() ? 2 : 0;
00303 
00304     //---------------------------------------------------------------
00305     switch ( that->GetType() ) {
00306         case Enum::BVH_TREE_BINARY_SPHERE:
00307             switch ( val ) {
00308                 case 0:
00309                     return TestOverlap_vs_BinarySphere_TillLeafNodes( 
00310                                 m_pRoot, 
00311                                 that->Root() );
00312                     break;
00313                 case 1:
00314                     return TestOverlap_vs_BinarySphere_TillLeafNodes( 
00315                                 m_pRoot, 
00316                                 that->Root(), that->GetTransform().GetMatrixTransform() );
00317                     break;
00318                 case 2:
00319                     return TestOverlap_vs_BinarySphere_TillLeafNodes( 
00320                                 m_pRoot, GetTransform().GetMatrixTransform(), 
00321                                 that->Root() );
00322                     break;
00323                 case 3:
00324                     return TestOverlap_vs_BinarySphere_TillLeafNodes( 
00325                                 m_pRoot, GetTransform().GetMatrixTransform(), 
00326                                 that->Root(), that->GetTransform().GetMatrixTransform() );
00327                     break;
00328             }
00329             break;
00330 
00331         case Enum::BVH_TREE_QUAD_SPHERE:
00332         case Enum::BVH_TREE_OCTANT_SPHERE:
00333         case Enum::BVH_TREE_GENERIC_SPHERE:
00334             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 010)" << std::endl;
00335             break;
00336 
00337         default:
00338             std::cout << "Error: BVHNode_BinarySphere<T>::TestOverlapWithTillLeafNodes Fn!" << std::endl;
00339             assert( false );
00340             break;
00341     }
00342     //---------------------------------------------------------------
00343     return false;
00344 }


Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  output,
BVHTree_BinarySphere< T > const &  obj 
) [friend]

Definition at line 31 of file TAPsBVHTree_BinarySphere.hpp.

00032     {
00033         output  << "BVHTree_BinarySphere<" << typeid(T).name() << "> ID:"
00034                 << " with " << obj.m_iTotalNodes << " nodes"
00035                 << " and the root ptr is " << obj.m_pRoot 
00036                 << "\n";
00037         return output;
00038     }


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

Generated on Mon Oct 13 11:44:26 2008 for TAPs by  doxygen 1.5.6