EdgeSubsetData.h

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_H
00026 #define SOFA_COMPONENT_TOPOLOGY_EDGESUBSETDATA_H
00027 
00028 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00029 #include <map>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace topology
00038 {
00039     using core::componentmodel::topology::BaseMeshTopology;
00040     typedef BaseMeshTopology::Edge Edge;
00041 
00045     template < typename T >
00046     inline void ed_basicCreateFunc(unsigned int , 
00047                                 void* , T& t, 
00048                                 const Edge& ,  
00049                                 const std::vector< unsigned int > &,
00050                                 const std::vector< double >&)
00051     {
00052         t = T();
00053         //return;
00054     }
00055 
00059     template < typename T >
00060     inline void ed_basicDestroyFunc(unsigned int , void* , T& )
00061     {
00062         return;
00063     }
00064 
00070     template< class T > 
00071     class EdgeSubsetData : public std::map<unsigned int,T> 
00072     {
00073     public:
00075         typedef typename std::map<unsigned int,T>::size_type size_type;
00077         typedef typename std::map<unsigned int,T>::reference reference;
00079         typedef typename std::map<unsigned int,T>::const_reference const_reference;
00080 
00081     public:
00083         EdgeSubsetData(size_type n, const T& value): std::map<unsigned int,T>(n,value) {}
00085         EdgeSubsetData(int n, const T& value): std::map<unsigned int,T>(n,value) {}
00087         EdgeSubsetData(long n, const T& value): std::map<unsigned int,T>(n,value) {}
00089         explicit EdgeSubsetData(size_type n): std::map<unsigned int,T>(n) {}
00091         EdgeSubsetData(const std::map<unsigned int,T>& x): std::map<unsigned int,T>(x) {}
00092 
00093 #ifdef __STL_MEMBER_TEMPLATES
00095         template <class InputIterator>
00096         EdgeSubsetData(InputIterator first, InputIterator last): std::map<unsigned int,T>(first,last){}
00097 #else /* __STL_MEMBER_TEMPLATES */
00099         EdgeSubsetData(typename EdgeSubsetData<T>::const_iterator first, typename EdgeSubsetData<T>::const_iterator last): std::map<unsigned int,T>(first,last){}
00100 #endif /* __STL_MEMBER_TEMPLATES */
00101 
00103         EdgeSubsetData( void (*createFunc) (unsigned int, void*, T&, const Edge &,const std::vector< unsigned int >&, const std::vector< double >&) = ed_basicCreateFunc,  
00104                         void* createParam  = (void*)NULL, 
00105                         void (*destroyFunc)(unsigned int, void*, T&                                     ) = ed_basicDestroyFunc, 
00106                         void* destroyParam = (void*)NULL ) 
00107         : std::map<unsigned int,T>(), 
00108         m_createFunc(createFunc), m_destroyFunc(destroyFunc), 
00109         m_createTriangleFunc(0), m_destroyTriangleFunc(0), 
00110         m_createTetrahedronFunc(0), m_destroyTetrahedronFunc(0), 
00111         m_createParam(createParam), m_destroyParam(destroyParam),
00112         lastEdgeIndex(0)
00113         {}
00114 
00116         void handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt, 
00117                                 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end ,
00118                                 const unsigned int totalEdgeSetArraySize);
00119 
00120         void setCreateFunction(void (*createFunc )(unsigned int, void*, T&, const Edge&, const std::vector< unsigned int >&, const std::vector< double>& )) 
00121         {
00122             m_createFunc=createFunc;
00123         }
00124 
00125         void setDestroyFunction( void (*destroyFunc)(unsigned int, void*, T&) ) 
00126         {
00127             m_destroyFunc=destroyFunc;
00128         }
00129 
00130         void setDestroyParameter( void* destroyParam ) 
00131         {
00132             m_destroyParam=destroyParam;
00133         }
00134 
00135         void setCreateParameter( void* createParam ) 
00136         {
00137             m_createParam=createParam;
00138         }
00139 
00140         void setCreateTriangleFunction( void (*createTriangleFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &) ) 
00141         {
00142             m_createTriangleFunc=createTriangleFunc;
00143         }
00144 
00145         void setDestroyTriangleFunction(void (*destroyTriangleFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &) ) 
00146         {
00147             m_destroyTriangleFunc=destroyTriangleFunc;
00148         }
00149 
00150         void setCreateQuadFunction( void (*createQuadFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &) ) 
00151         {
00152             m_createQuadFunc=createQuadFunc;
00153         }
00154 
00155         void setDestroyQuadFunction(void (*destroyQuadFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &) ) 
00156         {
00157             m_destroyQuadFunc=destroyQuadFunc;
00158         }
00159 
00160         void setCreateTetrahedronFunction(  void (*createTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T >&) ) 
00161         {
00162             m_createTetrahedronFunc=createTetrahedronFunc;
00163         }
00164 
00165         void setDestroyTetrahedronFunction(void (*destroyTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &) ) 
00166         {
00167             m_destroyTetrahedronFunc=destroyTetrahedronFunc;
00168         }
00169 
00170     private:
00172         void add( unsigned int nbEdges,
00173                 const sofa::helper::vector< Edge >& edge,
00174                 const sofa::helper::vector< sofa::helper::vector< unsigned int > > &ancestors, 
00175                 const sofa::helper::vector< sofa::helper::vector< double > >& coefs);
00176 
00178         void remove( const std::vector<unsigned int> &index );
00179 
00180         void setTotalEdgeSetArraySize(const unsigned int s) 
00181         {
00182             lastEdgeIndex=s-1;
00183         }
00184 
00185     private:
00187         void (*m_createFunc)(unsigned int, void*, T&, const Edge&, const std::vector< unsigned int >&, const std::vector< double >& );
00188 
00190         void (*m_destroyFunc)(unsigned int, void*, T&);
00191 
00193         void (*m_createTriangleFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &);
00194 
00196         void (*m_destroyTriangleFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T >&);
00197 
00199         void (*m_createQuadFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &);
00200 
00202         void (*m_destroyQuadFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T >&);
00203 
00205         void (*m_createTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T >&);
00206 
00208         void (*m_destroyTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &);
00209 
00214         void* m_createParam;
00215 
00220         void* m_destroyParam;
00222         unsigned int lastEdgeIndex;
00223     };
00224 
00225 } // namespace topology
00226 
00227 } // namespace component
00228 
00229 } // namespace sofa
00230 
00231 #endif // _EdgeSubsetDATA_H_

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