From 91205e63461aa56143497795b519a39a983d3838 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Thu, 29 Apr 2004 01:00:07 +0000 Subject: [PATCH] created --- vcg/complex/edgemesh/allocate.h | 198 ++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 vcg/complex/edgemesh/allocate.h diff --git a/vcg/complex/edgemesh/allocate.h b/vcg/complex/edgemesh/allocate.h new file mode 100644 index 00000000..bf16afb2 --- /dev/null +++ b/vcg/complex/edgemesh/allocate.h @@ -0,0 +1,198 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + + +****************************************************************************/ + +#ifndef __VCGLIB_EDGEALLOCATOR +#define __VCGLIB_EDGEALLOCATOR + +namespace vcg { +namespace edge { +/** \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::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 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 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=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