CudaContactMapper.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 #ifndef SOFA_GPU_CUDA_CUDACONTACTMAPPER_H
00026 #define SOFA_GPU_CUDA_CUDACONTACTMAPPER_H
00027 
00028 #include <sofa/component/collision/BarycentricContactMapper.h>
00029 #include <sofa/gpu/cuda/CudaDistanceGridCollisionModel.h>
00030 #include <sofa/gpu/cuda/CudaPointModel.h>
00031 #include <sofa/gpu/cuda/CudaCollisionDetection.h>
00032 #include <sofa/gpu/cuda/CudaRigidMapping.h>
00033 #include <sofa/gpu/cuda/CudaSubsetMapping.h>
00034 
00035 
00036 namespace sofa
00037 {
00038 
00039 namespace gpu
00040 {
00041 
00042 namespace cuda
00043 {
00044 
00045 extern "C"
00046 {
00047 void RigidContactMapperCuda3f_setPoints2(unsigned int size, unsigned int nbTests, unsigned int maxPoints, const void* tests, const void* contacts, void* map);
00048 void SubsetContactMapperCuda3f_setPoints1(unsigned int size, unsigned int nbTests, unsigned int maxPoints, unsigned int nbPointsPerElem, const void* tests, const void* contacts, void* map);
00049 }
00050 
00051 } // namespace cuda
00052 
00053 } // namespace gpu
00054 
00055 namespace component
00056 {
00057 
00058 namespace collision
00059 {
00060 
00061 using namespace sofa::defaulttype;
00062 using sofa::core::componentmodel::collision::GPUDetectionOutputVector;
00063 
00064 
00066 template <class DataTypes>
00067 class ContactMapper<sofa::gpu::cuda::CudaRigidDistanceGridCollisionModel,DataTypes> : public RigidContactMapper<sofa::gpu::cuda::CudaRigidDistanceGridCollisionModel,DataTypes>
00068 {
00069 public:
00070     typedef typename DataTypes::Real Real;
00071     typedef typename DataTypes::Coord Coord;
00072     typedef RigidContactMapper<sofa::gpu::cuda::CudaRigidDistanceGridCollisionModel,DataTypes> Inherit;
00073     typedef typename Inherit::MMechanicalState MMechanicalState;
00074     typedef typename Inherit::MCollisionModel MCollisionModel;
00075     
00076     int addPoint(const Coord& P, int index, Real& r)
00077     {
00078         int i = this->Inherit::addPoint(P, index, r);
00079         if (!this->mapping)
00080         {
00081             MCollisionModel* model = this->model;
00082             MMechanicalState* outmodel = this->outmodel;
00083             typename DataTypes::Coord& x = (*outmodel->getX())[i];
00084             typename DataTypes::Deriv& v = (*outmodel->getV())[i];
00085             if (model->isTransformed(index))
00086             {
00087                 x = model->getTranslation(index) + model->getRotation(index) * P;
00088             }
00089             else
00090             {
00091                 x = P;
00092             }
00093             v = typename DataTypes::Deriv();
00094         }
00095         return i;
00096     }
00097 
00098     void setPoints2(GPUDetectionOutputVector* outputs)
00099     {
00100         int n = outputs->size();
00101         int nt = outputs->nbTests();
00102         int maxp = 0;
00103         for (int i=0;i<nt;i++)
00104             if (outputs->rtest(i).curSize > maxp) maxp = outputs->rtest(i).curSize;
00105         if (this->outmodel)
00106             this->outmodel->resize(n);
00107         if (this->mapping)
00108         {
00109             this->mapping->points.beginEdit()->fastResize(n);
00110             this->mapping->rotatedPoints.fastResize(n);
00111             RigidContactMapperCuda3f_setPoints2(n, nt, maxp, outputs->tests.deviceRead(), outputs->results.deviceRead(), this->mapping->points.beginEdit()->deviceWrite());
00112         }
00113         else
00114         {
00115             RigidContactMapperCuda3f_setPoints2(n, nt, maxp, outputs->tests.deviceRead(), outputs->results.deviceRead(), this->outmodel->getX()->deviceWrite());
00116         }
00117     }
00118 };
00119 
00120 
00122 template <class DataTypes>
00123 class ContactMapper<sofa::gpu::cuda::CudaPointModel,DataTypes> : public SubsetContactMapper<sofa::gpu::cuda::CudaPointModel,DataTypes>
00124 {
00125 public:
00126     typedef typename DataTypes::Real Real;
00127     typedef typename DataTypes::Coord Coord;
00128     typedef SubsetContactMapper<sofa::gpu::cuda::CudaPointModel,DataTypes> Inherit;
00129     typedef typename Inherit::MMechanicalState MMechanicalState;
00130     typedef typename Inherit::MCollisionModel MCollisionModel;
00131     
00132     int addPoint(const Coord& P, int index, Real& r)
00133     {
00134         int i = Inherit::addPoint(P, index, r);
00135         return i;
00136     }
00137 
00138     void setPoints1(GPUDetectionOutputVector* outputs)
00139     {
00140         int n = outputs->size();
00141         int nt = outputs->nbTests();
00142         int maxp = 0;
00143         for (int i=0;i<nt;i++)
00144             if (outputs->rtest(i).curSize > maxp) maxp = outputs->rtest(i).curSize;
00145         this->mapping->data.map.fastResize(n);
00146         SubsetContactMapperCuda3f_setPoints1(n, nt, maxp, this->model->groupSize.getValue(), outputs->tests.deviceRead(), outputs->results.deviceRead(), this->mapping->data.map.deviceWrite());
00147     }
00148 };
00149 
00150 
00152 template <class DataTypes>
00153 class ContactMapper<sofa::gpu::cuda::CudaSphereModel,DataTypes> : public SubsetContactMapper<sofa::gpu::cuda::CudaSphereModel,DataTypes>
00154 {
00155 public:
00156     typedef typename DataTypes::Real Real;
00157     typedef typename DataTypes::Coord Coord;
00158     typedef SubsetContactMapper<sofa::gpu::cuda::CudaSphereModel,DataTypes> Inherit;
00159     typedef typename Inherit::MMechanicalState MMechanicalState;
00160     typedef typename Inherit::MCollisionModel MCollisionModel;
00161     
00162     int addPoint(const Coord& P, int index, Real& r)
00163     {
00164         int i = this->Inherit::addPoint(P, index, r);
00165         return i;
00166     }
00167 
00168     void setPoints1(GPUDetectionOutputVector* outputs)
00169     {
00170         int n = outputs->size();
00171         int nt = outputs->nbTests();
00172         int maxp = 0;
00173         for (int i=0;i<nt;i++)
00174             if (outputs->rtest(i).curSize > maxp) maxp = outputs->rtest(i).curSize;
00175         this->mapping->data.map.fastResize(n);
00176         SubsetContactMapperCuda3f_setPoints1(n, nt, maxp, 0, outputs->tests.deviceRead(), outputs->results.deviceRead(), this->mapping->data.map.deviceWrite());
00177     }
00178 };
00179 
00180 
00181 
00182 } // namespace collision
00183 
00184 } // namespace component
00185 
00186 } // namespace sofa
00187 
00188 #endif

Generated on Sun Nov 23 03:58:24 2008 for Sofa by  doxygen 1.5.7.1