PointSubset.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_POINTSUBSET_H
00026 #define SOFA_COMPONENT_TOPOLOGY_POINTSUBSET_H
00027 
00028 #include <sofa/helper/vector.h>
00029 #include <list>
00030 #include <iostream>
00031 
00032 namespace sofa
00033 {
00034     namespace core{ namespace componentmodel{ namespace topology{ class TopologyChange; }}}
00035 
00036 namespace component
00037 {
00038 
00039 namespace topology
00040 {
00041 
00045     inline bool ps_testNewPointFunc(int , void* , 
00046                                     const sofa::helper::vector< unsigned int > &,
00047                                     const sofa::helper::vector< double       > &)
00048     {
00049         return false;
00050     }
00051 
00055     inline void ps_removeFunc(int , void* )
00056     {
00057         return;
00058     }
00059 
00065     class PointSubset 
00066     {
00067     public:
00068         // forwardinging Commonvector methods and typdefs
00069         typedef  helper::vector<unsigned int>::value_type                value_type;
00070         typedef  helper::vector<unsigned int>::pointer                   pointer;
00071         typedef  helper::vector<unsigned int>::reference                 reference;
00072         typedef  helper::vector<unsigned int>::const_reference           const_reference;
00073         typedef  helper::vector<unsigned int>::size_type                 size_type;
00074         typedef  helper::vector<unsigned int>::difference_type          difference_type;
00075         typedef  helper::vector<unsigned int>::iterator                  iterator;
00076         typedef  helper::vector<unsigned int>::const_iterator            const_iterator;
00077         typedef  helper::vector<unsigned int>::reverse_iterator          reverse_iterator;
00078         typedef  helper::vector<unsigned int>::const_reverse_iterator    const_reverse_iterator;
00079 
00080     public:
00082         PointSubset( bool (*testNewPointFunc)(int, void*, const sofa::helper::vector< unsigned int > &, const sofa::helper::vector< double >&)=ps_testNewPointFunc, 
00083                     void* testParam  = (void*)NULL, 
00084                     void (*removeFunc)(int, void*) = ps_removeFunc, 
00085                     void* removeParam = (void*)NULL ) 
00086         : m_testNewPointFunc(testNewPointFunc), 
00087         m_removalFunc(removeFunc), m_testParam(testParam), m_removeParam(removeParam), lastPointIndex(0)
00088         {}
00089 
00091         void handleTopologyEvents( std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator changeIt, 
00092                                 std::list< const core::componentmodel::topology::TopologyChange *>::const_iterator &end,
00093                                 const unsigned int totalPointSetArraySize);
00094 
00095         // defining operators so that pointSubset can be used in a Data (see Data class).
00096         friend std::ostream& operator<< (std::ostream& ostream, const PointSubset& pointSubset);
00097         friend std::istream& operator>> (std::istream& i,             PointSubset& pointSubset);
00098 
00099         void setTestFunction(bool (*testNewPointFunc )(int, void*, const sofa::helper::vector< unsigned int > &, 
00100                                                         const sofa::helper::vector< double >& )) 
00101         {
00102             m_testNewPointFunc=testNewPointFunc;
00103         }
00104 
00105         void setRemovalFunction( void (*removeFunc)(int, void*) ) 
00106         {
00107             m_removalFunc=removeFunc;
00108         }
00109 
00110         void setRemovalParameter( void* removeParam ) 
00111         {
00112             m_removeParam=removeParam;
00113         }
00114 
00115         void setTestParameter( void* testParam ) 
00116         {
00117             m_testParam=testParam;
00118         }
00119 
00120         const helper::vector< unsigned int > & getArray() const { return m_subset; }
00121 
00122         iterator begin() { return m_subset.begin(); }
00123 
00124         iterator end() {return m_subset.end(); }
00125 
00126         const_iterator begin() const { return m_subset.begin(); }
00127 
00128         const_iterator end() const { return m_subset.end(); }
00129 
00130         reverse_iterator rbegin() { return m_subset.rbegin(); }
00131 
00132         reverse_iterator rend() { return m_subset.rend(); }
00133 
00134         const_reverse_iterator rbegin() const { return m_subset.rbegin(); }
00135 
00136         const_reverse_iterator rend() const { return m_subset.rend(); }
00137 
00138         size_type size() const { return m_subset.size(); }
00139 
00140         size_type max_size() const { return m_subset.max_size(); }
00141 
00142         size_type capacity() const { return m_subset.capacity(); }
00143 
00144         bool empty() const { return m_subset.empty(); }
00145 
00146         reference operator[]( size_type n ) { return m_subset[n]; }
00147 
00148         const_reference operator[]( size_type i ) const { return m_subset[i]; }
00149 
00150         //        PointSubset& operator=( const sofa::helper::vector<unsigned int> & vector ) { m_subset( vector ); return *this; }
00151 
00152         //        PointSubset& operator=( const PointSubset& pointSubset ) { m_subset( pointSubset.m_subset ); return *this; }
00153 
00154         void reserve( size_t n ) { m_subset.reserve( n ); }
00155 
00156         reference front() { return m_subset.front(); }
00157 
00158         const_reference front() const { return m_subset.front(); }
00159 
00160         reference back() { return m_subset.back(); }
00161 
00162         const_reference back() const { return m_subset.back(); }
00163 
00164         void push_back( const unsigned int  t ) { m_subset.push_back( t ); }
00165 
00166         void pop_back() { m_subset.pop_back(); }
00167 
00168         void swap( helper::vector<unsigned int> &vector ) { m_subset.swap( vector ); }
00169 
00170         void swap( PointSubset &pointSubset) { m_subset.swap( pointSubset.m_subset ); }
00171 
00172         void clear() { m_subset.clear(); }
00173 
00174         void resize( size_t n ) { m_subset.resize( n ); }
00175 
00176     private:
00178         void swap( unsigned int i1, unsigned int i2 );
00179 
00181         void add( unsigned int nbPoints, 
00182                 const sofa::helper::vector< sofa::helper::vector< unsigned int > >& ancestors,
00183                 const sofa::helper::vector< sofa::helper::vector< double       > >& coefs);
00184 
00186         void remove( const sofa::helper::vector<unsigned int> &index );
00187 
00189         void renumber( const sofa::helper::vector<unsigned int> &index );
00190 
00191         void setTotalPointSetArraySize(const unsigned int s) { lastPointIndex=s-1; }
00192 
00193     private:
00195         helper::vector< unsigned int > m_subset;
00196 
00198         bool (*m_testNewPointFunc)(int, void*, const sofa::helper::vector< unsigned int > &, const sofa::helper::vector< double >&);
00199 
00201         void (*m_removalFunc)(int, void*);
00202 
00207         void* m_testParam;
00208 
00213         void* m_removeParam;
00214 
00216         unsigned int lastPointIndex;
00217     };
00218 
00220     std::ostream& operator<< (std::ostream& os, const PointSubset& pointSubset);
00221 
00223     std::istream& operator>>(std::istream& i, PointSubset& pointSubset);
00224 
00225 } // namespace topology
00226 
00227 } // namespace component
00228 
00229 } // namespace sofa
00230 
00231 #endif // _POINTSUBSET_H_

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