Added the CompactVertexVector garbage collecting function.
This commit is contained in:
parent
b8a4cd254d
commit
7d6a210e75
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.37 2007/10/16 16:46:53 cignoni
|
||||||
|
Added Allocator::DeleteFace and Allocator::DeleteVertex; Now the use of SetD() should be deprecated.
|
||||||
|
|
||||||
Revision 1.36 2007/01/11 10:24:25 cignoni
|
Revision 1.36 2007/01/11 10:24:25 cignoni
|
||||||
Added test in AddVertices to do not update un-initalized vert references (for newly allocated faces)
|
Added test in AddVertices to do not update un-initalized vert references (for newly allocated faces)
|
||||||
|
|
||||||
|
@ -153,6 +156,11 @@ Initial commit
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace tri {
|
namespace tri {
|
||||||
/** \addtogroup trimesh */
|
/** \addtogroup trimesh */
|
||||||
|
|
||||||
|
template <class vector_type>
|
||||||
|
void Reorder( vector<size_t> &newVertIndex, vector_type &vert)
|
||||||
|
{}
|
||||||
|
|
||||||
/*@{*/
|
/*@{*/
|
||||||
/// Class to safely add vertexes and faces to a mesh updating all the involved pointers.
|
/// Class to safely add vertexes and faces to a mesh updating all the involved pointers.
|
||||||
/// It provides static memeber to add either vertex or faces to a trimesh.
|
/// It provides static memeber to add either vertex or faces to a trimesh.
|
||||||
|
@ -356,8 +364,48 @@ namespace vcg {
|
||||||
--m.vn;
|
--m.vn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function to compact all the vertices that have been deleted and put them to the end of the vector.
|
||||||
|
after this pass the isD test in the scanning of vertex vector, is no more strongly necessary.
|
||||||
|
It should not be called when TemporaryData is active;
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void CompactVertexVector( MeshType &m )
|
||||||
|
{
|
||||||
|
// newVertIndex [ <old_vert_position> ] gives you the new position of the vertex in the vector;
|
||||||
|
vector<size_t> newVertIndex(m.vert.size());
|
||||||
|
|
||||||
}; // end class
|
size_t pos=0;
|
||||||
|
size_t i=0;
|
||||||
|
|
||||||
|
for(i=0;i<m.vert.size();++i)
|
||||||
|
{
|
||||||
|
if(!m.vert[i].IsD())
|
||||||
|
{
|
||||||
|
if(pos!=i)
|
||||||
|
m.vert[pos]=m.vert[i];
|
||||||
|
newVertIndex[i]=pos;
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(pos==m.vn);
|
||||||
|
Reorder<typename MeshType::VertContainer>(newVertIndex,m.vert);
|
||||||
|
m.vert.resize(m.vn);
|
||||||
|
FaceIterator fi;
|
||||||
|
VertexPointer vbase=&m.vert[0];
|
||||||
|
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
|
if(!(*fi).IsD())
|
||||||
|
for(i=0;i<3;++i)
|
||||||
|
{
|
||||||
|
size_t oldIndex = (*fi).V(i) - vbase;
|
||||||
|
assert(oldIndex >=0 && oldIndex < newVertIndex.size());
|
||||||
|
(*fi).V(i) = vbase+newVertIndex[oldIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}; // end class
|
||||||
|
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
} // End Namespace TriMesh
|
} // End Namespace TriMesh
|
||||||
} // End Namespace vcg
|
} // End Namespace vcg
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.9 2006/12/11 23:42:00 ganovelli
|
||||||
|
bug Index()() instead of Index()
|
||||||
|
|
||||||
Revision 1.8 2006/12/04 11:17:42 ganovelli
|
Revision 1.8 2006/12/04 11:17:42 ganovelli
|
||||||
added forward declaration of TriMesh
|
added forward declaration of TriMesh
|
||||||
|
|
||||||
|
@ -97,29 +100,52 @@ public:
|
||||||
void pop_back();
|
void pop_back();
|
||||||
void resize(const unsigned int & _size)
|
void resize(const unsigned int & _size)
|
||||||
{
|
{
|
||||||
int oldsize = BaseType::size();
|
int oldsize = BaseType::size();
|
||||||
BaseType::resize(_size);
|
BaseType::resize(_size);
|
||||||
if(oldsize<_size){
|
if(oldsize<_size){
|
||||||
ThisTypeIterator firstnew = BaseType::begin();
|
ThisTypeIterator firstnew = BaseType::begin();
|
||||||
advance(firstnew,oldsize);
|
advance(firstnew,oldsize);
|
||||||
_updateOVP(firstnew,(*this).end());
|
_updateOVP(firstnew,(*this).end());
|
||||||
}
|
}
|
||||||
if(ColorEnabled) CV.resize(_size);
|
if(ColorEnabled) CV.resize(_size);
|
||||||
if(NormalEnabled) NV.resize(_size);
|
if(NormalEnabled) NV.resize(_size);
|
||||||
}
|
}
|
||||||
void reserve(const unsigned int & _size)
|
|
||||||
|
void reserve(const unsigned int & _size)
|
||||||
{
|
{
|
||||||
BaseType::reserve(_size);
|
BaseType::reserve(_size);
|
||||||
if (ColorEnabled) CV.reserve(_size);
|
if (ColorEnabled) CV.reserve(_size);
|
||||||
if (NormalEnabled) NV.reserve(_size);
|
if (NormalEnabled) NV.reserve(_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateOVP(ThisTypeIterator lbegin, ThisTypeIterator lend)
|
void _updateOVP(ThisTypeIterator lbegin, ThisTypeIterator lend)
|
||||||
{
|
{
|
||||||
ThisTypeIterator vi;
|
ThisTypeIterator vi;
|
||||||
for(vi=lbegin;vi!=lend;++vi)
|
for(vi=lbegin;vi!=lend;++vi)
|
||||||
(*vi)._ovp=this;
|
(*vi)._ovp=this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this function is called by the specialized Reorder function, that is called whenever someone call the allocator::CompactVertVector
|
||||||
|
void Reorder(std::vector<size_t> &newVertIndex )
|
||||||
|
{
|
||||||
|
size_t pos=0;
|
||||||
|
size_t i=0;
|
||||||
|
if(ColorEnabled) assert( CV.size() == newVertIndex.size() );
|
||||||
|
if(NormalEnabled) assert( NV.size() == newVertIndex.size() );
|
||||||
|
|
||||||
|
for(i=0;i<newVertIndex.size();++i)
|
||||||
|
{
|
||||||
|
if(newVertIndex[i] != std::numeric_limits<size_t>::max() )
|
||||||
|
{
|
||||||
|
assert(newVertIndex[i] <= i);
|
||||||
|
if(ColorEnabled) CV[newVertIndex[i]] = CV[i];
|
||||||
|
if(NormalEnabled) NV[newVertIndex[i]] = NV[i];;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
// Enabling Eunctions
|
// Enabling Eunctions
|
||||||
|
|
||||||
|
@ -295,6 +321,11 @@ namespace tri
|
||||||
else return VertexType::HasQuality();
|
else return VertexType::HasQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template < class VertexType >
|
||||||
|
void Reorder( std::vector<size_t> &newVertIndex, vert::vector_ocf< VertexType > &vertVec)
|
||||||
|
{
|
||||||
|
vertVec.Reorder(newVertIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}// end namespace vcg
|
}// end namespace vcg
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue