CudaRigidMapping.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_GPU_CUDA_CUDARIGIDMAPPING_INL
00026 #define SOFA_GPU_CUDA_CUDARIGIDMAPPING_INL
00027 
00028 #include "CudaRigidMapping.h"
00029 #include <sofa/component/mapping/RigidMapping.inl>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace gpu
00035 {
00036 
00037 namespace cuda
00038 {
00039 
00040 using sofa::defaulttype::Mat3x3f;
00041 using sofa::defaulttype::Vec3f;
00042 
00043 extern "C"
00044 {
00045 void RigidMappingCuda3f_apply(unsigned int size, const Mat3x3f& rotation, const Vec3f& translation, void* out, void* rotated, const void* in);
00046 void RigidMappingCuda3f_applyJ(unsigned int size, const Vec3f& v, const Vec3f& omega, void* out, const void* rotated);
00047 void RigidMappingCuda3f_applyJT(unsigned int size, void* out, const void* rotated, const void* in);
00048 }
00049 
00050 } // namespace cuda
00051 
00052 } // namespace gpu
00053 
00054 namespace component
00055 {
00056 
00057 namespace mapping
00058 {
00059 
00060 using namespace gpu::cuda;
00061 
00062 template <>
00063 void RigidMapping<sofa::core::componentmodel::behavior::MechanicalMapping< sofa::core::componentmodel::behavior::MechanicalState<gpu::cuda::CudaRigid3fTypes>, sofa::core::componentmodel::behavior::MechanicalState<gpu::cuda::CudaVec3fTypes> > >::apply( Out::VecCoord& out, const In::VecCoord& in )
00064 {
00065     const VecCoord& points = this->points.getValue();
00066     Coord translation;
00067     Mat rotation;
00068     rotatedPoints.resize(points.size());
00069     out.fastResize(points.size());
00070 
00071     translation = in[index.getValue()].getCenter();
00072     in[index.getValue()].writeRotationMatrix(rotation);
00073 
00074     //for(unsigned int i=0;i<points.size();i++)
00075     //{
00076     //    rotatedPoints[i] = rotation*points[i];
00077     //    out[i] = rotatedPoints[i];
00078     //    out[i] += translation;
00079     //}
00080     RigidMappingCuda3f_apply(points.size(), rotation, translation, out.deviceWrite(), rotatedPoints.deviceWrite(), points.deviceRead());
00081 }
00082 
00083 template <>
00084 void RigidMapping<sofa::core::componentmodel::behavior::MechanicalMapping< sofa::core::componentmodel::behavior::MechanicalState<gpu::cuda::CudaRigid3fTypes>, sofa::core::componentmodel::behavior::MechanicalState<gpu::cuda::CudaVec3fTypes> > >::applyJ( Out::VecDeriv& out, const In::VecDeriv& in )
00085 {
00086     const VecCoord& points = this->points.getValue();
00087     Deriv v,omega;
00088     out.fastResize(points.size());
00089     v = in[index.getValue()].getVCenter();
00090     omega = in[index.getValue()].getVOrientation();
00091     //for(unsigned int i=0;i<points.size();i++)
00092     //{
00093     //    // out = J in
00094     //    // J = [ I -OM^ ]
00095     //    out[i] =  v - cross(rotatedPoints[i],omega);
00096     //}
00097     RigidMappingCuda3f_applyJ(points.size(), v, omega, out.deviceWrite(), rotatedPoints.deviceRead());
00098 }
00099 
00100 template <>
00101 void RigidMapping<sofa::core::componentmodel::behavior::MechanicalMapping< sofa::core::componentmodel::behavior::MechanicalState<gpu::cuda::CudaRigid3fTypes>, sofa::core::componentmodel::behavior::MechanicalState<gpu::cuda::CudaVec3fTypes> > >::applyJT( In::VecDeriv& out, const Out::VecDeriv& in )
00102 {
00103     const VecCoord& points = this->points.getValue();
00104     Deriv v,omega;
00105     int nbloc = ((points.size()+BSIZE-1)/BSIZE);
00106     data.tmp.fastResize(2*nbloc);
00107     RigidMappingCuda3f_applyJT(points.size(), data.tmp.deviceWrite(), rotatedPoints.deviceRead(), in.deviceRead());
00108     for(int i=0;i<nbloc;i++)
00109     {
00110         v += data.tmp[i];
00111         omega += data.tmp[i+nbloc];
00112     }
00113     out[index.getValue()].getVCenter() += v;
00114     out[index.getValue()].getVOrientation() += omega;
00115 }
00116 
00117 template <>
00118 void RigidMapping<sofa::core::Mapping< sofa::core::componentmodel::behavior::State<gpu::cuda::CudaRigid3fTypes>, sofa::core::componentmodel::behavior::MappedModel<gpu::cuda::CudaVec3fTypes> > >::apply( Out::VecCoord& out, const In::VecCoord& in )
00119 {
00120     const VecCoord& points = this->points.getValue();
00121     Coord translation;
00122     Mat rotation;
00123     rotatedPoints.resize(points.size());
00124     out.fastResize(points.size());
00125 
00126     translation = in[index.getValue()].getCenter();
00127     in[index.getValue()].writeRotationMatrix(rotation);
00128 
00129     //for(unsigned int i=0;i<points.size();i++)
00130     //{
00131     //    rotatedPoints[i] = rotation*points[i];
00132     //    out[i] = rotatedPoints[i];
00133     //    out[i] += translation;
00134     //}
00135     RigidMappingCuda3f_apply(points.size(), rotation, translation, out.deviceWrite(), rotatedPoints.deviceWrite(), points.deviceRead());
00136 }
00137 
00138 template <>
00139 void RigidMapping<sofa::core::Mapping< sofa::core::componentmodel::behavior::State<gpu::cuda::CudaRigid3fTypes>, sofa::core::componentmodel::behavior::MappedModel<gpu::cuda::CudaVec3fTypes> > >::applyJ( Out::VecDeriv& out, const In::VecDeriv& in )
00140 {
00141     const VecCoord& points = this->points.getValue();
00142     Deriv v,omega;
00143     out.fastResize(points.size());
00144     v = in[index.getValue()].getVCenter();
00145     omega = in[index.getValue()].getVOrientation();
00146     //for(unsigned int i=0;i<points.size();i++)
00147     //{
00148     //    // out = J in
00149     //    // J = [ I -OM^ ]
00150     //    out[i] =  v - cross(rotatedPoints[i],omega);
00151     //}
00152     RigidMappingCuda3f_applyJ(points.size(), v, omega, out.deviceWrite(), rotatedPoints.deviceRead());
00153 }
00154 
00155 } // namespace mapping
00156 
00157 } // namespace component
00158 
00159 } // namespace sofa
00160 
00161 #endif

Generated on Sun Nov 23 04:00:41 2008 for Sofa by  doxygen 1.5.7.1