2004-07-15 11:52:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
2004-09-08 16:33:31 +02:00
|
|
|
$Log: not supported by cvs2svn $
|
2005-01-19 11:35:28 +01:00
|
|
|
Revision 1.15 2004/12/10 01:03:53 cignoni
|
|
|
|
better comments and removed logging
|
|
|
|
|
2004-12-10 02:03:53 +01:00
|
|
|
Revision 1.14 2004/11/23 10:34:23 cignoni
|
|
|
|
passed parameters by reference in many funcs and gcc cleaning
|
|
|
|
|
2004-11-23 11:34:45 +01:00
|
|
|
Revision 1.13 2004/10/25 16:28:32 ganovelli
|
|
|
|
pos to edge
|
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
Revision 1.12 2004/09/15 11:16:02 ganovelli
|
|
|
|
changed P() to cP()
|
|
|
|
|
2004-09-15 13:20:15 +02:00
|
|
|
Revision 1.11 2004/09/09 13:23:01 ponchio
|
|
|
|
Header guards typo
|
|
|
|
|
2004-09-09 15:23:01 +02:00
|
|
|
Revision 1.10 2004/09/09 13:01:12 ponchio
|
|
|
|
Linux compatible path in #include
|
|
|
|
|
2004-09-09 15:02:12 +02:00
|
|
|
Revision 1.9 2004/09/08 15:13:29 ganovelli
|
|
|
|
changes for gc
|
|
|
|
|
2004-09-08 17:13:29 +02:00
|
|
|
Revision 1.8 2004/09/08 14:33:31 ganovelli
|
|
|
|
*** empty log message ***
|
|
|
|
|
2004-09-08 16:33:31 +02:00
|
|
|
|
2004-07-15 11:52:07 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __VCG_DECIMATION_TRICOLLAPSE
|
2004-09-09 15:23:01 +02:00
|
|
|
#define __VCG_DECIMATION_TRICOLLAPSE
|
2004-07-15 11:52:07 +02:00
|
|
|
|
2004-09-09 15:02:12 +02:00
|
|
|
#include<vcg/complex/trimesh/edge_collapse.h>
|
|
|
|
#include<vcg/simplex/face/pos.h>
|
|
|
|
#include<vcg/complex/local_optimization.h>
|
2004-07-15 11:52:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace vcg{
|
|
|
|
namespace tri{
|
|
|
|
|
|
|
|
/** \addtogroup trimesh */
|
|
|
|
/*@{*/
|
2004-12-10 02:03:53 +01:00
|
|
|
/// This Class is specialization of LocalModification for the edge collapse.
|
2004-07-15 11:52:07 +02:00
|
|
|
/// 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
|
2004-12-10 02:03:53 +01:00
|
|
|
/// 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.
|
|
|
|
/// Each derived class
|
2004-07-15 11:52:07 +02:00
|
|
|
|
2004-09-07 17:40:04 +02:00
|
|
|
template<class TriMeshType,class MYTYPE>
|
2004-07-27 11:46:15 +02:00
|
|
|
class TriEdgeCollapse: public LocalOptimization<TriMeshType>::LocModType , public EdgeCollapse<TriMeshType>
|
2004-07-15 11:52:07 +02:00
|
|
|
{
|
2004-07-27 11:46:15 +02:00
|
|
|
public:
|
|
|
|
/// static data to gather statistical information about the reasons of collapse failures
|
2004-11-23 11:34:45 +01:00
|
|
|
class FailStat {
|
|
|
|
public:
|
2004-07-27 11:46:15 +02:00
|
|
|
static int &Volume() {static int vol=0; return vol;}
|
|
|
|
static int &LinkConditionFace(){static int lkf=0; return lkf;}
|
|
|
|
static int &LinkConditionEdge(){static int lke=0; return lke;}
|
|
|
|
static int &LinkConditionVert(){static int lkv=0; return lkv;}
|
|
|
|
static int &OutOfDate() {static int ofd=0; return ofd;}
|
|
|
|
static int &Border() {static int bor=0; return bor;}
|
2004-09-08 16:33:31 +02:00
|
|
|
static void Init()
|
2004-07-27 11:46:15 +02:00
|
|
|
{
|
|
|
|
Volume() =0;
|
|
|
|
LinkConditionFace()=0;
|
|
|
|
LinkConditionEdge()=0;
|
|
|
|
LinkConditionVert()=0;
|
|
|
|
OutOfDate() =0;
|
|
|
|
Border() =0;
|
|
|
|
}
|
|
|
|
};
|
2004-09-15 13:20:15 +02:00
|
|
|
protected:
|
2004-07-15 11:52:07 +02:00
|
|
|
typedef typename TriMeshType::FaceType FaceType;
|
2004-10-25 18:28:32 +02:00
|
|
|
typedef typename TriMeshType::FaceType::VertexType VertexType;
|
|
|
|
typedef typename FaceType::EdgeType EdgeType;
|
2004-07-27 11:46:15 +02:00
|
|
|
typedef typename FaceType::VertexType::CoordType CoordType;
|
2004-07-15 11:52:07 +02:00
|
|
|
typedef typename TriMeshType::VertexType::ScalarType ScalarType;
|
2004-07-27 11:46:15 +02:00
|
|
|
typedef typename LocalOptimization<TriMeshType>::HeapElem HeapElem;
|
2004-09-15 13:20:15 +02:00
|
|
|
typedef typename LocalOptimization<TriMeshType>::HeapType HeapType;
|
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
TriMeshType *mt;
|
|
|
|
///the pair to collapse
|
|
|
|
EdgeType pos;
|
2004-07-15 11:52:07 +02:00
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
///mark for up_dating
|
|
|
|
static int& GlobalMark(){ static int im=0; return im;}
|
2004-08-10 18:33:58 +02:00
|
|
|
|
|
|
|
///mark for up_dating
|
2004-10-25 18:28:32 +02:00
|
|
|
int localMark;
|
2004-08-10 18:33:58 +02:00
|
|
|
|
2004-07-15 11:52:07 +02:00
|
|
|
/// priority in the heap
|
|
|
|
ScalarType _priority;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Default Constructor
|
2004-10-25 18:28:32 +02:00
|
|
|
inline TriEdgeCollapse()
|
2004-07-15 11:52:07 +02:00
|
|
|
{}
|
|
|
|
///Constructor with postype
|
2004-11-23 11:34:45 +01:00
|
|
|
inline TriEdgeCollapse(const EdgeType &p, int mark)
|
2004-07-15 11:52:07 +02:00
|
|
|
{
|
2004-10-25 18:28:32 +02:00
|
|
|
localMark = mark;
|
2004-07-15 11:52:07 +02:00
|
|
|
pos=p;
|
2004-07-27 11:46:15 +02:00
|
|
|
_priority = ComputePriority();
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~TriEdgeCollapse()
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
inline ScalarType ComputePriority()
|
2004-07-15 11:52:07 +02:00
|
|
|
{
|
2004-10-25 18:28:32 +02:00
|
|
|
_priority = Distance(pos.V(0)->cP(),pos.V(1)->cP());
|
2004-07-27 11:46:15 +02:00
|
|
|
return _priority;
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
|
|
|
|
2004-07-27 11:46:15 +02:00
|
|
|
virtual const char *Info(TriMeshType &m) {
|
2004-10-25 18:28:32 +02:00
|
|
|
mt = &m;
|
2004-07-27 11:46:15 +02:00
|
|
|
static char buf[60];
|
2004-10-25 18:28:32 +02:00
|
|
|
sprintf(buf,"%i -> %i %g\n", pos.V(0)-&m.vert[0], pos.V(1)-&m.vert[0],-_priority);
|
|
|
|
return buf;
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
2004-07-27 11:46:15 +02:00
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
inline void Execute(TriMeshType &m)
|
2004-07-27 11:46:15 +02:00
|
|
|
{
|
2004-10-25 18:28:32 +02:00
|
|
|
CoordType MidPoint=(pos.V(0)->P()+pos.V(1)->P())/2.0;
|
2004-12-10 02:03:53 +01:00
|
|
|
int FaceDel=DoCollapse(pos, MidPoint);
|
2004-07-27 11:46:15 +02:00
|
|
|
m.fn-=FaceDel;
|
|
|
|
--m.vn;
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
|
|
|
|
2004-12-10 02:03:53 +01:00
|
|
|
static bool IsSymmetric() { return true;}
|
2004-07-15 11:52:07 +02:00
|
|
|
|
2004-12-10 02:03:53 +01:00
|
|
|
inline void UpdateHeap(HeapType & h_ret)
|
2004-07-15 11:52:07 +02:00
|
|
|
{
|
2004-12-10 02:03:53 +01:00
|
|
|
GlobalMark()++; int nn=0;
|
2004-10-25 18:28:32 +02:00
|
|
|
VertexType *v[2];
|
|
|
|
v[0]= pos.V(0);v[1]=pos.V(1);
|
|
|
|
v[1]->IMark() = GlobalMark();
|
|
|
|
|
2004-11-23 11:34:45 +01:00
|
|
|
// First loop around the remaining vertex to unmark visited flags
|
|
|
|
vcg::face::VFIterator<FaceType> vfi(v[1]->VFp(),v[1]->VFi());
|
2004-10-25 18:28:32 +02:00
|
|
|
while (!vfi.End()){
|
|
|
|
vfi.F()->V1(vfi.I())->ClearV();
|
|
|
|
vfi.F()->V2(vfi.I())->ClearV();
|
|
|
|
++vfi;
|
|
|
|
}
|
2004-11-23 11:34:45 +01:00
|
|
|
|
|
|
|
// Second Loop
|
2004-10-25 18:28:32 +02:00
|
|
|
vfi.F() = v[1]->VFp();
|
|
|
|
vfi.I() = v[1]->VFi();
|
2004-09-15 13:20:15 +02:00
|
|
|
while (!vfi.End())
|
2004-07-15 11:52:07 +02:00
|
|
|
{
|
2004-10-25 18:28:32 +02:00
|
|
|
assert(!vfi.F()->IsD());
|
2004-07-15 11:52:07 +02:00
|
|
|
for (int j=0;j<3;j++)
|
2004-10-25 18:28:32 +02:00
|
|
|
{
|
|
|
|
if( !(vfi.F()->V1(vfi.I())->IsV()) && (vfi.F()->V1(vfi.I())->IsRW()))
|
|
|
|
{
|
|
|
|
vfi.F()->V1(vfi.I())->SetV();
|
|
|
|
h_ret.push_back(HeapElem(new MYTYPE(EdgeType (vfi.F()->V(vfi.I()),vfi.F()->V1(vfi.I())),GlobalMark())));
|
|
|
|
std::push_heap(h_ret.begin(),h_ret.end());
|
2004-12-10 02:03:53 +01:00
|
|
|
if(this->IsSymmetric()){
|
|
|
|
h_ret.push_back(HeapElem(new MYTYPE(EdgeType (vfi.F()->V1(vfi.I()),vfi.F()->V(vfi.I())),GlobalMark())));
|
|
|
|
std::push_heap(h_ret.begin(),h_ret.end());
|
|
|
|
}
|
2004-10-25 18:28:32 +02:00
|
|
|
}
|
|
|
|
if( !(vfi.F()->V2(vfi.I())->IsV()) && (vfi.F()->V2(vfi.I())->IsRW()))
|
|
|
|
{
|
|
|
|
vfi.F()->V2(vfi.I())->SetV();
|
|
|
|
h_ret.push_back(HeapElem(new MYTYPE(EdgeType (vfi.F()->V(vfi.I()),vfi.F()->V2(vfi.I())),GlobalMark())));
|
2004-07-15 11:52:07 +02:00
|
|
|
std::push_heap(h_ret.begin(),h_ret.end());
|
2004-10-25 18:28:32 +02:00
|
|
|
//if(false){
|
|
|
|
// h_ret.push_back(HeapElem(new MYTYPE(EdgeType (vfi.F()->V1(vfi.I()),vfi.F()->V(vfi.I())),GlobalMark())));
|
|
|
|
// std::push_heap(h_ret.begin(),h_ret.end());
|
|
|
|
// }
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
2004-10-25 18:28:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
++vfi;nn++;
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
2004-10-25 18:28:32 +02:00
|
|
|
// printf("ADDED %d\n",nn);
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ModifierType IsOfType(){ return TriEdgeCollapseOp;}
|
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
inline bool IsFeasible(){
|
2004-07-27 11:46:15 +02:00
|
|
|
return LinkConditions(pos);
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
inline bool IsUpToDate(){
|
|
|
|
// if(pos.V(1)->IsD()) {
|
|
|
|
// ++FailStat::OutOfDate();
|
|
|
|
// return false;
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
// if(pos.V(1)->IsD()) {
|
|
|
|
// ++FailStat::OutOfDate();
|
|
|
|
// return false;
|
|
|
|
//}
|
2004-07-27 11:46:15 +02:00
|
|
|
|
2004-10-25 18:28:32 +02:00
|
|
|
VertexType *v0=pos.V(0);
|
|
|
|
VertexType *v1=pos.V(1);
|
2004-07-15 11:52:07 +02:00
|
|
|
|
2005-01-19 11:35:28 +01:00
|
|
|
//if(! (( (!v0->IsD()) && (!v1->IsD())) &&
|
|
|
|
// localMark>=v0->IMark() &&
|
|
|
|
// localMark>=v1->IMark()))
|
|
|
|
if( v0->IsD() || v1->IsD() ||
|
|
|
|
localMark < v0->IMark() ||
|
|
|
|
localMark < v1->IMark() )
|
2004-07-15 11:52:07 +02:00
|
|
|
{
|
2004-07-27 11:46:15 +02:00
|
|
|
++FailStat::OutOfDate();
|
2004-07-15 11:52:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-07-27 11:46:15 +02:00
|
|
|
virtual ScalarType Priority() const {
|
|
|
|
return _priority;
|
2004-07-18 12:10:56 +02:00
|
|
|
}
|
2004-07-15 11:52:07 +02:00
|
|
|
|
2004-09-15 13:20:15 +02:00
|
|
|
static void Init(TriMeshType&m,HeapType&h_ret){
|
2004-07-15 11:52:07 +02:00
|
|
|
h_ret.clear();
|
2004-09-08 17:13:29 +02:00
|
|
|
typename TriMeshType::FaceIterator fi;
|
2004-07-15 11:52:07 +02:00
|
|
|
for(fi = m.face.begin(); fi != m.face.end();++fi)
|
|
|
|
if(!(*fi).IsD()){
|
|
|
|
for (int j=0;j<3;j++)
|
|
|
|
{
|
2004-10-25 18:28:32 +02:00
|
|
|
EdgeType p=EdgeType(&*fi,j,(*fi).V(j));
|
2004-09-07 17:40:04 +02:00
|
|
|
h_ret.push_back(HeapElem(new MYTYPE(p,m.IMark())));
|
2004-07-27 11:46:15 +02:00
|
|
|
//printf("Inserting in heap coll %3i ->%3i %f\n",p.V()-&m.vert[0],p.VFlip()-&m.vert[0],h_ret.back().locModPtr->Priority());
|
2004-07-15 11:52:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}//end namespace tri
|
|
|
|
}//end namespace vcg
|
|
|
|
|
2004-09-08 17:13:29 +02:00
|
|
|
#endif
|