ContactGeometry.h

Go to the documentation of this file.
00001 #ifndef SimTK_SIMBODY_CONTACT_GEOMETRY_H_
00002 #define SimTK_SIMBODY_CONTACT_GEOMETRY_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 
00036 #include "SimTKcommon.h"
00037 
00038 #include "simbody/internal/common.h"
00039 #include "simbody/internal/OrientedBoundingBox.h"
00040 #include <vector>
00041 
00042 namespace SimTK {
00043 
00044 class ContactGeometryImpl;
00045 class OBBTreeNodeImpl;
00046 
00051 class SimTK_SIMBODY_EXPORT ContactGeometry {
00052 public:
00053     class HalfSpace;
00054     class Sphere;
00055     class TriangleMesh;
00056     class HalfSpaceImpl;
00057     class SphereImpl;
00058     class TriangleMeshImpl;
00059     ContactGeometry() : impl(0) {
00060     }
00061     ContactGeometry(const ContactGeometry& src);
00062     explicit ContactGeometry(ContactGeometryImpl* impl);
00063     virtual ~ContactGeometry();
00073     Vec3 findNearestPoint(const Vec3& position, bool& inside, UnitVec3& normal) const;
00085     bool intersectsRay(const Vec3& origin, const UnitVec3& direction, Real& distance, UnitVec3& normal) const;
00092     void getBoundingSphere(Vec3& center, Real& radius) const;
00093     bool isOwnerHandle() const;
00094     bool isEmptyHandle() const;
00095     ContactGeometry& operator=(const ContactGeometry& src);
00096     bool hasImpl() const {
00097         return impl != 0;
00098     }
00099     const ContactGeometryImpl& getImpl() const {
00100         assert(impl);
00101         return *impl;
00102     }
00103     ContactGeometryImpl& updImpl() {
00104         assert(impl);
00105         return *impl;
00106     }
00111     const std::string& getType() const;
00116     int getTypeIndex() const;
00117 protected:
00118     ContactGeometryImpl* impl;
00119 };
00120 
00125 class SimTK_SIMBODY_EXPORT ContactGeometry::HalfSpace : public ContactGeometry {
00126 public:
00127     HalfSpace();
00128 };
00129 
00133 class SimTK_SIMBODY_EXPORT ContactGeometry::Sphere : public ContactGeometry {
00134 public:
00135     Sphere(Real radius);
00136     Real getRadius() const;
00137     void setRadius(Real radius);
00138     const SphereImpl& getImpl() const;
00139     SphereImpl& updImpl();
00140 };
00141 
00162 class SimTK_SIMBODY_EXPORT ContactGeometry::TriangleMesh : public ContactGeometry {
00163 public:
00164     class OBBTreeNode;
00176     TriangleMesh(const std::vector<Vec3>& vertices, const std::vector<int>& faceIndices, bool smooth=false);
00186     TriangleMesh(const PolygonalMesh& mesh, bool smooth=false);
00190     int getNumEdges() const;
00194     int getNumFaces() const;
00198     int getNumVertices() const;
00205     const Vec3& getVertexPosition(int index) const;
00214     int getFaceEdge(int face, int edge) const;
00222     int getFaceVertex(int face, int vertex) const;
00230     int getEdgeFace(int edge, int face) const;
00238     int getEdgeVertex(int edge, int vertex) const;
00245     void findVertexEdges(int vertex, std::vector<int>& edges) const;
00251     const UnitVec3& getFaceNormal(int face) const;
00257     Real getFaceArea(int face) const;
00264     UnitVec3 findNormalAtPoint(int face, const Vec2& uv) const;
00274     Vec3 findNearestPoint(const Vec3& position, bool& inside, UnitVec3& normal) const;
00286     Vec3 findNearestPoint(const Vec3& position, bool& inside, int& face, Vec2& uv) const;
00298     bool intersectsRay(const Vec3& origin, const UnitVec3& direction, Real& distance, UnitVec3& normal) const;
00312     bool intersectsRay(const Vec3& origin, const UnitVec3& direction, Real& distance, int& face, Vec2& uv) const;
00316     OBBTreeNode getOBBTreeNode() const;
00317     const TriangleMeshImpl& getImpl() const;
00318     TriangleMeshImpl& updImpl();
00319 };
00320 
00328 class SimTK_SIMBODY_EXPORT ContactGeometry::TriangleMesh::OBBTreeNode {
00329 public:
00330     OBBTreeNode(const OBBTreeNodeImpl& impl);
00334     const OrientedBoundingBox& getBounds() const;
00338     bool isLeafNode() const;
00342     const OBBTreeNode getFirstChildNode() const;
00346     const OBBTreeNode getSecondChildNode() const;
00350     const std::vector<int>& getTriangles() const;
00355     int getNumTriangles() const;
00356 private:
00357     const OBBTreeNodeImpl* impl;
00358 };
00359 
00360 } // namespace SimTK
00361 
00362 #endif // SimTK_SIMBODY_CONTACT_GEOMETRY_H_

Generated by  doxygen 1.6.2