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 SOFA_COMPONENT_TOPOLOGY_TETRAHEDRONDATA_H
00026 #define SOFA_COMPONENT_TOPOLOGY_TETRAHEDRONDATA_H
00027
00028 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00029 #include <sofa/helper/vector.h>
00030
00031 namespace sofa
00032 {
00033
00034 namespace component
00035 {
00036
00037 namespace topology
00038 {
00039 using core::componentmodel::topology::BaseMeshTopology;
00040 typedef BaseMeshTopology::Tetra Tetra;
00041 typedef Tetra Tetrahedron;
00042
00046 template < typename T >
00047 inline void td_basicCreateFunc(int ,
00048 void* , T& t,
00049 const Tetrahedron& ,
00050 const sofa::helper::vector< unsigned int > &,
00051 const sofa::helper::vector< double >&)
00052 {
00053 t = T();
00054
00055 }
00056
00060 template < typename T >
00061 inline void td_basicDestroyFunc(int , void* , T& )
00062 {
00063 return;
00064 }
00065
00071 template< class T, class Alloc = std::allocator<T> >
00072 class TetrahedronData : public sofa::helper::vector<T, Alloc>
00073 {
00074 public:
00076 typedef typename sofa::helper::vector<T,Alloc>::size_type size_type;
00078 typedef typename sofa::helper::vector<T,Alloc>::reference reference;
00080 typedef typename sofa::helper::vector<T,Alloc>::const_reference const_reference;
00081
00082 public:
00084 TetrahedronData(size_type n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00086 TetrahedronData(int n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00088 TetrahedronData(long n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00090 explicit TetrahedronData(size_type n): sofa::helper::vector<T,Alloc>(n) {}
00092 TetrahedronData(const sofa::helper::vector<T, Alloc>& x): sofa::helper::vector<T,Alloc>(x) {}
00093
00094
00095 #ifdef __STL_MEMBER_TEMPLATES
00097 template <class InputIterator>
00098 TetrahedronData(InputIterator first, InputIterator last): sofa::helper::vector<T,Alloc>(first,last){}
00099 #else
00101 TetrahedronData(typename TetrahedronData<T>::const_iterator first, typename TetrahedronData<T,Alloc>::const_iterator last): sofa::helper::vector<T,Alloc>(first,last){}
00102 #endif
00103
00104
00106 TetrahedronData( void (*createFunc) (int, void*, T&,const Tetrahedron& , const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >&) = td_basicCreateFunc,
00107 void* createParam = (void*)NULL,
00108 void (*destroyFunc)(int, void*, T& ) = td_basicDestroyFunc,
00109 void* destroyParam = (void*)NULL )
00110 : sofa::helper::vector<T,Alloc>(),
00111 m_createFunc(createFunc), m_destroyFunc(destroyFunc),
00112 m_createParam(createParam), m_destroyParam(destroyParam)
00113 {}
00114
00116 void handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt,
00117 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end );
00118
00119 void setCreateFunction(void (*createFunc )(int, void*, T&, const Tetrahedron&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double>& ))
00120 {
00121 m_createFunc=createFunc;
00122 }
00123
00124 void setDestroyFunction( void (*destroyFunc)(int, void*, T&) )
00125 {
00126 m_destroyFunc=destroyFunc;
00127 }
00128
00129 void setDestroyParameter( void* destroyParam )
00130 {
00131 m_destroyParam=destroyParam;
00132 }
00133
00134 void setCreateParameter( void* createParam )
00135 {
00136 m_createParam=createParam;
00137 }
00138
00139 private:
00141 void swap( unsigned int i1, unsigned int i2 );
00142
00144 void add( unsigned int nbTetrahedra,
00145 const sofa::helper::vector< Tetrahedron >& tetrahedron,
00146 const sofa::helper::vector< sofa::helper::vector< unsigned int > > &ancestors,
00147 const sofa::helper::vector< sofa::helper::vector< double > >& coefs);
00148
00150 void remove( const sofa::helper::vector<unsigned int> &index );
00151
00152 private:
00154 void (*m_createFunc)(int, void*, T&, const Tetrahedron&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >& );
00155
00157 void (*m_destroyFunc)(int, void*, T&);
00158
00163 void* m_createParam;
00164
00169 void* m_destroyParam;
00170 };
00171
00172 }
00173
00174 }
00175
00176 }
00177
00178 #endif // _TetrahedronDATA_H_