TetrahedronData.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_TETRAHEDRONDATA_H
00026 #define SOFA_COMPONENT_TOPOLOGY_TETRAHEDRONDATA_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::Tetra Tetra;
00041     typedef Tetra Tetrahedron;
00042 
00046     template < typename T >
00047     inline void td_basicCreateFunc(int , 
00048                                     void* , T& t, 
00049                                     const Tetrahedron& ,  
00050                                     const sofa::helper::vector< unsigned int > &,
00051                                     const sofa::helper::vector< double >&)
00052     {
00053         t = T();
00054         //return;
00055     }
00056 
00060     template < typename T >
00061     inline void td_basicDestroyFunc(int , void* , T& )
00062     {
00063         return;
00064     }
00065 
00071     template< class T, class Alloc = std::allocator<T> > 
00072     class TetrahedronData : public sofa::helper::vector<T, Alloc> 
00073     {
00074     public:
00076         typedef typename sofa::helper::vector<T,Alloc>::size_type size_type;
00078         typedef typename sofa::helper::vector<T,Alloc>::reference reference;
00080         typedef typename sofa::helper::vector<T,Alloc>::const_reference const_reference;
00081 
00082     public:
00084         TetrahedronData(size_type n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00086         TetrahedronData(int n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00088         TetrahedronData(long n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00090         explicit TetrahedronData(size_type n): sofa::helper::vector<T,Alloc>(n) {}
00092         TetrahedronData(const sofa::helper::vector<T, Alloc>& x): sofa::helper::vector<T,Alloc>(x) {}
00093 
00094 
00095 #ifdef __STL_MEMBER_TEMPLATES
00097         template <class InputIterator>
00098         TetrahedronData(InputIterator first, InputIterator last): sofa::helper::vector<T,Alloc>(first,last){}
00099 #else /* __STL_MEMBER_TEMPLATES */
00101         TetrahedronData(typename TetrahedronData<T>::const_iterator first, typename TetrahedronData<T,Alloc>::const_iterator last): sofa::helper::vector<T,Alloc>(first,last){}
00102 #endif /* __STL_MEMBER_TEMPLATES */
00103 
00104 
00106         TetrahedronData( void (*createFunc) (int, void*, T&,const Tetrahedron& , const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >&) = td_basicCreateFunc,  
00107                         void* createParam  = (void*)NULL, 
00108                         void (*destroyFunc)(int, void*, T&                                     ) = td_basicDestroyFunc, 
00109                         void* destroyParam = (void*)NULL ) 
00110         : sofa::helper::vector<T,Alloc>(), 
00111         m_createFunc(createFunc), m_destroyFunc(destroyFunc), 
00112         m_createParam(createParam), m_destroyParam(destroyParam)
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 
00119         void setCreateFunction(void (*createFunc )(int, void*, T&, const Tetrahedron&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double>& )) 
00120         {
00121             m_createFunc=createFunc;
00122         }
00123 
00124         void setDestroyFunction( void (*destroyFunc)(int, void*, T&) ) 
00125         {
00126             m_destroyFunc=destroyFunc;
00127         }
00128 
00129         void setDestroyParameter( void* destroyParam ) 
00130         {
00131             m_destroyParam=destroyParam;
00132         }
00133 
00134         void setCreateParameter( void* createParam ) 
00135         {
00136             m_createParam=createParam;
00137         }
00138 
00139     private:
00141         void swap( unsigned int i1, unsigned int i2 );
00142 
00144         void add( unsigned int nbTetrahedra,
00145                 const sofa::helper::vector< Tetrahedron >& tetrahedron,
00146                 const sofa::helper::vector< sofa::helper::vector< unsigned int > > &ancestors, 
00147                 const sofa::helper::vector< sofa::helper::vector< double > >& coefs);
00148 
00150         void remove( const sofa::helper::vector<unsigned int> &index );
00151 
00152     private:
00154         void (*m_createFunc)(int, void*, T&, const Tetrahedron&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >& );
00155 
00157         void (*m_destroyFunc)(int, void*, T&);
00158 
00163         void* m_createParam;
00164 
00169         void* m_destroyParam;
00170     };
00171 
00172 } // namespace topology
00173 
00174 } // namespace component
00175 
00176 } // namespace sofa
00177 
00178 #endif // _TetrahedronDATA_H_

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