HexahedronData.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_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                 // Ignore events that are not Hexahedron or Point related.
00068                 break;
00069             }; // switch( changeType )
00070 
00071             ++changeIt;
00072         } // while( changeIt != last; )
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         // Using default values
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 } // namespace topology
00123 
00124 } // namespace component
00125 
00126 } // namespace sofa
00127 
00128 #endif // _HexahedronDATA_INL_

Generated on Sun Nov 23 03:43:32 2008 for Sofa by  doxygen 1.5.7.1