HexahedronData.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_HEXAHEDRONDATA_H
00026 #define SOFA_COMPONENT_TOPOLOGY_HEXAHEDRONDATA_H
00027 
00028 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00029 #include <sofa/helper/vector.h>
00030 #include <list>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace component
00036 {
00037 
00038 namespace topology
00039 {
00040     using core::componentmodel::topology::BaseMeshTopology;
00041     typedef BaseMeshTopology::Hexa Hexa;
00042     typedef Hexa Hexahedron;
00043 
00047     template < typename T >
00048     inline void td_basicCreateFunc(int , 
00049                                 void* , T& t, 
00050                                 const Hexahedron& ,  
00051                                 const sofa::helper::vector< unsigned int > &,
00052                                 const sofa::helper::vector< double >&)
00053     {
00054         t = T();
00055         //return;
00056     }
00057 
00061     template < typename T >
00062     inline void hd_basicDestroyFunc(int , void* , T& )
00063     {
00064         return;
00065     }
00066 
00072     template< class T, class Alloc = std::allocator<T> > 
00073     class HexahedronData : public sofa::helper::vector<T, Alloc> 
00074     {
00075     public:
00077         typedef typename sofa::helper::vector<T,Alloc>::size_type size_type;
00079         typedef typename sofa::helper::vector<T,Alloc>::reference reference;
00081         typedef typename sofa::helper::vector<T,Alloc>::const_reference const_reference;
00082 
00083     public:
00085         HexahedronData(size_type n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00087         HexahedronData(int n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00089         HexahedronData(long n, const T& value): sofa::helper::vector<T,Alloc>(n,value) {}
00091         explicit HexahedronData(size_type n): sofa::helper::vector<T,Alloc>(n) {}
00093         HexahedronData(const sofa::helper::vector<T, Alloc>& x): sofa::helper::vector<T,Alloc>(x) {}
00094 
00095 #ifdef __STL_MEMBER_TEMPLATES
00097         template <class InputIterator>
00098         HexahedronData(InputIterator first, InputIterator last): sofa::helper::vector<T,Alloc>(first,last){}
00099 #else /* __STL_MEMBER_TEMPLATES */
00101         HexahedronData(typename HexahedronData<T>::const_iterator first, typename HexahedronData<T,Alloc>::const_iterator last): sofa::helper::vector<T,Alloc>(first,last){}
00102 #endif /* __STL_MEMBER_TEMPLATES */
00103 
00105         HexahedronData( void (*createFunc) (int, void*, T&,const Hexahedron& , const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >&) = td_basicCreateFunc,  
00106                         void* createParam  = (void*)NULL, 
00107                         void (*destroyFunc)(int, void*, T&                                     ) = hd_basicDestroyFunc, 
00108                         void* destroyParam = (void*)NULL ) 
00109         : sofa::helper::vector<T,Alloc>(), 
00110         m_createFunc(createFunc), m_destroyFunc(destroyFunc), 
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 Hexahedron&, 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     private:
00140         void swap( unsigned int i1, unsigned int i2 );
00141 
00143         void add( unsigned int nbHexahedra,
00144             const sofa::helper::vector< Hexahedron >& hexahedron,
00145             const sofa::helper::vector< sofa::helper::vector< unsigned int > > &ancestors, 
00146             const sofa::helper::vector< sofa::helper::vector< double > >& coefs);
00147 
00149         void remove( const sofa::helper::vector<unsigned int> &index );
00150 
00151     private:
00153         void (*m_createFunc)(int, void*, T&, const Hexahedron&, const sofa::helper::vector< unsigned int >&, const sofa::helper::vector< double >& );
00154 
00156         void (*m_destroyFunc)(int, void*, T&);
00157 
00162         void* m_createParam;
00163 
00168         void* m_destroyParam;
00169     };
00170 
00171 
00172 } // namespace topology
00173 
00174 } // namespace component
00175 
00176 } // namespace sofa
00177 
00178 #endif // _HexahedronDATA_H_

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