TetrahedronData.inl

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
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             // Ignore events that are not Tetrahedron or Point related.
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         // Using default values
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 } // namespace topology
00124 
00125 } // namespace component
00126 
00127 } // namespace sofa
00128 
00129 #endif // _TetrahedronDATA_INL_

Generated on Sun Nov 23 03:45:51 2008 for Sofa by  doxygen 1.5.7.1