SkinningMapping.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_MAPPING_SKINNINGMAPPING_H
00026 #define SOFA_COMPONENT_MAPPING_SKINNINGMAPPING_H
00027
00028 #include <sofa/core/componentmodel/behavior/MechanicalMapping.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00030 #include <sofa/defaulttype/RigidTypes.h>
00031 #include <vector>
00032
00033 namespace sofa
00034 {
00035
00036 namespace component
00037 {
00038
00039 namespace mapping
00040 {
00041
00042 template <class BasicMapping>
00043 class SkinningMapping : public BasicMapping, public virtual core::objectmodel::BaseObject
00044 {
00045 public:
00046 typedef BasicMapping Inherit;
00047 typedef typename Inherit::In In;
00048 typedef typename Inherit::Out Out;
00049 typedef typename Out::VecCoord VecCoord;
00050 typedef typename Out::VecDeriv VecDeriv;
00051 typedef typename Out::Coord Coord;
00052 typedef typename Out::Deriv Deriv;
00053 typedef typename In::Coord InCoord;
00054 typedef typename In::Deriv InDeriv;
00055 typedef typename In::VecCoord VecInCoord;
00056 typedef typename In::SparseDeriv InSparseDeriv;
00057 typedef typename Coord::value_type Real;
00058 enum { N=Coord::static_size };
00059 typedef defaulttype::Mat<N,N,Real> Mat;
00060
00061 protected:
00062 sofa::helper::vector<InCoord> initPos;
00063 Coord translation;
00064 Mat rotation;
00065 sofa::helper::vector<Coord> rotatedPoints;
00066
00067 class Loader;
00068 void load(const char* filename);
00069
00070 Data<sofa::helper::vector<unsigned int> > repartition;
00071 Data<sofa::helper::vector<double> > coefs;
00072 Data<unsigned int> nbRefs;
00073
00074 bool computeWeights;
00075
00076 public:
00077
00078 SkinningMapping(In* from, Out* to)
00079 : Inherit(from, to)
00080 , repartition(initData(&repartition,"repartition","repartition between input DOFs and skinned vertices"))
00081 , coefs(initData(&coefs,"coefs","weights list for the influences of the references Dofs"))
00082 , nbRefs(initData(&nbRefs,(unsigned)3,"nbRefs","nb references for skinning"))
00083 , computeWeights(true)
00084 {
00085 }
00086
00087 virtual ~SkinningMapping(){}
00088
00089 void init();
00090
00091 void parse(core::objectmodel::BaseObjectDescription* arg)
00092 {
00093 if (arg->getAttribute("filename"))
00094 this->load(arg->getAttribute("filename"));
00095 this->Inherit::parse(arg);
00096 }
00097
00098 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00099
00100 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00101
00102 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00103
00104 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00105
00106
00107 void draw();
00108
00109 void clear();
00110
00111 void setNbRefs(unsigned int nb){ nbRefs.setValue(nb); }
00112 void setWeightCoefs(sofa::helper::vector<double> &weights);
00113 void setRepartition(sofa::helper::vector<unsigned int> &rep);
00114 void setComputeWeights(bool val){computeWeights=val;}
00115
00116 unsigned int getNbRefs(){ return nbRefs.getValue(); }
00117 const sofa::helper::vector<double>& getWeightCoefs() { return coefs.getValue(); }
00118 const sofa::helper::vector<unsigned int>& getRepartition() { return repartition.getValue(); }
00119 bool getComputeWeights(){ return computeWeights; }
00120 };
00121
00122 }
00123
00124 }
00125
00126 }
00127
00128 #endif