CudaSpatialGridContainer.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 //
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_INL
00038 #define SOFA_GPU_CUDA_CUDASPATIALGRIDCONTAINER_INL
00039 
00040 #include <sofa/gpu/cuda/CudaSpatialGridContainer.h>
00041 #include <sofa/component/container/SpatialGridContainer.inl>
00042 
00043 namespace sofa
00044 {
00045 
00046 namespace gpu
00047 {
00048 
00049 namespace cuda
00050 {
00051 
00052 extern "C"
00053 {
00054 void SpatialGridContainer3f_updateGrid(int cellBits, float cellWidth, int nbPoints, void* particleHash, void* sortTmp, void* cellStart, const void* x);
00055 void SpatialGridContainer3f1_updateGrid(int cellBits, float cellWidth, int nbPoints, void* particleHash, void* sortTmp, void* cellStart, const void* x);
00056 void SpatialGridContainer3f_reorderData(int nbPoints, const void* particleHash, void* sorted, const void* x);
00057 void SpatialGridContainer3f1_reorderData(int nbPoints, const void* particleHash, void* sorted, const void* x);
00058 }
00059 
00060 } // namespace cuda
00061 
00062 } // namespace gpu
00063     
00064 namespace component
00065 {
00066 
00067 namespace container
00068 {
00069 
00070 using namespace sofa::helper;
00071 
00072 //      template<class TCoord, class TDeriv, class TReal>
00073 //      typename SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::Grid SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::emptyGrid;
00074 
00075 template<class TCoord, class TDeriv, class TReal>
00076 SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::SpatialGrid(Real cellWidth)
00077 : cellWidth(cellWidth), invCellWidth(1/cellWidth), lastX(NULL)
00078 {
00079     cellBits = 16;
00080     nbCells = 1<<cellBits;
00081 }
00082 
00083 template<class TCoord, class TDeriv, class TReal> template<class NeighborListener>
00084 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::findNeighbors(NeighborListener* /*dest*/, Real /*dist*/)
00085 {
00086     std::cerr << "TODO: SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::findNeighbors(NeighborListener* dest, Real dist)"<<std::endl;
00087 }
00088 
00089 template<class TCoord, class TDeriv, class TReal>
00090 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::computeField(ParticleField* /*field*/, Real /*dist*/)
00091 {
00092     std::cerr << "TODO: SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::computeField(ParticleField* field, Real dist)"<<std::endl;
00093 }
00094 
00095 template<class TCoord, class TDeriv, class TReal>
00096 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::reorderIndices(helper::vector<unsigned int>* /*old2new*/, helper::vector<unsigned int>* /*new2old*/)
00097 {
00098     std::cerr << "TODO: SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::reorderIndices(helper::vector<unsigned int>* old2new, helper::vector<unsigned int>* new2old)"<<std::endl;
00099 }
00100 
00101 template<>
00102 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVec3fTypes > >::kernel_updateGrid(int cellBits, float cellWidth, int nbPoints, void* particleHash, void* sortTmp, void* cellStart, const void* x)
00103 {
00104     gpu::cuda::SpatialGridContainer3f_updateGrid(cellBits, cellWidth, nbPoints, particleHash, sortTmp, cellStart, x);
00105 }
00106 
00107 template<>
00108 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVec3f1Types > >::kernel_updateGrid(int cellBits, float cellWidth, int nbPoints, void* particleHash, void* sortTmp, void* cellStart, const void* x)
00109 {
00110     gpu::cuda::SpatialGridContainer3f1_updateGrid(cellBits, cellWidth, nbPoints, particleHash, sortTmp, cellStart, x);
00111 }
00112 
00113 template<>
00114 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVec3fTypes > >::kernel_reorderData(int nbPoints, const void* particleHash, void* sorted, const void* x)
00115 {
00116     gpu::cuda::SpatialGridContainer3f_reorderData(nbPoints, particleHash, sorted, x);
00117 }
00118 
00119 template<>
00120 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVec3f1Types > >::kernel_reorderData(int nbPoints, const void* particleHash, void* sorted, const void* x)
00121 {
00122     gpu::cuda::SpatialGridContainer3f1_reorderData(nbPoints, particleHash, sorted, x);
00123 }
00124 
00125 template<class TCoord, class TDeriv, class TReal>
00126 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::update(const VecCoord& x)
00127 {
00128     lastX = &x;
00129     data.clear();
00130     int nbPoints = x.size();
00131     particleHash.fastResize(nbPoints);
00132     sortTmp.fastResize(nbPoints);
00133     cellStart.fastResize(nbCells);
00134     sortedPos.fastResize(nbPoints);
00135     kernel_updateGrid(cellBits, cellWidth, nbPoints, particleHash.deviceWrite(), sortTmp.deviceWrite(), cellStart.deviceWrite(), x.deviceRead());
00136     kernel_reorderData(nbPoints, particleHash.deviceRead(), sortedPos.deviceWrite(), x.deviceRead());
00137 }
00138 
00139 template<class TCoord, class TDeriv, class TReal>
00140 void SpatialGrid< SpatialGridTypes < gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > >::draw()
00141 {
00142     if (!lastX) return;
00143     int nbPoints = particleHash.size();
00144     glDisable(GL_LIGHTING);
00145     glColor4f(1,1,1,1);
00146     glPointSize(3);
00147     glBegin(GL_POINTS);
00148     for (int i=0;i<nbPoints;i++)
00149     {
00150     unsigned int cell = particleHash[i][0];
00151     //unsigned int p = particleHash[i][1];
00152     //if (cell != 0 && cell != 65535)
00153     //    std::cout << i << ": "<<p<<" -> "<<cell<<", "<<(*lastX)[p]<<" -> "<<sortedPos[i]<<std::endl;
00154     int r = cell&3;
00155     int g = (cell>>2)&3;
00156     int b = (cell>>4)&3;
00157     glColor4ub(63+r*64,63+g*64,63+b*64,255);
00158     glVertex3fv(sortedPos[i].ptr());
00159     //glVertex3fv((*lastX)[p].ptr());
00160     }
00161     glEnd();
00162     glPointSize(1);
00163 }
00164 
00165 } // namespace container
00166 
00167 } // namespace component
00168 
00169 } // namespace sofa
00170 
00171 #endif

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