Added a RequirePerVertexMark to the init function of the collapse framework.

This commit is contained in:
Paolo Cignoni 2015-03-24 17:57:40 +00:00
parent 7b31a05a99
commit f2d3ff160c
1 changed files with 51 additions and 50 deletions

View File

@ -8,7 +8,7 @@
* \ * * \ *
* All rights reserved. * * All rights reserved. *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
@ -38,24 +38,24 @@ namespace tri{
/// This Class is specialization of LocalModification for the edge collapse. /// This Class is specialization of LocalModification for the edge collapse.
/// It wraps the atomic operation EdgeCollapse to be used in a optimizatin routine. /// 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 /// 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; /// it is responsible of updating it after a collapse has been performed;
/// This is the base class of all the specialized collapse classes like for example Quadric Edge Collapse. /// This is the base class of all the specialized collapse classes like for example Quadric Edge Collapse.
/// Each derived class /// Each derived class
template<class TriMeshType, class VertexPair, class MYTYPE> template<class TriMeshType, class VertexPair, class MYTYPE>
class TriEdgeCollapse: public LocalOptimization<TriMeshType>::LocModType class TriEdgeCollapse: public LocalOptimization<TriMeshType>::LocModType
{ {
public: public:
/// static data to gather statistical information about the reasons of collapse failures /// static data to gather statistical information about the reasons of collapse failures
class FailStat { class FailStat {
public: public:
static int &Volume() {static int vol=0; return vol;} static int &Volume() {static int vol=0; return vol;}
static int &LinkConditionFace(){static int lkf=0; return lkf;} static int &LinkConditionFace(){static int lkf=0; return lkf;}
static int &LinkConditionEdge(){static int lke=0; return lke;} static int &LinkConditionEdge(){static int lke=0; return lke;}
static int &LinkConditionVert(){static int lkv=0; return lkv;} static int &LinkConditionVert(){static int lkv=0; return lkv;}
static int &OutOfDate() {static int ofd=0; return ofd;} static int &OutOfDate() {static int ofd=0; return ofd;}
static int &Border() {static int bor=0; return bor;} static int &Border() {static int bor=0; return bor;}
static void Init() static void Init()
{ {
Volume() =0; Volume() =0;
LinkConditionFace()=0; LinkConditionFace()=0;
@ -72,35 +72,35 @@ protected:
typedef typename FaceType::VertexType::CoordType CoordType; typedef typename FaceType::VertexType::CoordType CoordType;
typedef typename TriMeshType::VertexType::ScalarType ScalarType; typedef typename TriMeshType::VertexType::ScalarType ScalarType;
typedef typename LocalOptimization<TriMeshType>::HeapElem HeapElem; typedef typename LocalOptimization<TriMeshType>::HeapElem HeapElem;
typedef typename LocalOptimization<TriMeshType>::HeapType HeapType; typedef typename LocalOptimization<TriMeshType>::HeapType HeapType;
TriMeshType *mt; TriMeshType *mt;
///the pair to collapse ///the pair to collapse
VertexPair pos; VertexPair pos;
///mark for up_dating ///mark for up_dating
static int& GlobalMark(){ static int im=0; return im;} static int& GlobalMark(){ static int im=0; return im;}
///mark for up_dating ///mark for up_dating
int localMark; int localMark;
/// priority in the heap
ScalarType _priority;
public: /// priority in the heap
/// Default Constructor ScalarType _priority;
inline TriEdgeCollapse()
{} public:
///Constructor with postype /// Default Constructor
inline TriEdgeCollapse()
{}
///Constructor with postype
inline TriEdgeCollapse(const VertexPair &p, int mark, BaseParameterClass *pp) inline TriEdgeCollapse(const VertexPair &p, int mark, BaseParameterClass *pp)
{ {
localMark = mark; localMark = mark;
pos=p; pos=p;
_priority = ComputePriority(pp); _priority = ComputePriority(pp);
} }
~TriEdgeCollapse() ~TriEdgeCollapse()
{} {}
private: private:
@ -108,26 +108,26 @@ private:
public: public:
inline ScalarType ComputePriority(BaseParameterClass *) inline ScalarType ComputePriority(BaseParameterClass *)
{ {
_priority = Distance(pos.V(0)->cP(),pos.V(1)->cP()); _priority = Distance(pos.V(0)->cP(),pos.V(1)->cP());
return _priority; return _priority;
} }
virtual const char *Info(TriMeshType &m) { virtual const char *Info(TriMeshType &m) {
mt = &m; mt = &m;
static char buf[60]; static char buf[60];
sprintf(buf,"%i -> %i %g\n", int(pos.V(0)-&m.vert[0]), int(pos.V(1)-&m.vert[0]),-_priority); sprintf(buf,"%i -> %i %g\n", int(pos.V(0)-&m.vert[0]), int(pos.V(1)-&m.vert[0]),-_priority);
return buf; return buf;
} }
inline void Execute(TriMeshType &m, BaseParameterClass *) inline void Execute(TriMeshType &m, BaseParameterClass *)
{ {
CoordType MidPoint=(pos.V(0)->P()+pos.V(1)->P())/2.0; CoordType MidPoint=(pos.V(0)->P()+pos.V(1)->P())/2.0;
EdgeCollapser<TriMeshType,VertexPair>::Do(m, pos, MidPoint); EdgeCollapser<TriMeshType,VertexPair>::Do(m, pos, MidPoint);
} }
static bool IsSymmetric(BaseParameterClass *) { return true;} static bool IsSymmetric(BaseParameterClass *) { return true;}
// This function is called after an action to re-add in the heap elements whose priority could have been changed. // This function is called after an action to re-add in the heap elements whose priority could have been changed.
// in the plain case we just put again in the heap all the edges around the vertex resulting from the previous collapse: v[1]. // in the plain case we just put again in the heap all the edges around the vertex resulting from the previous collapse: v[1].
// if the collapse is not symmetric you should add also backward edges (because v0->v1 collapse could be different from v1->v0) // if the collapse is not symmetric you should add also backward edges (because v0->v1 collapse could be different from v1->v0)
@ -190,28 +190,29 @@ public:
inline bool IsFeasible(BaseParameterClass *){ inline bool IsFeasible(BaseParameterClass *){
return EdgeCollapser<TriMeshType,VertexPair>::LinkConditions(pos); return EdgeCollapser<TriMeshType,VertexPair>::LinkConditions(pos);
} }
inline bool IsUpToDate() const inline bool IsUpToDate() const
{ {
VertexType *v0=pos.cV(0); VertexType *v0=pos.cV(0);
VertexType *v1=pos.cV(1); VertexType *v1=pos.cV(1);
if( v0->IsD() || v1->IsD() || if( v0->IsD() || v1->IsD() ||
localMark < v0->IMark() || localMark < v0->IMark() ||
localMark < v1->IMark() ) localMark < v1->IMark() )
{ {
++FailStat::OutOfDate(); ++FailStat::OutOfDate();
return false; return false;
} }
return true; return true;
} }
virtual ScalarType Priority() const { virtual ScalarType Priority() const {
return _priority; return _priority;
} }
static void Init(TriMeshType &m, HeapType &h_ret, BaseParameterClass *pp) static void Init(TriMeshType &m, HeapType &h_ret, BaseParameterClass *pp)
{ {
vcg::tri::RequirePerVertexMark(m);
vcg::tri::UpdateTopology<TriMeshType>::VertexFace(m); vcg::tri::UpdateTopology<TriMeshType>::VertexFace(m);
h_ret.clear(); h_ret.clear();
typename TriMeshType::FaceIterator fi; typename TriMeshType::FaceIterator fi;
@ -225,7 +226,7 @@ public:
//printf("Inserting in heap coll %3i ->%3i %f\n",p.V()-&m.vert[0],p.VFlip()-&m.vert[0],h_ret.back().locModPtr->Priority()); //printf("Inserting in heap coll %3i ->%3i %f\n",p.V()-&m.vert[0],p.VFlip()-&m.vert[0],h_ret.back().locModPtr->Priority());
} }
} }
} }
}; };
}//end namespace tri }//end namespace tri