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

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