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_LINEMODEL_H 00026 #define SOFA_COMPONENT_COLLISION_LINEMODEL_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 <sofa/component/collision/PointModel.h> 00033 00034 namespace sofa 00035 { 00036 00037 namespace component 00038 { 00039 00040 namespace collision 00041 { 00042 00043 using namespace sofa::defaulttype; 00044 00045 class LineModel; 00046 00047 class Line : public core::TCollisionElementIterator<LineModel> 00048 { 00049 public: 00050 Line(LineModel* model, int index); 00051 00052 explicit Line(core::CollisionElementIterator& i); 00053 00054 unsigned i1() const; 00055 unsigned i2() const; 00056 00057 const Vector3& p1() const; 00058 const Vector3& p2() const; 00059 00060 const Vector3& p1Free() const; 00061 const Vector3& p2Free() const; 00062 00063 const Vector3& v1() const; 00064 const Vector3& v2() const; 00065 00066 // Return respectively the Vertex composing the neighbor Rigt and Left Triangle 00067 // const Vector3* tRight() const; 00068 // const Vector3* tLeft() const; 00069 }; 00070 00071 class LineModel : public core::CollisionModel 00072 { 00073 protected: 00074 struct LineData 00075 { 00076 int i1,i2; 00077 // Triangles neighborhood 00078 // int tRight, tLeft; 00079 }; 00080 00081 sofa::helper::vector<LineData> elems; 00082 bool needsUpdate; 00083 virtual void updateFromTopology(); 00084 00085 00086 public: 00087 typedef Vec3Types InDataTypes; 00088 typedef Vec3Types DataTypes; 00089 typedef DataTypes::VecCoord VecCoord; 00090 typedef DataTypes::VecDeriv VecDeriv; 00091 typedef DataTypes::Coord Coord; 00092 typedef DataTypes::Deriv Deriv; 00093 typedef Line Element; 00094 00095 friend class Line; 00096 00097 LineModel(); 00098 00099 virtual void init(); 00100 00101 // -- CollisionModel interface 00102 00103 virtual void resize(int size); 00104 00105 virtual void computeBoundingTree(int maxDepth=0); 00106 00107 virtual void computeContinuousBoundingTree(double dt, int maxDepth=0); 00108 00109 void draw(int index); 00110 00111 void draw(); 00112 00113 virtual void handleTopologyChange(); 00114 00115 bool canCollideWithElement(int index, CollisionModel* model2, int index2); 00116 00117 core::componentmodel::behavior::MechanicalState<Vec3Types>* getMechanicalState() { return mstate; } 00118 00119 //virtual const char* getTypeName() const { return "Line"; } 00120 00121 protected: 00122 00123 core::componentmodel::behavior::MechanicalState<Vec3Types>* mstate; 00124 Topology* topology; 00125 PointModel* mpoints; 00126 int meshRevision; 00127 }; 00128 00129 inline Line::Line(LineModel* model, int index) 00130 : core::TCollisionElementIterator<LineModel>(model, index) 00131 {} 00132 00133 inline Line::Line(core::CollisionElementIterator& i) 00134 : core::TCollisionElementIterator<LineModel>(static_cast<LineModel*>(i.getCollisionModel()), i.getIndex()) 00135 { 00136 } 00137 00138 inline unsigned Line::i1() const { return model->elems[index].i1; } 00139 inline unsigned Line::i2() const { return model->elems[index].i2; } 00140 00141 inline const Vector3& Line::p1() const { return (*model->mstate->getX())[model->elems[index].i1]; } 00142 inline const Vector3& Line::p2() const { return (*model->mstate->getX())[model->elems[index].i2]; } 00143 00144 inline const Vector3& Line::p1Free() const { return (*model->mstate->getXfree())[model->elems[index].i1]; } 00145 inline const Vector3& Line::p2Free() const { return (*model->mstate->getXfree())[model->elems[index].i2]; } 00146 00147 inline const Vector3& Line::v1() const { return (*model->mstate->getV())[model->elems[index].i1]; } 00148 inline const Vector3& Line::v2() const { return (*model->mstate->getV())[model->elems[index].i2]; } 00149 00150 //inline const Vector3* Line::tRight() const { 00151 // if (model->elems[index].tRight != -1) 00152 // return &(*model->mstate->getX())[model->elems[index].tRight]; 00153 // else 00154 // return NULL; 00155 //} 00156 00157 //inline const Vector3* Line::tLeft() const { 00158 // if (model->elems[index].tLeft != -1) 00159 // return &(*model->mstate->getX())[model->elems[index].tLeft]; 00160 // else 00161 // return NULL; 00162 //} 00163 00164 //class LineMeshModel : public LineModel 00165 //{ 00166 //protected: 00167 // int meshRevision; 00168 // void updateFromTopology(); 00169 // 00170 //public: 00171 // typedef topology::MeshTopology Topology; 00172 // 00173 // LineMeshModel(); 00174 // 00175 // virtual void init(); 00176 // 00177 // Topology* getMeshTopology() { return mesh; } 00178 // 00179 //protected: 00180 // Topology* mesh; 00181 //}; 00182 00183 //class LineSetModel : public LineModel 00184 //{ 00185 //public: 00186 // 00187 // LineSetModel(); 00188 // 00189 // ///\Todo 00190 // virtual void init(); 00191 // 00192 // Topology* getMeshTopology() { return mesh; } 00193 // 00194 //protected: 00195 // 00196 // Topology* mesh; 00197 // 00198 // void updateFromTopology(); 00199 //}; 00200 00201 } // namespace collision 00202 00203 } // namespace component 00204 00205 } // namespace sofa 00206 00207 #endif
1.5.7.1