CudaPointModel.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_CUDAPOINTMODEL_H
00026 #define SOFA_GPU_CUDA_CUDAPOINTMODEL_H
00027 
00028 #include "CudaTypes.h"
00029 
00030 #include <sofa/core/CollisionModel.h>
00031 #include <sofa/component/MechanicalObject.h>
00032 #include <sofa/defaulttype/Vec3Types.h>
00033 #include <sofa/defaulttype/RigidTypes.h>
00034 #include <sofa/helper/io/Mesh.h>
00035 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00036 
00037 namespace sofa
00038 {
00039 
00040 namespace gpu
00041 {
00042 
00043 namespace cuda
00044 {
00045 
00046 using namespace sofa::defaulttype;
00047 //using namespace sofa::component::collision;
00048 
00049 class CudaPointModel;
00050 
00051 class CudaPoint : public core::TCollisionElementIterator<CudaPointModel>
00052 {
00053 public:
00054     CudaPoint(CudaPointModel* model, int index);
00055 
00056         int i0();
00057         int getSize();
00058 
00059     explicit CudaPoint(const core::CollisionElementIterator& i);
00060 };
00061 
00062 class CudaPointModel : public core::CollisionModel
00063 {
00064 public:
00065     typedef CudaVec3fTypes InDataTypes;
00066     typedef CudaVec3fTypes DataTypes;
00067     typedef DataTypes::VecCoord VecCoord;
00068     typedef DataTypes::VecDeriv VecDeriv;
00069     typedef DataTypes::Coord Coord;
00070     typedef DataTypes::Deriv Deriv;
00071     typedef CudaPoint Element;
00072     friend class CudaPoint;
00073 
00074         Data<int> groupSize;
00075     
00076     CudaPointModel();
00077 
00078     virtual void init();
00079 
00080     // -- CollisionModel interface
00081 
00082     virtual void resize(int size);
00083 
00084     virtual void computeBoundingTree(int maxDepth=0);
00085 
00086     //virtual void computeContinuousBoundingTree(double dt, int maxDepth=0);
00087     
00088     void draw(int index);
00089     
00090     void draw();
00091 
00092     core::componentmodel::behavior::MechanicalState<InDataTypes>* getMechanicalState() { return mstate; }
00093 
00094 protected:
00095 
00096     core::componentmodel::behavior::MechanicalState<InDataTypes>* mstate;
00097 };
00098 
00099 inline CudaPoint::CudaPoint(CudaPointModel* model, int index)
00100 : core::TCollisionElementIterator<CudaPointModel>(model, index)
00101 {}
00102 
00103 inline CudaPoint::CudaPoint(const core::CollisionElementIterator& i)
00104 : core::TCollisionElementIterator<CudaPointModel>(static_cast<CudaPointModel*>(i.getCollisionModel()), i.getIndex())
00105 {
00106 }
00107 
00108 inline int CudaPoint::i0()
00109 {
00110     return model->groupSize.getValue()*index;
00111 }
00112 
00113 inline int CudaPoint::getSize()
00114 {
00115     if (index == model->getSize()-1)
00116         return model->getMechanicalState()->getX()->size();
00117     else
00118         return model->groupSize.getValue();
00119 }
00120 
00121 } // namespace cuda
00122 
00123 } // namespace gpu
00124 
00125 } // namespace sofa
00126 
00127 #endif

Generated on Sun Nov 23 04:00:41 2008 for Sofa by  doxygen 1.5.7.1