RigidRigidMapping.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_MAPPING_RIGIDRIGIDMAPPING_H
00026 #define SOFA_COMPONENT_MAPPING_RIGIDRIGIDMAPPING_H
00027 
00028 #include <sofa/component/mapping/RigidMapping.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalMapping.h>
00030 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00031 #include <sofa/defaulttype/RigidTypes.h>
00032 #include <sofa/defaulttype/Vec.h>
00033 #include <vector>
00034 
00035 using namespace sofa::defaulttype;
00036 
00037 namespace sofa
00038 {
00039 
00040 namespace component
00041 {
00042 
00043 namespace mapping
00044 {
00045 
00046 template <class BasicMapping>
00047 class RigidRigidMapping : public BasicMapping, public virtual core::objectmodel::BaseObject
00048 {
00049 public:
00050     typedef BasicMapping Inherit;
00051     typedef typename Inherit::In In;
00052     typedef typename Inherit::Out Out;
00053     typedef typename Out::VecCoord VecCoord;
00054     typedef typename Out::VecDeriv VecDeriv;
00055     typedef typename Out::Coord Coord;
00056     typedef typename Out::Deriv Deriv;
00057     typedef typename In::Coord InCoord;
00058     typedef typename In::Deriv InDeriv;
00059     typedef typename In::SparseDeriv InSparseDeriv;
00060     typedef typename Coord::value_type Real;
00061     enum { N=Coord::static_size };
00062     typedef defaulttype::Mat<N,N,Real> Mat;
00063     typedef Vec<N,Real> Vector ;
00064     
00065 protected:
00066     Data < VecCoord > points;
00067     VecCoord pointsR0;
00068     Mat rotation;
00069     class Loader;
00070     void load(const char* filename);
00071     Data<sofa::helper::vector<unsigned int> >  repartition;
00072 
00073 public:
00074     Data<unsigned> index;
00075     Data< std::string > filename;
00076     //axis length for display
00077     Data<double> axisLength;
00078     
00079     RigidRigidMapping(In* from, Out* to)
00080       : Inherit(from, to),    
00081       points(initData(&points, "initialPoints", "Initial position of the points")),
00082       repartition(initData(&repartition,"repartition","number of dest dofs per entry dof")),
00083       index(initData(&index,(unsigned)0,"index","input DOF index")),
00084       filename(initData(&filename,"filename","Filename")),
00085       axisLength(initData( &axisLength, 0.7, "axisLength", "axis length for display"))
00086     {
00087     }
00088     
00089     virtual ~RigidRigidMapping()
00090     {
00091     }
00092     
00093     void init();
00094 
00095     //  void disable(); //useless now that points are saved in a Data
00096 
00097     void parse(core::objectmodel::BaseObjectDescription* arg)
00098     {
00099       if (!filename.getValue().empty())
00100     this->load(filename.getValue().c_str());
00101       this->Inherit::parse(arg);
00102     }
00103     
00104     void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00105     
00106     void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00107     
00108     void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00109 
00110     //void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00111 
00112     void draw();
00113 
00114     void clear();
00115 
00116     sofa::helper::vector<unsigned int> getRepartition() {return repartition.getValue(); }
00117 
00118     void setRepartition(unsigned int value);
00119     void setRepartition(sofa::helper::vector<unsigned int> values);
00120 
00121 protected:
00122 
00123     bool getShow(const core::objectmodel::BaseObject* m) const { return m->getContext()->getShowMappings(); }
00124 
00125     bool getShow(const core::componentmodel::behavior::BaseMechanicalMapping* m) const { return m->getContext()->getShowMechanicalMappings(); }
00126 };
00127 
00128 } // namespace mapping
00129 
00130 } // namespace component
00131 
00132 } // namespace sofa
00133 
00134 #endif

Generated on Sun Nov 23 03:33:51 2008 for Sofa by  doxygen 1.5.7.1