TrianglePressureForceField.h

Go to the documentation of this file.
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_FORCEFIELD_TRIANGLEPRESSUREFORCEFIELD_H
00026 #define SOFA_COMPONENT_FORCEFIELD_TRIANGLEPRESSUREFORCEFIELD_H
00027 
00028 
00029 #include <sofa/core/componentmodel/behavior/ForceField.h>
00030 #include <sofa/component/topology/TriangleSubsetData.h>
00031 
00032 
00033 
00034 namespace sofa
00035 {
00036 
00037 namespace component
00038 {
00039 
00040 namespace forcefield
00041 {
00042 
00043 using namespace sofa::defaulttype;
00044 using namespace sofa::component::topology;
00045 
00046 template<class DataTypes>
00047 class TrianglePressureForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00048 {
00049 public:
00050     typedef typename DataTypes::VecCoord VecCoord;
00051     typedef typename DataTypes::VecDeriv VecDeriv;
00052     typedef typename DataTypes::Coord    Coord   ;
00053     typedef typename DataTypes::Deriv    Deriv   ;
00054     typedef typename Coord::value_type   Real    ;
00055 
00056 protected: 
00057 
00058    class TrianglePressureInformation
00059     {
00060     public:
00061             Real area;
00062             Deriv force;
00063 
00064             TrianglePressureInformation() {}
00065             TrianglePressureInformation(const TrianglePressureInformation &e)
00066             : area(e.area),force(e.force)
00067             { }
00068     };
00069 
00070    TriangleSubsetData<TrianglePressureInformation> trianglePressureMap;
00071 
00072     sofa::core::componentmodel::topology::BaseMeshTopology* _topology;
00073 
00074     Data<Deriv> pressure;
00075 
00076     Data<std::string> triangleList;
00077 
00079     Data<Deriv> normal;
00080 
00081     Data<Real> dmin; // coordinates min of the plane for the vertex selection
00082     Data<Real> dmax;// coordinates max of the plane for the vertex selection
00083 
00084 public:
00085 
00086     TrianglePressureForceField():
00087     pressure(initData(&pressure, "pressure", "Pressure force per unit area"))
00088     , triangleList(initData(&triangleList,std::string(),"triangleList", "Indices of triangles separated with commas where a pressure is applied"))
00089     , normal(initData(&normal,"normal", "Normal direction for the plane selection of triangles"))
00090     , dmin(initData(&dmin,(Real)0.0, "dmin", "Minimum distance from the origin along the normal direction"))
00091     , dmax(initData(&dmax,(Real)0.0, "dmax", "Maximum distance from the origin along the normal direction"))
00092     {
00093     }
00094 
00095     virtual ~TrianglePressureForceField();
00096 
00097     virtual void init();
00098 
00099     virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00100     virtual void addDForce (VecDeriv& /*df*/, const VecDeriv& /*dx*/) {}
00101     virtual double getPotentialEnergy(const VecCoord& x);
00102 
00103     // Handle topological changes
00104     virtual void handleTopologyChange();
00105 
00106 
00107     void draw();
00108 
00109     void setDminAndDmax(const double _dmin, const double _dmax) { 
00110         dmin.setValue((Real)_dmin);dmax.setValue((Real)_dmax);}
00111     void setNormal(const Coord n) { normal.setValue(n);}
00112  
00113     void setPressure(Deriv _pressure) { this->pressure = _pressure; updateTriangleInformation(); }
00114 
00115 protected :
00116     void selectTrianglesAlongPlane();
00117     void selectTrianglesFromString();
00118     void updateTriangleInformation();
00119     void initTriangleInformation();
00120     bool isPointInPlane(Coord p) {
00121         Real d=dot(p,normal.getValue());
00122         if ((d>dmin.getValue())&& (d<dmax.getValue())) 
00123             return true;
00124         else
00125             return false;
00126     }
00127 };
00128 
00129 
00130 } // namespace forcefield
00131 
00132 } // namespace component
00133 
00134 } // namespace sofa
00135 
00136 #endif /* _TRIANGLEPRESSUREFORCEFIELD_H_ */

Generated on Sun Nov 23 03:15:42 2008 for Sofa by  doxygen 1.5.7.1