From baad6db4b9ae0f46c878d29c24709bcf94d814a2 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Tue, 28 Feb 2006 12:13:49 +0000 Subject: [PATCH] fix bug end iterator++ --- vcg/complex/trimesh/allocate.h | 496 +++++++++++++++++---------------- 1 file changed, 253 insertions(+), 243 deletions(-) diff --git a/vcg/complex/trimesh/allocate.h b/vcg/complex/trimesh/allocate.h index 9a926a8b..af575677 100644 --- a/vcg/complex/trimesh/allocate.h +++ b/vcg/complex/trimesh/allocate.h @@ -21,9 +21,12 @@ * * ****************************************************************************/ /**************************************************************************** - History +History $Log: not supported by cvs2svn $ +Revision 1.25 2005/11/10 15:37:58 cignoni +Removed flags clearing (now it should be in the constructor of face and vertex) + Revision 1.24 2005/10/13 09:32:11 cignoni Re-inserted the cFFp and cVFp access. If only the const version of the member function exists, the compiler will call it when a non-const object invokes that function @@ -113,265 +116,272 @@ Initial commit #include namespace vcg { -namespace tri { -/** \addtogroup trimesh */ -/*@{*/ -/// 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. -template -class Allocator -{ - -public: -typedef AllocateMeshType MeshType; -typedef typename MeshType::VertexType VertexType; -typedef typename MeshType::VertexPointer VertexPointer; -typedef typename MeshType::VertexIterator VertexIterator; -typedef typename MeshType::FaceType FaceType; -typedef typename MeshType::FacePointer FacePointer; -typedef typename MeshType::FaceIterator FaceIterator; - -/** This class is used when allocating new vertexes and faces to update - the pointers that can be changed when resizing the involved vectors of vertex or faces. - It can also be used to prevent any update of the various mesh fields - (e.g. in case you are building all the connections by hand as in a importer); -*/ -template -class PointerUpdater -{ -public: - void Clear(){newBase=oldBase=newEnd=oldEnd=0;preventUpdateFlag=false;}; - void Update(SimplexPointerType &vp) - { - vp=newBase+(vp-oldBase); - } - bool NeedUpdate() {if(newBase!=oldBase && !preventUpdateFlag) return true; else return false;} - - SimplexPointerType oldBase; - SimplexPointerType newBase; - SimplexPointerType newEnd; - SimplexPointerType oldEnd; - bool preventUpdateFlag; /// when true no update is considered necessary. -}; - - -/** Function to add n vertices to the mesh. The second parameter hold a vector of - pointers to pointer to elements of the mesh that should be updated after a - possible vector realloc. - @param n Il numero di vertici che si vuole aggiungere alla mesh. - @param local_var Vettore di variabili locali che rappresentano puntatori a vertici. - restituisce l'iteratore al primo elemento aggiunto. -*/ -static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater &pu) -{ - VertexIterator last=m.vert.end(); - pu.Clear(); - if(m.vert.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element - else pu.oldBase=&*m.vert.begin(); - - for(int i=0; i + class Allocator { - FaceIterator fi; - for (fi=m.face.begin(); fi!=m.face.end(); ++fi) - if(!(*fi).IsD()) - { - pu.Update((*fi).V(0)); - pu.Update((*fi).V(1)); - pu.Update((*fi).V(2)); - } - // e poiche' lo spazio e' cambiato si ricalcola anche last da zero - unsigned int siz=(unsigned int) m.vert.size()-n; + public: + typedef AllocateMeshType MeshType; + typedef typename MeshType::VertexType VertexType; + typedef typename MeshType::VertexPointer VertexPointer; + typedef typename MeshType::VertexIterator VertexIterator; + typedef typename MeshType::FaceType FaceType; + typedef typename MeshType::FacePointer FacePointer; + typedef typename MeshType::FaceIterator FaceIterator; - last = m.vert.begin(); - advance(last,siz); -} - - return last;// deve restituire l'iteratore alla prima faccia aggiunta; -} + /** This class is used when allocating new vertexes and faces to update + the pointers that can be changed when resizing the involved vectors of vertex or faces. + It can also be used to prevent any update of the various mesh fields + (e.g. in case you are building all the connections by hand as in a importer); + */ + template + class PointerUpdater + { + public: + void Clear(){newBase=oldBase=newEnd=oldEnd=0;preventUpdateFlag=false;}; + void Update(SimplexPointerType &vp) + { + vp=newBase+(vp-oldBase); + } + bool NeedUpdate() {if(newBase!=oldBase && !preventUpdateFlag) return true; else return false;} -static VertexIterator AddVertices(MeshType &m, int n) -{ - PointerUpdater pu; - return AddVertices(m, n,pu); -} + SimplexPointerType oldBase; + SimplexPointerType newBase; + SimplexPointerType newEnd; + SimplexPointerType oldEnd; + bool preventUpdateFlag; /// when true no update is considered necessary. + }; -/** Function to add n faces to the mesh. - @param n Il numero di facce che si vuole aggiungere alla mesh -*/ -static FaceIterator AddFaces(MeshType &m, int n,std::vector &local_var) -{ - PointerUpdater pu; - return AddFaces(m,n,pu,local_var); -} -/** Function to add n faces to the mesh. - NOTA: Aggiorna fn; -*/ -static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater &pu,std::vector &local_var) -{ - FaceIterator last = m.face.end(); - pu.Clear(); - if(m.face.empty()) { - pu.oldBase=0; // if the vector is empty we cannot find the last valid element - } else { - pu.oldBase=&*m.face.begin(); - last=m.face.end(); - } - for(int i=0; i &pu) + { + VertexIterator last; + pu.Clear(); + if(m.vert.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element + else pu.oldBase=&*m.vert.begin(); - m.fn+=n; - - pu.newBase = &*m.face.begin(); + for(int i=0; i::iterator it; - for (it=local_var.begin();it::iterator jit; - for(jit=local_var.begin(); jit!=local_var.end(); ++jit) - if((**jit) !=0 ) - { - //FaceType **f =(**jit); - pu.Update(**jit); - } + pu.newBase = &*m.vert.begin(); + if(pu.NeedUpdate()) + { + FaceIterator fi; + for (fi=m.face.begin(); fi!=m.face.end(); ++fi) + if(!(*fi).IsD()) + { + pu.Update((*fi).V(0)); + pu.Update((*fi).V(1)); + pu.Update((*fi).V(2)); + } - FaceIterator fi; - for (fi=m.face.begin(); fi!=m.face.end(); ++fi) - if(!(*fi).IsD()) - { - if(FaceType::HasFFAdjacency()) - { - pu.Update((*fi).FFp(0)); - pu.Update((*fi).FFp(1)); - pu.Update((*fi).FFp(2)); - } - if(FaceType::HasVFAdjacency()) - { - if ((*fi).VFp(0)!=0) - pu.Update((*fi).VFp(0)); - if ((*fi).VFp(1)!=0) - pu.Update((*fi).VFp(1)); - if ((*fi).VFp(2)!=0) - pu.Update((*fi).VFp(2)); - } - } - VertexIterator vi; - for (vi=m.vert.begin(); vi!=m.vert.end(); ++vi) - if(!(*vi).IsD()) - { - if(VertexType::HasVFAdjacency()) - if ((*vi).VFp()!=0) - pu.Update((*vi).VFp()); - } - // e poiche' lo spazio e' cambiato si ricalcola anche last da zero - unsigned int siz=m.face.size()-n; + // e poiche' lo spazio e' cambiato si ricalcola anche last da zero - last = m.face.begin(); - advance(last,siz); -} - - return last; -} + } + unsigned int siz=(unsigned int)m.vert.size()-n; + //if(last!=(VertexIterator)0) + //{ + last = m.vert.begin(); + advance(last,siz); + //} + //else last=m.vert.begin(); -/** Function to add n faces to the mesh. - @param n Il numero di facce che si vuole aggiungere alla mesh -*/ -static FaceIterator AddFaces(MeshType &m, int n) -{ - PointerUpdater pu; - return AddFaces(m,n,pu); -} -/** Function to add n faces to the mesh. - NOTA: Aggiorna fn; -*/ -static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater &pu) -{ - FaceIterator last = m.face.end(); - pu.Clear(); - if(m.face.empty()) { - pu.oldBase=0; // if the vector is empty we cannot find the last valid element - } else { - pu.oldBase=&*m.face.begin(); - last=m.face.end(); - } - - m.face.resize(m.face.size()+n); - /* for(int i=0; i pu; + return AddVertices(m, n,pu); + } -}; // end class -/*@}*/ -} // End Namespace TriMesh + + /** Function to add n faces to the mesh. + @param n Il numero di facce che si vuole aggiungere alla mesh + */ + static FaceIterator AddFaces(MeshType &m, int n,std::vector &local_var) + { + PointerUpdater pu; + return AddFaces(m,n,pu,local_var); + } + /** Function to add n faces to the mesh. + NOTA: Aggiorna fn; + */ + static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater &pu,std::vector &local_var) + { + FaceIterator last = m.face.end(); + pu.Clear(); + if(m.face.empty()) { + pu.oldBase=0; // if the vector is empty we cannot find the last valid element + } else { + pu.oldBase=&*m.face.begin(); + last=m.face.end(); + } + for(int i=0; i::iterator it; + for (it=local_var.begin();it::iterator jit; + for(jit=local_var.begin(); jit!=local_var.end(); ++jit) + if((**jit) !=0 ) + { + //FaceType **f =(**jit); + pu.Update(**jit); + } + + FaceIterator fi; + for (fi=m.face.begin(); fi!=m.face.end(); ++fi) + if(!(*fi).IsD()) + { + if(FaceType::HasFFAdjacency()) + { + pu.Update((*fi).FFp(0)); + pu.Update((*fi).FFp(1)); + pu.Update((*fi).FFp(2)); + } + if(FaceType::HasVFAdjacency()) + { + if ((*fi).VFp(0)!=0) + pu.Update((*fi).VFp(0)); + if ((*fi).VFp(1)!=0) + pu.Update((*fi).VFp(1)); + if ((*fi).VFp(2)!=0) + pu.Update((*fi).VFp(2)); + } + } + VertexIterator vi; + for (vi=m.vert.begin(); vi!=m.vert.end(); ++vi) + if(!(*vi).IsD()) + { + if(VertexType::HasVFAdjacency()) + if ((*vi).VFp()!=0) + pu.Update((*vi).VFp()); + } + // e poiche' lo spazio e' cambiato si ricalcola anche last da zero + unsigned int siz=m.face.size()-n; + + last = m.face.begin(); + advance(last,siz); + } + + return last; + } + + + /** Function to add n faces to the mesh. + @param n Il numero di facce che si vuole aggiungere alla mesh + */ + static FaceIterator AddFaces(MeshType &m, int n) + { + PointerUpdater pu; + return AddFaces(m,n,pu); + } + /** Function to add n faces to the mesh. + NOTA: Aggiorna fn; + */ + static FaceIterator AddFaces(MeshType &m, int n, PointerUpdater &pu) + { + FaceIterator last = m.face.end(); + pu.Clear(); + if(m.face.empty()) { + pu.oldBase=0; // if the vector is empty we cannot find the last valid element + } else { + pu.oldBase=&*m.face.begin(); + last=m.face.end(); + } + + m.face.resize(m.face.size()+n); + /* for(int i=0; i