AttachConstraint.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 #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
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
00110
00111
00112 virtual void draw();
00113
00114
00115
00116 bool isHolonomic() {return true;}
00117
00118 protected :
00119 void projectPosition(Coord& x1, Coord& x2, bool , unsigned ) { x2 = x1; }
00120 void projectVelocity(Deriv& x1, Deriv& x2, bool , unsigned ) { x2 = x1; }
00121 void projectResponse(Deriv& dx1, Deriv& dx2, bool , bool twoway, unsigned )
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 ) { return Deriv::size(); }
00134
00135 void calcRestRotations();
00136
00137
00138
00139
00140
00141
00142
00143 };
00144
00145 }
00146
00147 }
00148
00149 }
00150
00151
00152 #endif