RigidMapping.cpp

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 #include <sofa/component/mapping/RigidMapping.inl>
00026 #include <sofa/core/ObjectFactory.h>
00027 #include <sofa/core/componentmodel/behavior/MappedModel.h>
00028 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00029 #include <sofa/core/componentmodel/behavior/MechanicalMapping.inl>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace mapping
00038 {
00039 
00040 SOFA_DECL_CLASS(RigidMapping)
00041 
00042 using namespace defaulttype;
00043 using namespace core;
00044 using namespace core::componentmodel::behavior;
00045 
00046 
00047 // Register in the Factory
00048 int RigidMappingClass = core::RegisterObject("Set the positions and velocities of points attached to a rigid parent")
00049 #ifndef SOFA_FLOAT
00050 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid3dTypes>, MechanicalState<Vec3dTypes> > > >()
00051 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid2dTypes>, MechanicalState<Vec2dTypes> > > >()
00052 .add< RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<Vec3dTypes> > > >()
00053 .add< RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<ExtVec3fTypes> > > >()
00054 // .add< RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<ExtVec3dTypes> > > >()
00055 #endif
00056 #ifndef SOFA_DOUBLE
00057 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid3fTypes>, MechanicalState<Vec3fTypes> > > >()
00058 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid2fTypes>, MechanicalState<Vec2fTypes> > > >()
00059 .add< RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<Vec3fTypes> > > >()
00060 .add< RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<ExtVec3fTypes> > > >()
00061 // .add< RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<ExtVec3dTypes> > > >()
00062 #endif
00063 
00064 #ifndef SOFA_FLOAT
00065 #ifndef SOFA_DOUBLE
00066 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid3dTypes>, MechanicalState<Vec3fTypes> > > >()
00067 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid3fTypes>, MechanicalState<Vec3dTypes> > > >()
00068 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid2dTypes>, MechanicalState<Vec2fTypes> > > >()
00069 .add< RigidMapping< MechanicalMapping< MechanicalState<Rigid2fTypes>, MechanicalState<Vec2dTypes> > > >()
00070 .add< RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<Vec3fTypes> > > >()
00071 .add< RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<Vec3dTypes> > > >()
00072 #endif
00073 #endif
00074 ;
00075 
00076 #ifndef SOFA_FLOAT
00077 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid3dTypes>, MechanicalState<Vec3dTypes> > >;
00078 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid2dTypes>, MechanicalState<Vec2dTypes> > >;
00079 template class RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<Vec3dTypes> > >;
00080 // template class RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<ExtVec3dTypes> > >;
00081 template class RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<ExtVec3fTypes> > >;
00082 #endif
00083 #ifndef SOFA_DOUBLE
00084 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid3fTypes>, MechanicalState<Vec3fTypes> > >;
00085 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid2fTypes>, MechanicalState<Vec2fTypes> > >;
00086 template class RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<Vec3fTypes> > >;
00087 // template class RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<ExtVec3dTypes> > >;
00088 template class RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<ExtVec3fTypes> > >;
00089 #endif
00090 
00091 #ifndef SOFA_FLOAT
00092 #ifndef SOFA_DOUBLE
00093 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid3dTypes>, MechanicalState<Vec3fTypes> > >;
00094 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid3fTypes>, MechanicalState<Vec3dTypes> > >;
00095 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid2dTypes>, MechanicalState<Vec2fTypes> > >;
00096 template class RigidMapping< MechanicalMapping<MechanicalState<Rigid2fTypes>, MechanicalState<Vec2dTypes> > >;
00097 template class RigidMapping< Mapping< State<Rigid3dTypes>, MappedModel<Vec3fTypes> > >;
00098 template class RigidMapping< Mapping< State<Rigid3fTypes>, MappedModel<Vec3dTypes> > >;
00099 #endif
00100 #endif
00101 
00102 
00103 
00106 #ifndef SOFA_FLOAT
00107 
00108 template<>
00109 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2dTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2dTypes > > >::applyJ( Out::VecDeriv& out, const In::VecDeriv& in )
00110 {
00111     const VecCoord& pts = this->getPoints();
00112     Deriv v;
00113     Real omega;
00114     v = in[0].getVCenter();
00115     omega = (Real)in[0].getVOrientation();
00116     out.resize(pts.size());
00117     for(unsigned int i=0;i<pts.size();i++)
00118     {
00119         out[i] =  v + Deriv(-rotatedPoints[i][1],rotatedPoints[i][0])*omega;
00120     }
00121 }
00122 
00123 template<>
00124 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2dTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2dTypes > > >::applyJT( In::VecDeriv& out, const Out::VecDeriv& in )
00125 {
00126     const VecCoord& pts = this->getPoints();
00127     Deriv v;
00128     Real omega = (Real)0;
00129     for(unsigned int i=0;i<pts.size();i++)
00130     {
00131         Deriv f = in[i];
00132         v += f;
00133         omega += cross(rotatedPoints[i],f);
00134     }
00135     out[0].getVCenter() += v;
00136     out[0].getVOrientation() += (In::Real)omega;
00137 }
00138 
00139 template<>
00140 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2dTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2dTypes > > >::applyJT( In::VecConst& out, const Out::VecConst& in )
00141 {
00142     out.resize(in.size());
00144 }
00145 #endif
00146 
00147 #ifndef SOFA_DOUBLE
00148 template<>
00149 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2fTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2fTypes > > >::applyJ( Out::VecDeriv& out, const In::VecDeriv& in )
00150 {
00151     const VecCoord& pts = this->getPoints();
00152     Deriv v;
00153     Real omega;
00154     v = in[0].getVCenter();
00155     omega = (Real)in[0].getVOrientation();
00156     out.resize(pts.size());
00157     for(unsigned int i=0;i<pts.size();i++)
00158     {
00159         out[i] =  v + Deriv(-rotatedPoints[i][1],rotatedPoints[i][0])*omega;
00160     }
00161 }
00162 
00163 
00164 
00165 template<>
00166 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2fTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2fTypes > > >::applyJT( In::VecDeriv& out, const Out::VecDeriv& in )
00167 {
00168     const VecCoord& pts = this->getPoints();
00169     Deriv v;
00170     Real omega = (Real)0;
00171     for(unsigned int i=0;i<pts.size();i++)
00172     {
00173         Deriv f = in[i];
00174         v += f;
00175         omega += cross(rotatedPoints[i],f);
00176     }
00177     out[0].getVCenter() += v;
00178     out[0].getVOrientation() += (In::Real)omega;
00179 }
00180 
00181 template<>
00182     void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2fTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2fTypes > > >::applyJT( In::VecConst& out, const Out::VecConst& in )
00183 {
00184   out.resize(in.size());
00186 }
00187 #endif
00188 
00189 #ifndef SOFA_FLOAT
00190 #ifndef SOFA_DOUBLE
00191 
00192 
00193 template<>
00194 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2fTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2dTypes > > >::applyJ( Out::VecDeriv& out, const In::VecDeriv& in )
00195 {
00196     const VecCoord& pts = this->getPoints();
00197     Deriv v;
00198     Real omega;
00199     v = in[0].getVCenter();
00200     omega = (Real)in[0].getVOrientation();
00201     out.resize(pts.size());
00202     for(unsigned int i=0;i<pts.size();i++)
00203     {
00204         out[i] =  v + Deriv(-rotatedPoints[i][1],rotatedPoints[i][0])*omega;
00205     }
00206 }
00207 
00208 
00209 template<>
00210 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2fTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2dTypes > > >::applyJT( In::VecDeriv& out, const Out::VecDeriv& in )
00211 {
00212     const VecCoord& pts = this->getPoints();
00213     Deriv v;
00214     Real omega = (Real)0;
00215     for(unsigned int i=0;i<pts.size();i++)
00216     {
00217         Deriv f = in[i];
00218         v += f;
00219         omega += cross(rotatedPoints[i],f);
00220     }
00221     out[0].getVCenter() += v;
00222     out[0].getVOrientation() += (In::Real)omega;
00223 }
00224 
00225 template<>
00226 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2fTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2dTypes > > >::applyJT( In::VecConst& out, const Out::VecConst& in )
00227 {
00228     out.resize(in.size());
00230 }
00231 
00232 template<>
00233 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2dTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2fTypes > > >::applyJ( Out::VecDeriv& out, const In::VecDeriv& in )
00234 {
00235     const VecCoord& pts = this->getPoints();
00236     Deriv v;
00237     Real omega;
00238     v = in[0].getVCenter();
00239     omega = (Real)in[0].getVOrientation();
00240     out.resize(pts.size());
00241     for(unsigned int i=0;i<pts.size();i++)
00242     {
00243         out[i] =  v + Deriv(-rotatedPoints[i][1],rotatedPoints[i][0])*omega;
00244     }
00245 }
00246 
00247 
00248 
00249 template<>
00250 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2dTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2fTypes > > >::applyJT( In::VecDeriv& out, const Out::VecDeriv& in )
00251 {
00252     const VecCoord& pts = this->getPoints();
00253     Deriv v;
00254     Real omega = (Real)0;
00255     for(unsigned int i=0;i<pts.size();i++)
00256     {
00257         Deriv f = in[i];
00258         v += f;
00259         omega += cross(rotatedPoints[i],f);
00260     }
00261     out[0].getVCenter() += v;
00262     out[0].getVOrientation() += (In::Real)omega;
00263 }
00264 
00265 
00266 template<>
00267 void RigidMapping< core::componentmodel::behavior::MechanicalMapping< core::componentmodel::behavior::MechanicalState< defaulttype::Rigid2dTypes >, core::componentmodel::behavior::MechanicalState< defaulttype::Vec2fTypes > > >::applyJT( In::VecConst& out, const Out::VecConst& in )
00268 {
00269     out.resize(in.size());
00271 }
00272 
00273 #endif
00274 #endif
00275 
00276 
00277 
00278 
00279 } // namespace mapping
00280 
00281 } // namespace component
00282 
00283 } // namespace sofa
00284 

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