00001 /**************************************************************************** 00002 * VCGLib o o * 00003 * Visual and Computer Graphics Library o o * 00004 * _ O _ * 00005 * Copyright(C) 2004 \/)\/ * 00006 * Visual Computing Lab /\/| * 00007 * ISTI - Italian National Research Council | * 00008 * \ * 00009 * All rights reserved. * 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This program is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 00020 * for more details. * 00021 * * 00022 ****************************************************************************/ 00023 /**************************************************************************** 00024 History 00025 00026 $Log: not supported by cvs2svn $ 00027 00028 00029 ****************************************************************************/ 00030 00031 #ifndef __VCGLIB_VERTEXALLOCATOR 00032 #define __VCGLIB_VERTEXALLOCATOR 00033 00034 namespace vcg { 00035 namespace vrt { 00038 00039 00040 template <class AllocateMeshType> 00041 class Allocator 00042 { 00043 00044 public: 00045 typedef AllocateMeshType MeshType; 00046 typedef typename MeshType::VertexType VertexType; 00047 typedef typename MeshType::VertexPointer VertexPointer; 00048 typedef typename MeshType::VertexIterator VertexIterator; 00049 00055 template<class SimplexPointerType> 00056 class PointerUpdater 00057 { 00058 public: 00059 void Clear(){newBase=oldBase=newEnd=oldEnd=0;preventUpdateFlag=false;}; 00060 void Update(SimplexPointerType &vp) 00061 { 00062 vp=newBase+(vp-oldBase); 00063 } 00064 bool NeedUpdate() {if(newBase!=oldBase && !preventUpdateFlag) return true; else return false;} 00065 00066 SimplexPointerType oldBase; 00067 SimplexPointerType newBase; 00068 SimplexPointerType newEnd; 00069 SimplexPointerType oldEnd; 00070 bool preventUpdateFlag; 00071 }; 00072 00073 00080 static VertexIterator AddVertices(MeshType &m,int n, PointerUpdater<VertexPointer> &pu) 00081 { 00082 VertexIterator last=m.vert.end(); 00083 pu.Clear(); 00084 if(m.vert.empty()) pu.oldBase=0; // if the vector is empty we cannot find the last valid element 00085 else pu.oldBase=&*m.vert.begin(); 00086 00087 for(int i=0; i<n; ++i) 00088 { 00089 m.vert.push_back(MeshType::VertexType()); 00090 m.vert.back().ClearFlags(); 00091 } 00092 00093 m.vn+=n; 00094 return last;// iterator to the first added vertex 00095 } 00096 00097 static VertexIterator AddVertices(MeshType &m, int n) 00098 { 00099 PointerUpdater<VertexPointer> pu; 00100 return AddVertices(m, n,pu); 00101 } 00102 }; // end class 00104 } // End Namespace TriMesh 00105 } // End Namespace vcg 00106 00107 #endif