TriangleSubsetData.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_TRIANGLESUBSETDATA_H
00026 #define SOFA_COMPONENT_TOPOLOGY_TRIANGLESUBSETDATA_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::Triangle Triangle;
00041 
00045     template < typename T >
00046     inline void tsd_basicCreateFunc(unsigned int , 
00047                                     void* , T& t, 
00048                                     const Triangle& ,  
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 tsd_basicDestroyFunc(unsigned int , void* , T& )
00061     {
00062         return;
00063     }
00064 
00070     template< class T > 
00071     class TriangleSubsetData : 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         TriangleSubsetData(size_type n, const T& value): std::map<unsigned int,T>(n,value) {}
00085         TriangleSubsetData(int n, const T& value): std::map<unsigned int,T>(n,value) {}
00087         TriangleSubsetData(long n, const T& value): std::map<unsigned int,T>(n,value) {}
00089         explicit TriangleSubsetData(size_type n): std::map<unsigned int,T>(n) {}
00091         TriangleSubsetData(const std::map<unsigned int,T>& x): std::map<unsigned int,T>(x) {}
00092 
00093 #ifdef __STL_MEMBER_TEMPLATES
00095         template <class InputIterator>
00096         TriangleSubsetData(InputIterator first, InputIterator last): std::map<unsigned int,T>(first,last){}
00097 #else /* __STL_MEMBER_TEMPLATES */
00099         TriangleSubsetData(typename TriangleSubsetData<T>::const_iterator first, typename TriangleSubsetData<T>::const_iterator last): std::map<unsigned int,T>(first,last){}
00100 #endif /* __STL_MEMBER_TEMPLATES */
00101 
00103         TriangleSubsetData( void (*createFunc) (unsigned int, void*, T&, const Triangle &,const std::vector< unsigned int >&, const std::vector< double >&) = tsd_basicCreateFunc,  
00104             void* createParam  = (void*)NULL, 
00105             void (*destroyFunc)(unsigned int, void*, T&                                     ) = tsd_basicDestroyFunc, 
00106             void* destroyParam = (void*)NULL ) 
00107             : std::map<unsigned int,T>(), 
00108             m_createFunc(createFunc), m_destroyFunc(destroyFunc), 
00109             m_createTetrahedronFunc(0), m_destroyTetrahedronFunc(0),
00110             m_createParam(createParam), m_destroyParam(destroyParam),lastTriangleIndex(0)
00111         {}
00112 
00114         void handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt,
00115                                 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end,
00116                                 const unsigned int totalTriangleSetArraySize);
00117 
00118         void setCreateFunction(void (*createFunc )(unsigned int, void*, T&, const Triangle&, const std::vector< unsigned int >&, const std::vector< double>& )) 
00119         {
00120             m_createFunc=createFunc;
00121         }
00122 
00123         void setDestroyFunction( void (*destroyFunc)(unsigned 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 setCreateTetrahedronFunction(  void (*createTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T >&) ) 
00139         {
00140             m_createTetrahedronFunc=createTetrahedronFunc;
00141         }
00142 
00143         void setDestroyTetrahedronFunction(void (*destroyTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &) ) 
00144         {
00145             m_destroyTetrahedronFunc=destroyTetrahedronFunc;
00146         }
00147 
00148     private:
00150         void add( unsigned int nbTriangles,
00151                 const helper::vector< Triangle >& triangle,
00152                 const helper::vector< helper::vector< unsigned int > > &ancestors, 
00153                 const helper::vector< helper::vector< double > >& coefs);
00154 
00156         void remove( const helper::vector<unsigned int> &index );
00157 
00158         void setTotalTriangleSetArraySize(const unsigned int s) 
00159         {
00160             lastTriangleIndex=s-1;
00161         }
00162 
00163     private:
00165         void (*m_createFunc)(unsigned int, void*, T&, const Triangle&, const std::vector< unsigned int >&, const std::vector< double >& );
00166 
00168         void (*m_destroyFunc)(unsigned int, void*, T&);
00169 
00171         void (*m_createTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T >&);
00172 
00174         void (*m_destroyTetrahedronFunc)(const std::vector<unsigned int> &, void*,  std::map<unsigned int, T > &);
00175 
00180         void* m_createParam;
00181 
00186         void* m_destroyParam;
00187 
00189         unsigned int lastTriangleIndex;
00190     };
00191 
00192 } // namespace topology
00193 
00194 } // namespace component
00195 
00196 } // namespace sofa
00197 
00198 #endif // _TriangleSubsetDATA_H_

Generated on Sun Nov 23 03:47:40 2008 for Sofa by  doxygen 1.5.7.1