IdentityMapping.inl

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_IDENTITYMAPPING_INL
00026 #define SOFA_COMPONENT_MAPPING_IDENTITYMAPPING_INL
00027 
00028 #include <sofa/component/mapping/IdentityMapping.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalMapping.inl>
00030 #include <sofa/defaulttype/RigidTypes.h>
00031 #include <sofa/defaulttype/VecTypes.h>
00032 
00033 
00034 namespace sofa
00035 {
00036 
00037 namespace component
00038 {
00039 
00040 namespace mapping
00041 {
00042 
00043 template<class T1, class T2>
00044 extern void eq(T1& dest, const T2& src)
00045 {
00046     dest = (T1)(src);
00047 }
00048 
00049 template<class T1, class T2>
00050 extern void peq(T1& dest, const T2& src)
00051 {
00052     dest += (T1)(src);
00053 }
00054 
00055 template<int N, typename real1, typename real2>
00056 extern void eq(defaulttype::RigidCoord<N,real1>& dest, const defaulttype::RigidCoord<N,real2>& src)
00057 {
00058     dest.getCenter() = src.getCenter();
00059     dest.getOrientation() = src.getOrientation();
00060 }
00061 
00062 template<typename real1, typename real2>
00063 extern void eq(defaulttype::RigidCoord<2,real1>& dest, const defaulttype::RigidCoord<2,real2>& src)
00064 {
00065     dest.getCenter() = src.getCenter();
00066     dest.getOrientation() = (real1)src.getOrientation();
00067 }
00068 
00069 template<int N, typename real1, typename real2>
00070 extern void peq(defaulttype::RigidCoord<N,real1>& dest, const defaulttype::RigidCoord<N,real2>& src)
00071 {
00072     dest.getCenter() += src.getCenter();
00073     dest.getOrientation() += src.getOrientation();
00074 }
00075 
00076 template<typename real1, typename real2>
00077 extern void peq(defaulttype::RigidCoord<2,real1>& dest, const defaulttype::RigidCoord<2,real2>& src)
00078 {
00079     dest.getCenter() += src.getCenter();
00080     dest.getOrientation() += (real1)src.getOrientation();
00081 }
00082 
00083 template<int N, typename real1, typename real2>
00084 extern void eq(defaulttype::RigidDeriv<N,real1>& dest, const defaulttype::RigidDeriv<N,real2>& src)
00085 {
00086     dest.getVCenter() = src.getVCenter();
00087     dest.getVOrientation() = src.getVOrientation();
00088 }
00089 
00090 template<typename real1, typename real2>
00091 extern void eq(defaulttype::RigidDeriv<2,real1>& dest, const defaulttype::RigidDeriv<2,real2>& src)
00092 {
00093     dest.getVCenter() = src.getVCenter();
00094     dest.getVOrientation() = (real1)src.getVOrientation();
00095 }
00096 
00097 template<int N, typename real1, typename real2>
00098 extern void peq(defaulttype::RigidDeriv<N,real1>& dest, const defaulttype::RigidDeriv<N,real2>& src)
00099 {
00100     dest.getVCenter() += src.getVCenter();
00101     dest.getVOrientation() += src.getVOrientation();
00102 }
00103 
00104 template<typename real1, typename real2>
00105 extern void peq(defaulttype::RigidDeriv<2,real1>& dest, const defaulttype::RigidDeriv<2,real2>& src)
00106 {
00107     dest.getVCenter() += src.getVCenter();
00108     dest.getVOrientation() += (real1)src.getVOrientation();
00109 }
00110 
00111 template<int N, typename real1, typename real2>
00112 extern void eq(defaulttype::Vec<N,real1>& dest, const defaulttype::RigidCoord<N,real2>& src)
00113 {
00114     dest = src.getCenter();
00115 }
00116 
00117 template<int N, typename real1, typename real2>
00118 extern void peq(defaulttype::Vec<N,real1>& dest, const defaulttype::RigidCoord<N,real2>& src)
00119 {
00120     dest += src.getCenter();
00121 }
00122 
00123 template<int N, typename real1, typename real2>
00124 extern void eq(defaulttype::Vec<N,real1>& dest, const defaulttype::RigidDeriv<N,real2>& src)
00125 {
00126     dest = src.getVCenter();
00127 }
00128     
00129 template<int N, typename real1, typename real2>
00130 extern void peq(defaulttype::Vec<N,real1>& dest, const defaulttype::RigidDeriv<N,real2>& src)
00131 {
00132     dest += src.getVCenter();
00133 }
00134 
00135 template<int N, typename real1, typename real2>
00136 extern void eq(defaulttype::RigidCoord<N,real1>& dest, const defaulttype::Vec<N,real2>& src)
00137 {
00138     dest.getCenter() = src;
00139 }
00140 
00141 template<int N, typename real1, typename real2>
00142 extern void peq(defaulttype::RigidCoord<N,real1>& dest, const defaulttype::Vec<N,real2>& src)
00143 {
00144     dest.getCenter() += src;
00145 }
00146 
00147 template<int N, typename real1, typename real2>
00148 extern void eq(defaulttype::RigidDeriv<N,real1>& dest, const defaulttype::Vec<N,real2>& src)
00149 {
00150     dest.getVCenter() = src;
00151 }
00152 
00153 template<int N, typename real1, typename real2>
00154 extern void peq(defaulttype::RigidDeriv<N,real1>& dest, const defaulttype::Vec<N,real2>& src)
00155 {
00156     dest.getVCenter() += src;
00157 }
00158 
00159 template <class BasicMapping>
00160 void IdentityMapping<BasicMapping>::apply( typename Out::VecCoord& out, const typename In::VecCoord& in )
00161 {
00162     //const unsigned int N = Coord::size() < InCoord::size() ? Coord::size() : InCoord::size();
00163     out.resize(in.size());
00164     for(unsigned int i=0;i<out.size();i++)
00165     {
00166         //for (unsigned int j=0;j < N;++j)
00167         //    out[i][j] = (OutReal)in[i][j];
00168         //out[i] = in[i];
00169         eq(out[i], in[i]);
00170     }
00171 }
00172 
00173 template <class BasicMapping>
00174 void IdentityMapping<BasicMapping>::applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in )
00175 {
00176     //const unsigned int N = Deriv::size() < InDeriv::size() ? Deriv::size() : InDeriv::size();
00177     out.resize(in.size());
00178     for(unsigned int i=0;i<out.size();i++)
00179     {
00180         //for (unsigned int j=0;j < N;++j)
00181         //    out[i][j] = (OutReal)in[i][j];
00182         eq(out[i], in[i]);
00183     }
00184 }
00185 
00186 template <class BasicMapping>
00187 void IdentityMapping<BasicMapping>::applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in )
00188 {
00189     //const unsigned int N = Deriv::size() < InDeriv::size() ? Deriv::size() : InDeriv::size();
00190     for(unsigned int i=0;i<out.size();i++)
00191     {
00192         //for (unsigned int j=0;j < N;++j)
00193     //    out[i][j] += (Real)in[i][j];
00194         peq(out[i], in[i]);
00195     }
00196 }
00197 
00198 template <class BaseMapping>
00199 void IdentityMapping<BaseMapping>::applyJT( typename In::VecConst& out, const typename Out::VecConst& in )
00200 {
00201     unsigned int outSize = out.size();
00202     out.resize(in.size() + outSize); // we can accumulate in "out" constraints from several mappings
00203     //const unsigned int N = Deriv::size() < InDeriv::size() ? Deriv::size() : InDeriv::size();
00204     for(unsigned int i=0;i<in.size();i++)
00205     {
00206         typename In::SparseVecDeriv& o = out[i+outSize];
00207         o.reserve(in[i].size());
00208         for(unsigned int j=0;j<in[i].size();j++)
00209         {
00210             const typename Out::SparseDeriv& cIn = in[i][j];
00211             InDeriv value;
00212             //for (unsigned int k=0;k<N;++k)
00213             //    value[k] = (Real) cIn.data[k];
00214             eq(value, cIn.data);
00215         //std::cout << "n= "<<cIn.data<<" -> "<<value<<std::endl;
00216             o.push_back( typename In::SparseDeriv(cIn.index, value) );
00217         }
00218     }
00219 }
00220 
00221 } // namespace mapping
00222 
00223 } // namespace component
00224 
00225 } // namespace sofa
00226 
00227 #endif

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