PairInteractionConstraint.inl

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 :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
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 } // namespace behavior
00125 
00126 } // namespace componentmodel
00127 
00128 } // namespace core
00129 
00130 } // namespace sofa
00131 
00132 #endif

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