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
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
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 }
00361
00362 #endif // SimTK_SIMBODY_CONTACT_GEOMETRY_H_