CudaTetrahedralVisualModel.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 CUDAOGLTETRAHEDRALMODEL_H_
00026 #define CUDAOGLTETRAHEDRALMODEL_H_
00027 
00028 #include <sofa/component/visualmodel/OglTetrahedralModel.h>
00029 #include <sofa/gpu/cuda/CudaTypes.h>
00030 
00031 namespace sofa
00032 {
00033 namespace component
00034 {
00035 namespace visualmodel
00036 {
00037 
00038 template<class TCoord, class TDeriv, class TReal>
00039 class OglTetrahedralModel< gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> > : public core::VisualModel
00040 {
00041 public:
00042     typedef gpu::cuda::CudaVectorTypes<TCoord,TDeriv,TReal> DataTypes;
00043     typedef typename DataTypes::Real Real;
00044     typedef typename DataTypes::Coord Coord;
00045     typedef typename DataTypes::VecCoord VecCoord;
00046     typedef core::componentmodel::topology::BaseMeshTopology::Tetra Tetra;
00047     typedef core::componentmodel::topology::BaseMeshTopology::SeqTetras SeqTetras;
00048 
00049 private:
00050     core::componentmodel::topology::BaseMeshTopology* topo;
00051     core::componentmodel::behavior::MechanicalState<DataTypes>* nodes;
00052 
00053     bool needUpdateTopology;
00054     gpu::cuda::CudaVector<Tetra> tetras;
00055 
00056     Data<bool> depthTest;
00057     Data<bool> blending;
00058     Data<bool> useVBO;
00059     
00060 public:
00061     OglTetrahedralModel();
00062     virtual ~OglTetrahedralModel();
00063     
00064     void init();
00065     void drawTransparent();
00066     bool addBBox(double* minBBox, double* maxBBox);
00067 
00068     void handleTopologyChange()
00069     {
00070         needUpdateTopology = true;
00071     }
00072     
00073     void updateVisual()
00074     {
00075         //if (!getContext()->getShowVisualModels()) return;
00076         updateTopology();
00077     }
00078 
00081     template<class T>
00082     static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
00083     {
00084         if (dynamic_cast<core::componentmodel::behavior::MechanicalState<DataTypes>*>(context->getMechanicalState()) == NULL)
00085             return false;
00086         return core::objectmodel::BaseObject::canCreate(obj, context, arg);
00087     }
00088 
00089 protected:
00090 
00091     void updateTopology()
00092     {
00093         if (!topo || !nodes) return;
00094         if (!needUpdateTopology) return;
00095         needUpdateTopology = false;
00096         const SeqTetras& t = topo->getTetras();
00097         tetras.clear();
00098         if (!t.empty())
00099         {
00100             tetras.fastResize(t.size());
00101             std::copy ( t.begin(), t.end(), tetras.hostWrite() );
00102         }
00103     }
00104 
00105 };
00106 
00107 #endif /*OGLTETRAHEDRALMODEL_H_*/
00108 }
00109 }
00110 }

Generated on Sun Nov 23 04:03:20 2008 for Sofa by  doxygen 1.5.7.1