00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2019 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : JM Godinaud (Jan 2006) 00022 **=======================================================================*/ 00023 00024 #ifndef _SO_DUAL_SCENE_COLLIDER_ 00025 #define _SO_DUAL_SCENE_COLLIDER_ 00026 00027 #include <Inventor/SbBasic.h> 00028 #include <Inventor/SbLinear.h> 00029 #include <Inventor/sensors/SoNodeSensor.h> 00030 00031 class SoNode; 00032 class SoGroup; 00033 class SoPath; 00034 class SoTransform; 00035 00036 class SoCmStaticScene; 00037 class SoCmMovingScene; 00038 00112 class SoDualSceneCollider { 00113 00114 public: 00115 00119 SoDualSceneCollider(); 00120 virtual ~SoDualSceneCollider(); 00121 00130 void setMovingScene(SoPath* object, int max_triangles_per_leaf=0); 00131 00140 void setStaticScene(SoPath* scene, int max_triangles_per_leaf=0); 00141 00148 void activate(SoTransform* transform); 00149 00156 virtual SbBool checkCollision() const; 00157 00162 virtual SbBool searchNextIntersection() const { return FALSE; } 00163 00164 00173 void setMinEdgeLength(double minEdgeLength); 00174 00180 double getMinEdgeLength() const; 00181 00196 void enableMultiThread(bool enable); 00197 00202 bool isMultiThreadEnabled() const 00203 { return m_isMultiThread; } 00204 00205 private: protected: 00206 00212 const SoPath* getCollidingStaticPath() const; 00213 00219 const SoPath* getCollidingMovingPath() const; 00220 00226 void getCollidingStaticTriangle(SbVec3f &v0, SbVec3f &v1, SbVec3f &v2) const; 00227 00233 void getCollidingMovingTriangle(SbVec3f &v0, SbVec3f &v1, SbVec3f &v2) const; 00234 00240 void getCommonPoints(SbVec3f &p0, SbVec3f &p1) const; 00241 00248 virtual SbBool isSensitiveStaticObject(const SoPath *object_path) const; 00249 00256 virtual SbBool isSensitiveMovingObject(const SoPath *object_path) const; 00257 00267 virtual void staticTriangleListBuilt(int num_triangles) const; 00268 00277 virtual void staticLeafBuilt(int num_triangles) const; 00278 00288 virtual void movingTriangleListBuilt(int num_triangles) const; 00289 00298 virtual void movingLeafBuilt(int num_triangles) const; 00299 00300 private: 00301 //private usage 00302 void updateMovingScene(); 00303 void triangleListBuilt(int num_triangles) const; 00304 void leafBuilt(int num_triangles) const; // a new leaf is built : it contains num_triangles 00305 SbBool isSensitiveObject(const SoPath *object_path) const; 00306 00307 // return true if checkcollision should stop for searching new intersection 00308 bool isStopIntersectionSearchRequested() const 00309 { return m_stopSearchingforIntersection; } 00310 // reset flag the searching flag 00311 void setStopIntersectionSearchRequested(bool value) 00312 { m_stopSearchingforIntersection = value; } 00313 00314 // return the octree depth where parallelism should be used 00315 int getMaxParallelDepth() const 00316 { return m_maxparallelDepth; } 00317 00318 private: 00319 00320 SoPath *m_staticPath; 00321 SoCmStaticScene *m_staticScene; 00322 SoCmMovingScene *m_movingScene; 00323 SoPath *m_movingPath; 00324 00325 private: 00326 SoNodeSensor m_sensor; 00327 SoTransform *m_transform; 00328 int m_trianglePerStaticLeaf; 00329 int m_trianglePerMovingLeaf; 00330 SbBool m_staticSceneBeingBuilt; 00331 double m_minEdgeLength; 00332 bool m_stopSearchingforIntersection; 00333 bool m_isMultiThread; 00334 int m_maxparallelDepth; 00335 }; 00336 00337 inline SbBool 00338 SoDualSceneCollider::isSensitiveStaticObject(const SoPath *) const 00339 { return TRUE; } 00340 00341 inline SbBool 00342 SoDualSceneCollider::isSensitiveMovingObject(const SoPath *) const 00343 { return TRUE; } 00344 00345 inline void 00346 SoDualSceneCollider::staticTriangleListBuilt(int) const 00347 {} 00348 00349 inline void 00350 SoDualSceneCollider::staticLeafBuilt(int) const 00351 {} 00352 00353 inline void 00354 SoDualSceneCollider::movingTriangleListBuilt(int) const 00355 {} 00356 00357 inline void 00358 SoDualSceneCollider::movingLeafBuilt(int) const 00359 {} 00360 00361 00362 00363 #endif // SO_DUAL_SCENE_COLLIDER_ 00364 00365 00366