MixedInteractionForceField.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MIXEDINTERACTIONFORCEFIELD_H
00028 #define SOFA_CORE_COMPONENTMODEL_BEHAVIOR_MIXEDINTERACTIONFORCEFIELD_H
00029
00030 #include <sofa/core/componentmodel/behavior/InteractionForceField.h>
00031 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00032 #include <sofa/defaulttype/Vec.h>
00033
00034 namespace sofa
00035 {
00036
00037 namespace core
00038 {
00039
00040 namespace componentmodel
00041 {
00042
00043 namespace behavior
00044 {
00045
00052 template<class TDataTypes1, class TDataTypes2>
00053 class MixedInteractionForceField : public InteractionForceField
00054 {
00055 public:
00056 typedef TDataTypes1 DataTypes1;
00057 typedef typename DataTypes1::VecCoord VecCoord1;
00058 typedef typename DataTypes1::VecDeriv VecDeriv1;
00059 typedef typename DataTypes1::Coord Coord1;
00060 typedef typename DataTypes1::Deriv Deriv1;
00061 typedef TDataTypes2 DataTypes2;
00062 typedef typename DataTypes2::VecCoord VecCoord2;
00063 typedef typename DataTypes2::VecDeriv VecDeriv2;
00064 typedef typename DataTypes2::Coord Coord2;
00065 typedef typename DataTypes2::Deriv Deriv2;
00066
00067 MixedInteractionForceField(MechanicalState<DataTypes1> *mm1 = NULL, MechanicalState<DataTypes2> *mm2 = NULL);
00068
00069 virtual ~MixedInteractionForceField();
00070
00071 virtual void init();
00072
00074 MechanicalState<DataTypes1>* getMState1() { return mstate1; }
00075 BaseMechanicalState* getMechModel1() { return mstate1; }
00077 MechanicalState<DataTypes2>* getMState2() { return mstate2; }
00078 BaseMechanicalState* getMechModel2() { return mstate2; }
00079
00082
00093 virtual void addForce();
00094
00108 virtual void addDForce(double kFactor, double bFactor);
00109
00118 virtual void addDForceV(double kFactor, double bFactor);
00119
00128 virtual double getPotentialEnergy();
00129
00139 virtual void addForce(VecDeriv1& f1, VecDeriv2& f2, const VecCoord1& x1, const VecCoord2& x2, const VecDeriv1& v1, const VecDeriv2& v2) = 0;
00140
00157 virtual void addDForce(VecDeriv1& df1, VecDeriv2& df2, const VecDeriv1& dx1, const VecDeriv2& dx2);
00158
00175 virtual void addDForce(VecDeriv1& df1, VecDeriv2& df2, const VecDeriv1& dx1, const VecDeriv2& dx2, double kFactor, double bFactor);
00176
00184 virtual double getPotentialEnergy(const VecCoord1& x1, const VecCoord2& x2) =0;
00185
00187
00190 template<class T>
00191 static bool canCreate(T*& obj, objectmodel::BaseContext* context, objectmodel::BaseObjectDescription* arg)
00192 {
00193 if (arg->getAttribute("object1") || arg->getAttribute("object2"))
00194 {
00195 if (dynamic_cast<MechanicalState<DataTypes1>*>(arg->findObject(arg->getAttribute("object1",".."))) == NULL)
00196 return false;
00197 if (dynamic_cast<MechanicalState<DataTypes2>*>(arg->findObject(arg->getAttribute("object2",".."))) == NULL)
00198 return false;
00199 }
00200 return InteractionForceField::canCreate(obj, context, arg);
00201 }
00202
00204 template<class T>
00205 static void create(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00206 {
00207 core::componentmodel::behavior::InteractionForceField::create(obj, context, arg);
00208 if (arg && (arg->getAttribute("object1") || arg->getAttribute("object2")))
00209 {
00210 obj->mstate1 = dynamic_cast<MechanicalState<DataTypes1>*>(arg->findObject(arg->getAttribute("object1","..")));
00211 obj->mstate2 = dynamic_cast<MechanicalState<DataTypes2>*>(arg->findObject(arg->getAttribute("object2","..")));
00212 }
00213 }
00214
00215 virtual std::string getTemplateName() const
00216 {
00217 return templateName(this);
00218 }
00219
00220 static std::string templateName(const MixedInteractionForceField<DataTypes1,DataTypes2>* = NULL)
00221 {
00222 return DataTypes1::Name()+std::string(",")+DataTypes2::Name();
00223 }
00224
00225 protected:
00226 MechanicalState<DataTypes1> *mstate1;
00227 MechanicalState<DataTypes2> *mstate2;
00228 };
00229
00230 }
00231
00232 }
00233
00234 }
00235
00236 }
00237
00238 #endif