Added Callback in refine

This commit is contained in:
Paolo Cignoni 2005-12-13 11:01:01 +00:00
parent abbcfe10a9
commit 9b82d2e334
1 changed files with 23 additions and 8 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.7 2005/12/02 00:06:37 cignoni
commented out an old TRACE
Revision 1.6 2005/07/11 13:13:33 cignoni Revision 1.6 2005/07/11 13:13:33 cignoni
small gcc-related compiling issues (typenames,ending cr, initialization order) small gcc-related compiling issues (typenames,ending cr, initialization order)
@ -58,6 +61,8 @@ first working version
#include <vcg/simplex/face/pos.h> #include <vcg/simplex/face/pos.h>
#include<vcg/complex/trimesh/allocate.h> #include<vcg/complex/trimesh/allocate.h>
#include<vcg/complex/trimesh/update/topology.h> #include<vcg/complex/trimesh/update/topology.h>
#include<wrap/callback.h>
namespace vcg{ namespace vcg{
/* Tabella che codifica le modalita' di split a seconda di quali dei tre edge sono da splittare /* Tabella che codifica le modalita' di split a seconda di quali dei tre edge sono da splittare
@ -293,22 +298,25 @@ bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep, bool RefineSelectedP=false
/*********************************************************/ /*********************************************************/
template<class MESH_TYPE,class MIDPOINT> template<class MESH_TYPE,class MIDPOINT>
bool Refine(MESH_TYPE &m, MIDPOINT mid, typename MESH_TYPE::ScalarType thr=0,bool RefineSelected=false) bool Refine(MESH_TYPE &m, MIDPOINT mid, typename MESH_TYPE::ScalarType thr=0,bool RefineSelected=false, CallBackPos *cb = 0)
{ {
EdgeLen <typename MESH_TYPE::ScalarType> ep; EdgeLen <typename MESH_TYPE::ScalarType> ep;
ep.thr2=thr*thr; ep.thr2=thr*thr;
return RefineE(m,mid,ep,RefineSelected); return RefineE(m,mid,ep,RefineSelected,cb);
} }
template<class MESH_TYPE,class MIDPOINT, class EDGEPRED> template<class MESH_TYPE,class MIDPOINT, class EDGEPRED>
bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false) bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false, CallBackPos *cb = 0)
{ {
int j,NewVertNum=0,NewFaceNum=0; int j,NewVertNum=0,NewFaceNum=0;
typedef std::pair<typename MESH_TYPE::VertexPointer,typename MESH_TYPE::VertexPointer> vvpair; typedef std::pair<typename MESH_TYPE::VertexPointer,typename MESH_TYPE::VertexPointer> vvpair;
std::map<vvpair,typename MESH_TYPE::VertexPointer> Edge2Vert; std::map<vvpair,typename MESH_TYPE::VertexPointer> Edge2Vert;
// Primo ciclo si conta quanti sono i vertici e facce da aggiungere // Primo ciclo si conta quanti sono i vertici e facce da aggiungere
typename MESH_TYPE::FaceIterator fi; typename MESH_TYPE::FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) int step=0,PercStep=m.fn/33;
for(fi=m.face.begin(),j=0;fi!=m.face.end();++fi) if(!(*fi).IsD())
{
if(cb && (++step%PercStep)==0)(*cb)(step/PercStep,"Refining...");
for(j=0;j<3;j++){ for(j=0;j<3;j++){
if(ep((*fi).V(j)->P(),(*fi).V1(j)->P()) && if(ep((*fi).V(j)->P(),(*fi).V1(j)->P()) &&
(!RefineSelected || ((*fi).IsS() && (*fi).FFp(j)->IsS())) ){ (!RefineSelected || ((*fi).IsS() && (*fi).FFp(j)->IsS())) ){
@ -318,13 +326,17 @@ bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false)
++NewVertNum; ++NewVertNum;
} }
} }
} // end face loop
if(NewVertNum==0) return false; if(NewVertNum==0) return false;
typename MESH_TYPE::VertexIterator lastv = tri::Allocator<MESH_TYPE>::AddVertices(m,NewVertNum); typename MESH_TYPE::VertexIterator lastv = tri::Allocator<MESH_TYPE>::AddVertices(m,NewVertNum);
// typename MESH_TYPE::VertexIterator lastv=m.AddVertices(NewVertNum); // typename MESH_TYPE::VertexIterator lastv=m.AddVertices(NewVertNum);
// Secondo Ciclo si inizializza la mappa da edge a vertici // Secondo Ciclo si inizializza la mappa da edge a vertici
// e la posizione dei nuovi vertici // e la posizione dei nuovi vertici
//j=0;
for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
{
if(cb && (++step%PercStep)==0)(*cb)(step/PercStep,"Refining...");
for(j=0;j<3;j++) for(j=0;j<3;j++)
if(ep((*fi).V(j)->P(),(*fi).V1(j)->P()) && if(ep((*fi).V(j)->P(),(*fi).V1(j)->P()) &&
(!RefineSelected || ((*fi).IsS() && (*fi).FFp(j)->IsS())) ) (!RefineSelected || ((*fi).IsS() && (*fi).FFp(j)->IsS())) )
@ -335,6 +347,7 @@ bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false)
Edge2Vert[ vvpair((*fi).V(j),(*fi).V1(j)) ] = &*lastv; Edge2Vert[ vvpair((*fi).V(j),(*fi).V1(j)) ] = &*lastv;
++lastv; ++lastv;
} }
}
assert(lastv==m.vert.end()); assert(lastv==m.vert.end());
typename MESH_TYPE::FaceIterator lastf = tri::Allocator<MESH_TYPE>::AddFaces(m,NewFaceNum); typename MESH_TYPE::FaceIterator lastf = tri::Allocator<MESH_TYPE>::AddFaces(m,NewFaceNum);
@ -367,7 +380,9 @@ bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false)
int fca=0,fcn =0; int fca=0,fcn =0;
for(fi=m.face.begin();fi!=oldendf;++fi) if(!(*fi).IsD()) for(fi=m.face.begin();fi!=oldendf;++fi) if(!(*fi).IsD())
{fcn++; {
if(cb && (++step%PercStep)==0)(*cb)(step/PercStep,"Refining...");
fcn++;
vv[0]=(*fi).V(0); vv[0]=(*fi).V(0);
vv[1]=(*fi).V(1); vv[1]=(*fi).V(1);
vv[2]=(*fi).V(2); vv[2]=(*fi).V(2);