EdgeData.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_EDGEDATA_INL
00026 #define SOFA_COMPONENT_TOPOLOGY_EDGEDATA_INL
00027 
00028 #include <sofa/component/topology/EdgeData.h>
00029 #include <sofa/component/topology/EdgeSetTopologyChange.h>
00030 #include <sofa/component/topology/TriangleSetTopologyChange.h>  
00031 #include <sofa/component/topology/TetrahedronSetTopologyChange.h> 
00032 #include <sofa/component/topology/QuadSetTopologyChange.h>      
00033 
00034 namespace sofa
00035 {
00036 
00037 namespace component
00038 {
00039 
00040 namespace topology
00041 {
00045 
00046     template <typename T, typename Alloc>
00047     void EdgeData<T,Alloc>::handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt, 
00048                                                 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end ) 
00049     {
00050         while( changeIt != end )
00051         {
00052             core::componentmodel::topology::TopologyChangeType changeType = (*changeIt)->getChangeType();
00053 
00054             switch( changeType ) 
00055             {
00056              case core::componentmodel::topology::TETRAHEDRAADDED:
00057              {
00058                  if (m_createTetrahedronFunc) 
00059                  {
00060                      const TetrahedraAdded *ea=static_cast< const TetrahedraAdded* >( *changeIt );
00061                      (*m_createTetrahedronFunc)(ea->tetrahedronIndexArray,m_createParam,*this);
00062                  }
00063                  break;
00064              }
00065              case core::componentmodel::topology::TETRAHEDRAREMOVED:
00066              {
00067                  if (m_destroyTetrahedronFunc) 
00068                  {
00069                      const TetrahedraRemoved *er=static_cast< const TetrahedraRemoved * >( *changeIt );
00070                      (*m_destroyTetrahedronFunc)(er->getArray(),m_createParam,*this);
00071                  }
00072                  break;
00073              }      
00074              case core::componentmodel::topology::TRIANGLESADDED:
00075              {
00076                  if (m_createTriangleFunc) 
00077                  {
00078                      const TrianglesAdded *ea=static_cast< const TrianglesAdded* >( *changeIt );
00079                      (*m_createTriangleFunc)(ea->triangleIndexArray,m_createParam,*this);
00080                  }
00081                  break;
00082              }
00083              case core::componentmodel::topology::TRIANGLESREMOVED:
00084              {
00085                  if (m_destroyTriangleFunc) 
00086                  {
00087                      const TrianglesRemoved *er=static_cast< const TrianglesRemoved * >( *changeIt );
00088                      (*m_destroyTriangleFunc)(er->getArray(),m_createParam,*this);
00089                  }
00090                  break;
00091              }  
00092              case core::componentmodel::topology::QUADSADDED:
00093              {
00094                  if (m_createQuadFunc) 
00095                  {
00096                      const QuadsAdded *ea=static_cast< const QuadsAdded* >( *changeIt );
00097                      (*m_createQuadFunc)(ea->quadIndexArray,m_createParam,*this);
00098                  }
00099                  break;
00100              }
00101              case core::componentmodel::topology::QUADSREMOVED:
00102              {
00103                  if (m_destroyQuadFunc) 
00104                  {
00105                      const QuadsRemoved *er=static_cast< const QuadsRemoved * >( *changeIt );
00106                      (*m_destroyQuadFunc)(er->getArray(),m_createParam,*this);
00107                  }
00108                  break;
00109              }  
00110              case core::componentmodel::topology::EDGESADDED:
00111              {
00112                  const EdgesAdded *ea=static_cast< const EdgesAdded * >( *changeIt );
00113                  add( ea->getNbAddedEdges(), ea->edgeArray, ea->ancestorsList, ea->coefs );
00114                  break;
00115              }
00116              case core::componentmodel::topology::EDGESREMOVED:
00117              {
00118                  const sofa::helper::vector<unsigned int> &tab = ( static_cast< const EdgesRemoved *>( *changeIt ) )->getArray();
00119                  remove( tab );
00120                  break;
00121              }
00122              default:
00123                  // Ignore events that are not Edge or Point related.
00124                  break;
00125             }; // switch( changeType )
00126 
00127             ++changeIt;
00128         } 
00129     }
00130 
00131     template <typename T, typename Alloc>
00132     void EdgeData<T,Alloc>::swap( unsigned int i1, unsigned int i2 ) 
00133     {
00134         T tmp = (*this)[i1];
00135         (*this)[i1] = (*this)[i2];
00136         (*this)[i2] = tmp;
00137     }
00138 
00139     template <typename T, typename Alloc>
00140     void EdgeData<T,Alloc>::add( unsigned int nbEdges, 
00141                                 const sofa::helper::vector< Edge >& edge, 
00142                                 const sofa::helper::vector< sofa::helper::vector< unsigned int > >& ancestors, 
00143                                 const sofa::helper::vector< sofa::helper::vector< double > >& coefs ) 
00144     {
00145         // Using default values
00146         unsigned int i0 = this->size();
00147         this->resize(i0+nbEdges);
00148 
00149         for (unsigned int i = 0; i < nbEdges; ++i)
00150         {
00151             T& t = (*this)[i0+i];
00152             if (ancestors.empty() || coefs.empty())
00153             {
00154                 const sofa::helper::vector< unsigned int > empty_vecint;
00155                 const sofa::helper::vector< double > empty_vecdouble;
00156                 m_createFunc( i0+i, m_createParam, t, edge[i], empty_vecint, empty_vecdouble);
00157             }
00158             else
00159                 m_createFunc( i0+i, m_createParam, t, edge[i], ancestors[i], coefs[i] );
00160         }
00161     }
00162 
00163     template <typename T, typename Alloc>
00164     void EdgeData<T,Alloc>::remove( const sofa::helper::vector<unsigned int> &index ) 
00165     {
00166         unsigned int last = this->size() -1;            
00167 
00168         for (unsigned int i = 0; i < index.size(); ++i)
00169         {
00170             m_destroyFunc( index[i], m_destroyParam, (*this)[index[i]] );
00171             swap( index[i], last );
00172             --last;
00173         }
00174 
00175         resize( this->size() - index.size() );
00176 
00177         //std::cout << "EdgeData: vector has now "<<this->size()<<" entries."<<std::endl; 
00178     }
00179 
00180 } // namespace topology
00181 
00182 } // namespace component
00183 
00184 } // namespace sofa
00185 
00186 #endif // SOFA_COMPONENT_TOPOLOGY_EDGEDATA_INL

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