00001 #ifndef SimTK_SIMBODY_COLLISION_DETECTION_ALGORITHM_H_
00002 #define SimTK_SIMBODY_COLLISION_DETECTION_ALGORITHM_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "SimTKcommon.h"
00036 #include "simbody/internal/common.h"
00037 #include "simbody/internal/ContactGeometry.h"
00038 #include <map>
00039
00040 namespace SimTK {
00041
00042 class Contact;
00043
00052 class SimTK_SIMBODY_EXPORT CollisionDetectionAlgorithm {
00053 public:
00054 class HalfSpaceSphere;
00055 class SphereSphere;
00056 class HalfSpaceTriangleMesh;
00057 class SphereTriangleMesh;
00058 class TriangleMeshTriangleMesh;
00072 virtual void processObjects(int index1, const ContactGeometry& object1, const Transform& transform1,
00073 int index2, const ContactGeometry& object2, const Transform& transform2, std::vector<Contact>& contacts) const = 0;
00081 static void registerAlgorithm(const std::string& type1, const std::string& type2, CollisionDetectionAlgorithm* algorithm);
00089 static CollisionDetectionAlgorithm* getAlgorithm(int typeIndex1, int typeIndex2);
00090 private:
00091 static std::map<std::pair<int, int>, CollisionDetectionAlgorithm*>& getAlgorithmMap();
00092 };
00093
00097 class SimTK_SIMBODY_EXPORT CollisionDetectionAlgorithm::HalfSpaceSphere : public CollisionDetectionAlgorithm {
00098 public:
00099 void processObjects(int index1, const ContactGeometry& object1, const Transform& transform1,
00100 int index2, const ContactGeometry& object2, const Transform& transform2, std::vector<Contact>& contacts) const;
00101 };
00102
00106 class SimTK_SIMBODY_EXPORT CollisionDetectionAlgorithm::SphereSphere : public CollisionDetectionAlgorithm {
00107 public:
00108 void processObjects(int index1, const ContactGeometry& object1, const Transform& transform1,
00109 int index2, const ContactGeometry& object2, const Transform& transform2, std::vector<Contact>& contacts) const;
00110 };
00111
00115 class SimTK_SIMBODY_EXPORT CollisionDetectionAlgorithm::HalfSpaceTriangleMesh : public CollisionDetectionAlgorithm {
00116 public:
00117 void processObjects(int index1, const ContactGeometry& object1, const Transform& transform1,
00118 int index2, const ContactGeometry& object2, const Transform& transform2, std::vector<Contact>& contacts) const;
00119 private:
00120 void processBox(const ContactGeometry::TriangleMesh& mesh, const ContactGeometry::TriangleMesh::OBBTreeNode& node,
00121 const Transform& transform, std::set<int>& insideFaces) const;
00122 };
00123
00127 class SimTK_SIMBODY_EXPORT CollisionDetectionAlgorithm::SphereTriangleMesh : public CollisionDetectionAlgorithm {
00128 public:
00129 void processObjects(int index1, const ContactGeometry& object1, const Transform& transform1,
00130 int index2, const ContactGeometry& object2, const Transform& transform2, std::vector<Contact>& contacts) const;
00131 private:
00132 void processBox(const Vec3& center, Real radius2, const ContactGeometry::TriangleMesh& mesh, const ContactGeometry::TriangleMesh::OBBTreeNode& node,
00133 std::set<int>& insideFaces) const;
00134 };
00135
00139 class SimTK_SIMBODY_EXPORT CollisionDetectionAlgorithm::TriangleMeshTriangleMesh : public CollisionDetectionAlgorithm {
00140 public:
00141 void processObjects(int index1, const ContactGeometry& object1, const Transform& transform1,
00142 int index2, const ContactGeometry& object2, const Transform& transform2, std::vector<Contact>& contacts) const;
00143 private:
00144 void processNodes(const ContactGeometry::TriangleMesh& mesh1, const ContactGeometry::TriangleMesh& mesh2,
00145 const ContactGeometry::TriangleMesh::OBBTreeNode& node1, const ContactGeometry::TriangleMesh::OBBTreeNode& node2,
00146 const Transform& transform, std::set<int>& triangles1, std::set<int>& triangles2) const;
00147 void findInsideTriangles(const ContactGeometry::TriangleMesh& mesh, const ContactGeometry::TriangleMesh& otherMesh,
00148 const Transform& transform, std::set<int>& triangles) const;
00149 void tagFaces(const ContactGeometry::TriangleMesh& mesh, std::vector<int>& faceType, std::set<int>& triangles, int index) const;
00150 static const int OUTSIDE = -1;
00151 static const int UNKNOWN = 0;
00152 static const int BOUNDARY = 1;
00153 static const int INSIDE = 2;
00154 };
00155
00156 }
00157
00158 #endif // SimTK_SIMBODY_COLLISION_DETECTION_ALGORITHM_H_