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_QUADDATA_H
00026 #define SOFA_COMPONENT_TOPOLOGY_QUADDATA_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::Quad Quad;
00041
00045 template < typename T >
00046 inline void trd_basicCreateFunc(int ,
00047 void* , T& t,
00048 const Quad& ,
00049 const sofa::helper::vector< unsigned int > &,
00050 const sofa::helper::vector< double >&)
00051 {
00052 t = T();
00053
00054 }
00055
00059 template < typename T >
00060 inline void qd_basicDestroyFunc(int , void* , T& )
00061 {
00062 return;
00063 }
00064
00070 template< class T, class Alloc = std::allocator<T> >
00071 class QuadData : public sofa::helper::vector<T, Alloc>
00072 {
00073 public:
00075 typedef typename sofa::helper::vector<T,Alloc>::size_type size_type;
00077 typedef typename sofa::helper::vector<T,Alloc>::reference reference;
00079 typedef typename sofa::helper::vector<T,Alloc>::const_reference const_reference;
00080
00081 public:
00083 QuadData(size_type n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00085 QuadData(int n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00087 QuadData(long n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00089 explicit QuadData(size_type n): sofa::helper::vector<T,Alloc>(n) {}
00091 QuadData(const sofa::helper::vector<T, Alloc>& x): sofa::helper::vector<T,Alloc>(x) {}
00092
00093
00094 #ifdef __STL_MEMBER_TEMPLATES
00096 template <class InputIterator>
00097 QuadData(InputIterator first, InputIterator last): sofa::helper::vector<T,Alloc>(first,last){}
00098 #else
00100 QuadData(typename QuadData<T>::const_iterator first, typename QuadData<T,Alloc>::const_iterator last): sofa::helper::vector<T,Alloc>(first,last){}
00101 #endif
00102
00103
00105 QuadData( void (*createFunc) (int, void*, T&, const Quad& ,const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >&) = trd_basicCreateFunc,
00106 void* createParam = (void*)NULL,
00107 void (*destroyFunc)(int, void*, T& ) = qd_basicDestroyFunc,
00108 void* destroyParam = (void*)NULL )
00109 : sofa::helper::vector<T,Alloc>(),
00110 m_createFunc(createFunc), m_destroyFunc(destroyFunc)
00111
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
00120 void setCreateFunction(void (*createFunc )(int, void*, T&, const Quad&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double>& ))
00121 {
00122 m_createFunc=createFunc;
00123 }
00124
00125 void setDestroyFunction( void (*destroyFunc)(int, void*, T&) )
00126 {
00127 m_destroyFunc=destroyFunc;
00128 }
00129
00130 void setDestroyParameter( void* destroyParam )
00131 {
00132 m_destroyParam=destroyParam;
00133 }
00134
00135 void setCreateParameter( void* createParam )
00136 {
00137 m_createParam=createParam;
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 private:
00154 void swap( unsigned int i1, unsigned int i2 );
00155
00157 void add( unsigned int nbQuads,
00158 const sofa::helper::vector< Quad >& quad,
00159 const sofa::helper::vector< sofa::helper::vector< unsigned int > > &ancestors,
00160 const sofa::helper::vector< sofa::helper::vector< double > >& coefs);
00161
00163 void remove( const sofa::helper::vector<unsigned int> &index );
00164
00165 private:
00167 void (*m_createFunc)(int, void*, T&, const Quad&,
00168 const sofa::helper::vector< unsigned int >&,
00169 const sofa::helper::vector< double >& );
00170
00172 void (*m_destroyFunc)(int, void*, T&);
00173
00175
00176
00178
00179
00180
00185 void* m_createParam;
00186
00191 void* m_destroyParam;
00192 };
00193
00194 }
00195
00196 }
00197
00198 }
00199
00200 #endif // _QuadDATA_H_