Cleaning unused stuff and better comments

This commit is contained in:
Paolo Cignoni 2017-02-21 17:47:29 +01:00
parent 82ddb476a4
commit 0478f436b4
1 changed files with 46 additions and 79 deletions
vcg/complex/algorithms

View File

@ -38,7 +38,7 @@ enum ModifierType{ TetraEdgeCollapseOp, TriEdgeSwapOp, TriVertexSplitOp,
QuadDiagCollapseOp, QuadEdgeCollapseOp}; QuadDiagCollapseOp, QuadEdgeCollapseOp};
/** \addtogroup tetramesh */ /** \addtogroup tetramesh */
/*@{*/ /*@{*/
/// This abstract class define which functions a local modification to be used in the LocalOptimization. /// This abstract class define which functions a local modification class must have to be used in the LocalOptimization framework.
template <class MeshType> template <class MeshType>
class LocalModification class LocalModification
{ {
@ -46,7 +46,6 @@ class LocalModification
typedef typename LocalOptimization<MeshType>::HeapType HeapType; typedef typename LocalOptimization<MeshType>::HeapType HeapType;
typedef typename MeshType::ScalarType ScalarType; typedef typename MeshType::ScalarType ScalarType;
inline LocalModification(){} inline LocalModification(){}
virtual ~LocalModification(){} virtual ~LocalModification(){}
@ -95,19 +94,12 @@ template<class MeshType>
class LocalOptimization class LocalOptimization
{ {
public: public:
LocalOptimization(MeshType &mm, BaseParameterClass *_pp): m(mm){ ClearTermination();e=0.0;HeapSimplexRatio=5; pp=_pp;} LocalOptimization(MeshType &mm, BaseParameterClass *_pp): m(mm){ ClearTermination();HeapSimplexRatio=5; pp=_pp;}
struct HeapElem; struct HeapElem;
// scalar type
typedef typename MeshType::ScalarType ScalarType; typedef typename MeshType::ScalarType ScalarType;
// type of the heap
typedef typename std::vector<HeapElem> HeapType; typedef typename std::vector<HeapElem> HeapType;
// modification type
typedef LocalModification <MeshType> LocModType; typedef LocalModification <MeshType> LocModType;
// modification Pointer type
typedef LocalModification <MeshType> * LocModPtrType;
/// termination conditions /// termination conditions
enum LOTermination { enum LOTermination {
@ -118,9 +110,9 @@ public:
LOTime = 0x10 // test how much time is passed since the start LOTime = 0x10 // test how much time is passed since the start
} ; } ;
int tf; int tf; // Termination Flag
int nPerfmormedOps, int nPerformedOps,
nTargetOps, nTargetOps,
nTargetSimplices, nTargetSimplices,
nTargetVertices; nTargetVertices;
@ -159,8 +151,6 @@ public:
/// the mesh to optimize /// the mesh to optimize
MeshType & m; MeshType & m;
///the heap of operations ///the heap of operations
HeapType h; HeapType h;
@ -175,15 +165,14 @@ public:
~HeapElem(){} ~HeapElem(){}
///pointer to instance of local modifier ///pointer to instance of local modifier
LocModPtrType locModPtr; LocModType *locModPtr;
float pri; float pri;
inline HeapElem( LocModPtrType _locModPtr) inline HeapElem( LocModType *_locModPtr)
{ {
locModPtr = _locModPtr; locModPtr = _locModPtr;
pri=float(locModPtr->Priority()); pri=float(locModPtr->Priority());
}; }
/// STL heap has the largest element as the first one. /// STL heap has the largest element as the first one.
/// usually we mean priority as an error so we should invert the comparison /// usually we mean priority as an error so we should invert the comparison
@ -206,35 +195,37 @@ public:
typename HeapType::iterator i; typename HeapType::iterator i;
for(i = h.begin(); i != h.end(); i++) for(i = h.begin(); i != h.end(); i++)
delete (*i).locModPtr; delete (*i).locModPtr;
}; }
double e;
/// main cycle of optimization /// main cycle of optimization
bool DoOptimization() bool DoOptimization()
{ {
assert ( ( ( tf & LOnSimplices )==0) || ( nTargetSimplices!= -1));
assert ( ( ( tf & LOnVertices )==0) || ( nTargetVertices != -1));
assert ( ( ( tf & LOnOps )==0) || ( nTargetOps != -1));
assert ( ( ( tf & LOMetric )==0) || ( targetMetric != -1));
assert ( ( ( tf & LOTime )==0) || ( timeBudget != -1));
start=clock(); start=clock();
nPerfmormedOps =0; nPerformedOps =0;
while( !GoalReached() && !h.empty()) while( !GoalReached() && !h.empty())
{ {
if(h.size()> m.SimplexNumber()*HeapSimplexRatio ) ClearHeap(); if(h.size()> m.SimplexNumber()*HeapSimplexRatio ) ClearHeap();
std::pop_heap(h.begin(),h.end()); std::pop_heap(h.begin(),h.end());
LocModPtrType locMod = h.back().locModPtr; LocModType *locMod = h.back().locModPtr;
currMetric=h.back().pri; currMetric=h.back().pri;
h.pop_back(); h.pop_back();
if( locMod->IsUpToDate() ) if( locMod->IsUpToDate() )
{ {
//printf("popped out: %s\n",locMod->Info(m)); //printf("popped out: %s\n",locMod->Info(m));
// check if it is feasible
if (locMod->IsFeasible(this->pp)) if (locMod->IsFeasible(this->pp))
{ {
nPerfmormedOps++; nPerformedOps++;
locMod->Execute(m,this->pp); locMod->Execute(m,this->pp);
locMod->UpdateHeap(h,this->pp); locMod->UpdateHeap(h,this->pp);
} }
} }
//else printf("popped out unfeasible\n");
delete locMod; delete locMod;
} }
return !(h.empty()); return !(h.empty());
@ -243,31 +234,30 @@ public:
// It removes from the heap all the operations that are no more 'uptodate' // It removes from the heap all the operations that are no more 'uptodate'
// (e.g. collapses that have some recently modified vertices) // (e.g. collapses that have some recently modified vertices)
// This function is called from time to time by the doOptimization (e.g. when the heap is larger than fn*3) // This function is called from time to time by the doOptimization (e.g. when the heap is larger than fn*3)
void ClearHeap() void ClearHeap()
{ {
typename HeapType::iterator hi; // int sz=h.size(); int t0=clock();
//int sz=h.size(); for(auto hi=h.begin();hi!=h.end();)
for(hi=h.begin();hi!=h.end();) {
{ if(!(*hi).locModPtr->IsUpToDate())
if(!(*hi).locModPtr->IsUpToDate()) {
{ delete (*hi).locModPtr;
delete (*hi).locModPtr; *hi=h.back();
*hi=h.back(); if(&*hi==&h.back())
if(&*hi==&h.back()) {
{ hi=h.end();
hi=h.end(); h.pop_back();
h.pop_back(); break;
break; }
} h.pop_back();
h.pop_back(); continue;
continue; }
} ++hi;
++hi; }
} // printf("\nReduced heap from %7i to %7i (fn %7i) in %7.2f \n",sz,h.size(),m.fn,float(clock()-t0)/CLOCKS_PER_SEC);
//qDebug("\nReduced heap from %7i to %7i (fn %7i) ",sz,h.size(),m.fn); make_heap(h.begin(),h.end());
make_heap(h.begin(),h.end()); }
}
///initialize for all vertex the temporary mark must call only at the start of decimation ///initialize for all vertex the temporary mark must call only at the start of decimation
///by default it takes the first element in the heap and calls Init (static funcion) of that type ///by default it takes the first element in the heap and calls Init (static funcion) of that type
///of local modification. ///of local modification.
@ -293,16 +283,10 @@ void ClearHeap()
/// say if the process is to end or not: the process ends when any of the termination conditions is verified /// say if the process is to end or not: the process ends when any of the termination conditions is verified
/// override this function to implemetn other tests /// override this function to implemetn other tests
bool GoalReached(){ bool GoalReached(){
assert ( ( ( tf & LOnSimplices )==0) || ( nTargetSimplices!= -1)); if ( IsTerminationFlag(LOnSimplices) && ( m.SimplexNumber()<= nTargetSimplices)) return true;
assert ( ( ( tf & LOnVertices )==0) || ( nTargetVertices != -1)); if ( IsTerminationFlag(LOnVertices) && ( m.VertexNumber() <= nTargetVertices)) return true;
assert ( ( ( tf & LOnOps )==0) || ( nTargetOps != -1)); if ( IsTerminationFlag(LOnOps) && (nPerformedOps == nTargetOps)) return true;
assert ( ( ( tf & LOMetric )==0) || ( targetMetric != -1)); if ( IsTerminationFlag(LOMetric) && ( currMetric > targetMetric)) return true;
assert ( ( ( tf & LOTime )==0) || ( timeBudget != -1));
if ( IsTerminationFlag(LOnSimplices) && ( m.SimplexNumber()<= nTargetSimplices)) return true;
if ( IsTerminationFlag(LOnVertices) && ( m.VertexNumber() <= nTargetVertices)) return true;
if ( IsTerminationFlag(LOnOps) && (nPerfmormedOps == nTargetOps)) return true;
if ( IsTerminationFlag(LOMetric) && ( currMetric > targetMetric)) return true;
if ( IsTerminationFlag(LOTime) ) if ( IsTerminationFlag(LOTime) )
{ {
clock_t cur = clock(); clock_t cur = clock();
@ -314,23 +298,6 @@ void ClearHeap()
return false; return false;
} }
///erase from the heap the operations that are out of date
void ClearHeapOld()
{
typename HeapType::iterator hi;
for(hi=h.begin();hi!=h.end();++hi)
if(!(*hi).locModPtr->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());
}
};//end class decimation };//end class decimation
}//end namespace }//end namespace