diff --git a/vcg/complex/tetramesh/allocate.h b/vcg/complex/tetramesh/allocate.h new file mode 100644 index 00000000..0ef8f406 --- /dev/null +++ b/vcg/complex/tetramesh/allocate.h @@ -0,0 +1,263 @@ +/**************************************************************************** +* 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 + +Revision 1.1 2004/19/04 13:05 pietroni +Initial commit + + +****************************************************************************/ +#ifndef __VCG_TETRA_ALLOCATE +#define __VCG_TETRA_ALLOCATE +#include +using namespace std; +namespace vcg { +namespace tetra { +/** \addtogroup tetramesh */ +/*@{*/ + + /** Class Allocate. + This is class for Allocate new vertices or tetrahedron on the mesh. + @param TM_TYPE (Template Parameter) Specifies the type of the tetrahedral mesh. + */ + +template < class TM_TYPE > +class Allocator +{ + +public: + + /// The tetramesh type + typedef TM_TYPE TetraMeshType; + + + /// The vertex type + typedef typename TM_TYPE::VertexType VertexType; + + /// The tetrahedron type + typedef typename TM_TYPE::TetraType TetraType; + + /// The type of vertex iterator + typedef typename TM_TYPE::VertexIterator VertexIterator; + + /// The type of tetra iterator + typedef typename TM_TYPE::TetraIterator TetraIterator; + + /// The type of constant vertex iterator + typedef typename TM_TYPE::const_VertexIterator const_VertexIterator; + + /// The type of constant face iterator + typedef typename TM_TYPE::const_TetraIterator const_TetraIterator; + + +public: + + /** 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. +*/ + +VertexIterator AddVertices(TetraMeshType &m,int n, vector &local_var) +{ + VertexIterator oldbegin, newbegin; + oldbegin = m.vert.begin(); + VertexIterator last=m.vert.end(); + if(m.vert.empty()) last=0; // if the vector is empty we cannot find the last valid element + else --last; + unsigned int siz=0; +#ifdef __STL_CONFIG_H +if(last!=0) distance(m.vert.begin(),last,siz); +#else +if(last!=0) siz=distance(m.vert.begin(),last); +#endif + for(unsigned int i=0; i +void SubSetT(STL_CONT & subSet, TetraMeshType & m) +{ + vector< InsertedVT > newVertices; + STL_CONT :: iterator pfi; + newVertices.clear(); + + for(pfi = subSet.begin(); pfi != subSet.end(); ++pfi) + m.tetra.push_back((*pfi)); + + TetraIterator fi; + for(fi = m.tetra.begin(); fi != m.tetra.end(); ++fi) + { + newVertices.push_back(InsertedVT( (*fi).V(0),&(*fi),0)); + newVertices.push_back(InsertedVT( (*fi).V(1),&(*fi),1)); + newVertices.push_back(InsertedVT( (*fi).V(2),&(*fi),2)); + newVertices.push_back(InsertedVT( (*fi).V(3),&(*fi),3)); + } + + sort(newVertices.begin(),newVertices.end()); + + vector< InsertedVT >::iterator curr,next; + int pos = 0; + curr = next = newVertices.begin(); + while( next != newVertices.end()) + { + if((*curr)!=(*next)) + pos++; + (*next).t->V( (*next).z) = (VertexType *)pos; + curr = next; + next++; + } + + vector::iterator newE = unique(newVertices.begin(),newVertices.end()); + + for(curr = newVertices.begin();curr!= newE;++curr) + m.vert.push_back(*((*curr).v)); + + for(fi = m.tetra.begin(); fi != m.tetra.end(); ++fi) + { + (*fi).V(0) = &(m.vert[(int)(*fi).V(0)]); + (*fi).V(1) = &(m.vert[(int)(*fi).V(1)]); + (*fi).V(2) = &(m.vert[(int)(*fi).V(2)]); + (*fi).V(3) = &(m.vert[(int)(*fi).V(3)]); + } + m.vn = m.vert.size(); + m.tn = m.tetra.size(); +} + +}; // end class + + +/*@}*/ +} // End namespace +} // End namespace + + +#endif