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;
00086 bool isOwnerHandle() const;
00087 bool isEmptyHandle() const;
00088 ContactGeometry& operator=(const ContactGeometry& src);
00089 bool hasImpl() const {
00090 return impl != 0;
00091 }
00092 const ContactGeometryImpl& getImpl() const {
00093 assert(impl);
00094 return *impl;
00095 }
00096 ContactGeometryImpl& updImpl() {
00097 assert(impl);
00098 return *impl;
00099 }
00104 const std::string& getType() const;
00109 int getTypeIndex() const;
00110 protected:
00111 ContactGeometryImpl* impl;
00112 };
00113
00118 class SimTK_SIMBODY_EXPORT ContactGeometry::HalfSpace : public ContactGeometry {
00119 public:
00120 HalfSpace();
00121 };
00122
00126 class SimTK_SIMBODY_EXPORT ContactGeometry::Sphere : public ContactGeometry {
00127 public:
00128 Sphere(Real radius);
00129 Real getRadius() const;
00130 void setRadius(Real radius);
00131 const SphereImpl& getImpl() const;
00132 SphereImpl& updImpl();
00133 };
00134
00155 class SimTK_SIMBODY_EXPORT ContactGeometry::TriangleMesh : public ContactGeometry {
00156 public:
00157 class OBBTreeNode;
00169 TriangleMesh(const std::vector<Vec3>& vertices, const std::vector<int>& faceIndices, bool smooth=false);
00179 TriangleMesh(const PolygonalMesh& mesh, bool smooth=false);
00183 int getNumEdges() const;
00187 int getNumFaces() const;
00191 int getNumVertices() const;
00198 const Vec3& getVertexPosition(int index) const;
00207 int getFaceEdge(int face, int edge) const;
00215 int getFaceVertex(int face, int vertex) const;
00223 int getEdgeFace(int edge, int face) const;
00231 int getEdgeVertex(int edge, int vertex) const;
00238 void findVertexEdges(int vertex, std::vector<int>& edges) const;
00244 const UnitVec3& getFaceNormal(int face) const;
00250 Real getFaceArea(int face) const;
00257 UnitVec3 findNormalAtPoint(int face, const Vec2& uv) const;
00267 Vec3 findNearestPoint(const Vec3& position, bool& inside, UnitVec3& normal) const;
00279 Vec3 findNearestPoint(const Vec3& position, bool& inside, int& face, Vec2& uv) const;
00291 bool intersectsRay(const Vec3& origin, const UnitVec3& direction, Real& distance, UnitVec3& normal) const;
00305 bool intersectsRay(const Vec3& origin, const UnitVec3& direction, Real& distance, int& face, Vec2& uv) const;
00309 OBBTreeNode getOBBTreeNode() const;
00310 const TriangleMeshImpl& getImpl() const;
00311 TriangleMeshImpl& updImpl();
00312 };
00313
00321 class SimTK_SIMBODY_EXPORT ContactGeometry::TriangleMesh::OBBTreeNode {
00322 public:
00323 OBBTreeNode(const OBBTreeNodeImpl& impl);
00327 const OrientedBoundingBox& getBounds() const;
00331 bool isLeafNode() const;
00335 const OBBTreeNode getFirstChildNode() const;
00339 const OBBTreeNode getSecondChildNode() const;
00343 const std::vector<int>& getTriangles() const;
00344 private:
00345 const OBBTreeNodeImpl* impl;
00346 };
00347
00348 }
00349
00350 #endif // SimTK_SIMBODY_CONTACT_GEOMETRY_H_