PairInteractionConstraint.inl
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_PAIRINTERACTIONCONSTRAINT_INL
00028 #define SOFA_CORE_COMPONENTMODEL_BEHAVIOR_PAIRINTERACTIONCONSTRAINT_INL
00029
00030 #include <sofa/core/objectmodel/DataPtr.h>
00031 #include "PairInteractionConstraint.h"
00032
00033 namespace sofa
00034 {
00035
00036 namespace core
00037 {
00038
00039 namespace componentmodel
00040 {
00041
00042 namespace behavior
00043 {
00044
00045 template<class DataTypes>
00046 PairInteractionConstraint<DataTypes>::PairInteractionConstraint(MechanicalState<DataTypes> *mm1, MechanicalState<DataTypes> *mm2)
00047 : endTime( initData(&endTime,(double)-1,"endTime","The constraint stops acting after the given value.\nUse a negative value for infinite constraints") )
00048 , object1( initData(&object1, "object1", "First Object to Constraint"))
00049 , object2( initData(&object2, "object2", "Second Object to Constraint"))
00050 , mstate1(mm1), mstate2(mm2)
00051 {
00052 }
00053
00054 template<class DataTypes>
00055 PairInteractionConstraint<DataTypes>::~PairInteractionConstraint()
00056 {
00057 }
00058
00059 template<class DataTypes>
00060 void PairInteractionConstraint<DataTypes>::init()
00061 {
00062 InteractionConstraint::init();
00063 if (mstate1 == NULL || mstate2 == NULL)
00064 {
00065 mstate1 = mstate2 = dynamic_cast< MechanicalState<DataTypes>* >(getContext()->getMechanicalState());
00066 }
00067 }
00068
00069 template<class DataTypes>
00070 bool PairInteractionConstraint<DataTypes>::isActive() const
00071 {
00072 if( endTime.getValue()<0 ) return true;
00073 return endTime.getValue()>getContext()->getTime();
00074 }
00075
00076 template<class DataTypes>
00077 void PairInteractionConstraint<DataTypes>::projectResponse()
00078 {
00079 if( !isActive() ) return;
00080 if (mstate1 && mstate2)
00081 projectResponse(*mstate1->getDx(), *mstate2->getDx());
00082 }
00083
00084 template<class DataTypes>
00085 void PairInteractionConstraint<DataTypes>::projectVelocity()
00086 {
00087 if( !isActive() ) return;
00088 if (mstate1 && mstate2)
00089 projectVelocity(*mstate1->getV(), *mstate2->getV());
00090 }
00091
00092 template<class DataTypes>
00093 void PairInteractionConstraint<DataTypes>::projectPosition()
00094 {
00095 if( !isActive() ) return;
00096 if (mstate1 && mstate2)
00097 projectPosition(*mstate1->getX(), *mstate2->getX());
00098 }
00099
00100 template<class DataTypes>
00101 void PairInteractionConstraint<DataTypes>::projectFreeVelocity()
00102 {
00103 if( !isActive() ) return;
00104 if (mstate1 && mstate2)
00105 projectVelocity(*mstate1->getVfree(), *mstate2->getVfree());
00106 }
00107
00108 template<class DataTypes>
00109 void PairInteractionConstraint<DataTypes>::projectFreePosition()
00110 {
00111 if( !isActive() ) return;
00112 if (mstate1 && mstate2)
00113 projectPosition(*mstate1->getXfree(), *mstate2->getXfree());
00114 }
00115
00116 template<class DataTypes>
00117 void PairInteractionConstraint<DataTypes>::applyConstraint(unsigned int &contactId)
00118 {
00119 if( !isActive() ) return;
00120 if (mstate1 && mstate2)
00121 applyConstraint(*mstate1->getC(), *mstate2->getC(), contactId);
00122 }
00123
00124 }
00125
00126 }
00127
00128 }
00129
00130 }
00131
00132 #endif