TAPs 0.7.7.3
TAPsBVHTree_BinarySphere.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsBVHTree_BinarySphere.hpp
00003 ******************************************************************************/
00004 // See comment below
00005 /******************************************************************************
00006 SUKITTI PUNAK   (07/11/2008)
00007 UPDATE          (10/10/2010)
00008 ******************************************************************************/
00009 #include "TAPsBVHTree_BinarySphere.hpp"
00010 // Using Inclusion Model (i.e. definitions are included in declarations)
00011 //                       (this name.cpp is included in name.hpp)
00012 // Each friend is defined directly inside its declaration.
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 // Constructor and Destructor
00017 //-----------------------------------------------------------------------------
00018 template <typename T>
00019 BVHTree_BinarySphere<T>::BVHTree_BinarySphere ( 
00020     TransformationSupport<T> & transform, 
00021     int numOfNodes, 
00022     BVHNode<T> * rootNode )
00023     : BVHTree<T>( transform, Enum::BVH_TREE_BINARY_SPHERE, numOfNodes, rootNode )
00024 {}
00025 //-----------------------------------------------------------------------------
00026 template <typename T>
00027 BVHTree_BinarySphere<T>::BVHTree_BinarySphere ( 
00028     TransformationSupport<T> & 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 }
00056 //-----------------------------------------------------------------------------
00057 template <typename T>
00058 BVHTree_BinarySphere<T>::~BVHTree_BinarySphere ()
00059 {}
00060 //-----------------------------------------------------------------------------
00061 
00062 //-----------------------------------------------------------------------------
00063 // TestOverlapWith a BVHTree
00064 template <typename T>
00065 bool BVHTree_BinarySphere<T>::TestOverlapWith ( BVHTree<T> const * const that )
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     //---------------------------------------------------------------
00075     switch ( that->GetType() ) {
00076         case Enum::BVH_TREE_BINARY_SPHERE:
00077         case Enum::BVH_NODE_LEAF_SPHERE:
00078             return TestOverlap_vs_BinarySphere( m_pRoot, GetTransform().GetMatrixTransform(), that->Root(), that->GetTransform().GetMatrixTransform() );
00079             break;
00080 
00081         case Enum::BVH_TREE_QUAD_SPHERE:
00082         case Enum::BVH_TREE_OCTANT_SPHERE:
00083         case Enum::BVH_TREE_GENERIC_SPHERE:
00084             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 002)" << std::endl;
00085             break;
00086 
00087         default:
00088             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlapWith Fn!" << std::endl;
00089             assert( false );
00090             break;
00091     }
00092     //---------------------------------------------------------------
00093     return false;
00094 }
00095 //-----------------------------------------------------------------------------
00096 // TestOverlapWith a BVHNode
00097 template <typename T>
00098 bool BVHTree_BinarySphere<T>::TestOverlapWith ( BVHNode<T> const * const node )
00099 {
00100     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00101     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWith( BVHNode<T> const * const " << node << " )\n";
00102     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00103 
00104     //std::cout << "\tNOT IMPLEMENTED YET!\n";
00105 
00106     m_svCollidedNode.clear();
00107     m_svCollidedNodeThat.clear();
00108     //---------------------------------------------------------------
00109     switch ( node->GetType() ) {
00110         case Enum::BVH_NODE_BINARY_SPHERE:
00111         case Enum::BVH_NODE_LEAF_SPHERE:
00112             return TestOverlap_vs_BinarySphere( m_pRoot, GetTransform().GetMatrixTransform(), node, CGMath<T>::IdentityMatrix4x4 );
00113             break;
00114 
00115         case Enum::BVH_NODE_QUAD_SPHERE:
00116         case Enum::BVH_NODE_OCTANT_SPHERE:
00117         case Enum::BVH_NODE_GENERIC_SPHERE:
00118             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 004)" << std::endl;
00119             break;
00120         default:
00121             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlapWith Fn!" << std::endl;
00122             assert( false );
00123             break;
00124     }
00125     //---------------------------------------------------------------
00126     return false;
00127 }
00128 //-----------------------------------------------------------------------------
00129 // TestOverlapWith a MultiBoundingVolume
00130 template <typename T>
00131 bool BVHTree_BinarySphere<T>::TestOverlapWith ( MultiBoundingVolume<T> const * const pMBV )
00132 {
00133     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00134     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWith( MultiBoundingVolume<T> const * const " << pMBV << " )\n";
00135     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00136 
00137     //m_svCollidedNodeThat.clear();
00138     m_svCollidedBVAndNodeList.clear();
00139 
00140     bool bResult = false;
00141     //---------------------------------------------------------------
00142     // Traverse the list of bounding volumes
00143     std::vector< BoundingVolume<T> * >::iterator pos = const_cast< MultiBoundingVolume<T> * >( pMBV )->GetBoundingVolumeList().begin();
00144 
00145     while ( pos != pMBV->GetBoundingVolumeList().end() ) {
00146         m_svCollidedNode.clear();
00147         assert( *pos != NULL );
00148         // Store the transformation of the bounding volume
00149         TransformationSupport<T> trx = (*pos)->GetTransform();
00150         (*pos)->GetTransform().SetMatrixTransform( pMBV->GetTransform().GetMatrixTransform() * trx.GetMatrixTransform() );
00151 
00152         // Collision Detection
00153         bool result = TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), *pos, (*pos)->GetTransform().GetMatrixTransform() );
00154 
00155         // Restore the transformation of the bounding volume
00156         (*pos)->GetTransform().SetMatrixTransform( trx.GetMatrixTransform() );
00157         // Set result and keep records
00158         if ( result ) {
00159             bResult = true;
00160             //for ( int i = 0; i < static_cast<int>( m_svCollidedNodeThat.size() ); ++i ) {
00161             //  m_svCollidedNode.push_back( m_svCollidedNodeThat[i] );
00162             //  m_svCollidedBVList.push_back( *pos );
00163             //}
00164             m_svCollidedBVAndNodeList.push_back( BVsAndNodesList<T>( *pos, m_svCollidedNode ) );
00165         }
00166         // Next Bounding Volume
00167         ++pos;
00168 
00169         //pos = const_cast< MultiBoundingVolume<T> * >( pMBV )->GetBoundingVolumeList().end();
00170     }
00171 
00172     return bResult;
00173 }
00174 //-----------------------------------------------------------------------------
00175 // TestOverlapWith a BoundingVolume
00176 template <typename T>
00177 bool BVHTree_BinarySphere<T>::TestOverlapWith ( BoundingVolume<T> const * const pBV )
00178 {
00179     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00180     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWith( BoundingVolume<T> const * const " << pBV << " )\n";
00181     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00182 
00183     // After finish the content in m_svCollidedNodeThat will be moved into m_svCollidedNode.
00184     // m_svCollidedNode must be priorly cleared by a caller function.
00185 
00186     m_svCollidedNode.clear();
00187     //m_svCollidedNodeThat.clear();
00188     // m_svCollidedBVAndNodeList is not cleared, so that this fn can be used for overlap test with MBV.
00189 
00190     return TestOverlap_vs_BV( m_pRoot, GetTransform().GetMatrixTransform(), pBV, pBV->GetTransform().GetMatrixTransform() );
00191 }
00192 
00193 
00194 
00195 //-----------------------------------------------------------------------------
00196 // TestOverlapWithTillLeafNodes with a BVHTree
00197 template <typename T>
00198 bool BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes ( BVHTree<T> const * const that )
00199 {
00200     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00201     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( BVHTree<T> const * const " << that << " )\n";
00202     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00203 
00204     m_svCollidedNode.clear();
00205     m_svCollidedNodeThat.clear();
00206 
00207     //---------------------------------------------------------------
00208     switch ( that->GetType() ) {
00209         case Enum::BVH_TREE_BINARY_SPHERE:
00210         case Enum::BVH_NODE_LEAF_SPHERE:
00211             return TestOverlap_vs_BinarySphere_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), that->Root(), that->GetTransform().GetMatrixTransform() );
00212             break;
00213 
00214         case Enum::BVH_TREE_QUAD_SPHERE:
00215         case Enum::BVH_TREE_OCTANT_SPHERE:
00216         case Enum::BVH_TREE_GENERIC_SPHERE:
00217             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 010)" << std::endl;
00218             break;
00219 
00220         default:
00221             std::cout << "Error: BVHNode_BinarySphere<T>::TestOverlapWithTillLeafNodes Fn!" << std::endl;
00222             assert( false );
00223             break;
00224     }
00225     //---------------------------------------------------------------
00226     return false;
00227 }
00228 //-----------------------------------------------------------------------------
00229 // TestOverlapWithTillLeafNodes with a BVHNode
00230 template <typename T>
00231 bool BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes ( BVHNode<T> const * const node )
00232 {
00233     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00234     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( BVHNode<T> const * const " << node << " )\n";
00235     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00236 
00237     //std::cout << "\tNOT IMPLEMENTED YET!\n";
00238 
00239     m_svCollidedNode.clear();
00240     m_svCollidedNodeThat.clear();
00241     //---------------------------------------------------------------
00242     switch ( node->GetType() ) {
00243         case Enum::BVH_NODE_BINARY_SPHERE:
00244         case Enum::BVH_NODE_LEAF_SPHERE:
00245             return TestOverlap_vs_BinarySphere_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), node, CGMath<T>::IdentityMatrix4x4 );
00246             break;
00247 
00248         case Enum::BVH_NODE_QUAD_SPHERE:
00249         case Enum::BVH_NODE_OCTANT_SPHERE:
00250         case Enum::BVH_NODE_GENERIC_SPHERE:
00251             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree<T> 012)" << std::endl;
00252             break;
00253         default:
00254             std::cout << "Error: BVHNode<T>::TestOverlapWithTillLeafNodes Fn!" << std::endl;
00255             assert( false );
00256             break;
00257     }
00258     //---------------------------------------------------------------
00259     return false;
00260 }
00261 //-----------------------------------------------------------------------------
00262 // TestOverlapWithTillLeafNodes with a MultiBoundingVolume
00263 template <typename T>
00264 bool BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes ( MultiBoundingVolume<T> const * const pMBV )
00265 {
00266     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00267     //std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( MultiBoundingVolume<T> const * const " << pMBV << " )\n";
00268     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00269 
00270     // After finish the content in m_svCollidedNodeThat will be moved into m_svCollidedNode.
00271     // m_svCollidedNode must be priorly cleared by a caller function.
00272 
00273     //m_svCollidedNodeThat.clear();
00274     m_svCollidedBVAndNodeList.clear();
00275 
00276     bool bResult = false;
00277     //---------------------------------------------------------------
00278     // Traverse the list of bounding volumes
00279     std::vector< BoundingVolume<T> * >::iterator pos = const_cast< MultiBoundingVolume<T> * >( pMBV )->GetBoundingVolumeList().begin();
00280 
00281     while ( pos != pMBV->GetBoundingVolumeList().end() ) {
00282         m_svCollidedNode.clear();
00283         assert( *pos != NULL );
00284         // Store the transformation of the bounding volume
00285         TransformationSupport<T> trx = (*pos)->GetTransform();
00286         (*pos)->GetTransform().SetMatrixTransform( pMBV->GetTransform().GetMatrixTransform() * trx.GetMatrixTransform() );
00287 
00288         // Collision Detection
00289         bool result = TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), *pos, (*pos)->GetTransform().GetMatrixTransform() );
00290 
00291         // Restore the transformation of the bounding volume
00292         (*pos)->GetTransform().SetMatrixTransform( trx.GetMatrixTransform() );
00293         // Set result and keep records
00294         if ( result ) {
00295             bResult = true;
00296             //for ( int i = 0; i < static_cast<int>( m_svCollidedNodeThat.size() ); ++i ) {
00297             //  m_svCollidedNode.push_back( m_svCollidedNodeThat[i] );
00298             //  m_svCollidedBVList.push_back( *pos );
00299             //}
00300             m_svCollidedBVAndNodeList.push_back( BVsAndNodesList<T>( *pos, m_svCollidedNode ) );
00301         }
00302         // Next Bounding Volume
00303         ++pos;
00304     }
00305 
00306     return bResult;
00307 }
00308 //-----------------------------------------------------------------------------
00309 // TestOverlapWithTillLeafNodes with a BoundingVolume
00310 template <typename T>
00311 bool BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes ( BoundingVolume<T> const * const pBV )
00312 {
00313     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00314     std::cout << "BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes( BoundingVolume<T> const * const " << pBV << " )\n";
00315     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00316 
00317     // After finish the content in m_svCollidedNodeThat will be moved into m_svCollidedNode.
00318     // m_svCollidedNode must be priorly cleared by a caller function.
00319 
00320     m_svCollidedNode.clear();
00321     //m_svCollidedNodeThat.clear();
00322     // m_svCollidedBVAndNodeList is not cleared, so that this fn can be used for overlap test with MBV.
00323 
00324     return TestOverlap_vs_BV_TillLeafNodes( m_pRoot, GetTransform().GetMatrixTransform(), pBV, pBV->GetTransform().GetMatrixTransform() );
00325 }
00326 //-----------------------------------------------------------------------------
00327 
00328 
00329 
00330 
00331 //=============================================================================
00332 // START: Test Intersection with a Line Segment
00333 //-----------------------------------------------------------------------------
00334 template <typename T>
00335 bool BVHTree_BinarySphere<T>::TestIntersectionWithLineSegmentTillLeafNodes ( 
00336     Vector3<T> const * const ptA, Vector3<T> const * const ptB )
00337 {
00338     // Transform ptA and ptB to the local coordinate system of the CD tree
00339     TAPs::Matrix4x4<T> invTrx( GetTransform().RefToMatrixTransform().GetInverse() );
00340     Vector3<T> A = invTrx * *ptA;
00341     Vector3<T> B = invTrx * *ptB;
00342 
00343     m_svCollidedNode.clear();
00344     return TestIntersectionWithLineSegmentTillLeafNodesRecursive( Root(), &A, &B );
00345 }
00346 //-----------------------------------------------------------------------------
00347 template <typename T>
00348 bool BVHTree_BinarySphere<T>::TestIntersectionWithLineSegmentTillLeafNodesRecursive ( 
00349     BVHNode<T> const * const node, 
00350     Vector3<T> const * const ptA, 
00351     Vector3<T> const * const ptB )
00352 {
00353     // Need to add transformation of the node into the computation !!!
00354 
00355     T ratio, distance;
00356     Vector3<T> projPt;
00357     CGMath<T>::FindProjectedPointOnALine ( 
00358             node->GetCenter(),  
00359             *ptA,   
00360             *ptB,   
00361             ratio,      
00362             projPt,     
00363             distance    
00364     );
00365     //---------------------------------------------------------------
00366     // Test overlapping
00367     if ( distance > node->GetRadius() ) {
00368         return false;
00369     }
00370     //---------------------------------------------------------------
00371     // If node A is leaf
00372     else if ( node->IsLeaf() ) {
00373         if ( ratio < 0 || 1 < ratio ) {
00374             return false;
00375         }
00376         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( node ) );
00377         return true;
00378     }
00379     //---------------------------------------------------------------
00380     // If node A is not leaf
00381     else {
00382         bool overlap1 = false, overlap2 = false;
00383         if ( node->Child(0) ) {
00384             overlap1 = TestIntersectionWithLineSegmentTillLeafNodesRecursive( node->Child(0), ptA, ptB );
00385         }
00386         if ( node->Child(1) ) {
00387             overlap2 = TestIntersectionWithLineSegmentTillLeafNodesRecursive( node->Child(1), ptA, ptB );
00388         }
00389         if ( overlap1 || overlap2 ) {
00390             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
00391                 const_cast< BVHNode<T> * >( node )->flag = true;
00392             #endif//TAPs_DEBUG_COLLISION_DETECTION
00393             return true;
00394         }
00395         else {
00396             return false;
00397         }
00398     }
00399 }
00400 //-----------------------------------------------------------------------------
00401 // END: Test Intersection with a Line Segment
00402 //=============================================================================
00403 
00404 
00405 
00406 
00407 //=============================================================================
00408 // START: Test Intersection with a circle
00409 //-----------------------------------------------------------------------------
00410 template <typename T>
00411 bool BVHTree_BinarySphere<T>::TestIntersectionWithCircleTillLeafNodes ( 
00412     Vector3<T> const * const circleNormalPlane, Vector3<T> const * const circleCenter, T circleRadius )
00413 {
00414     // Transform the circle's center to the local coordinate system of the CD tree
00415     TAPs::Matrix4x4<T> invTrx( GetTransform().RefToMatrixTransform().GetInverse() );
00416     Vector3<T> C = invTrx * *circleCenter;
00417     Vector3<T> N = invTrx * (*circleNormalPlane + *circleCenter) - C;
00418 
00419     // Calculate the transform that transform the circle to lie flat 
00420     // on the x-y plane with normal plane point to z-positive.
00421     Matrix4x4<T> Translation = CGMath<T>::MatrixTranslation( -C );
00422     Matrix4x4<T> Rotation = CGMath<T>::CreateRotationMatrix4x4FromVectorAtoVectorB( N, Vector3<T>(0,0,1) );
00423     Matrix4x4<T> Trx = Rotation * Translation;  // first translate the center to the origin, then rotate the normal plane to <0,0,1>
00424     //Trx.Inversed();
00425     //C = Trx * C;
00426 
00427     m_svCollidedNode.clear();
00428     return TestIntersectionWithCircleTillLeafNodesRecursive( Trx, Root(), circleRadius );
00429 }
00430 //-----------------------------------------------------------------------------
00431 template <typename T>
00432 bool BVHTree_BinarySphere<T>::TestIntersectionWithCircleTillLeafNodesRecursive (
00433     Matrix4x4<T> Trx,   
00434     BVHNode<T> const * const node,
00435     T circleRadius )
00436 {
00437     // The circle's center is assumed to be at the origin
00438     // The circle is assumed to lie flat on the xy-plane, i.e. its normal plane point to the z-positive direction.
00439 
00440     Vector3<T> center = Trx * node->GetCenter();
00441 
00442     //---------------------------------------------------------------
00443     // Test overlapping
00444     T offset = fabs(center[2]);
00445     if ( offset > node->GetRadius() ) {
00446         return false;
00447     }
00448     else {
00449         T ratio = offset/node->GetRadius();
00450         offset = sqrt( 1 - ratio*ratio ) * node->GetRadius();
00451 
00452         //offset = node->GetRadius();
00453     }
00454     //---------------------------------------------------------------
00455     if ( center[0]*center[0] + center[1]*center[1] - offset > circleRadius*circleRadius ) {
00456         return false;
00457     }
00458     //---------------------------------------------------------------
00459     // If node A is leaf
00460     else if ( node->IsLeaf() ) {
00461         //if ( ratio < 0 || 1 < ratio ) {
00462         //  return false;
00463         //}
00464         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( node ) );
00465         return true;
00466     }
00467     //---------------------------------------------------------------
00468     // If node A is not leaf
00469     else {
00470         bool overlap1 = false, overlap2 = false;
00471         if ( node->Child(0) ) {
00472             overlap1 = TestIntersectionWithCircleTillLeafNodesRecursive( Trx, node->Child(0), circleRadius );
00473         }
00474         if ( node->Child(1) ) {
00475             overlap2 = TestIntersectionWithCircleTillLeafNodesRecursive( Trx, node->Child(1), circleRadius );
00476         }
00477         if ( overlap1 || overlap2 ) {
00478             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
00479                 const_cast< BVHNode<T> * >( node )->flag = true;
00480             #endif//TAPs_DEBUG_COLLISION_DETECTION
00481             return true;
00482         }
00483         else {
00484             return false;
00485         }
00486     }
00487 }
00488 //-----------------------------------------------------------------------------
00489 // END: Test Intersection with a circle
00490 //=============================================================================
00491 
00492 
00493 
00494 
00495 //=============================================================================
00496 // START: Test Intersection with an interaction point group
00497 //-----------------------------------------------------------------------------
00498 template <typename T>
00499 bool BVHTree_BinarySphere<T>::TestOverlapWith (
00500     InteractionPointGroup<T> * const    pIPG,           
00501     std::vector< PointForce<T> > & ListOfPointForces    
00502 )
00503 {
00504     m_svCollidedNode.clear();
00505 
00506     unsigned int countPF = ListOfPointForces.size();
00507 
00508     // Transform the interaction point group to the body space of BVHTree
00509     InteractionPointGroup<T> IPG_Local( *pIPG );
00510     Matrix4x4<T> invTrx = GetTransform().GetMatrixTransform().GetInverse();
00511     IPG_Local.TransformedBy( invTrx );
00512 
00513     bool bResult = TestOverlapWithIPGRecursive( Root(), &IPG_Local, ListOfPointForces );
00514 
00515     // Transform the point forces to world space
00516     if ( bResult ) {
00517         for ( unsigned int i = countPF; i < ListOfPointForces.size(); ++i ) {
00518             ListOfPointForces[i].RefToPosition() = GetTransform().GetMatrixTransform() * ListOfPointForces[i].RefToPosition();
00519 
00520             //ListOfPointForces[i].RefToForce() = GetTransform().GetMatrixTransform() * ListOfPointForces[i].RefToForce() - ListOfPointForces[i].RefToPosition();
00521         }
00522     }
00523 
00524     return bResult;
00525 }
00526 //-----------------------------------------------------------------------------
00527 template <typename T>
00528 bool BVHTree_BinarySphere<T>::TestOverlapWithTillLeafNodes (
00529     InteractionPointGroup<T> * const    pIPG,           
00530     std::vector< PointForce<T> > & ListOfPointForces    
00531 )
00532 {
00533     m_svCollidedNode.clear();
00534 
00535     unsigned int countPF = ListOfPointForces.size();
00536 
00537     // Transform the interaction point group to the body space of BVHTree
00538     InteractionPointGroup<T> IPG_Local( *pIPG );
00539     Matrix4x4<T> invTrx = GetTransform().GetMatrixTransform().GetInverse();
00540     IPG_Local.TransformedBy( invTrx );
00541 
00542     bool bResult = TestOverlapWithIPGTillLeafNodesRecursive( Root(), &IPG_Local, ListOfPointForces );
00543 
00544     // Transform the point forces to world space
00545     if ( bResult ) {
00546         for ( unsigned int i = countPF; i < ListOfPointForces.size(); ++i ) {
00547             ListOfPointForces[i].RefToPosition() = GetTransform().GetMatrixTransform() * ListOfPointForces[i].RefToPosition();
00548 
00549             //ListOfPointForces[i].RefToForce() = GetTransform().GetMatrixTransform() * ListOfPointForces[i].RefToForce() - ListOfPointForces[i].RefToPosition();
00550         }
00551     }
00552 
00553     return bResult;
00554 }
00555 //-----------------------------------------------------------------------------
00556 template <typename T>
00557 bool BVHTree_BinarySphere<T>::TestOverlapWithIPGRecursive (
00558     BVHNode<T> const * const node,
00559     InteractionPointGroup<T> * const    pIPG,           
00560     std::vector< PointForce<T> > & ListOfPointForces    
00561 )
00562 {
00563     bool bCD = false;
00564 
00565     // Node is not leaf
00566     if ( !node->IsLeaf() ) {
00567         for ( std::vector< InteractionPoint<T> >::iterator it = pIPG->GetTheSetOfInteractionPoints().begin();
00568             it != pIPG->GetTheSetOfInteractionPoints().end(); ++it )
00569         {
00570             Vector3<T> separationCenter = node->GetCenter() - it->GetPosition();
00571             T length = separationCenter.Length() - ( node->GetRadius() + it->GetSize() );
00572             if ( length < 0 ) {
00573                 bCD = true;
00574                 break;
00575             }
00576         }
00577 
00578         if ( bCD == false ) return false;
00579 
00580         // Traverse to child nodes
00581         bool overlap1 = false, overlap2 = false;
00582         if ( node->Child(0) ) {
00583             overlap1 = TestOverlapWithIPGRecursive( node->Child(0), pIPG, ListOfPointForces );
00584         }
00585         if ( node->Child(1) ) {
00586             overlap2 = TestOverlapWithIPGRecursive( node->Child(1), pIPG, ListOfPointForces );
00587         }
00588         if ( overlap1 || overlap2 ) {
00589             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
00590                 const_cast< BVHNode<T> * >( node )->flag = true;
00591             #endif//TAPs_DEBUG_COLLISION_DETECTION
00592             return true;
00593         }
00594         else {
00595             return false;
00596         }
00597     }
00598     // Node is leaf
00599     else {
00600         for ( std::vector< InteractionPoint<T> >::iterator it = pIPG->GetTheSetOfInteractionPoints().begin();
00601             it != pIPG->GetTheSetOfInteractionPoints().end(); ++it )
00602         {
00603             Vector3<T> separation = node->GetCenter() - it->GetPosition();
00604             T len = separation.Length();
00605             T length = len - ( node->GetRadius() + it->GetSize() );
00606             if ( length < 0 ) {
00607 
00608                 // Test with primitive (a triangle)
00609                 HEFace<T> * pHEFace = node->GetAPrimitiveHalfEdgeFace();
00610                 std::vector< HEVertex<T> * const >  listOfHEVertices = pHEFace->GetPtrsToVertices();
00611                 Vector3<T> outVec[3];
00612                 bCD = CGMath<T>::FindIntersectionSphereTriangle(
00613                     it->GetPosition(),  // sphere's center
00614                     it->GetSize(),      // sphere's radius
00615                     listOfHEVertices[0]->GetPosition(), listOfHEVertices[1]->GetPosition(), listOfHEVertices[2]->GetPosition(), // triangle's vertices
00616                     outVec[0], outVec[1], outVec[2] // out vectors for resolving the CD
00617                     //, &contactPt      // the contact point on the triangle
00618                 );
00619 
00620                 if ( bCD ) {
00621                     //separation *= length/len;
00622                     separation = ( outVec[0] + outVec[1] + outVec[2] ) / T(-3);
00623                     ListOfPointForces.push_back( PointForce<T>( it->GetPosition(), separation ) );
00624                 }
00625             }
00626         }
00627     }
00628 
00629     return bCD;
00630 }
00631 //-----------------------------------------------------------------------------
00632 template <typename T>
00633 bool BVHTree_BinarySphere<T>::TestOverlapWithIPGTillLeafNodesRecursive (
00634     BVHNode<T> const * const node,
00635     InteractionPointGroup<T> * const    pIPG,           
00636     std::vector< PointForce<T> > & ListOfPointForces    
00637 )
00638 {
00639     bool bCD = false;
00640 
00641     // Node is not leaf
00642     if ( !node->IsLeaf() ) {
00643         for ( std::vector< InteractionPoint<T> >::iterator it = pIPG->GetTheSetOfInteractionPoints().begin();
00644             it != pIPG->GetTheSetOfInteractionPoints().end(); ++it )
00645         {
00646             Vector3<T> separationCenter = node->GetCenter() - it->GetPosition();
00647             T length = separationCenter.Length() - ( node->GetRadius() + it->GetSize() );
00648             if ( length < 0 ) {
00649                 bCD = true;
00650                 break;
00651             }
00652         }
00653 
00654         if ( bCD == false ) return false;
00655 
00656         // Traverse to child nodes
00657         bool overlap1 = false, overlap2 = false;
00658         if ( node->Child(0) ) {
00659             overlap1 = TestOverlapWithIPGTillLeafNodesRecursive( node->Child(0), pIPG, ListOfPointForces );
00660         }
00661         if ( node->Child(1) ) {
00662             overlap2 = TestOverlapWithIPGTillLeafNodesRecursive( node->Child(1), pIPG, ListOfPointForces );
00663         }
00664         if ( overlap1 || overlap2 ) {
00665             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
00666                 const_cast< BVHNode<T> * >( node )->flag = true;
00667             #endif//TAPs_DEBUG_COLLISION_DETECTION
00668             return true;
00669         }
00670         else {
00671             return false;
00672         }
00673     }
00674     // Node is leaf
00675     else {
00676         for ( std::vector< InteractionPoint<T> >::iterator it = pIPG->GetTheSetOfInteractionPoints().begin();
00677             it != pIPG->GetTheSetOfInteractionPoints().end(); ++it )
00678         {
00679             Vector3<T> separation = node->GetCenter() - it->GetPosition();
00680             T len = separation.Length();
00681             T length = len - ( node->GetRadius() + it->GetSize() );
00682             if ( length < 0 ) {
00683                 bCD = true;
00684                 separation *= length/len;
00685                 ListOfPointForces.push_back( PointForce<T>( it->GetPosition(), separation ) );
00686             }
00687         }
00688     }
00689 
00690     return bCD;
00691 }
00692 
00693 //-----------------------------------------------------------------------------
00694 // END: Test Intersection with an interaction point group
00695 //=============================================================================
00696 
00697 
00698 
00699 
00700 //=============================================================================
00701 // START: Test Overlap with a MultiBoundingVolume
00702 //-----------------------------------------------------------------------------
00703 //-----------------------------------------------------------------------------
00704 // END: Test Overlap with a MultiBoundingVolume
00705 //=============================================================================
00706 
00707 
00708 
00709 
00710 //=============================================================================
00711 // START: Test Overlap with a BoundingVolume
00712 //-----------------------------------------------------------------------------
00713 // TestOverlap_vs_BV
00714 template <typename T>
00715 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV ( 
00716                 BVHNode<T> const * const nodeA, 
00717                 Matrix4x4<T> const & transformA, 
00718                 BoundingVolume<T> const * const pBV, 
00719                 Matrix4x4<T> const & transformB )
00720 {
00721     std::cout << "#4 BVHTree_BinarySphere<T>::TestOverlap_vs_BV( BVHNode<T>, Matrix4x4<T>, BoundingVolume<T>, Matrix4x4<T> )\n";
00722 
00723     //---------------------------------------------------------------
00724     switch ( pBV->GetType() ) {
00725         case Enum::BOUNDING_SPHERE:
00726             {
00727                 Vector3<T>  sphereCenter;
00728                 T           sphereRadius;
00729                 ForBVSphereTransformations( pBV, transformB, sphereCenter, sphereRadius );
00730 
00731                 // Collision Detection -- With Primitive-Primitive Test
00732                 return TestOverlap_vs_BV_Sphere( nodeA, transformA, sphereCenter, sphereRadius );
00733             }
00734             break;
00735         case Enum::BOUNDING_CYLINDER:
00736             {
00737                 Matrix4x4<T> nodeTransformation;
00738                 ForBVCylinderTransformations( transformA, pBV, transformB, nodeTransformation );
00739 
00740                 // Collision Detection -- With Primitive-Primitive Test
00741                 return TestOverlap_vs_BV_Cylinder_AtOrigin( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight()  );
00742             }
00743             break;
00744         case Enum::BOUNDING_BOX:
00745         case Enum::BOUNDING_ELLIPSOID:
00746         case Enum::BOUNDING_HALF_SPHERE:
00747         case Enum::BOUNDING_HALF_ELLIPSOID:
00748         case Enum::BOUNDING_CONE:
00749         case Enum::BOUNDING_CAPSULE:
00750         case Enum::BOUNDING_POLYTOPE:
00751             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 104)" << std::endl;
00752             break;
00753         default:
00754             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV Fn!" << std::endl;
00755             assert( false );
00756             break;
00757     }
00758     //---------------------------------------------------------------
00759     return false;
00760 }
00761 //-----------------------------------------------------------------------------
00762 
00763 
00764 
00765 
00766 //-----------------------------------------------------------------------------
00767 // TestOverlap_vs_BV_TillLeafNodes
00768 template <typename T>
00769 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes ( 
00770                 BVHNode<T> const * const nodeA, 
00771                 Matrix4x4<T> const & transformA, 
00772                 BoundingVolume<T> const * const pBV, 
00773                 Matrix4x4<T> const & transformB )
00774 {
00775     // TEST PASSED
00776     //std::cout << "#4 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes( BVHNode<T>, Matrix4x4<T>, BoundingVolume<T>, Matrix4x4<T> )\n";
00777 
00778     //---------------------------------------------------------------
00779     switch ( pBV->GetType() ) {
00780         case Enum::BOUNDING_SPHERE:
00781             {
00782                 Vector3<T>  sphereCenter;
00783                 T           sphereRadius;
00784                 ForBVSphereTransformations( pBV, transformB, sphereCenter, sphereRadius );
00785 
00786                 // Collision Detection -- W/O Primitive-Primitive Test
00787                 return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, transformA, sphereCenter, sphereRadius );
00788             }
00789             break;
00790         case Enum::BOUNDING_CYLINDER:
00791             {
00792                 Matrix4x4<T> nodeTransformation;
00793                 ForBVCylinderTransformations( transformA, pBV, transformB, nodeTransformation );
00794 
00795                 // Collision Detection -- W/O Primitive-Primitive Test
00796                 return TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, nodeTransformation, pBV->GetRadius(), pBV->GetHeight() );
00797             }
00798             break;
00799         case Enum::BOUNDING_BOX:
00800         case Enum::BOUNDING_ELLIPSOID:
00801         case Enum::BOUNDING_HALF_SPHERE:
00802         case Enum::BOUNDING_HALF_ELLIPSOID:
00803         case Enum::BOUNDING_CONE:
00804         case Enum::BOUNDING_CAPSULE:
00805         case Enum::BOUNDING_POLYTOPE:
00806             std::cout << "NOT IMPLEMENTED YET! (ID: BVHTree_BinarySphere<T> 204)" << std::endl;
00807             break;
00808         default:
00809             std::cout << "Error: BVHTree_BinarySphere<T>::TestOverlap_vs_BV_TillLeafNodes Fn!" << std::endl;
00810             assert( false );
00811             break;
00812     }
00813     //---------------------------------------------------------------
00814     return false;
00815 }
00816 //-----------------------------------------------------------------------------
00817 
00818 
00819 
00820 
00821 //-----------------------------------------------------------------------------
00822 // Transformations
00823 //-----------------------------------------------------------------------------
00824 template <typename T>
00825 void BVHTree_BinarySphere<T>::ForBVSphereTransformations ( 
00826         BoundingVolume<T> const * const pBV,    
00827         Matrix4x4<T> const & bvTransformation,  
00828         Vector3<T> & sphereCenter,              
00829         T & sphereRadius                        
00830 )
00831 {
00832     // Transform the pBV due to its transformation, center, and radius
00833     Vector3<T> C( pBV->GetCenter() );
00834     Matrix4x4<T> translation( 1, 0, 0, C[0], 
00835                               0, 1, 0, C[1],
00836                               0, 0, 1, C[2],
00837                               0, 0, 0, 1 );
00838     Vector3<T> S( pBV->GetRadius(), pBV->GetRadius(), pBV->GetRadius() );
00839     Matrix4x4<T> scale( S[0], 0,    0,    0, 
00840                         0,    S[1], 0,    0,
00841                         0,    0,    S[2], 0,
00842                         0,    0,    0,    1 );
00843     Matrix4x4<T> trx = bvTransformation * translation * scale;
00844 
00845     // Sphere's center and radius after the transformation
00846     sphereCenter = (trx * Vector4<T>(0,0,0,1)).GetVector3();
00847     sphereRadius = ( (trx * Vector4<T>(1,0,0,1)) - sphereCenter ).Length();
00848 
00849     /*
00850     // DEBUG
00851     std::cout << "(trx * Vector4<T>(S[0],0,0,1)): " << (trx * Vector4<T>(S[0],0,0,1)) << "\n";
00852 
00853     std::cout << "transformB: " << transformB;
00854     std::cout << "transformB * translation: " << transformB * translation;
00855     std::cout << "transformB * translation * scale: " << transformB * translation * scale;
00856     std::cout << "pBV: " << *pBV << "\n";
00857     std::cout << "Sphere: center " <<  sphereCenter << "; radius " << sphereRadius << "\n";
00858     //*/
00859 }
00860 //-----------------------------------------------------------------------------
00861 // ForBVCylinderTransformations #1
00862 template <typename T>
00863 void BVHTree_BinarySphere<T>::ForBVCylinderTransformations ( 
00864         BoundingVolume<T> const * const pBV,    
00865         Matrix4x4<T> & nodeTransform_OP         
00866 )
00867 {
00868     nodeTransform_OP = Matrix4x4<T>(    1, 0, 0, -pBV->GetCenter()[0], 
00869                                         0, 1, 0, -pBV->GetCenter()[1], 
00870                                         0, 0, 1, -pBV->GetCenter()[2], 
00871                                         0, 0, 0, 1
00872                                     );
00873 }
00874 //-----------------------------------------------------------------------------
00875 // ForBVCylinderTransformations #2
00876 template <typename T>
00877 void BVHTree_BinarySphere<T>::ForBVCylinderTransformations ( 
00878         BoundingVolume<T> const * const pBV,    
00879         Matrix4x4<T> const & bvTransformation,  
00880         Matrix4x4<T> & nodeTransform_OP         
00881 )
00882 {
00883     nodeTransform_OP = bvTransformation * Matrix4x4<T>( 1, 0, 0, pBV->GetCenter()[0], 
00884                                                         0, 1, 0, pBV->GetCenter()[1], 
00885                                                         0, 0, 1, pBV->GetCenter()[2], 
00886                                                         0, 0, 0, 1
00887                                                     );
00888     nodeTransform_OP.Inversed();
00889 }
00890 //-----------------------------------------------------------------------------
00891 // ForBVCylinderTransformations #3
00892 template <typename T>
00893 void BVHTree_BinarySphere<T>::ForBVCylinderTransformations ( 
00894         Matrix4x4<T> const & nodeTransform_IP,  
00895         BoundingVolume<T> const * const pBV,    
00896         Matrix4x4<T> & nodeTransform_OP         
00897 )
00898 {
00899     nodeTransform_OP = Matrix4x4<T>(    1, 0, 0, -pBV->GetCenter()[0], 
00900                                         0, 1, 0, -pBV->GetCenter()[1], 
00901                                         0, 0, 1, -pBV->GetCenter()[2], 
00902                                         0, 0, 0, 1
00903                                     )
00904                     * nodeTransform_IP;
00905 }
00906 //-----------------------------------------------------------------------------
00907 // ForBVCylinderTransformations #4
00908 template <typename T>
00909 void BVHTree_BinarySphere<T>::ForBVCylinderTransformations ( 
00910         Matrix4x4<T> const & nodeTransform_IP,  
00911         BoundingVolume<T> const * const pBV,    
00912         Matrix4x4<T> const & bvTransformation,  
00913         Matrix4x4<T> & nodeTransform_OP         
00914 )
00915 {
00916     nodeTransform_OP = bvTransformation * Matrix4x4<T>( 1, 0, 0, pBV->GetCenter()[0], 
00917                                                         0, 1, 0, pBV->GetCenter()[1], 
00918                                                         0, 0, 1, pBV->GetCenter()[2], 
00919                                                         0, 0, 0, 1
00920                                                     );
00921     nodeTransform_OP = nodeTransform_OP.Inversed() * nodeTransform_IP;
00922 }
00923 //-----------------------------------------------------------------------------
00924 // Transformations
00925 //-----------------------------------------------------------------------------
00926 
00927 
00928 
00929 
00930 //-----------------------------------------------------------------------------
00931 // With Sphere BV
00932 //-----------------------------------------------------------------------------
00933 // TestOverlap_vs_BV_Sphere #1
00934 template <typename T>
00935 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere ( 
00936         BVHNode<T> const * const nodeA, 
00937         Vector3<T> const & sphereCenter, 
00938         T sphereRadius )
00939 {
00940     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00941     std::cout << "#1 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere( BVHNode<T>, Vector3<T>, T )\n";
00942     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00943     std::cout << "\tCurrently call TestOverlap_vs_BV_Sphere_TillLeafNodes( ... ) instead\n";
00944 
00945     return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, sphereCenter, sphereRadius );
00946 
00947     //---------------------------------------------------------------
00948     // Do low level here!!!
00949     //---------------------------------------------------------------
00950 }
00951 //-----------------------------------------------------------------------------
00952 // TestOverlap_vs_BV_Sphere #2
00953 template <typename T>
00954 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere ( 
00955         BVHNode<T> const * const nodeA, 
00956         Matrix4x4<T> const & transformA, 
00957         Vector3<T> const & sphereCenter, 
00958         T sphereRadius )
00959 {
00960     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00961     std::cout << "#2 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere( BVHNode<T>, Matrix4x4<T>, Vector3<T>, sphereCenter, sphereRadius )\n";
00962     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
00963     std::cout << "\tCurrently call TestOverlap_vs_BV_Sphere_TillLeafNodes( ... ) instead\n";
00964 
00965     return TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA, transformA, sphereCenter, sphereRadius );
00966 
00967     //---------------------------------------------------------------
00968     // Do low level here!!!
00969     //---------------------------------------------------------------
00970 }
00971 //-----------------------------------------------------------------------------
00972 // With Sphere BV
00973 //-----------------------------------------------------------------------------
00974 
00975 
00976 
00977 
00978 //-----------------------------------------------------------------------------
00979 // With Sphere BV TillLeafNodes
00980 //-----------------------------------------------------------------------------
00981 // TestOverlap_vs_BV_Sphere_TillLeafNodes #1
00982 template <typename T>
00983 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere_TillLeafNodes ( 
00984         BVHNode<T> const * const nodeA, 
00985         Vector3<T> const & sphereCenter, 
00986         T sphereRadius )
00987 {
00988     //std::cout << "#1 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere_TillLeafNodes( BVHNode<T>, Vector3<T>, T )\n";
00989 
00990     //---------------------------------------------------------------
00991     // Test overlapping
00992     if ( nodeA->TestOverlapSphereWithBVSphere_NoPrimitiveTests( sphereCenter, sphereRadius ) > Math<T>::ZERO ) {
00993         return false;
00994     }
00995     //---------------------------------------------------------------
00996     // If node A is leaf
00997     if ( nodeA->IsLeaf() ) {
00998         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( nodeA ) );
00999         //std::cout << "\tTRUE -- nodeA: " << nodeA << "\n";
01000         #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01001             const_cast< BVHNode<T> * >( nodeA )->flag = true;
01002         #endif//TAPs_DEBUG_COLLISION_DETECTION
01003         return true;
01004     }
01005     //---------------------------------------------------------------
01006     // If node A is not leaf
01007     else {
01008         bool overlap1 = false, overlap2 = false;
01009         if ( nodeA->Child(0) ) {
01010             overlap1 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(0), sphereCenter, sphereRadius );
01011         }
01012         if ( nodeA->Child(1) ) {
01013             overlap2 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(1), sphereCenter, sphereRadius );
01014         }
01015         if ( overlap1 || overlap2 ) {
01016             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01017                 const_cast< BVHNode<T> * >( nodeA )->flag = true;
01018             #endif//TAPs_DEBUG_COLLISION_DETECTION
01019             return true;
01020         }
01021         else {
01022             return false;
01023         }
01024     }
01025     //---------------------------------------------------------------
01026 }
01027 //-----------------------------------------------------------------------------
01028 // TestOverlap_vs_BV_Sphere_TillLeafNodes #2
01029 template <typename T>
01030 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere_TillLeafNodes ( 
01031         BVHNode<T> const * const nodeA, 
01032         Matrix4x4<T> const & transformA, 
01033         Vector3<T> const & sphereCenter, 
01034         T sphereRadius )
01035 {
01036     //std::cout << "#2 BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Sphere_TillLeafNodes( BVHNode<T>, Matrix4x4<T>, Vector3<T>, T )\n";
01037     //---------------------------------------------------------------
01038     // Test overlapping
01039     if ( nodeA->TestOverlapSphereWithBVSphere_NoPrimitiveTests( transformA, sphereCenter, sphereRadius ) > Math<T>::ZERO ) {
01040         return false;
01041     }
01042     //---------------------------------------------------------------
01043     // If node A is leaf
01044     else if ( nodeA->IsLeaf() ) {
01045         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( nodeA ) );
01046         //std::cout << "\tTRUE -- nodeA: " << nodeA << "\n";
01047         #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01048             const_cast< BVHNode<T> * >( nodeA )->flag = true;
01049         #endif//TAPs_DEBUG_COLLISION_DETECTION
01050         return true;
01051     }
01052     //---------------------------------------------------------------
01053     // If node A is not leaf
01054     else {
01055         bool overlap1 = false, overlap2 = false;
01056         if ( nodeA->Child(0) ) {
01057             overlap1 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(0), transformA, sphereCenter, sphereRadius );
01058         }
01059         if ( nodeA->Child(1) ) {
01060             overlap2 = TestOverlap_vs_BV_Sphere_TillLeafNodes( nodeA->Child(1), transformA, sphereCenter, sphereRadius );
01061         }
01062         if ( overlap1 || overlap2 ) {
01063             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01064                 const_cast< BVHNode<T> * >( nodeA )->flag = true;
01065             #endif//TAPs_DEBUG_COLLISION_DETECTION
01066             return true;
01067         }
01068         else {
01069             return false;
01070         }
01071     }
01072     //---------------------------------------------------------------
01073 }
01074 //-----------------------------------------------------------------------------
01075 // With Sphere BV TillLeafNodes
01076 //-----------------------------------------------------------------------------
01077 
01078 
01079 
01080 
01081 
01082 //-----------------------------------------------------------------------------
01083 // With Cylinder BV
01084 //-----------------------------------------------------------------------------
01085 // TestOverlap_vs_BV_Cylinder
01086 template <typename T>
01087 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Cylinder_AtOrigin ( 
01088         BVHNode<T> const * const nodeA, 
01089         Matrix4x4<T> const & transformA, 
01090         T cylinderRadius, 
01091         T cylinderHeight )
01092 {
01093     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01094     std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Cylinder_AtOrigin( BVHNode<T>, Matrix4x4<T>, cylinderRadius, cylinderHeight )\n";
01095     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01096     std::cout << "\tCurrently call TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( ... ) instead\n";
01097 
01098     return TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA, transformA, cylinderRadius, cylinderHeight );
01099 
01100     //---------------------------------------------------------------
01101     // Do low level here!!!
01102     //---------------------------------------------------------------
01103 }
01104 //-----------------------------------------------------------------------------
01105 // With Cylinder BV
01106 //-----------------------------------------------------------------------------
01107 
01108 
01109 
01110 
01111 //-----------------------------------------------------------------------------
01112 // With Cylinder BV TillLeafNodes
01113 //-----------------------------------------------------------------------------
01114 // TestOverlap_vs_BV_Cylinder_TillLeafNodes
01115 template <typename T>
01116 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes ( 
01117         BVHNode<T> const * const nodeA, 
01118         Matrix4x4<T> const & transformA, 
01119         T cylinderRadius, 
01120         T cylinderHeight )
01121 {
01122     //std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BV_Cylinder_TillLeafNodes( BVHNode<T>, Matrix4x4<T>, cylinderRadius, cylinderHeight )\n";
01123 
01124     //---------------------------------------------------------------
01125     // Test overlapping
01126     if ( nodeA->TestOverlapSphereWithBVCylinder_AtOrigin_NoPrimitiveTests( transformA, cylinderRadius, cylinderHeight ) == false ) {
01127         return false;
01128     }
01129     //---------------------------------------------------------------
01130     // If node A is leaf
01131     else if ( nodeA->IsLeaf() ) {
01132         #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01133             const_cast< BVHNode<T> * >( nodeA )->flag = true;
01134         #endif//TAPs_DEBUG_COLLISION_DETECTION
01135         m_svCollidedNode.push_back( const_cast< BVHNode<T> * >( nodeA ) );
01136         //std::cout << "\tTRUE -- nodeA: " << nodeA << "\n";
01137         return true;
01138     }
01139     //---------------------------------------------------------------
01140     // If node A is not leaf
01141     else {
01142         bool overlap1 = false, overlap2 = false;
01143         if ( nodeA->Child(0) ) {
01144             overlap1 = TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA->Child(0), transformA, cylinderRadius, cylinderHeight );
01145         }
01146         if ( nodeA->Child(1) ) {
01147             overlap2 = TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes( nodeA->Child(1), transformA, cylinderRadius, cylinderHeight );
01148         }
01149         if ( overlap1 || overlap2 ) {
01150             #ifdef  TAPs_DEBUG_COLLISION_DETECTION
01151                 const_cast< BVHNode<T> * >( nodeA )->flag = true;
01152             #endif//TAPs_DEBUG_COLLISION_DETECTION
01153             return true;
01154         }
01155         else {
01156             return false;
01157         }
01158     }
01159     //---------------------------------------------------------------
01160 }
01161 //-----------------------------------------------------------------------------
01162 // With Cylinder BV TillLeafNodes
01163 //-----------------------------------------------------------------------------
01164 
01165 
01166 //-----------------------------------------------------------------------------
01167 // END: Test Overlap with a BoundingVolume
01168 //=============================================================================
01169 
01170 
01171 
01172 //=============================================================================
01173 // START: Test Overlap with Another BVHTree_BinarySphere
01174 //-----------------------------------------------------------------------------
01175 // TestOverlap_vs_BinarySphere
01176 template <typename T>
01177 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BinarySphere ( 
01178                         BVHNode<T> const * const nodeA, 
01179                         Matrix4x4<T> const & transformA, 
01180                         BVHNode<T> const * const nodeB, 
01181                         Matrix4x4<T> const & transformB )
01182 {
01183     #ifdef  TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01184     std::cout << "BVHTree_BinarySphere<T>::TestOverlap_vs_BinarySphere( BVHNode<T>, Matrix4x4<T>, BVHNode<T>, Matrix4x4<T> )\n";
01185     #endif//TAPs_DEBUG_BINARY_SPHERE_TREE_CDR
01186     std::cout << "\tCurrently call TestOverlap_vs_BinarySphere_TillLeafNodes( ... ) instead\n";
01187 
01188     bool bResult = TestOverlap_vs_BinarySphere_TillLeafNodes( nodeA, transformA, nodeB, transformB );
01189     if ( bResult ) {
01190         //-----------------------------------
01191         // Do Low-level Intersection Test HERE!
01192         //std::cout << "// Do Low-level Intersection Test HERE!\n";
01193         // E.g., Triangle-triangle intersection test
01194         //bResult = leaf node from nodeA->TestOverlapPrimitiveWithPrimitive( transformA, leaf node from nodeB, transformB );
01195     }
01196     return bResult;
01197 }
01198 //-----------------------------------------------------------------------------
01199 // TestOverlap_vs_BinarySphere_TillLeafNodes
01200 template <typename T>
01201 bool BVHTree_BinarySphere<T>::TestOverlap_vs_BinarySphere_TillLeafNodes ( 
01202                         BVHNode<T> const * const nodeA, 
01203                         Matrix4x4<T> const & transformA, 
01204                         BVHNode<T> const * const nodeB, 
01205                         Matrix4x4<T> const & transformB )
01206 {
01207     //---------------------------------------------------------------
01208     // Test overlapping
01209     if ( nodeA->TestOverlapSphereWithSphere_NoPrimitiveTests( transformA, nodeB, transformB ) > Math<T>::ZERO ) {
01210         return false;
01211     }
01212 
01213     //std::cout << "ah ha\n";
01214     //return true;
01215     //if ( false ) {}
01216 
01217     //---------------------------------------------------------------
01218     // If node A is leaf
01219     else if ( nodeA->IsLeaf() ) {
01220         //-------------------------------------------------
01221         // Both node A and node B are leaves
01222         if ( nodeB->IsLeaf() ) {
01223             //-----------------------------------
01224             // Do Low-level Intersection Test HERE!
01225             //std::cout << "// Do Low-level Intersection Test HERE!\n";
01226             //-----------------------------------
01227             //std::cout << "Distance (" << nodeA << "," << nodeB << "): " 
01228             //      << nodeA->TestOverlapSphereWithSphere_TillLeafNodes( nodeB ) << "\n";
01229             BVHNode<T> * nA = const_cast< BVHNode<T> * >( nodeA );
01230             BVHNode<T> * nB = const_cast< BVHNode<T> * >( nodeB );
01231             m_svCollidedNode.push_back( nA );
01232             m_svCollidedNodeThat.push_back( nB );
01233             //-----------------------------------
01234             return true;
01235         }
01236         //-------------------------------------------------
01237         // Node A is leaf, but node B is not
01238         else {
01239             bool overlap1 = false, overlap2 = false;
01240             if ( nodeB->Child(0) ) {
01241                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01242                                 nodeA, transformA, nodeB->Child(0), transformB );
01243             }
01244             if ( nodeB->Child(1) ) {
01245                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01246                                 nodeA, transformA, nodeB->Child(1), transformB );
01247             }
01248             if ( overlap1 || overlap2 ) return true;
01249             else                        return false;
01250         }
01251     }
01252     //---------------------------------------------------------------
01253     // If node A is not leaf
01254     else {
01255         //-------------------------------------------------
01256         // Node A is not leaf, but node B is
01257         if ( nodeB->IsLeaf() ) {
01258             bool overlap1 = false, overlap2 = false;
01259             if ( nodeA->Child(0) ) {
01260                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01261                                 nodeA->Child(0), transformA, nodeB, transformB );
01262             }
01263             if ( nodeA->Child(1) ) {
01264                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01265                                 nodeA->Child(1), transformA, nodeB, transformB );
01266             }
01267             if ( overlap1 || overlap2 ) return true;
01268             else                        return false;
01269         }
01270         //-------------------------------------------------
01271         // Both node A and node B are not leaves
01272         else {
01273             bool overlap1 = false, overlap2 = false, overlap3 = false, overlap4 = false;
01274             if ( nodeA->Child(0) && nodeB->Child(0) ) {
01275                 overlap1 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01276                                 nodeA->Child(0), transformA, nodeB->Child(0), transformB );
01277             }
01278             if ( nodeA->Child(0) && nodeB->Child(1) ) {
01279                 overlap2 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01280                                 nodeA->Child(0), transformA, nodeB->Child(1), transformB );
01281             }
01282             if ( nodeA->Child(1) && nodeB->Child(0) ) {
01283                 overlap3 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01284                                 nodeA->Child(1), transformA, nodeB->Child(0), transformB );
01285             }
01286             if ( nodeA->Child(1) && nodeB->Child(1) ) {
01287                 overlap4 = TestOverlap_vs_BinarySphere_TillLeafNodes( 
01288                                 nodeA->Child(1), transformA, nodeB->Child(1), transformB );
01289             }
01290             if ( overlap1 || overlap2 || overlap3 || overlap4 )
01291                 return true;
01292             else
01293                 return false;
01294         }
01295     }
01296     //---------------------------------------------------------------
01297 }
01298 //-----------------------------------------------------------------------------
01299 // END: Test Overlap with Another BVHTree_BinarySphere
01300 //=============================================================================
01301 
01302 
01303 //=============================================================================
01304 // BINARY SPHERE BOUNDING VOLUME HIERARCHY TREE
01305 //-----------------------------------------------------------------------------
01306 template <typename T>
01307 BVHTree<T> * BVHTree_BinarySphere<T>::BSphereBuild ( 
01308         TransformationSupport<T> & transform,       // I/O: Transform
01309         const std::list< HEFace<T>* > & heFaceList, // I/P half-edge face list
01310         BVHTree<T> * cdtree )                       // O/P pointer to BVHTree
01311 {
01312     //std::cout << "BSphereBuild (before): " << cdtree << std::endl;
01313     BVHNode<T> *node = CreateBVHNodeBSphere( NULL, heFaceList );
01314 //  node->listHEFace  = heFaceList;         // DEBUG
01315     cdtree = new BVHTree<T>( transform, Enum::BVH_TREE_BINARY_SPHERE, 1, node );
01316     //FindOBBOfFaceList( heFaceList, node );
01317     Vector3<T> U, V, W;
01318     FindOBBOfFaceList( heFaceList, node->GetCenter(), U, V, W );
01319     if ( node ) BSphereBuildChildren( node, heFaceList, U );
01320     //std::cout << "BSphereBuild (after): " << cdtree << std::endl;
01321 
01322     SetNumOfNodes( CountNodes() );
01323     return cdtree;
01324 }
01325 //-----------------------------------------------------------------------------
01326 // Create binary child spheres
01327 template <typename T>
01328 void BVHTree_BinarySphere<T>::BSphereBuildChildren ( 
01329     BVHNode<T> * pParentNode, 
01330     const std::list< HEFace<T> * > & heFaceList, 
01331     Vector3<T> const & principleVector )
01332 {
01333     int size = static_cast<int>( heFaceList.size() );
01334     std::list< HEFace<T> * > leftGroup, rightGroup;
01335     //---------------------------------------------------------------
01336     // CASE: one face
01337     // This is a leaf node.
01338     assert( size > 0 );         // ASSERT
01339     if ( 1 == size ) {
01340         return;
01341     }
01342     //---------------------------------------------------------------
01343     assert( pParentNode );          // ASSERT
01344     BVHNode<T> * leftChild  = NULL;
01345     BVHNode<T> * rightChild = NULL;
01346     //---------------------------------------------------------------
01347     // CASE: two faces
01348     // Create Two Leaf Nodes
01349     if ( 2 == size ) {
01350         //-------------------------------------------------
01351         // Separate two faces into left and right groups
01352         std::list< HEFace<T> * >::const_iterator face = heFaceList.begin();
01353         leftGroup.push_back( *face );
01354         ++face;
01355         rightGroup.push_back( *face );
01356         //-------------------------------------------------
01357         // Create Left Leaf Node
01358         leftChild  = CreateBVHNodeBSphere( pParentNode, leftGroup );
01359 //      leftChild->listHEFace  = leftGroup;         // DEBUG
01360         pParentNode->Child( 0, leftChild );
01361         //-------------------------------------------------
01362         // Create Right Leaf Node
01363         rightChild = CreateBVHNodeBSphere( pParentNode, rightGroup );
01364 //      rightChild->listHEFace = rightGroup;        // DEBUG
01365         pParentNode->Child( 1, rightChild );
01366         return;
01367     }
01368     //---------------------------------------------------------------
01369     // CASE: more than two faces
01370     // Didive into two groups
01371     BSphereDivideToFaceGroups(  heFaceList, leftGroup, rightGroup, 
01372                                 pParentNode->GetCenter(), 
01373                                 principleVector );
01374     //---------------------------------------------------------------
01375     // CASE: more than two faces and the divider failed to divide the face list
01376     if (   static_cast<int>( leftGroup.size() )  == size 
01377         || static_cast<int>( rightGroup.size() ) == size ) {
01378         //std::cout << "Total    : " << size;
01379         //std::cout << "; Left  Grp: " << leftGroup.size();
01380         //std::cout << "; Right Grp: " << rightGroup.size() << std::endl;
01381         leftGroup.clear();
01382         rightGroup.clear();
01383         std::list< HEFace<T> * >::const_iterator face = heFaceList.begin();
01384         int i = 0;
01385         for ( ; i < size/2; ++i ) {
01386             leftGroup.push_back( *face );
01387             ++face;
01388         }
01389         for ( ; i < size; ++i ) {
01390             rightGroup.push_back( *face );
01391             ++face;
01392         }
01393     }
01394     Vector3<T> U, V, W;
01395     //---------------------------------------------------------------
01396     // Create Left Child Node
01397     leftChild  = CreateBVHNodeBSphere( pParentNode, leftGroup );
01398     FindOBBOfFaceList( leftGroup, leftChild->GetCenter(), U, V, W );
01399 //  leftChild->listHEFace  = leftGroup;         // DEBUG
01400     pParentNode->Child( 0, leftChild );
01401     BSphereBuildChildren( leftChild, leftGroup, U );
01402     //---------------------------------------------------------------
01403     // Create Right Child Node
01404     rightChild = CreateBVHNodeBSphere( pParentNode, rightGroup );
01405     FindOBBOfFaceList( rightGroup, rightChild->GetCenter(), U, V, W );
01406 //  rightChild->listHEFace = rightGroup;        // DEBUG
01407     pParentNode->Child( 1, rightChild );
01408     BSphereBuildChildren( rightChild, rightGroup, U );
01409 }
01410 //-----------------------------------------------------------------------------
01411 // Find the group that this face belongs to
01412 template <typename T>
01413 int BVHTree_BinarySphere<T>::BSphereDetermineFaceGroup ( HEFace<T> * face, 
01414                                       const Vector3<T> & center, 
01415                                       const Vector3<T> & direction )
01416 {
01417     //-------------------------------------------------------------------------
01418     // Divided into an axis positive and negative
01419     //---------------------------------------------------------------
01420     // REMARK:
01421     //   To speed thing up, we can evaluate only the first vertex of the polygon.
01422     //---------------------------------------------------------------
01423     // Determine from all vertices
01424     int value = 0;
01425     HEHalfEdge<T> * firstHalfEdge = face->IncidentHalfEdge();
01426     HEHalfEdge<T> * halfEdge = firstHalfEdge;
01427     Vector3<T> vertex;
01428     do {
01429         /*
01430         vertex = halfEdge->Vertex()->GetPosition() - center;
01431         if ( vertex.GetY() >= 0 )   ++value;
01432         else                        --value;
01433         //*/
01434         //*
01435         if ( (halfEdge->Vertex()->GetPosition() - center) * direction >= 0 )
01436             ++value;
01437         else
01438             --value;
01439         //*/
01440         
01441         halfEdge = halfEdge->Next();
01442     } while ( halfEdge != firstHalfEdge );
01443     //---------------------------------------------------------------
01444     // Determine the group (left or right)
01445     return  value >= 0 ? 1 : 0;
01446 }
01447 //-----------------------------------------------------------------------------
01448 template <typename T>
01449 void BVHTree_BinarySphere<T>::BSphereDivideToFaceGroups ( 
01450                 const std::list< HEFace<T> * > & inputFaces,    // input
01451                 std::list< HEFace<T> * > & group1,              // output group1
01452                 std::list< HEFace<T> * > & group2,              // output group2
01453                 const Vector3<T> & center, 
01454                 const Vector3<T> & direction )
01455 {
01456     std::list< HEFace<T> * >::const_iterator face;
01457     for ( face = inputFaces.begin(); face != inputFaces.end(); ++face ) {
01458         if ( BSphereDetermineFaceGroup( *face, center, direction ) == 1 )
01459             group1.push_back( *face );
01460         else
01461             group2.push_back( *face );
01462     }
01463 }
01464 //*/
01465 //*
01466 //-----------------------------------------------------------------------------
01467 // Create a new sphere bounding volume node from the face list
01468 template <typename T>
01469 BVHNode<T> * BVHTree_BinarySphere<T>::CreateBVHNodeBSphere ( 
01470                         BVHNode<T> * pParentNode, 
01471                         const std::list< HEFace<T> * > & heFaceList )
01472 {
01473     //---------------------------------------------------------------
01474     Vector3<T> AABB[2];
01475     //HEVertex<T> * vertex = m_listVertex->Head();
01476     std::list< HEFace<T> * >::const_iterator face = heFaceList.begin();
01477     HEHalfEdge<T> * firstHalfEdge = (*face)->IncidentHalfEdge();
01478     HEHalfEdge<T> * halfEdge = firstHalfEdge;
01479     Vector3<T> vertex = halfEdge->Vertex()->GetPosition();
01480     AABB[0] = AABB[1] = vertex;
01481     //---------------------------------------------------------------
01482     // For Each Face
01483     for ( ; face != heFaceList.end(); ++face ) {
01484         halfEdge = firstHalfEdge = (*face)->IncidentHalfEdge();
01485         //-------------------------------------------------
01486         // For Each Vertex
01487         do {
01488             vertex = halfEdge->Vertex()->GetPosition();
01489             // Find the lowest an the highest of x, y, and z
01490             // AABB[0] is min and AABB[1] is max
01491             if      ( AABB[0][0] > vertex[0] )  AABB[0][0] = vertex[0];
01492             else if ( AABB[1][0] < vertex[0] )  AABB[1][0] = vertex[0];
01493             if      ( AABB[0][1] > vertex[1] )  AABB[0][1] = vertex[1];
01494             else if ( AABB[1][1] < vertex[1] )  AABB[1][1] = vertex[1];
01495             if      ( AABB[0][2] > vertex[2] )  AABB[0][2] = vertex[2];
01496             else if ( AABB[1][2] < vertex[2] )  AABB[1][2] = vertex[2];
01497             // Next vertex
01498             halfEdge = halfEdge->Next();
01499         } while ( halfEdge != firstHalfEdge );
01500     }
01501     //---------------------------------------------------------------
01502     // Find the bounding volume center from the AABB
01503     Vector3<T> vCenter( ( AABB[0][0] + AABB[1][0] ) / T(2.0),
01504                         ( AABB[0][1] + AABB[1][1] ) / T(2.0),
01505                         ( AABB[0][2] + AABB[1][2] ) / T(2.0) );
01506     //---------------------------------------------------------------
01507     // Find the Sphere Bounding Volume
01508     T radius = 0, squaredLength;
01509     for ( face = heFaceList.begin(); face != heFaceList.end(); ++face ) {
01510         halfEdge = firstHalfEdge = (*face)->IncidentHalfEdge();
01511         //-------------------------------------------------
01512         do {
01513             vertex = halfEdge->Vertex()->GetPosition();
01514             //squaredLength = (vertex - vCenter).SquaredLength();
01515             squaredLength = (vertex - vCenter).Length();
01516             if ( squaredLength > radius )   radius = squaredLength;
01517             halfEdge = halfEdge->Next();
01518         } while ( halfEdge != firstHalfEdge );
01519     }
01520     //radius = sqrt( radius );
01521     //---------------------------------------------------------------
01522     // Make the root node
01523     //-------------------------------------------
01524     // BVHNode Constructor
01525     //   BVHNode<T>(    Enum::CD type,
01526     //                  int id, 
01527     //                  BVHNode<T> * parent, 
01528     //                  BVHNode<T> ** children )
01529     //-------------------------------------------
01530     //BVHNode<T> * node;
01531     if ( 1 == static_cast<int>( heFaceList.size() ) ) {
01532         /*
01533         node = new BVHNode<T>( Enum::BVH_NODE_BINARY_SPHERE, 
01534                                 -1, pParentNode, NULL );
01535         //*/
01536         //*
01537         BVHNodeLeafHalfEdgeAPrim<T> * node = new BVHNodeLeafHalfEdgeAPrim<T>( 
01538                 Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM, 
01539                 -1, pParentNode );
01540         node->m_primHEFace = heFaceList.front();
01541 //      BVHNodeLeafHalfEdgePrims<T> * node = new BVHNodeLeafHalfEdgePrims<T>( 
01542 //              Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS, 
01543 //              -1, pParentNode );
01544         //node->listHEFace = heFaceList;
01545         node->SetCenter( vCenter );
01546         node->SetRadius( radius );
01547         return node;
01548         //*/
01549     }
01550     else {
01551         BVHNode<T> * node = new BVHNode<T>( Enum::BVH_NODE_BINARY_SPHERE, 
01552                                             -1, pParentNode, NULL );
01553         node->SetCenter( vCenter );
01554         node->SetRadius( radius );
01555         return node;
01556     }
01557 }
01558 //*/
01559 //-----------------------------------------------------------------------------
01560 //=============================================================================
01561 END_NAMESPACE_TAPs
01562 //34567890123456789012345678901234567890123456789012345678901234567890123456789
01563 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines