![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsBVHTree_BinarySphere.hpp 00003 ******************************************************************************/ 00009 /****************************************************************************** 00010 SUKITTI PUNAK (07/11/2008) 00011 UPDATE (10/12/2010) 00012 ******************************************************************************/ 00013 #ifndef TAPs_BVH_TREE_BINARY_SPHERE_HPP 00014 #define TAPs_BVH_TREE_BINARY_SPHERE_HPP 00015 00016 #include "TAPsBVHTree.hpp" 00017 00018 #ifdef TAPs_DEBUG_MODE 00019 //#define TAPs_DEBUG_BINARY_SPHERE_TREE_CDR 00020 #endif//TAPs_DEBUG_MODE 00021 00022 00023 BEGIN_NAMESPACE_TAPs 00024 //============================================================================= 00025 template <typename T> 00026 class BVHTree_BinarySphere : public /*virtual*/ BVHTree<T> { 00027 //============================================================================= 00028 // Member Functions 00029 public: 00030 //------------------------------------------------------------------------- 00031 // Output Operator << 00032 friend std::ostream & operator<< ( std::ostream &output, BVHTree_BinarySphere<T> const &obj ) 00033 { 00034 output << "BVHTree_BinarySphere<" << typeid(T).name() << "> ID:" 00035 << " with " << obj.m_iTotalNodes << " nodes" 00036 << " and the root ptr is " << obj.m_pRoot 00037 << "\n"; 00038 return output; 00039 } 00040 //------------------------------------------------------------------------- 00041 // Constructor and Destructor 00042 00043 BVHTree_BinarySphere ( TransformationSupport<T> & transform, 00044 //Enum::CD type = Enum::UNDEFINED_TREE, 00045 int numOfNodes = 0, 00046 BVHNode<T> * rootNode = NULL ); 00047 00048 BVHTree_BinarySphere ( 00049 TransformationSupport<T> & transform, 00050 HEFaceList<T> * heFaceList 00051 ); 00052 00053 virtual ~BVHTree_BinarySphere (); 00054 //------------------------------------------------------------------------- 00055 00056 //========================================================================= 00057 // OVERRIDE PURE VIRTUAL FNs ---------------------------------------------- 00058 //------------------------------------------------------------------------- 00064 virtual bool TestOverlapWith ( BVHTree<T> const * const that ); 00065 00071 virtual bool TestOverlapWithTillLeafNodes ( BVHTree<T> const * const that ); 00072 00077 virtual bool TestOverlapWith ( BVHNode<T> const * const node ); 00078 00083 virtual bool TestOverlapWithTillLeafNodes ( BVHNode<T> const * const node ); 00084 00090 virtual bool TestOverlapWith ( MultiBoundingVolume<T> const * const pMBV ); 00091 00097 virtual bool TestOverlapWithTillLeafNodes ( MultiBoundingVolume<T> const * const pMBV ); 00098 00103 virtual bool TestOverlapWith ( BoundingVolume<T> const * const pBV ); 00104 00109 virtual bool TestOverlapWithTillLeafNodes ( BoundingVolume<T> const * const pBV ); 00110 00115 virtual bool TestIntersectionWithLineSegmentTillLeafNodes ( Vector3<T> const * const ptA, Vector3<T> const * const ptB ); 00116 00122 virtual bool TestIntersectionWithCircleTillLeafNodes ( Vector3<T> const * const circleNormalPlane, Vector3<T> const * const circleCenter, T circleRadius ); 00123 00131 virtual bool TestOverlapWith ( 00132 InteractionPointGroup<T> * const pIPG, 00133 std::vector< PointForce<T> > & ListOfPointForces 00134 ); 00135 00143 virtual bool TestOverlapWithTillLeafNodes ( 00144 InteractionPointGroup<T> * const pIPG, 00145 std::vector< PointForce<T> > & ListOfPointForces 00146 ); 00147 00148 //------------------------------------------------------------------------- 00149 // OVERRIDE PURE VIRTUAL FNs ---------------------------------------------- 00150 //========================================================================= 00151 00152 //========================================================================= 00153 // Bounding Volume Hierarchy Tree Creation 00154 //------------------------------------------------------------------------- 00155 // Create a Bounding Volume Hierarchy Tree for collision detection 00156 // BVHTree<T> * Build ( 00157 // TransformationSupport<T> & transform, //!< I/O: Transform 00158 // HEFaceList<T> * heFaceList, //!< I/P: half-edge face list 00159 // Enum::CD treeType, //!< I/P: BVHTree type 00160 // BVHTree<T> * cdtree ); //!< O/P: pointer to BVHTree 00161 static BVHTree<T> * Build ( 00162 TransformationSupport<T> & transform, 00163 std::list< HEFace<T>* > const * const heFaceList, 00164 Enum::CD treeType, 00165 BVHTree<T> * cdtree ); 00166 //------------------------------------------------------------------------- 00167 00168 protected: 00169 00170 //------------------------------------------------------------------------- 00172 bool TestIntersectionWithLineSegmentTillLeafNodesRecursive ( 00173 BVHNode<T> const * const node, 00174 Vector3<T> const * const ptA, 00175 Vector3<T> const * const ptB 00176 ); 00177 //------------------------------------------------------------------------- 00178 00179 //------------------------------------------------------------------------- 00181 bool TestIntersectionWithCircleTillLeafNodesRecursive ( 00182 Matrix4x4<T> Trx, 00183 BVHNode<T> const * const node, 00184 T circleRadius 00185 ); 00186 //------------------------------------------------------------------------- 00187 00188 //------------------------------------------------------------------------- 00190 bool TestOverlapWithIPGRecursive ( 00191 BVHNode<T> const * const node, 00192 InteractionPointGroup<T> * const pIPG, 00193 std::vector< PointForce<T> > & ListOfPointForces 00194 ); 00196 bool TestOverlapWithIPGTillLeafNodesRecursive ( 00197 BVHNode<T> const * const node, 00198 InteractionPointGroup<T> * const pIPG, 00199 std::vector< PointForce<T> > & ListOfPointForces 00200 ); 00201 //------------------------------------------------------------------------- 00202 00203 //========================================================================= 00204 // Test Overlap with a BoundingVolume 00205 //------------------------------------------------------------------------- 00212 virtual bool TestOverlap_vs_BV ( 00213 BVHNode<T> const * const nodeA, 00214 Matrix4x4<T> const & transformA, 00215 BoundingVolume<T> const * const pBV, 00216 Matrix4x4<T> const & transformB ); 00217 //------------------------------------------------------------------------- 00221 virtual bool TestOverlap_vs_BV_TillLeafNodes ( 00222 BVHNode<T> const * const nodeA, 00223 Matrix4x4<T> const & transformA, 00224 BoundingVolume<T> const * const pBV, 00225 Matrix4x4<T> const & transformB ); 00226 //------------------------------------------------------------------------- 00227 //========================================================================= 00228 00229 //========================================================================= 00230 // Transformations 00231 //------------------------------------------------------------------------- 00233 inline void ForBVSphereTransformations ( 00234 BoundingVolume<T> const * const pBV, 00235 Matrix4x4<T> const & bvTransformation, 00236 Vector3<T> & sphereCenter, 00237 T & sphereRadius 00238 ); 00239 00242 inline void ForBVCylinderTransformations ( 00243 BoundingVolume<T> const * const pBV, 00244 Matrix4x4<T> & nodeTransform_OP 00245 ); 00248 inline void ForBVCylinderTransformations ( 00249 BoundingVolume<T> const * const pBV, 00250 Matrix4x4<T> const & bvTransformation, 00251 Matrix4x4<T> & nodeTransform_OP 00252 ); 00255 inline void ForBVCylinderTransformations ( 00256 Matrix4x4<T> const & nodeTransform_IP, 00257 BoundingVolume<T> const * const pBV, 00258 Matrix4x4<T> & nodeTransform_OP 00259 ); 00262 inline void ForBVCylinderTransformations ( 00263 Matrix4x4<T> const & nodeTransform_IP, 00264 BoundingVolume<T> const * const pBV, 00265 Matrix4x4<T> const & bvTransformation, 00266 Matrix4x4<T> & nodeTransform_OP 00267 ); 00268 //------------------------------------------------------------------------- 00269 //========================================================================= 00270 00271 //========================================================================= 00272 // With Sphere BV 00273 //------------------------------------------------------------------------- 00275 bool TestOverlap_vs_BV_Sphere ( 00276 BVHNode<T> const * const nodeA, 00277 Vector3<T> const & sphereCenter, 00278 T sphereRadius ); 00279 bool TestOverlap_vs_BV_Sphere ( 00280 BVHNode<T> const * const nodeA, 00281 Matrix4x4<T> const & transformA, 00282 Vector3<T> const & sphereCenter, 00283 T sphereRadius ); 00284 //------------------------------------------------------------------------- 00285 // With Sphere BV TillLeafNodes 00286 //------------------------------------------------------------------------- 00288 bool TestOverlap_vs_BV_Sphere_TillLeafNodes ( 00289 BVHNode<T> const * const nodeA, 00290 Vector3<T> const & sphereCenter, 00291 T sphereRadius ); 00292 bool TestOverlap_vs_BV_Sphere_TillLeafNodes ( 00293 BVHNode<T> const * const nodeA, 00294 Matrix4x4<T> const & transformA, 00295 Vector3<T> const & sphereCenter, 00296 T sphereRadius ); 00297 //------------------------------------------------------------------------- 00298 //========================================================================= 00299 00300 //========================================================================= 00301 // With Cylinder BV 00302 //------------------------------------------------------------------------- 00307 bool TestOverlap_vs_BV_Cylinder_AtOrigin ( 00308 BVHNode<T> const * const nodeA, 00309 Matrix4x4<T> const & transformA, 00310 T cylinderRadius, 00311 T cylinderHeight ); 00312 //------------------------------------------------------------------------- 00313 // With Cylinder BV TillLeafNodes 00314 //------------------------------------------------------------------------- 00319 bool TestOverlap_vs_BV_Cylinder_AtOrigin_TillLeafNodes ( 00320 BVHNode<T> const * const nodeA, 00321 Matrix4x4<T> const & transformA, 00322 T cylinderRadius, 00323 T cylinderHeight ); 00324 //------------------------------------------------------------------------- 00325 //========================================================================= 00326 00327 //========================================================================= 00328 // Test Overlap with Another BVHTree_BinarySphere 00329 //------------------------------------------------------------------------- 00336 virtual bool TestOverlap_vs_BinarySphere ( 00337 BVHNode<T> const * const nodeA, 00338 Matrix4x4<T> const & transformA, 00339 BVHNode<T> const * const nodeB, 00340 Matrix4x4<T> const & transformB ); 00341 //------------------------------------------------------------------------- 00345 virtual bool TestOverlap_vs_BinarySphere_TillLeafNodes ( 00346 BVHNode<T> const * const nodeA, 00347 Matrix4x4<T> const & transformA, 00348 BVHNode<T> const * const nodeB, 00349 Matrix4x4<T> const & transformB ); 00350 //------------------------------------------------------------------------- 00351 //========================================================================= 00352 00353 /* 00354 //========================================================================= 00355 // Test Overlap with Another BVHTree_BinaryAABB 00356 //------------------------------------------------------------------------- 00363 virtual bool TestOverlap_vs_BinaryAABB ( 00364 BVHNode<T> const * const nodeA, 00365 Matrix4x4<T> const & transformA, 00366 BVHNode<T> const * const nodeB, 00367 Matrix4x4<T> const & transformB ) = 0; 00368 //------------------------------------------------------------------------- 00372 virtual bool TestOverlap_vs_BinaryAABB_TillLeafNodes ( 00373 BVHNode<T> const * const nodeA, 00374 Matrix4x4<T> const & transformA, 00375 BVHNode<T> const * const nodeB, 00376 Matrix4x4<T> const & transformB ) = 0; 00377 //------------------------------------------------------------------------- 00378 //========================================================================= 00379 //*/ 00380 00381 /* 00382 //========================================================================= 00383 // Test Overlap with Another BVHTree_BinaryOBB 00384 //------------------------------------------------------------------------- 00391 virtual bool TestOverlap_vs_BinaryOBB ( 00392 BVHNode<T> const * const nodeA, 00393 Matrix4x4<T> const & transformA, 00394 BVHNode<T> const * const nodeB, 00395 Matrix4x4<T> const & transformB ) = 0; 00396 //------------------------------------------------------------------------- 00400 virtual bool TestOverlap_vs_BinaryOBB_TillLeafNodes ( 00401 BVHNode<T> const * const nodeA, 00402 Matrix4x4<T> const & transformA, 00403 BVHNode<T> const * const nodeB, 00404 Matrix4x4<T> const & transformB ) = 0; 00405 //------------------------------------------------------------------------- 00406 //========================================================================= 00407 //*/ 00408 00409 private: 00410 //========================================================================= 00411 // BINARY SPHERE BOUNDING VOLUME HIERARCHY TREE 00412 //------------------------------------------------------------------------- 00413 // Create Binary Sphere Tree 00414 static BVHTree<T> * BSphereBuild ( 00415 TransformationSupport<T> & transform, 00416 const std::list< HEFace<T> * > & heFaceList, 00417 BVHTree<T> * cdtree ); 00418 //------------------------------------------------------------------------- 00419 // Create Binary Child Spheres 00420 static void BSphereBuildChildren ( BVHNode<T> * pParentNode, 00421 const std::list< HEFace<T> * > & heFaceList, 00422 Vector3<T> const & principleVector ); 00423 //------------------------------------------------------------------------- 00424 // Find the group that this face belongs to 00425 static int BSphereDetermineFaceGroup ( 00426 HEFace<T> * face, 00427 const Vector3<T> & center, 00428 const Vector3<T> & direction ); 00429 static void BSphereDivideToFaceGroups ( 00430 const std::list< HEFace<T> * > & faces, // input 00431 std::list< HEFace<T> * > & group1, // output group1 00432 std::list< HEFace<T> * > & group2, // output group2 00433 const Vector3<T> & center, 00434 const Vector3<T> & direction ); 00435 //------------------------------------------------------------------------- 00436 // Create a new sphere bounding volume node from the face list 00437 static BVHNode<T> * CreateBVHNodeBSphere ( 00438 BVHNode<T> * pParentNode, 00439 const std::list< HEFace<T> * > & heFaceList ); 00440 //------------------------------------------------------------------------- 00441 }; // END CLASS BVHTree_BinarySphere 00442 //============================================================================= 00443 //----------------------------------------------------------------------------- 00446 typedef BVHTree_BinarySphere<int> BVHTree_BinarySpherei; 00447 typedef BVHTree_BinarySphere<float> BVHTree_BinarySpheref; 00448 typedef BVHTree_BinarySphere<double> BVHTree_BinarySphered; 00449 typedef BVHTree_BinarySphere<long double> BVHTree_BinarySphereld; 00450 //============================================================================= 00451 END_NAMESPACE_TAPs 00452 //----------------------------------------------------------------------------- 00453 // Include definition if TAPs_USE_EXPORT is not defined 00454 //#if !defined( TAPs_USE_EXPORT ) 00455 #include "TAPsBVHTree_BinarySphere.cpp" 00456 //#endif 00457 //----------------------------------------------------------------------------- 00458 #endif 00459 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00460 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----