LineSetSkinningMapping.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 
00026 #ifndef SOFA_COMPONENT_MAPPING_LINESETSKINNINGMAPPING_H
00027 #define SOFA_COMPONENT_MAPPING_LINESETSKINNINGMAPPING_H
00028 
00029 #include <sofa/core/componentmodel/behavior/MechanicalMapping.h>
00030 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00031 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00032 #include <sofa/defaulttype/RigidTypes.h>
00033 #include <sofa/helper/gl/template.h>
00034 #include <sofa/defaulttype/Vec3Types.h>
00035 #include <vector>
00036 
00037 namespace sofa
00038 {
00039 
00040 namespace component
00041 {
00042 
00043 namespace mapping
00044 {
00045 
00046 using namespace sofa::defaulttype;
00047 
00048 template <class BasicMapping>
00049 class LineSetSkinningMapping : public BasicMapping, public virtual core::objectmodel::BaseObject
00050 {
00051 public:
00052     typedef BasicMapping Inherit;
00053     typedef typename Inherit::In In;
00054     typedef typename Inherit::Out Out;
00055     typedef typename Out::VecCoord OutVecCoord;
00056     typedef typename Out::VecDeriv OutVecDeriv;
00057     typedef typename Out::Coord OutCoord;
00058     typedef typename Out::Deriv OutDeriv;
00059     typedef typename Out::SparseVecDeriv OutSparseVecDeriv;
00060     typedef typename Out::SparseDeriv OutSparseDeriv;
00061     typedef typename In::VecCoord InVecCoord;
00062     typedef typename In::VecDeriv InVecDeriv;
00063     typedef typename In::Coord InCoord;
00064     typedef typename In::Deriv InDeriv;
00065     typedef typename In::SparseVecDeriv InSparseVecDeriv;
00066     typedef typename In::SparseDeriv InSparseDeriv;
00067     typedef typename In::Real Real;
00068     typedef typename OutCoord::value_type OutReal;
00069 
00070     
00071     LineSetSkinningMapping(In* from, Out* to)
00072     : Inherit(from, to)
00073     , nvNeighborhood(initData(&nvNeighborhood,(unsigned int)3,"neighborhoodLevel","Set the neighborhood line level"))
00074     , numberInfluencedLines(initData(&numberInfluencedLines,(unsigned int)4,"numberInfluencedLines","Set the number of most influenced lines by each vertice"))
00075     , weightCoef(initData(&weightCoef, (int) 4,"weightCoef","Set the coefficient used to compute the weight of lines"))
00076     {
00077     }
00078     
00079     virtual ~LineSetSkinningMapping()
00080     {
00081     }
00082 
00083     void init();
00084 
00085     void reinit();
00086 
00087     void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00088     
00089     void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00090     
00091     void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00092 
00093     void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00094 
00095     void draw();
00096 
00097 protected:
00098 
00099     sofa::core::componentmodel::topology::BaseMeshTopology* t;
00100 
00104     Data<unsigned int> nvNeighborhood;
00105 
00109     Data<unsigned int> numberInfluencedLines;
00110 
00114     Data<int> weightCoef;
00115 
00116     bool getShow(const core::objectmodel::BaseObject* m) const { return m->getContext()->getShowMappings(); }
00117 
00118     bool getShow(const core::componentmodel::behavior::BaseMechanicalMapping* m) const { return m->getContext()->getShowMechanicalMappings(); }
00119 
00120 private:
00121 
00125     class influencedLineType
00126     {
00127     public:
00128         influencedLineType()
00129         {
00130             weight = 0.0;
00131         };
00132         ~influencedLineType(){};
00133         int lineIndex;
00134         double weight;
00135         OutCoord position;
00136     };
00137 
00141     class influencedVerticeType
00142     {
00143     public:
00144         influencedVerticeType()
00145         {
00146             weight = 0.0;
00147         };
00148         ~influencedVerticeType(){};
00149         int verticeIndex;
00150         double weight;
00151         OutCoord position;
00152     };
00153 
00157     Vec<3,double> projectToSegment(Vec<3,Real>& first, Vec<3,Real>& last, OutCoord& vertice);
00158 
00162     double convolutionSegment(Vec<3,Real>& first, Vec<3,Real>& last, OutCoord& vertice);
00163 
00167     vector<vector<influencedLineType> > linesInfluencedByVertice; 
00168 
00172     vector<vector<influencedVerticeType> > verticesInfluencedByLine;
00173 
00177     vector<std::set<int> > neighborhoodLinesSet;
00178 
00182     vector<std::set<int> > neighborhood;    
00183 };
00184 
00185 } // namespace mapping
00186 
00187 } // namespace component
00188 
00189 } // namespace sofa
00190 
00191 #endif

Generated on Sun Nov 23 03:32:36 2008 for Sofa by  doxygen 1.5.7.1