diff --git a/vcg/complex/trimesh/allocate.h b/vcg/complex/trimesh/allocate.h index 525d9df1..77fd1619 100644 --- a/vcg/complex/trimesh/allocate.h +++ b/vcg/complex/trimesh/allocate.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.39 2007/12/11 20:18:55 cignoni +forgotten required std:: + Revision 1.38 2007/12/11 11:35:50 cignoni Added the CompactVertexVector garbage collecting function. @@ -160,10 +163,17 @@ namespace vcg { namespace tri { /** \addtogroup trimesh */ + + // Placeholder. + // this one is called by the Compact and overridden by more specialized functions for OCF classes. + // that manage also the additional types template <class vector_type> - void Reorder( std::vector<size_t> &newVertIndex, vector_type &vert) + void ReorderFace( std::vector<size_t> &newVertIndex, vector_type &vert) {} - + template <class vector_type> + void ReorderVert( std::vector<size_t> &newVertIndex, vector_type &vert) + {} + /*@{*/ /// 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. @@ -376,7 +386,7 @@ namespace vcg { static void CompactVertexVector( MeshType &m ) { // newVertIndex [ <old_vert_position> ] gives you the new position of the vertex in the vector; - std::vector<size_t> newVertIndex(m.vert.size()); + std::vector<size_t> newVertIndex(m.vert.size(),std::numeric_limits<size_t>::max() ); size_t pos=0; size_t i=0; @@ -392,7 +402,11 @@ namespace vcg { } } assert(pos==m.vn); - Reorder<typename MeshType::VertContainer>(newVertIndex,m.vert); + + // call a templated reordering function that manage any additional data internally stored by the vector + // for the default std::vector no work is needed (some work is typically needed for the OCF stuff) + ReorderVert<typename MeshType::VertContainer>(newVertIndex,m.vert); + m.vert.resize(m.vn); FaceIterator fi; VertexPointer vbase=&m.vert[0]; @@ -406,6 +420,77 @@ namespace vcg { } } + + /* + 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 CompactFaceVector( MeshType &m ) + { + // newFaceIndex [ <old_face_position> ] gives you the new position of the face in the vector; + std::vector<size_t> newFaceIndex(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) + { + if(!m.face[i].IsD()) + { + if(pos!=i) + m.face[pos]=m.face[i]; + newFaceIndex[i]=pos; + ++pos; + } + } + assert(pos==m.fn); + + // call a templated reordering function that manage any additional data internally stored by the vector + // for the default std::vector no work is needed (some work is typically needed for the OCF stuff) + ReorderFace<typename MeshType::FaceType>(newFaceIndex,m.face); + + // 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) + if(!(*vi).IsD()) + { + if(HasVFAdjacency(m)) + if ((*vi).cVFp()!=0) + { + size_t oldIndex = (*vi).cVFp() - fbase; + assert(oldIndex >=0 && oldIndex < newFaceIndex.size()); + (*vi).VFp() = fbase+newFaceIndex[oldIndex]; + } + } + + // Loop on the faces to correct VF and FF relations + m.face.resize(m.fn); + FaceIterator fi; + for(fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) + { + if(HasVFAdjacency(m)) + for(i=0;i<3;++i) + if ((*fi).cVFp(i)!=0) + { + size_t oldIndex = (*fi).VFp(i) - fbase; + assert(oldIndex >=0 && oldIndex < newFaceIndex.size()); + (*fi).VFp(i) = fbase+newFaceIndex[oldIndex]; + } + if(HasFFAdjacency(m)) + for(i=0;i<3;++i) + if ((*fi).cFFp(i)!=0) + { + size_t oldIndex = (*fi).FFp(i) - fbase; + assert(oldIndex >=0 && oldIndex < newFaceIndex.size()); + (*fi).FFp(i) = fbase+newFaceIndex[oldIndex]; + } + } + } + }; // end class diff --git a/vcg/simplex/faceplus/component_ocf.h b/vcg/simplex/faceplus/component_ocf.h index d9f61e18..13917e0e 100644 --- a/vcg/simplex/faceplus/component_ocf.h +++ b/vcg/simplex/faceplus/component_ocf.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.24 2008/02/28 15:41:17 cignoni +Added FFpi methods and better init of texture coords + Revision 1.23 2008/02/05 10:11:34 cignoni A small typo (a T:: instead of TT::) @@ -226,6 +229,43 @@ public: for(fi=lbegin;fi!=lend;++fi) (*fi)._ovp=this; } + + + +// this function is called by the specialized Reorder function, that is called whenever someone call the allocator::CompactVertVector +void ReorderFace(std::vector<size_t> &newFaceIndex ) +{ + size_t pos=0; + size_t i=0; + if (ColorEnabled) assert( CV.size() == newFaceIndex.size() ); + if (MarkEnabled) assert( MV.size() == newFaceIndex.size() ); + if (NormalEnabled) assert( NV.size() == newFaceIndex.size() ); + if (VFAdjacencyEnabled)assert( AV.size() == newFaceIndex.size() ); + if (FFAdjacencyEnabled)assert( AF.size() == newFaceIndex.size() ); + if (WedgeTexEnabled) assert(WTV.size() == newFaceIndex.size() ); + + for(i=0;i<newFaceIndex.size();++i) + { + if(newFaceIndex[i] != std::numeric_limits<size_t>::max() ) + { + assert(newFaceIndex[i] <= i); + if (ColorEnabled) CV[newFaceIndex[i]] = CV[i]; + if (MarkEnabled) MV[newFaceIndex[i]] = MV[i]; + if (NormalEnabled) NV[newFaceIndex[i]] = NV[i]; + if (VFAdjacencyEnabled) AV[newFaceIndex[i]] = AV[i]; + if (FFAdjacencyEnabled) AF[newFaceIndex[i]] = AF[i]; + if (WedgeTexEnabled) WTV[newFaceIndex[i]] = WTV[i]; + } + } + + if (ColorEnabled) CV.resize(BaseType::size()); + if (MarkEnabled) MV.resize(BaseType::size()); + if (NormalEnabled) NV.resize(BaseType::size()); + if (VFAdjacencyEnabled) AV.resize(BaseType::size()); + if (FFAdjacencyEnabled) AF.resize(BaseType::size()); + if (WedgeTexEnabled) WTV.resize(BaseType::size()); +} + //////////////////////////////////////// // Enabling Functions @@ -546,6 +586,13 @@ public: if(FaceType::HasFaceMarkOcf()) return m.face.IsMarkEnabled(); else return FaceType::HasFaceMark(); } + + template < class FaceType > + void ReorderFace( std::vector<size_t> &newFaceIndex, face::vector_ocf< FaceType > &faceVec) + { + faceVec.ReorderFace(newFaceIndex); + } + } }// end namespace vcg #endif diff --git a/vcg/simplex/vertexplus/component_ocf.h b/vcg/simplex/vertexplus/component_ocf.h index 29c019d4..7e598d90 100644 --- a/vcg/simplex/vertexplus/component_ocf.h +++ b/vcg/simplex/vertexplus/component_ocf.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.13 2008/02/05 20:42:43 cignoni +Other small typos + Revision 1.12 2008/02/04 21:26:49 ganovelli added ImportLocal which imports all local attributes into vertexplus and faceplus. A local attribute is everything (N(), C(), Q()....) except pointers to other simplices @@ -138,7 +141,7 @@ public: } // 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 ) +void ReorderVert(std::vector<size_t> &newVertIndex ) { size_t pos=0; size_t i=0; @@ -349,9 +352,9 @@ namespace tri } template < class VertexType > - void Reorder( std::vector<size_t> &newVertIndex, vert::vector_ocf< VertexType > &vertVec) + void ReorderVert( std::vector<size_t> &newVertIndex, vert::vector_ocf< VertexType > &vertVec) { - vertVec.Reorder(newVertIndex); + vertVec.ReorderVert(newVertIndex); } } }// end namespace vcg