CudaSpatialGridContainer.h
Go to the documentation of this file.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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef SOFA_GPU_CUDA_CUDASPATIALGRIDCONTAINER_H
00038 #define SOFA_GPU_CUDA_CUDASPATIALGRIDCONTAINER_H
00039
00040 #include <sofa/component/container/SpatialGridContainer.h>
00041 #include <sofa/gpu/cuda/CudaTypes.h>
00042 #include <sofa/defaulttype/Vec.h>
00043
00044 namespace sofa
00045 {
00046
00047 namespace component
00048 {
00049
00050 namespace container
00051 {
00052
00053 using namespace sofa::defaulttype;
00054
00055 template<class TCoord, class TDeriv, class TReal>
00056 class SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >
00057 {
00058 public:
00059 typedef SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > DataTypes;
00060 typedef typename DataTypes::Real Real;
00061 typedef typename DataTypes::Coord Coord;
00062 typedef typename DataTypes::VecCoord VecCoord;
00063 typedef typename DataTypes::CellData CellData;
00064 typedef typename DataTypes::GridData GridData;
00065
00066 typedef typename DataTypes::ParticleField ParticleField;
00067
00068 public:
00069 SpatialGrid(Real cellWidth);
00070
00071 void update(const VecCoord& x);
00072
00073 void draw();
00074
00075 template<class NeighborListener>
00076 void findNeighbors(NeighborListener* dest, Real dist);
00077
00078 void computeField(ParticleField* field, Real dist);
00079
00083 void reorderIndices(helper::vector<unsigned int>* old2new, helper::vector<unsigned int>* new2old);
00084 #if 0
00085 enum { GRIDDIM_LOG2 = DataTypes::GRIDDIM_LOG2, GRIDDIM = 1<<GRIDDIM_LOG2 };
00086 enum { NCELL = GRIDDIM*GRIDDIM*GRIDDIM };
00087 enum { DX = 1, DY = GRIDDIM, DZ = GRIDDIM*GRIDDIM };
00088
00089 class Entry
00090 {
00091 public:
00092 int index;
00093 Coord pos;
00094 Entry(int i, const Coord& p) : index(i), pos(p) {}
00095 };
00096
00097 class Cell
00098 {
00099 public:
00100 std::list<Entry> plist;
00101 CellData data;
00102 void clear()
00103 {
00104 plist.clear();
00105 data.clear();
00106 }
00107 };
00108 #endif
00109
00110 GridData data;
00111
00112 Real getCellWidth() const { return cellWidth; }
00113 Real getInvCellWidth() const { return invCellWidth; }
00114
00115 protected:
00116 const Real cellWidth;
00117 const Real invCellWidth;
00118 int cellBits, nbCells;
00119 sofa::gpu::cuda::CudaVector< sofa::helper::fixed_array<int,2> > particleHash, sortTmp;
00120 sofa::gpu::cuda::CudaVector<int> cellStart;
00121 sofa::gpu::cuda::CudaVector< sofa::gpu::cuda::Vec3f1 > sortedPos;
00122 const VecCoord* lastX;
00123
00124 static void kernel_updateGrid(int cellBits, float cellWidth, int nbPoints, void* particleHash, void* sortTmp, void* cellStart, const void* x);
00125 static void kernel_reorderData(int nbPoints, const void* particleHash, void* sorted, const void* x);
00126
00127 };
00128
00129 }
00130
00131 }
00132
00133 }
00134
00135 #endif