00001 /****************************************************************************** 00002 * SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3 * 00003 * (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify it * 00006 * under the terms of the GNU Lesser General Public License as published by * 00007 * the Free Software Foundation; either version 2.1 of the License, or (at * 00008 * your option) any later version. * 00009 * * 00010 * This library is distributed in the hope that it will be useful, but WITHOUT * 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * 00013 * for more details. * 00014 * * 00015 * You should have received a copy of the GNU Lesser General Public License * 00016 * along with this library; if not, write to the Free Software Foundation, * 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 00018 ******************************************************************************* 00019 * SOFA :: Modules * 00020 * * 00021 * Authors: The SOFA Team and external contributors (see Authors.txt) * 00022 * * 00023 * Contact information: contact@sofa-framework.org * 00024 ******************************************************************************/ 00025 #ifndef SOFA_COMPONENT_COLLISION_POINTMODEL_H 00026 #define SOFA_COMPONENT_COLLISION_POINTMODEL_H 00027 00028 #include <sofa/core/CollisionModel.h> 00029 #include <sofa/component/MechanicalObject.h> 00030 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h> 00031 #include <sofa/defaulttype/Vec3Types.h> 00032 #include <vector> 00033 00034 namespace sofa 00035 { 00036 00037 namespace component 00038 { 00039 00040 namespace collision 00041 { 00042 00043 using namespace sofa::defaulttype; 00044 00045 class PointModel; 00046 00047 class Point : public core::TCollisionElementIterator<PointModel> 00048 { 00049 public: 00050 Point(PointModel* model, int index); 00051 00052 explicit Point(core::CollisionElementIterator& i); 00053 00054 const Vector3& p() const; 00055 const Vector3& pFree() const; 00056 const Vector3& v() const; 00057 Vector3 n() const; 00058 00059 bool testLMD(const Vector3 &, double &, double &); 00060 }; 00061 00062 class PointModel : public core::CollisionModel 00063 { 00064 public: 00065 typedef Vec3Types InDataTypes; 00066 typedef Vec3Types DataTypes; 00067 typedef DataTypes::VecCoord VecCoord; 00068 typedef DataTypes::VecDeriv VecDeriv; 00069 typedef DataTypes::Coord Coord; 00070 typedef DataTypes::Deriv Deriv; 00071 typedef Point Element; 00072 friend class Point; 00073 00074 PointModel(); 00075 00076 virtual void init(); 00077 00078 // -- CollisionModel interface 00079 00080 virtual void resize(int size); 00081 00082 virtual void computeBoundingTree(int maxDepth=0); 00083 00084 virtual void computeContinuousBoundingTree(double dt, int maxDepth=0); 00085 00086 void draw(int index); 00087 00088 void draw(); 00089 00090 virtual bool canCollideWithElement(int index, CollisionModel* model2, int index2); 00091 00092 core::componentmodel::behavior::MechanicalState<Vec3Types>* getMechanicalState() { return mstate; } 00093 00094 //virtual const char* getTypeName() const { return "Point"; } 00095 00096 00097 00098 protected: 00099 00100 core::componentmodel::behavior::MechanicalState<Vec3Types>* mstate; 00101 00102 Data<bool> computeNormals; 00103 00104 VecDeriv normals; 00105 00106 void updateNormals(); 00107 }; 00108 00109 inline Point::Point(PointModel* model, int index) 00110 : core::TCollisionElementIterator<PointModel>(model, index) 00111 {} 00112 00113 inline Point::Point(core::CollisionElementIterator& i) 00114 : core::TCollisionElementIterator<PointModel>(static_cast<PointModel*>(i.getCollisionModel()), i.getIndex()) 00115 { 00116 } 00117 00118 inline const Vector3& Point::p() const { return (*model->mstate->getX())[index]; } 00119 00120 inline const Vector3& Point::pFree() const { return (*model->mstate->getXfree())[index]; } 00121 00122 inline const Vector3& Point::v() const { return (*model->mstate->getV())[index]; } 00123 00124 inline Vector3 Point::n() const { return ((unsigned)index<model->normals.size()) ? model->normals[index] : Vector3(); } 00125 00126 //bool Point::testLMD(const Vector3 &PQ, double &coneFactor, double &coneExtension); 00127 00128 } // namespace collision 00129 00130 } // namespace component 00131 00132 } // namespace sofa 00133 00134 #endif
1.5.7.1