00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 }
00051
00052 }
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
00075
00076
00077
00078
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
00092
00093
00094
00095
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
00130
00131
00132
00133
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
00147
00148
00149
00150
00151
00152 RigidMappingCuda3f_applyJ(points.size(), v, omega, out.deviceWrite(), rotatedPoints.deviceRead());
00153 }
00154
00155 }
00156
00157 }
00158
00159 }
00160
00161 #endif