CollisionDetectionAlgorithm.h

Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_COLLISION_DETECTION_ALGORITHM_H_
00002 #define SimTK_SIMBODY_COLLISION_DETECTION_ALGORITHM_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                      SimTK Core: SimTK Simbody(tm)                         *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK Core biosimulation toolkit originating from      *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00011  *                                                                            *
00012  * Portions copyright (c) 2008 Stanford University and the Authors.           *
00013  * Authors: Peter Eastman                                                     *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
00017  * copy of this software and associated documentation files (the "Software"), *
00018  * to deal in the Software without restriction, including without limitation  *
00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00020  * and/or sell copies of the Software, and to permit persons to whom the      *
00021  * Software is furnished to do so, subject to the following conditions:       *
00022  *                                                                            *
00023  * The above copyright notice and this permission notice shall be included in *
00024  * all copies or substantial portions of the Software.                        *
00025  *                                                                            *
00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
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 } // namespace SimTK
00157 
00158 #endif // SimTK_SIMBODY_COLLISION_DETECTION_ALGORITHM_H_

Generated on Fri Sep 26 07:44:08 2008 for SimTKcore by  doxygen 1.5.6