TetrahedronData.inl
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 SOFA_COMPONENT_TOPOLOGY_TETRAHEDRONDATA_INL
00026 #define SOFA_COMPONENT_TOPOLOGY_TETRAHEDRONDATA_INL
00027
00028 #include <sofa/component/topology/TetrahedronData.h>
00029 #include <sofa/component/topology/TetrahedronSetTopologyChange.h>
00030
00031 namespace sofa
00032 {
00033
00034 namespace component
00035 {
00036
00037 namespace topology
00038 {
00042
00043 template <typename T, typename Alloc>
00044 void TetrahedronData<T,Alloc>::handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt,
00045 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end )
00046 {
00047 while( changeIt != end )
00048 {
00049 core::componentmodel::topology::TopologyChangeType changeType = (*changeIt)->getChangeType();
00050
00051 switch( changeType )
00052 {
00053 case core::componentmodel::topology::TETRAHEDRAADDED:
00054 {
00055 const TetrahedraAdded *ta = static_cast< const TetrahedraAdded * >( *changeIt );
00056 add( ta->getNbAddedTetrahedra(), ta->tetrahedronArray, ta->ancestorsList, ta->coefs );
00057 break;
00058 }
00059 case core::componentmodel::topology::TETRAHEDRAREMOVED:
00060 {
00061 const sofa::helper::vector<unsigned int> &tab = ( static_cast< const TetrahedraRemoved *>( *changeIt ) )->getArray();
00062 remove( tab );
00063 break;
00064 }
00065 default:
00066
00067 break;
00068 };
00069
00070 ++changeIt;
00071 }
00072 }
00073
00074 template <typename T, typename Alloc>
00075 void TetrahedronData<T,Alloc>::swap( unsigned int i1, unsigned int i2 )
00076 {
00077 T tmp = (*this)[i1];
00078 (*this)[i1] = (*this)[i2];
00079 (*this)[i2] = tmp;
00080 }
00081
00082 template <typename T, typename Alloc>
00083 void TetrahedronData<T,Alloc>::add( unsigned int nbTetrahedra,
00084 const sofa::helper::vector< Tetrahedron >& tetrahedron,
00085 const sofa::helper::vector< sofa::helper::vector< unsigned int > >& ancestors,
00086 const sofa::helper::vector< sofa::helper::vector< double > >& coefs )
00087 {
00088
00089 unsigned int i0 = this->size();
00090 this->resize(i0+nbTetrahedra);
00091 for (unsigned int i = 0; i < nbTetrahedra; ++i)
00092 {
00093 T& t = (*this)[i0+i];
00094 if (ancestors.empty() || coefs.empty())
00095 {
00096 const sofa::helper::vector< unsigned int > empty_vecint;
00097 const sofa::helper::vector< double > empty_vecdouble;
00098 m_createFunc(i0+i, m_createParam, t, tetrahedron[i], empty_vecint, empty_vecdouble);
00099 }
00100 else
00101 m_createFunc(i0+i, m_createParam, t, tetrahedron[i], ancestors[i], coefs[i] );
00102 }
00103 }
00104
00105
00106
00107 template <typename T, typename Alloc>
00108 void TetrahedronData<T,Alloc>::remove( const sofa::helper::vector<unsigned int> &index ) {
00109 unsigned int last = this->size() -1;
00110
00111 for (unsigned int i = 0; i < index.size(); ++i)
00112 {
00113 m_destroyFunc( index[i], m_destroyParam, (*this)[index[i]] );
00114 swap( index[i], last );
00115 --last;
00116 }
00117
00118 resize( this->size() - index.size() );
00119 }
00120
00121
00122
00123 }
00124
00125 }
00126
00127 }
00128
00129 #endif // _TetrahedronDATA_INL_