Clear Patch for OpenMesh.. free all used memory on mesh clear
git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@190 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -257,14 +257,20 @@ void ArrayKernel::garbage_collection(bool _v, bool _e, bool _f)
|
||||
|
||||
void ArrayKernel::clear()
|
||||
{
|
||||
vertices_.clear();
|
||||
edges_.clear();
|
||||
faces_.clear();
|
||||
vprops_clear();
|
||||
eprops_clear();
|
||||
hprops_clear();
|
||||
fprops_clear();
|
||||
|
||||
vertices_.clear();
|
||||
VertexContainer().swap( vertices_ );
|
||||
|
||||
edges_.clear();
|
||||
EdgeContainer().swap( edges_ );
|
||||
|
||||
faces_.clear();
|
||||
FaceContainer().swap( faces_ );
|
||||
|
||||
vprops_resize(0);
|
||||
eprops_resize(0);
|
||||
hprops_resize(0);
|
||||
fprops_resize(0);
|
||||
}
|
||||
|
||||
void ArrayKernel::resize( uint _n_vertices, uint _n_edges, uint _n_faces )
|
||||
|
||||
@@ -93,7 +93,12 @@ class BaseKernel
|
||||
public: //-------------------------------------------- constructor / destructor
|
||||
|
||||
BaseKernel() {}
|
||||
virtual ~BaseKernel() {}
|
||||
virtual ~BaseKernel() {
|
||||
vprops_.clear();
|
||||
eprops_.clear();
|
||||
hprops_.clear();
|
||||
fprops_.clear();
|
||||
}
|
||||
|
||||
|
||||
public: //-------------------------------------------------- add new properties
|
||||
@@ -504,29 +509,44 @@ protected: //------------------------------------------- synchronize properties
|
||||
|
||||
void vprops_reserve(unsigned int _n) const { vprops_.reserve(_n); }
|
||||
void vprops_resize(unsigned int _n) const { vprops_.resize(_n); }
|
||||
void vprops_clear() {
|
||||
vprops_.clear();
|
||||
}
|
||||
void vprops_swap(unsigned int _i0, unsigned int _i1) const {
|
||||
vprops_.swap(_i0, _i1);
|
||||
}
|
||||
|
||||
void hprops_reserve(unsigned int _n) const { hprops_.reserve(_n); }
|
||||
void hprops_resize(unsigned int _n) const { hprops_.resize(_n); }
|
||||
void hprops_clear() {
|
||||
hprops_.clear();
|
||||
}
|
||||
void hprops_swap(unsigned int _i0, unsigned int _i1) const {
|
||||
hprops_.swap(_i0, _i1);
|
||||
}
|
||||
|
||||
void eprops_reserve(unsigned int _n) const { eprops_.reserve(_n); }
|
||||
void eprops_resize(unsigned int _n) const { eprops_.resize(_n); }
|
||||
void eprops_clear() {
|
||||
eprops_.clear();
|
||||
}
|
||||
void eprops_swap(unsigned int _i0, unsigned int _i1) const {
|
||||
eprops_.swap(_i0, _i1);
|
||||
}
|
||||
|
||||
void fprops_reserve(unsigned int _n) const { fprops_.reserve(_n); }
|
||||
void fprops_resize(unsigned int _n) const { fprops_.resize(_n); }
|
||||
void fprops_clear() {
|
||||
fprops_.clear();
|
||||
}
|
||||
void fprops_swap(unsigned int _i0, unsigned int _i1) const {
|
||||
fprops_.swap(_i0, _i1);
|
||||
}
|
||||
|
||||
void mprops_resize(unsigned int _n) const { mprops_.resize(_n); }
|
||||
void mprops_clear() {
|
||||
mprops_.clear();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -97,6 +97,9 @@ public: // synchronized array interface
|
||||
/// Resize storage to hold n elements.
|
||||
virtual void resize(size_t _n) = 0;
|
||||
|
||||
/// Clear all elements and free memory.
|
||||
virtual void clear() = 0;
|
||||
|
||||
/// Extend the number of elements by one.
|
||||
virtual void push_back() = 0;
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ public: // inherited from BaseProperty
|
||||
|
||||
virtual void reserve(size_t _n) { data_.reserve(_n); }
|
||||
virtual void resize(size_t _n) { data_.resize(_n); }
|
||||
virtual void clear() { data_.clear(); vector_type().swap(data_); }
|
||||
virtual void push_back() { data_.push_back(T()); }
|
||||
virtual void swap(size_t _i0, size_t _i1)
|
||||
{ std::swap(data_[_i0], data_[_i1]); }
|
||||
@@ -230,6 +231,7 @@ public: // inherited from BaseProperty
|
||||
|
||||
virtual void reserve(size_t _n) { data_.reserve(_n); }
|
||||
virtual void resize(size_t _n) { data_.resize(_n); }
|
||||
virtual void clear() { data_.clear(); vector_type().swap(data_); }
|
||||
virtual void push_back() { data_.push_back(bool()); }
|
||||
virtual void swap(size_t _i0, size_t _i1)
|
||||
{ bool t(data_[_i0]); data_[_i0]=data_[_i1]; data_[_i1]=t; }
|
||||
@@ -387,6 +389,7 @@ public: // inherited from BaseProperty
|
||||
|
||||
virtual void reserve(size_t _n) { data_.reserve(_n); }
|
||||
virtual void resize(size_t _n) { data_.resize(_n); }
|
||||
virtual void clear() { data_.clear(); vector_type().swap(data_); }
|
||||
virtual void push_back() { data_.push_back(std::string()); }
|
||||
virtual void swap(size_t _i0, size_t _i1) {
|
||||
std::swap(data_[_i0], data_[_i1]);
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
//-------------------------------------------------- constructor / destructor
|
||||
|
||||
PropertyContainer() {}
|
||||
virtual ~PropertyContainer() { clear(); }
|
||||
virtual ~PropertyContainer() { std::for_each(properties_.begin(), properties_.end(), Delete()); }
|
||||
|
||||
|
||||
//------------------------------------------------------------- info / access
|
||||
@@ -177,7 +177,16 @@ public:
|
||||
|
||||
void clear()
|
||||
{
|
||||
std::for_each(properties_.begin(), properties_.end(), Delete());
|
||||
// Clear properties vector:
|
||||
// Replaced the old version with new one
|
||||
// which performs a swap to clear values and
|
||||
// deallocate memory.
|
||||
|
||||
// Old version (changed 22.07.09) {
|
||||
// std::for_each(properties_.begin(), properties_.end(), Delete());
|
||||
// }
|
||||
|
||||
std::for_each(properties_.begin(), properties_.end(), ClearAll());
|
||||
}
|
||||
|
||||
|
||||
@@ -256,6 +265,12 @@ private:
|
||||
size_t n_;
|
||||
};
|
||||
|
||||
struct ClearAll
|
||||
{
|
||||
ClearAll() {}
|
||||
void operator()(BaseProperty* _p) const { if (_p) _p->clear(); }
|
||||
};
|
||||
|
||||
struct Swap
|
||||
{
|
||||
Swap(size_t _i0, size_t _i1) : i0_(_i0), i1_(_i1) {}
|
||||
|
||||
Reference in New Issue
Block a user