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;
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 } // namespace SimTK
00349 
00350 #endif // SimTK_SIMBODY_CONTACT_GEOMETRY_H_

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