diff --git a/vcg/complex/edgemesh/allocate.h b/vcg/complex/edgemesh/allocate.h index 66269b02..a822da9f 100644 --- a/vcg/complex/edgemesh/allocate.h +++ b/vcg/complex/edgemesh/allocate.h @@ -21,9 +21,12 @@ * * ****************************************************************************/ /**************************************************************************** - History +History $Log: not supported by cvs2svn $ +Revision 1.6 2005/05/30 09:43:41 spinelli +vertexIterator sostituito con VertexIterator + Revision 1.5 2005/05/17 21:14:56 ganovelli some typecast (crs4) @@ -44,166 +47,170 @@ name of adhacency function updated #define __VCGLIB_EDGEALLOCATOR namespace vcg { -namespace edge { -/** \addtogroup edgemesh */ -/*@{*/ -/// 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 edgemesh. -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::EdgeType EdgeType; -typedef typename MeshType::EdgePointer EdgePointer; -typedef typename MeshType::EdgeIterator EdgeIterator; - -/** 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 safely add n vertices to a mesh. - - @param m The mesh to be expanded - @param n the number of vertexes to be added - @param pu A PointerUpdater that stores the relocation that can be happened. -*/ -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 { - EdgeIterator ei; - for (ei=m.edges.begin(); ei!=m.edges.end(); ++ei) - if(!(*ei).IsD()) - { - pu.Update((*ei).V(0)); - pu.Update((*ei).V(1)); - } - - // e poiche' lo spazio e' cambiato si ricalcola anche last da zero - unsigned int siz=m.vert.size()-n; - if(last!=(VertexIterator)0) - { + + public: + typedef AllocateMeshType MeshType; + typedef typename MeshType::VertexType VertexType; + typedef typename MeshType::VertexPointer VertexPointer; + typedef typename MeshType::VertexIterator VertexIterator; + typedef typename MeshType::EdgeType EdgeType; + typedef typename MeshType::EdgePointer EdgePointer; + typedef typename MeshType::EdgeIterator EdgeIterator; + + /** 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 safely add n vertices to a mesh. + + @param m The mesh to be expanded + @param n the number of vertexes to be added + @param pu A PointerUpdater that stores the relocation that can be happened. + */ + 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 pu; - return AddVertices(m, n,pu); -} + static VertexIterator AddVertices(MeshType &m, int n) + { + PointerUpdater pu; + return AddVertices(m, n,pu); + } -/** Function to add n faces to the mesh. - @param n Il numero di facce che si vuole aggiungere alla mesh -*/ -static EdgeIterator AddEdges(MeshType &m, int n) -{ - PointerUpdater pu; - return AddEdges(m,n,pu); -} -/** Function to add n faces to the mesh. - NOTA: Aggiorna fn; -*/ -static EdgeIterator AddEdges(MeshType &m, int n, PointerUpdater &pu) -{ - EdgeIterator last=(EdgeIterator)0; - pu.Clear(); - if(m.edges.empty()) { - pu.oldBase=0; // if the vector is empty we cannot find the last valid element - last=0; - } else { - pu.oldBase=&*m.edges.begin(); - last=m.edges.end(); - } - for(int i=0; i pu; + return AddEdges(m,n,pu); + } + /** Function to add n faces to the mesh. + NOTA: Aggiorna fn; + */ + static EdgeIterator AddEdges(MeshType &m, int n, PointerUpdater &pu) + { + EdgeIterator last=m.edges.end(); + pu.Clear(); + if(m.edges.empty()) { + pu.oldBase=0; // if the vector is empty we cannot find the last valid element + //last=0; + } else { + pu.oldBase=&*m.edges.begin(); + last=m.edges.end(); + } - m.en+=n; - - pu.newBase = &*m.edges.begin(); + m.edges.resize(m.edges.size()+n); + /*for(int i=0; i