QuadData.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_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             case core::componentmodel::topology::HEXAHEDRAADDED:
00056             {
00057                 if (m_createHexahedronFunc) 
00058                 {
00059                     const HexahedraAdded *ea=static_cast< const HexahedraAdded* >( *changeIt );
00060                     (*m_createHexahedronFunc)(ea->hexahedronIndexArray,m_createParam,*this);
00061                 }
00062                 break;
00063             }
00064             case core::componentmodel::topology::HEXAHEDRAREMOVED:
00065             {
00066                 if (m_destroyHexahedronFunc) 
00067                 {
00068                     const HexahedraRemoved *er=static_cast< const HexahedraRemoved * >( *changeIt );
00069                     (*m_destroyHexahedronFunc)(er->getArray(),m_createParam,*this);
00070                 }
00071                 break;
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                 // Ignore events that are not Quad or Point related.
00090                 break;
00091             }; // switch( changeType )
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         // Using default values
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 } // namespace topology
00145 
00146 } // namespace component
00147 
00148 } // namespace sofa
00149 
00150 #endif // _QuadDATA_INL_

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