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_CUDABARYCENTRICMAPPING_H
00026 #define SOFA_GPU_CUDA_CUDABARYCENTRICMAPPING_H
00027
00028 #include "CudaTypes.h"
00029 #include <sofa/component/mapping/BarycentricMapping.h>
00030 #include <sofa/core/componentmodel/behavior/MappedModel.h>
00031 #include <sofa/core/componentmodel/behavior/MechanicalState.h>
00032 #include <sofa/core/componentmodel/behavior/MechanicalMapping.h>
00033
00034 namespace sofa
00035 {
00036
00037 namespace component
00038 {
00039
00040 namespace mapping
00041 {
00042
00043 template <typename VecIn, typename VecOut>
00044 class BarycentricMapperRegularGridTopology< gpu::cuda::CudaVectorTypes<VecIn,VecIn,float>, gpu::cuda::CudaVectorTypes<VecOut,VecOut,float> > : public TopologyBarycentricMapper< gpu::cuda::CudaVectorTypes<VecIn,VecIn,float>, gpu::cuda::CudaVectorTypes<VecOut,VecOut,float> >
00045 {
00046 public:
00047 typedef gpu::cuda::CudaVectorTypes<VecIn,VecIn,float> In;
00048 typedef gpu::cuda::CudaVectorTypes<VecOut,VecOut,float> Out;
00049 typedef TopologyBarycentricMapper<In,Out> Inherit;
00050 typedef typename Inherit::Real Real;
00051 typedef typename Inherit::OutReal OutReal;
00052 typedef typename Inherit::CubeData CubeData;
00053 protected:
00054 gpu::cuda::CudaVector<CubeData> map;
00055 int maxNOut;
00056 gpu::cuda::CudaVector< std::pair<int,float> > mapT;
00057 topology::RegularGridTopology* topology;
00058 void calcMapT();
00059 public:
00060 BarycentricMapperRegularGridTopology(topology::RegularGridTopology* topology)
00061 : Inherit(topology)
00062 , maxNOut(0), topology(topology)
00063 {}
00064
00065 void clear(int reserve=0);
00066
00067 int addPointInCube(int cubeIndex, const Real* baryCoords);
00068
00069 bool isEmpty() { return map.size() == 0; }
00070 void setTopology(topology::RegularGridTopology* _topology) { topology = _topology; }
00071
00072 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00073 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00074 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00075 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00076 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00077 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00078
00079 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperRegularGridTopology<In, Out> &b )
00080 {
00081 in >> b.map;
00082 return in;
00083 }
00084
00085 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperRegularGridTopology<In, Out> & b ){
00086 out << b.map;
00087 return out;
00088 }
00089 };
00090
00091 template <typename VecIn, typename VecOut>
00092 class BarycentricMapperMeshTopology< gpu::cuda::CudaVectorTypes<VecIn,VecIn,float>, gpu::cuda::CudaVectorTypes<VecOut,VecOut,float> > : public TopologyBarycentricMapper< gpu::cuda::CudaVectorTypes<VecIn,VecIn,float>, gpu::cuda::CudaVectorTypes<VecOut,VecOut,float> >
00093 {
00094 public:
00095 typedef gpu::cuda::CudaVectorTypes<VecIn,VecIn,float> In;
00096 typedef gpu::cuda::CudaVectorTypes<VecOut,VecOut,float> Out;
00097 typedef TopologyBarycentricMapper<In,Out> Inherit;
00098 typedef typename Inherit::Real Real;
00099 typedef typename Inherit::OutReal OutReal;
00100 class MapData
00101 {
00102 public:
00103 class GPULinearData
00104 {
00105 public:
00106 int i;
00107 float val;
00108 };
00109 GPULinearData d[BSIZE];
00110
00111
00112 };
00113 protected:
00114 int maxNIn;
00115 int maxNOut;
00116 int insize,size;
00117 gpu::cuda::CudaVector< MapData > map;
00118 gpu::cuda::CudaVector< MapData > mapT;
00119 core::componentmodel::topology::BaseMeshTopology* topology;
00120 void resizeMap(int size2, int maxNIn2);
00121 void setMap(int outIndex, int j, int inIndex, Real val);
00122 void calcMapT();
00123 public:
00124 BarycentricMapperMeshTopology(core::componentmodel::topology::BaseMeshTopology* topology)
00125 : Inherit(topology)
00126 , maxNIn(0), maxNOut(0), insize(0), size(0), topology(topology)
00127 {
00128 if (topology==NULL || topology->getNbHexas()==0) maxNIn = 4;
00129 else maxNIn = 8;
00130 }
00131
00132 void clear(int reserve=0);
00133
00134 int addPointInLine(int lineIndex, const SReal* baryCoords);
00135 int createPointInLine(const typename Out::Coord& p, int lineIndex, const typename In::VecCoord* points);
00136
00137 int addPointInTriangle(int triangleIndex, const SReal* baryCoords);
00138 int createPointInTriangle(const typename Out::Coord& p, int triangleIndex, const typename In::VecCoord* points);
00139
00140 int addPointInQuad(int quadIndex, const SReal* baryCoords);
00141 int createPointInQuad(const typename Out::Coord& p, int quadIndex, const typename In::VecCoord* points);
00142
00143 int addPointInTetra(int tetraIndex, const SReal* baryCoords);
00144
00145 int addPointInCube(int cubeIndex, const SReal* baryCoords);
00146
00147 void init(const typename Out::VecCoord& out, const typename In::VecCoord& in);
00148 void apply( typename Out::VecCoord& out, const typename In::VecCoord& in );
00149 void applyJ( typename Out::VecDeriv& out, const typename In::VecDeriv& in );
00150 void applyJT( typename In::VecDeriv& out, const typename Out::VecDeriv& in );
00151 void applyJT( typename In::VecConst& out, const typename Out::VecConst& in );
00152 void draw( const typename Out::VecCoord& out, const typename In::VecCoord& in);
00153
00154 inline friend std::istream& operator >> ( std::istream& in, BarycentricMapperMeshTopology<In, Out> &b )
00155 {
00156 in >> b.map;
00157 return in;
00158 }
00159
00160 inline friend std::ostream& operator << ( std::ostream& out, const BarycentricMapperMeshTopology<In, Out> & b ){
00161 out << b.map;
00162 return out;
00163 }
00164 };
00165
00166 }
00167
00168 }
00169
00170 }
00171
00172 #endif