CudaSpatialGridContainer.h

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 //
00026 // C++ Interface: SpatialGridContainer
00027 //
00028 // Description: 
00029 //
00030 //
00031 // Author: The SOFA team <http://www.sofa-framework.org>, (C) 2006
00032 //
00033 // Copyright: See COPYING file that comes with this distribution
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     //typedef typename DataTypes::NeighborListener NeighborListener;
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 } // namespace container
00130 
00131 } // namespace component
00132 
00133 } // namespace sofa
00134 
00135 #endif

Generated on Sun Nov 23 04:01:08 2008 for Sofa by  doxygen 1.5.7.1