From b19307fbf0e3efc2132b032d3e8800b7602036e4 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Fri, 25 Jun 2004 11:30:25 +0000 Subject: [PATCH] decimation and optimizator of tetrahedral mesh --- vcg/complex/tetramesh/decimation/decimation.h | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 vcg/complex/tetramesh/decimation/decimation.h diff --git a/vcg/complex/tetramesh/decimation/decimation.h b/vcg/complex/tetramesh/decimation/decimation.h new file mode 100644 index 00000000..72e0b03b --- /dev/null +++ b/vcg/complex/tetramesh/decimation/decimation.h @@ -0,0 +1,220 @@ +/**************************************************************************** +* 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 +****************************************************************************/ + +#ifndef __VCG_TETRA_DECIMATION +#define __VCG_TETRA_DECIMATION +#include +#include +#include +#include +#include +#include + +namespace vcg{ +namespace tetra{ + + +template +class Decimation +{ +public: + + /// The tetrahedral mesh type + typedef typename TETRA_MESH_TYPE TetraMeshType; + // ///the decimator's type + //typedef typename Decimation DecimatorBase; + /// The tetrahedron type + typedef typename TetraMeshType::TetraType TetraType; + /// The vertex type + typedef typename TetraType::VertexType VertexType; + /// The coordinate type + typedef typename TetraType::VertexType::CoordType CoordType; + /// The scalar type + typedef typename TetraMeshType::VertexType::ScalarType ScalarType; + //local modification type + typedef typename vcg::tetra::LocalModification LocalModification; + /// The pos type + //typedef typename vcg::tetra::Pos PosType; + typedef typename vcg::tetra::LocalModification::PosType PosType; + + ///the element of the heap + struct HeapElem + { + ///the modifier's type + vcg::tetra::ModifiersType Mt; + ///the value of priority + ScalarType priority; + ///the pos where the modifier operate + PosType pos; + ///pointer to instance of local modifier + LocalModification*LM; + ///temporary mark for the opration + char Imark; + + HeapElem(vcg::tetra::ModifiersType Mtype,PosType p,char mark) + { + Mt=Mtype; + pos=p; + Imark=mark; + LM=NULL; + Instanciate(); + priority=LM->ComputePriority(); + delete(LM); + }; + + const bool operator <(const HeapElem & h) const + { + return (priority(pos); + } + + HeapElem & operator =( const HeapElem & h) + { + Mt=h.Mt; + priority=priority; + pos=h.pos; + LM=h.LM; + Imark=h.Imark; + return (*this); + } + + + bool IsUpToDate() + { + if (!pos.T()->IsD()) + { + VertexType *v0=pos.T()->V(Tetra::VofE(pos.E(),0)); + VertexType *v1=pos.T()->V(Tetra::VofE(pos.E(),1)); + + return (( (!v0->IsD()) && (!v1->IsD())) && + Imark>=v0->IMark() && + Imark>=v1->IMark()); + } + else + return false; + } + + }; + + /// The heap type + typedef typename vector HeapType; + + ///the pointer to tetramesh + TetraMeshType &tm; + ///the heap of operations + HeapType h; + + /// Default Constructor + Decimation(TETRA_MESH_TYPE &_tm):tm(_tm) + { + }; + + ~Decimation() + { + }; + + + void AddOperation(vcg::tetra::ModifiersType Mt,Pos pos) + { + h.push_back(HeapElem(Mt,pos,tm.GetMark())); + push_heap( h.begin(), h.end()); + } + + void DecimationStep(int nstep) + { + for (int i=0;iComputeError(); + LocalModification* LastMod= h.back().LM; + h.pop_back(); + if (LastMod->PreserveTopology()) + { + LastMod->Execute(); + LocalModification::HeapRetType h_ret=LastMod->UpdateHeap(); + LocalModification::HeapRetType::iterator hi; + for (hi=h_ret.begin();hi::iterator hi; + for(hi=h.begin();hi!=h.end();++hi) + if(!(*hi)->LM->IsUpToDate()) + { + *hi=h.back(); + h.pop_back(); + if(hi==h.end()) break; + } + //printf("\nReduced heap from %i to %i",sz,h.size()); + make_heap(h.begin(),h.end()); + } + + ///return true if the decimation have some operation to perform + bool HaveOperations() + { + return (h.size()>0); + } + +};//end class decimation + +}//end namespace +}//end namespace +#endif \ No newline at end of file