QuadData.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_QUADDATA_INL
00026 #define SOFA_COMPONENT_TOPOLOGY_QUADDATA_INL
00027
00028 #include <sofa/component/topology/QuadData.h>
00029 #include <sofa/component/topology/QuadSetTopologyChange.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 QuadData<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
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 case core::componentmodel::topology::QUADSADDED:
00075 {
00076 const QuadsAdded *qa=static_cast< const QuadsAdded * >( *changeIt );
00077 add( qa->getNbAddedQuads(), qa->quadArray, qa->ancestorsList, qa->coefs );
00078 break;
00079 }
00080
00081 case core::componentmodel::topology::QUADSREMOVED:
00082 {
00083 const sofa::helper::vector<unsigned int> &tab = ( static_cast< const QuadsRemoved *>( *changeIt ) )->getArray();
00084 remove( tab );
00085 break;
00086 }
00087
00088 default:
00089
00090 break;
00091 };
00092
00093 ++changeIt;
00094 }
00095 }
00096
00097 template <typename T, typename Alloc>
00098 void QuadData<T,Alloc>::swap( unsigned int i1, unsigned int i2 )
00099 {
00100 T tmp = (*this)[i1];
00101 (*this)[i1] = (*this)[i2];
00102 (*this)[i2] = tmp;
00103 }
00104
00105 template <typename T, typename Alloc>
00106 void QuadData<T,Alloc>::add( unsigned int nbQuads,
00107 const sofa::helper::vector< Quad >& quad,
00108 const sofa::helper::vector< sofa::helper::vector< unsigned int > >& ancestors,
00109 const sofa::helper::vector< sofa::helper::vector< double > >& coefs )
00110 {
00111
00112 unsigned int i0 = this->size();
00113 this->resize(i0+nbQuads);
00114
00115 for (unsigned int i = 0; i < nbQuads; ++i)
00116 {
00117 T& t = (*this)[i0+i];
00118 if (ancestors.empty() || coefs.empty())
00119 {
00120 const sofa::helper::vector< unsigned int > empty_vecint;
00121 const sofa::helper::vector< double > empty_vecdouble;
00122 m_createFunc( i0+i, m_createParam, t, quad[i], empty_vecint, empty_vecdouble);
00123 }
00124 else
00125 m_createFunc( i0+i, m_createParam, t, quad[i], ancestors[i], coefs[i] );
00126 }
00127 }
00128
00129 template <typename T, typename Alloc>
00130 void QuadData<T,Alloc>::remove( const sofa::helper::vector<unsigned int> &index )
00131 {
00132 unsigned int last = this->size() -1;
00133
00134 for (unsigned int i = 0; i < index.size(); ++i)
00135 {
00136 m_destroyFunc( index[i], m_destroyParam, (*this)[index[i]] );
00137 swap( index[i], last );
00138 --last;
00139 }
00140
00141 resize( this->size() - index.size() );
00142 }
00143
00144 }
00145
00146 }
00147
00148 }
00149
00150 #endif // _QuadDATA_INL_