Corrected the behavoiour of the allocate::Compact when managing uninitialized and null element in adjacency

This commit is contained in:
Paolo Cignoni 2013-03-13 14:33:09 +00:00
parent 4665f36e40
commit f62e07ee66
1 changed files with 341 additions and 338 deletions
vcg/complex

View File

@ -142,7 +142,7 @@ namespace tri {
SimplexPointerType oldBase;
SimplexPointerType newEnd;
SimplexPointerType oldEnd;
std::vector<size_t> remap;
std::vector<size_t> remap; // this vector keep the new position of an element. Uninitialized elements have max_int value to denote an element that has not to be remapped.
bool preventUpdateFlag; /// when true no update is considered necessary.
};
@ -599,12 +599,13 @@ namespace tri {
{
assert(!m.vert[i].IsD());
m.vert[ pu.remap [i] ].ImportData(m.vert[i]);
if(HasPerVertexVFAdjacency(m) &&HasPerFaceVFAdjacency(m) )
if (m.vert[i].cVFp()!=0)
if(HasVFAdjacency(m))
if (m.vert[i].IsVFInitialized())
{
m.vert[ pu.remap[i] ].VFp() = m.vert[i].cVFp();
m.vert[ pu.remap[i] ].VFi() = m.vert[i].cVFi();
}
else m.vert [ pu.remap[i] ].VFClear();
}
}
@ -793,7 +794,7 @@ namespace tri {
\brief Compact vector of faces removing deleted elements.
Deleted elements are put to the end of the vector and the vector is resized. Order between elements is preserved but not their position (hence the PointerUpdater)
After calling this function the \c IsD() test in the scanning a vector, is no more necessary.
Immediately after calling this function the \c IsD() test during the scanning a vector, is no more necessary.
\warning It should not be called when TemporaryData is active (but works correctly if attributes are present)
*/
static void CompactFaceVector( MeshType &m, PointerUpdater<FacePointer> &pu )
@ -805,9 +806,7 @@ namespace tri {
pu.remap.resize( m.face.size(),std::numeric_limits<size_t>::max() );
size_t pos=0;
size_t i=0;
for(i=0;i<m.face.size();++i)
for(size_t i=0;i<m.face.size();++i)
{
if(!m.face[i].IsD())
{
@ -817,12 +816,15 @@ namespace tri {
m.face[pos].V(0) = m.face[i].V(0);
m.face[pos].V(1) = m.face[i].V(1);
m.face[pos].V(2) = m.face[i].V(2);
if(HasPerVertexVFAdjacency(m) && HasPerFaceVFAdjacency(m))
if(HasVFAdjacency(m))
for(int j=0;j<3;++j)
if (m.face[i].cVFp(j)!=0) {
{
if (m.face[i].IsVFInitialized(j)) {
m.face[pos].VFp(j) = m.face[i].cVFp(j);
m.face[pos].VFi(j) = m.face[i].cVFi(j);
}
else m.face[pos].VFClear(j);
}
if(HasFFAdjacency(m))
for(int j=0;j<3;++j)
if (m.face[i].cFFp(j)!=0) {
@ -839,21 +841,22 @@ namespace tri {
// reorder the optional atttributes in m.face_attr to reflect the changes
ReorderAttribute(m.face_attr,pu.remap,m);
// Loop on the vertices to correct VF relation
VertexIterator vi;
FacePointer fbase=&m.face[0];
for (vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
// Loop on the vertices to correct VF relation
if(HasVFAdjacency(m))
{
for (VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
if(!(*vi).IsD())
{
if(HasPerVertexVFAdjacency(m) &&HasPerFaceVFAdjacency(m) )
if ((*vi).cVFp()!=0)
if ((*vi).IsVFInitialized() && (*vi).VFp()!=0 )
{
size_t oldIndex = (*vi).cVFp() - fbase;
assert(fbase <= (*vi).cVFp() && oldIndex < pu.remap.size());
(*vi).VFp() = fbase+pu.remap[oldIndex];
}
}
}
// Loop on the faces to correct VF and FF relations
pu.oldBase = &m.face[0];
@ -866,20 +869,20 @@ namespace tri {
// resize the optional atttributes in m.face_attr to reflect the changes
ResizeAttribute(m.face_attr,m.fn,m);
FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi)
// now we update the various (not null) face pointers (inside VF and FF relations)
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{
if(HasPerVertexVFAdjacency(m) &&HasPerFaceVFAdjacency(m) )
for(i=0;i<3;++i)
if ((*fi).cVFp(i)!=0)
if(HasVFAdjacency(m))
for(int i=0;i<3;++i)
if ((*fi).IsVFInitialized(i) && (*fi).VFp(i)!=0 )
{
size_t oldIndex = (*fi).VFp(i) - fbase;
assert(fbase <= (*fi).VFp(i) && oldIndex < pu.remap.size());
(*fi).VFp(i) = fbase+pu.remap[oldIndex];
}
if(HasFFAdjacency(m))
for(i=0;i<3;++i)
for(int i=0;i<3;++i)
if ((*fi).cFFp(i)!=0)
{
size_t oldIndex = (*fi).FFp(i) - fbase;