AttachConstraint.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_CONSTRAINT_ATTACHCONSTRAINT_H
00026 #define SOFA_COMPONENT_CONSTRAINT_ATTACHCONSTRAINT_H
00027 
00028 #include <sofa/core/componentmodel/behavior/PairInteractionConstraint.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00031 #include <sofa/core/objectmodel/Event.h>
00032 #include <sofa/defaulttype/BaseMatrix.h>
00033 #include <sofa/defaulttype/BaseVector.h>
00034 #include <sofa/helper/vector.h>
00035 #include <sofa/component/topology/PointSubset.h>
00036 #include <set>
00037 
00038 namespace sofa
00039 {
00040 
00041 namespace component
00042 {
00043 
00044 namespace constraint
00045 {
00046 
00047 using helper::vector;
00048 using core::objectmodel::Data;
00049 using namespace sofa::core::objectmodel;
00050 
00052 template <class DataTypes>
00053 class AttachConstraintInternalData
00054 {
00055 };
00056 
00059 template <class DataTypes>
00060 class AttachConstraint : public core::componentmodel::behavior::PairInteractionConstraint<DataTypes>, public virtual core::objectmodel::BaseObject
00061 {
00062 public:
00063         typedef typename DataTypes::VecCoord VecCoord;
00064         typedef typename DataTypes::VecDeriv VecDeriv;
00065     typedef typename DataTypes::Coord Coord;
00066     typedef typename DataTypes::Deriv Deriv;
00067     typedef typename DataTypes::Real Real;
00068     typedef topology::PointSubset SetIndex;
00069     typedef helper::vector<unsigned int> SetIndexArray;
00070 
00071 
00072 protected:
00073     AttachConstraintInternalData<DataTypes> data;
00074 
00075     sofa::core::componentmodel::topology::BaseMeshTopology* topology;
00076     
00077 public:
00078     Data<SetIndex> f_indices1;
00079     Data<SetIndex> f_indices2;
00080     Data<Real> f_radius;
00081     Data<bool> f_twoWay;
00082     Data<bool> f_freeRotations;
00083     Data<bool> f_lastFreeRotation;
00084     Data<bool> f_restRotations;
00085     Data<defaulttype::Vector3> f_lastPos;
00086     Data<defaulttype::Vector3> f_lastDir;
00087     Data<bool> f_clamp;
00088 
00089     helper::vector<bool> activeFlags;
00090     helper::vector<Real> lastDist;
00091     helper::vector<defaulttype::Quat> restRotations;
00092 
00093     AttachConstraint();
00094 
00095     virtual ~AttachConstraint();
00096 
00097     void clearConstraints();
00098     void addConstraint(unsigned int index1, unsigned int index2);
00099 
00100     // -- Constraint interface
00101     void init();
00102     void projectResponse(VecDeriv& dx1, VecDeriv& dx2);
00103     virtual void projectVelocity(VecDeriv& v1, VecDeriv& v2);
00104     virtual void projectPosition(VecCoord& x1, VecCoord& x2);
00105 
00106     void applyConstraint(defaulttype::BaseMatrix *mat, unsigned int &offset);
00107     void applyConstraint(defaulttype::BaseVector *vect, unsigned int &offset);
00108     
00109     // Handle topological changes
00110     //virtual void handleTopologyChange();
00111 
00112     virtual void draw();
00113 
00114 
00115     // this constraint is holonomic
00116     bool isHolonomic() {return true;}
00117 
00118 protected :
00119     void projectPosition(Coord& x1, Coord& x2, bool /*freeRotations*/, unsigned /*index*/) { x2 = x1; }
00120     void projectVelocity(Deriv& x1, Deriv& x2, bool /*freeRotations*/, unsigned /*index*/) { x2 = x1; }
00121     void projectResponse(Deriv& dx1, Deriv& dx2, bool /*freeRotations*/, bool twoway, unsigned /*index*/)
00122     {
00123         if (!twoway)
00124         {
00125             dx2 = Deriv();
00126         }
00127         else
00128         {
00129             dx1 += dx2;
00130             dx2 = dx1;
00131         }
00132     }
00133     static unsigned int DerivConstrainedSize(bool /*freeRotations*/) { return Deriv::size(); }
00134 
00135     void calcRestRotations();
00136 
00137     // Define TestNewPointFunction
00138     //static bool FCTestNewPointFunction(int, void*, const sofa::helper::vector< unsigned int > &, const sofa::helper::vector< double >& );
00139 
00140     // Define RemovalFunction
00141     //static void FCRemovalFunction ( int , void*);
00142 
00143 };
00144 
00145 } // namespace constraint
00146 
00147 } // namespace component
00148 
00149 } // namespace sofa
00150 
00151 
00152 #endif

Generated on Sun Nov 23 02:37:34 2008 for Sofa by  doxygen 1.5.7.1