PlaneForceField.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_INTERACTIONFORCEFIELD_PLANEFORCEFIELD_H
00026 #define SOFA_COMPONENT_INTERACTIONFORCEFIELD_PLANEFORCEFIELD_H
00027 
00028 #include <sofa/core/componentmodel/behavior/ForceField.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <sofa/core/objectmodel/Data.h>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace component
00036 {
00037 
00038 namespace forcefield
00039 {
00040 
00042 template<class DataTypes>
00043 class PlaneForceFieldInternalData
00044 {
00045 public:
00046 };
00047 
00048 template<class DataTypes>
00049 class PlaneForceField : public core::componentmodel::behavior::ForceField<DataTypes>, public virtual core::objectmodel::BaseObject
00050 {
00051 public:
00052     typedef core::componentmodel::behavior::ForceField<DataTypes> Inherit;
00053     typedef typename DataTypes::VecCoord VecCoord;
00054     typedef typename DataTypes::VecDeriv VecDeriv;
00055     typedef typename DataTypes::Coord Coord;
00056     typedef typename DataTypes::Deriv Deriv;
00057     typedef typename Coord::value_type Real;
00058     
00059 protected:
00060     sofa::helper::vector<unsigned int> contacts;
00061     
00062     PlaneForceFieldInternalData<DataTypes> data;
00063     
00064 public:
00065     
00066     Data<Deriv> planeNormal;
00067     Data<Real> planeD;
00068     Data<Real> stiffness;
00069     Data<Real> damping;
00070     Data<defaulttype::Vec3f> color;
00071     Data<bool> bDraw;
00072     
00073     PlaneForceField()
00074     : planeNormal(initData(&planeNormal, "normal", "plane normal"))
00075     , planeD(initData(&planeD, (Real)0, "d", "plane d coef"))
00076     , stiffness(initData(&stiffness, (Real)500, "stiffness", "force stiffness"))
00077     , damping(initData(&damping, (Real)5, "damping", "force damping"))
00078     , color(initData(&color, defaulttype::Vec3f(0.0f,.5f,.2f), "color", "plane color"))
00079     , bDraw(initData(&bDraw, false, "draw", "enable/disable drawing of plane"))
00080     {
00081        Deriv n;
00082        DataTypes::set(n, 0, 1, 0);
00083        planeNormal.setValue(n);
00084     }
00085     
00086     void setPlane(const Deriv& normal, Real d)
00087     {
00088         Real n = normal.norm();
00089         planeNormal.setValue( normal / n);
00090         planeD.setValue( d / n );
00091     }
00092     
00093     void setMState(  core::componentmodel::behavior::MechanicalState<DataTypes>* mstate ){ this->mstate = mstate; }
00094     
00095     void setStiffness(Real stiff)
00096     {
00097         stiffness.setValue( stiff );
00098     }
00099     
00100     void setDamping(Real damp)
00101     {
00102         damping.setValue( damp );
00103     }
00104     
00105     void rotate( Deriv axe, Real angle ); // around the origin (0,0,0)
00106     
00107     virtual void addForce (VecDeriv& f, const VecCoord& x, const VecDeriv& v);
00108     
00109     virtual void addDForce (VecDeriv& df, const VecDeriv& dx, double kFactor, double bFactor);
00110     
00111     virtual double getPotentialEnergy(const VecCoord& x);
00112     
00113     virtual void updateStiffness( const VecCoord& x );
00114     
00115     void draw();
00116     void drawPlane(float size=1000.0f);
00117     bool addBBox(double* minBBox, double* maxBBox);
00118 
00119 };
00120 
00121 } // namespace forcefield
00122 
00123 } // namespace component
00124 
00125 } // namespace sofa
00126 
00127 #endif

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