CudaTetrahedralVisualModel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
00108 }
00109 }
00110 }