TubularMapping.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_TUBULARMAPPING_INL
00026 #define SOFA_COMPONENT_MAPPING_TUBULARMAPPING_INL
00027 
00028 #include <sofa/component/mapping/TubularMapping.h>
00029 #include <sofa/defaulttype/VecTypes.h>
00030 #include <sofa/defaulttype/RigidTypes.h>
00031 #include <sofa/core/componentmodel/behavior/MechanicalMapping.inl>
00032 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00033 
00034 
00035 namespace sofa
00036 {
00037 
00038 namespace component
00039 {
00040 
00041 namespace mapping
00042 {
00043 
00044 template <class BasicMapping>
00045 void TubularMapping<BasicMapping>::init()
00046 {   
00047     this->BasicMapping::init();
00048     
00049 }
00050 
00051 
00052 
00053 template <class BasicMapping>
00054 void TubularMapping<BasicMapping>::apply ( typename Out::VecCoord& out, const typename In::VecCoord& in )
00055 {
00056     // Propagation of positions from the input DOFs to the output DOFs
00057 
00058     //std::cout << "TubularMapping<BasicMapping>::apply\n";
00059 
00060     if(out.size() != rotatedPoints.size()){
00061         rotatedPoints.resize(out.size());
00062     }
00063 
00064     unsigned int N = m_nbPointsOnEachCircle.getValue();
00065     double rho = m_radius.getValue();
00066     
00067     out.resize(in.size() * N);
00068     rotatedPoints.resize(in.size() * N);
00069 
00070     Vec Y0;
00071     Vec Z0;
00072     Y0[0] = (Real) (0.0); Y0[1] = (Real) (1.0); Y0[2] = (Real) (0.0);
00073     Z0[0] = (Real) (0.0); Z0[1] = (Real) (0.0); Z0[2] = (Real) (1.0);
00074 
00075     for (unsigned int i=0; i<in.size(); i++)
00076     {       
00077         Vec curPos = in[i].getCenter();
00078         
00079         Mat rotation;
00080         in[i].writeRotationMatrix(rotation);
00081 
00082         Vec Y; 
00083         Vec Z;
00084 
00085         Y = rotation * Y0;
00086         Z = rotation * Z0;      
00087 
00088         for(unsigned int j=0; j<N; ++j){
00089 
00090             rotatedPoints[i*N+j] = (Y*cos((Real) (2.0*j*M_PI/N)) + Z*sin((Real) (2.0*j*M_PI/N)))*((Real) rho);
00091             Vec x = curPos + rotatedPoints[i*N+j];
00092             //std::cout << "INFO_print : TubularMapping  DO move point - j = " << j << " , curPos = " << curPos <<  " , x = " << x << std::endl;
00093 
00094             out[i*N+j] = x;         
00095         }   
00096     }
00097 }
00098 
00099 
00100 
00101 template <class BasicMapping>
00102 void TubularMapping<BasicMapping>::applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in )
00103 {
00104     
00105     // Propagation of velocities from the input DOFs to the output DOFs
00106 
00107     if(out.size() != rotatedPoints.size()){
00108         rotatedPoints.resize(out.size());
00109     }
00110 
00111     unsigned int N = m_nbPointsOnEachCircle.getValue();
00112     
00113     out.resize(in.size() * N);
00114     Deriv v,omega;
00115 
00116     for (unsigned int i=0; i<in.size(); i++)
00117     {
00118         v = in[i].getVCenter();
00119         omega = in[i].getVOrientation();        
00120 
00121         for(unsigned int j=0; j<N; ++j){
00122 
00123             out[i*N+j] = v - cross(rotatedPoints[i*N+j],omega);     
00124             //std::cout << "INFO_print : TubularMapping  DO moveJ point - j = " << j << " , curPos = " << v <<  " , x = " << out[i*N+j] << std::endl;
00125         }   
00126     }
00127 }
00128 
00129 
00130 template <class BasicMapping>
00131 void TubularMapping<BasicMapping>::applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in )
00132 {   
00133     // usefull for a Mechanical Mapping that propagates forces from the output DOFs to the input DOFs
00134 
00135     //std::cout << "INFO_print : pass HERE applyJT !!!" << std::endl;
00136     
00137     if(in.size() != rotatedPoints.size()){
00138         rotatedPoints.resize(in.size());
00139     }
00140     
00141     unsigned int N = m_nbPointsOnEachCircle.getValue();
00142 
00143     Deriv v,omega;  
00144 
00145     for (unsigned int i=0; i<out.size(); i++)
00146     {
00147         for(unsigned int j=0; j<N; j++){
00148 
00149             Deriv f = in[i*N+j];
00150             v += f;
00151             omega += cross(rotatedPoints[i*N+j],f);
00152         }
00153 
00154             out[i].getVCenter() += v;   
00155             out[i].getVOrientation() += omega;  
00156             //std::cout << "INFO_print : TubularMapping  DO moveJT point - i = " << i << std::endl;         
00157     }
00158     
00159 }
00160 
00161 /*
00162 template <class BasicMapping>
00163 void TubularMapping<BasicMapping>::applyJT( typename In::VecConst& out, const typename Out::VecConst& in )
00164 {   
00165     std::cout << "INFO_print : pass HERE applyJT CONST !!!" << std::endl;
00166 
00167     Deriv v0;
00168     v0[0] = (Real) (0.0); v0[1] = (Real) (0.0); v0[2] = (Real) (0.0);
00169 
00170     for (unsigned int i=0; i<out.size(); i++)
00171     {
00172             out[i].getVCenter() = v0;   
00173             out[i].getVOrientation() = v0;  
00174             std::cout << "INFO_print : TubularMapping  DO moveJT point - i = " << i << std::endl;           
00175     }
00176 }
00177 */
00178 
00179 } // namespace mapping
00180 
00181 } // namespace component
00182 
00183 } // namespace sofa
00184 
00185 #endif // SOFA_COMPONENT_MAPPING_TUBULARMAPPING_INL

Generated on Sun Nov 23 03:35:04 2008 for Sofa by  doxygen 1.5.7.1