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_POINTDATA_H
00026 #define SOFA_COMPONENT_TOPOLOGY_POINTDATA_H
00027
00028 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00029 #include <sofa/helper/vector.h>
00030 #include <list>
00031
00032 namespace sofa
00033 {
00034 namespace core { namespace componentmodel { namespace topology { class TopologyChange; }}}
00035
00036 namespace component
00037 {
00038
00039 namespace topology
00040 {
00041
00045 template < typename T >
00046 inline void pd_basicCreateFunc(int , void* , T& t,
00047 const sofa::helper::vector< unsigned int > &,
00048 const sofa::helper::vector< double > &)
00049 {
00050 t = T();
00051
00052 }
00053
00057 template < typename T >
00058 inline void pd_basicDestroyFunc(int , void* , T& )
00059 {
00060 return;
00061 }
00062
00068 template< class T, class Alloc = std::allocator<T> >
00069 class PointData : public sofa::helper::vector<T, Alloc>
00070 {
00071 public:
00073 typedef typename sofa::helper::vector<T,Alloc>::size_type size_type;
00075 typedef typename sofa::helper::vector<T,Alloc>::reference reference;
00077 typedef typename sofa::helper::vector<T,Alloc>::const_reference const_reference;
00078
00079 public:
00081 PointData(size_type n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00083 PointData(int n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00085 PointData(long n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00087 explicit PointData(size_type n): sofa::helper::vector<T,Alloc>(n) {}
00089 PointData(const sofa::helper::vector<T, Alloc>& x): sofa::helper::vector<T,Alloc>(x) {}
00090
00091 #ifdef __STL_MEMBER_TEMPLATES
00093 template <class InputIterator>
00094 PointData(InputIterator first, InputIterator last): sofa::helper::vector<T,Alloc>(first,last){}
00095 #else
00097 PointData(typename PointData<T>::const_iterator first, typename PointData<T,Alloc>::const_iterator last): sofa::helper::vector<T,Alloc>(first,last){}
00098 #endif
00099
00100
00102 PointData( void (*createFunc) (int, void*, T&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >&) = pd_basicCreateFunc,
00103 void* createParam = (void*)NULL,
00104 void (*destroyFunc)(int, void*, T& ) = pd_basicDestroyFunc,
00105 void* destroyParam = (void*)NULL )
00106 : sofa::helper::vector<T,Alloc>(),
00107 m_createFunc(createFunc), m_destroyFunc(destroyFunc),
00108 m_createEdgeFunc(0), m_destroyEdgeFunc(0),
00109 m_createTriangleFunc(0), m_destroyTriangleFunc(0),
00110 m_createTetrahedronFunc(0), m_destroyTetrahedronFunc(0),
00111 m_createParam(createParam), m_destroyParam(destroyParam)
00112 {}
00113
00115 void handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt,
00116 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end );
00117
00118 void setCreateFunction(void (*createFunc )(int, void*, T&,
00119 const sofa::helper::vector< unsigned int > &,
00120 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 setCreateEdgeFunction( void (*createEdgeFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) )
00131 {
00132 m_createEdgeFunc=createEdgeFunc;
00133 }
00134 void setDestroyEdgeFunction(void (*destroyEdgeFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) ) {
00135 m_destroyEdgeFunc=destroyEdgeFunc;
00136 }
00137
00138 void setCreateTriangleFunction( void (*createTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) )
00139 {
00140 m_createTriangleFunc=createTriangleFunc;
00141 }
00142
00143 void setDestroyTriangleFunction(void (*destroyTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) )
00144 {
00145 m_destroyTriangleFunc=destroyTriangleFunc;
00146 }
00147
00148 void setCreateQuadFunction( void (*createQuadFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) )
00149 {
00150 m_createQuadFunc=createQuadFunc;
00151 }
00152
00153 void setDestroyQuadFunction(void (*destroyQuadFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) )
00154 {
00155 m_destroyQuadFunc=destroyQuadFunc;
00156 }
00157
00158 void setCreateTetrahedronFunction( void (*createTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) )
00159 {
00160 m_createTetrahedronFunc=createTetrahedronFunc;
00161 }
00162
00163 void setDestroyTetrahedronFunction(void (*destroyTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &) )
00164 {
00165 m_destroyTetrahedronFunc=destroyTetrahedronFunc;
00166 }
00167
00168 void setDestroyParameter( void* destroyParam )
00169 {
00170 m_destroyParam=destroyParam;
00171 }
00172
00173 void setCreateParameter( void* createParam )
00174 {
00175 m_createParam=createParam;
00176 }
00177
00178 private:
00180 void swap( unsigned int i1, unsigned int i2 );
00181
00183 void add( unsigned int nbPoints,
00184 const sofa::helper::vector< sofa::helper::vector< unsigned int > >& ancestors,
00185 const sofa::helper::vector< sofa::helper::vector< double > >& coefs);
00186
00188 void remove( const sofa::helper::vector<unsigned int> &index );
00189
00191 void renumber( const sofa::helper::vector<unsigned int> &index );
00192
00193 private:
00194
00196 void (*m_createFunc)(int, void*, T&,
00197 const sofa::helper::vector< unsigned int > &,
00198 const sofa::helper::vector< double >&);
00199
00201 void (*m_destroyFunc)(int, void*, T&);
00202
00204 void (*m_createEdgeFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00205
00207 void (*m_destroyEdgeFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00208
00210 void (*m_createTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00211
00213 void (*m_destroyTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00214
00216 void (*m_createQuadFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00217
00219 void (*m_destroyQuadFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00220
00222 void (*m_createTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00223
00225 void (*m_destroyTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*, helper::vector< T > &);
00226
00227
00232 void* m_createParam;
00233
00238 void* m_destroyParam;
00239 };
00240
00241 }
00242
00243 }
00244
00245 }
00246
00247 #endif // _POINTDATA_H_