EdgeData.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_EDGEDATA_H
00026 #define SOFA_COMPONENT_TOPOLOGY_EDGEDATA_H
00027 
00028 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00029 #include <sofa/helper/vector.h>
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(int , 
00047                                 void* , T& t, 
00048                                 const Edge& ,  
00049                                 const sofa::helper::vector< unsigned int > &,
00050                                 const sofa::helper::vector< double >&)
00051     {
00052         t = T();
00053         //return;
00054     }
00055 
00059     template < typename T >
00060     inline void ed_basicDestroyFunc(int , void* , T& )
00061     {
00062         return;
00063     }
00064 
00070     template< class T, class Alloc = std::allocator<T> > 
00071     class EdgeData : public sofa::helper::vector<T, Alloc> 
00072     {
00073     public:
00075         typedef typename sofa::helper::vector<T,Alloc>::size_type size_type;
00077         typedef typename sofa::helper::vector<T,Alloc>::reference reference;
00079         typedef typename sofa::helper::vector<T,Alloc>::const_reference const_reference;
00080 
00081     public:
00083         EdgeData(size_type n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00085         EdgeData(int n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00087         EdgeData(long n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00089         explicit EdgeData(size_type n): sofa::helper::vector<T,Alloc>(n) {}
00091         EdgeData(const sofa::helper::vector<T, Alloc>& x): sofa::helper::vector<T,Alloc>(x) {}
00092 
00093 #ifdef __STL_MEMBER_TEMPLATES
00095         template <class InputIterator>
00096         EdgeData(InputIterator first, InputIterator last): sofa::helper::vector<T,Alloc>(first,last){}
00097 #else /* __STL_MEMBER_TEMPLATES */
00099         EdgeData(typename EdgeData<T>::const_iterator first, typename EdgeData<T,Alloc>::const_iterator last): sofa::helper::vector<T,Alloc>(first,last){}
00100 #endif /* __STL_MEMBER_TEMPLATES */
00101 
00103         EdgeData( void (*createFunc) (int, void*, T&, const Edge &,const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >&) = ed_basicCreateFunc,  
00104                 void* createParam  = (void*)NULL, 
00105                 void (*destroyFunc)(int, void*, T&                                     ) = ed_basicDestroyFunc, 
00106                 void* destroyParam = (void*)NULL ) 
00107         : sofa::helper::vector<T,Alloc>(), 
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         {}
00113 
00115         void handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt, 
00116                                 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end );
00117 
00118         void setCreateFunction(void (*createFunc )(int, void*, T&, const Edge&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double>& )) 
00119         {
00120             m_createFunc=createFunc;
00121         }
00122 
00123         void setDestroyFunction( void (*destroyFunc)(int, void*, T&) ) 
00124         {
00125             m_destroyFunc=destroyFunc;
00126         }
00127 
00128         void setDestroyParameter( void* destroyParam ) 
00129         {
00130             m_destroyParam=destroyParam;
00131         }
00132 
00133         void setCreateParameter( void* createParam ) 
00134         {
00135             m_createParam=createParam;
00136         }
00137 
00138         void setCreateTriangleFunction( void (*createTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &) ) 
00139         {
00140             m_createTriangleFunc=createTriangleFunc;
00141         }
00142 
00143         void setDestroyTriangleFunction(void (*destroyTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &) ) 
00144         {
00145             m_destroyTriangleFunc=destroyTriangleFunc;
00146         }
00147 
00148         void setCreateQuadFunction( void (*createQuadFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &) ) 
00149         {
00150             m_createQuadFunc=createQuadFunc;
00151         }
00152 
00153         void setDestroyQuadFunction(void (*destroyQuadFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &) ) 
00154         {
00155             m_destroyQuadFunc=destroyQuadFunc;
00156         }
00157 
00158         void setCreateTetrahedronFunction(  void (*createTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &) ) 
00159         {
00160             m_createTetrahedronFunc=createTetrahedronFunc;
00161         }
00162 
00163         void setDestroyTetrahedronFunction(void (*destroyTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &) ) 
00164         {
00165             m_destroyTetrahedronFunc=destroyTetrahedronFunc;
00166         }
00167 
00168     private:
00170         void swap( unsigned int i1, unsigned int i2 );
00171 
00173         void add( unsigned int nbEdges,
00174             const sofa::helper::vector< Edge >& edge,
00175             const sofa::helper::vector< sofa::helper::vector< unsigned int > > &ancestors, 
00176             const sofa::helper::vector< sofa::helper::vector< double > >& coefs);
00177 
00179         void remove( const sofa::helper::vector<unsigned int> &index );
00180 
00181     private:
00183         void (*m_createFunc)(int, void*, T&, const Edge&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >& );
00184 
00186         void (*m_destroyFunc)(int, void*, T&);
00187 
00189         void (*m_createTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &);
00190 
00192         void (*m_destroyTriangleFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &);
00193 
00195         void (*m_createQuadFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &);
00196 
00198         void (*m_destroyQuadFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &);
00199 
00201         void (*m_createTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &);
00202 
00204         void (*m_destroyTetrahedronFunc)(const sofa::helper::vector<unsigned int> &, void*,  helper::vector< T > &);
00205 
00210         void* m_createParam;
00211 
00216         void* m_destroyParam;
00217     };
00218 
00219 } // namespace topology
00220 
00221 } // namespace component
00222 
00223 } // namespace sofa
00224 
00225 #endif // SOFA_COMPONENT_TOPOLOGY_EDGEDATA_H

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