TriangleData.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_TRIANGLEDATA_INL
00026 #define SOFA_COMPONENT_TOPOLOGY_TRIANGLEDATA_INL
00027
00028 #include <sofa/component/topology/TriangleData.h>
00029 #include <sofa/component/topology/TriangleSetTopologyChange.h>
00030 #include <sofa/component/topology/TetrahedronSetTopologyChange.h>
00031
00032 namespace sofa
00033 {
00034
00035 namespace component
00036 {
00037
00038 namespace topology
00039 {
00040
00044
00045 template <typename T, typename Alloc>
00046 void TriangleData<T,Alloc>::handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt,
00047 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end )
00048 {
00049 while( changeIt != end )
00050 {
00051 core::componentmodel::topology::TopologyChangeType changeType = (*changeIt)->getChangeType();
00052
00053 switch( changeType )
00054 {
00055 case core::componentmodel::topology::TETRAHEDRAADDED:
00056 {
00057 if (m_createTetrahedronFunc)
00058 {
00059 const TetrahedraAdded *ea = static_cast< const TetrahedraAdded* >( *changeIt );
00060 (*m_createTetrahedronFunc)(ea->tetrahedronIndexArray, m_createParam, *this);
00061 }
00062 break;
00063 }
00064 case core::componentmodel::topology::TETRAHEDRAREMOVED:
00065 {
00066 if (m_destroyTetrahedronFunc)
00067 {
00068 const TetrahedraRemoved *er = static_cast< const TetrahedraRemoved * >( *changeIt );
00069 (*m_destroyTetrahedronFunc)(er->getArray(), m_createParam, *this);
00070 }
00071 break;
00072 }
00073 case core::componentmodel::topology::TRIANGLESADDED:
00074 {
00075 const TrianglesAdded *ta = static_cast< const TrianglesAdded * >( *changeIt );
00076 add( ta->getNbAddedTriangles(), ta->triangleArray, ta->ancestorsList, ta->coefs );
00077 break;
00078 }
00079
00080 case core::componentmodel::topology::TRIANGLESREMOVED:
00081 {
00082 const sofa::helper::vector<unsigned int> &tab = ( static_cast< const TrianglesRemoved *>( *changeIt ) )->getArray();
00083 remove( tab );
00084 break;
00085 }
00086
00087 default:
00088
00089 break;
00090 };
00091
00092 ++changeIt;
00093 }
00094 }
00095
00096 template <typename T, typename Alloc>
00097 void TriangleData<T,Alloc>::swap( unsigned int i1, unsigned int i2 )
00098 {
00099 T tmp = (*this)[i1];
00100 (*this)[i1] = (*this)[i2];
00101 (*this)[i2] = tmp;
00102 }
00103
00104 template <typename T, typename Alloc>
00105 void TriangleData<T,Alloc>::add( unsigned int nbTriangles,
00106 const sofa::helper::vector< Triangle >& triangle,
00107 const sofa::helper::vector< sofa::helper::vector< unsigned int > >& ancestors,
00108 const sofa::helper::vector< sofa::helper::vector< double > >& coefs )
00109 {
00110
00111 unsigned int i0 = this->size();
00112 this->resize(i0+nbTriangles);
00113
00114 for (unsigned int i = 0; i < nbTriangles; ++i)
00115 {
00116 T& t = (*this)[i0+i];
00117 if (ancestors.empty() || coefs.empty())
00118 {
00119 const sofa::helper::vector< unsigned int > empty_vecint;
00120 const sofa::helper::vector< double > empty_vecdouble;
00121 m_createFunc( i0+i, m_createParam, t, triangle[i], empty_vecint, empty_vecdouble );
00122 }
00123 else
00124 m_createFunc( i0+i, m_createParam, t, triangle[i], ancestors[i], coefs[i] );
00125 }
00126 }
00127
00128 template <typename T, typename Alloc>
00129 void TriangleData<T,Alloc>::remove( const sofa::helper::vector<unsigned int> &index )
00130 {
00131 unsigned int last = this->size() -1;
00132
00133 for (unsigned int i = 0; i < index.size(); ++i)
00134 {
00135 m_destroyFunc( index[i], m_destroyParam, (*this)[index[i]] );
00136 swap( index[i], last );
00137 --last;
00138 }
00139
00140 resize( this->size() - index.size() );
00141 }
00142
00143 }
00144
00145 }
00146
00147 }
00148
00149 #endif // _TriangleDATA_INL_