diff --git a/vcg/complex/tetramesh/decimation/collapse.h b/vcg/complex/tetramesh/decimation/collapse.h deleted file mode 100644 index 141b16b9..00000000 --- a/vcg/complex/tetramesh/decimation/collapse.h +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** -* 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_DECIMATION_COLLAPSE -#define __VCG_DECIMATION_COLLAPSE - -#include -#include - - -namespace vcg{ -namespace tetra{ - -/** \addtogroup tetramesh */ -/*@{*/ -/// This Class is specialization of LocalModification for the edge collapse -/// It wraps the atomic operation EdgeCollapse to be used in a optimizatin routine. -/// Note that it has knowledge of the heap of the class LocalOptimization because -/// it is responsible of updating it after a collapse has been performed - -template -class Collapse: public LocalOptimization::LocModType -{ - - /// The tetrahedral mesh type - typedef typename TETRA_MESH_TYPE TetraMeshType; - /// 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; - /////the base type class - //typedef typename vcg::tetra::LocalModification LocalMod; - /// The HEdgePos type - typedef Pos PosType; - /// The HEdgePos Loop type - typedef PosLoop PosLType; - /// definition of the heap element - typedef typename LocalOptimization::HeapElem HeapElem; -private: - -///the new point that substitute the edge -Point3 _NewPoint; -///the pointer to edge collapser method -vcg::tetra::EdgeCollapse _EC; -///mark for up_dating -int _Imark; -///the pos of collapse -PosType pos; -///pointer to vertex that remain -VertexType *vrem; -/// priority in the heap -ScalarType _priority; - -public: -/// Default Constructor - Collapse() - {} - -///Constructor with postype - Collapse(PosType p,int mark) - { - _Imark = mark; - pos=p; - } - - ~Collapse() - {} - -private: - -///Return the aspect Ratio media of the tetrahedrons -///that share the adge to collapse -ScalarType _AspectRatioMedia(PosType p) -{ - PosLType posl=PosLType(p.T(),p.F(),p.E(),p.V()); - posl.Reset(); - int num=0; - ScalarType ratio_media=0.f; - while(!posl.LoopEnd()) - { - ratio_media+=posl.T()->AspectRatio(); - posl.NextT(); - num++; - } - ratio_media=ratio_media/num; - return (ratio_media); -} - - -///Modify pos and alfa to obtain the collapse that minimize the error -ScalarType _VolumePreservingError(PosType &pos,CoordType &new_point,int nsteps) -{ - VertexType *ve0=(pos.T()->V(Tetra::VofE(pos.E(),0))); - VertexType *ve1=(pos.T()->V(Tetra::VofE(pos.E(),1))); - vrem =ve0; - bool ext_v0=ve0->IsB(); - bool ext_v1=ve1->IsB(); - - ScalarType best_error=0.f; - if ((ext_v0)&&(!ext_v1)) - new_point=ve0->P(); - else - if ((!ext_v0)&&(ext_v1)) - new_point=ve1->P(); - else - if ((!ext_v0)&&(!ext_v1)) - new_point=(ve0->P()+ve1->P())/2.f; - else - if ((ext_v0)&&(ext_v1))//both are external vertex - { - ScalarType step=1.f/(nsteps-1); - ScalarType Vol_Original=_EC.VolumeOriginal(); - for (int i=0;iP()*alfatemp) +(ve1->P()*(1.f-alfatemp)); - //the error is the absolute value of difference of volumes - ScalarType error=fabs(Vol_Original-_EC.VolumeSimulateCollapse(pos,newPTemp)); - if(errorpos)); - } - - ScalarType ComputeError() - { - _EC.FindSets(pos); - return (_VolumePreservingError(pos,_NewPoint,5)); - } - - int Execute() - { - _EC.FindSets(pos); - return -_EC.DoCollapse(pos,_NewPoint); - } - - - void UpdateHeap(LocalOptimization::HeapType & h_ret) - { - assert(!vrem->IsD()); - VTIterator VTi(vrem->VTb(),vrem->VTi()); - while (!VTi.End()) - { - for (int j=0;j<6;j++) - { - vcg::tetra::Pos p=Pos(VTi.Vt(),Tetra::FofE(j,0),j,Tetra::VofE(j,0)); - h_ret.push_back(HeapElem(new Collapse(p,_Imark))); - } - VTi++; - } - } - - ModifierType IsOfType(){ return TetraEdgeCollapse;} - - bool IsFeasible(){ - _EC.FindSets(pos); - return(_EC.CheckPreconditions(pos,_NewPoint)); - } - - 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; - } - - virtual ScalarType Priority(){ - return _priority; - } - - virtual void Init(TetraMeshType&m,LocalOptimization::HeapType&h_ret){ - h_ret.clear(); - TetraMeshType::TetraIterator ti; - int j; - for(ti = m.tetra.begin(); ti != m.tetra.end();++ti) - for (int j=0;j<6;j++) - { - PosType p=PosType(&*ti,Tetra::FofE(j,0),j,Tetra::VofE(j,0)); - h_ret.push_back(HeapElem(new Collapse(p,m.IMark))); - } - - } - -}; -}//end namespace tetra -}//end namespace vcg -#endif \ No newline at end of file diff --git a/vcg/complex/tetramesh/decimation/decimation.h b/vcg/complex/tetramesh/decimation/decimation.h deleted file mode 100644 index 72e0b03b..00000000 --- a/vcg/complex/tetramesh/decimation/decimation.h +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** -* 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 diff --git a/vcg/complex/tetramesh/decimation/operationsdef.h b/vcg/complex/tetramesh/decimation/operationsdef.h deleted file mode 100644 index f15fb7d2..00000000 --- a/vcg/complex/tetramesh/decimation/operationsdef.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __VCG_TETRA_DECIMATION_OPERATION_DEFS -# define __VCG_TETRA_DECIMATION_OPERATION_DEFS - -namespace vcg{ - namespace tetra{ - - -enum ModifiersType{MTEdgeCollapse,MTEdgeSplit}; - - /** \addtogroup tetramesh */ -/*@{*/ -/// This Class is used to generalize a modifier - -template -class LocalModification -{ - - public: - /// The tetrahedral mesh type - typedef typename TETRA_MESH_TYPE TetraMeshType; - /// 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; - ///the pos type - typedef typename Pos PosType; - typedef typename std::pair HeapRetElem; - //the return type of heap updating - typedef typename std::vector HeapRetType; - /// Default Constructor - LocalModification() - { - }; - - ~LocalModification() - { - }; - - - virtual ScalarType ComputePriority()=0; - virtual ScalarType ComputeError()=0; - virtual void Execute()=0; - virtual bool PreserveTopology()=0; - virtual HeapRetType UpdateHeap()=0; - -};//end class local modification - - - } -} -#endif \ No newline at end of file