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