Changed to trisplit to make it c++ 01 compliant

This commit is contained in:
Paolo Cignoni 2014-03-04 17:18:03 +00:00
parent dc71da4424
commit 323362697a
2 changed files with 236 additions and 229 deletions

View File

@ -49,7 +49,7 @@ using namespace std;
class MyFace; class MyFace;
class MyVertex; class MyVertex;
struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType, struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
Use<MyFace> ::AsFaceType>{}; Use<MyFace> ::AsFaceType>{};
class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::BitFlags, vertex::Normal3f, vertex::Mark, vertex::Color4b >{}; class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::BitFlags, vertex::Normal3f, vertex::Mark, vertex::Color4b >{};
class MyFace : public Face < MyUsedTypes, face::VertexRef,face::FFAdj, face::Mark, face::BitFlags, face::Normal3f> {}; class MyFace : public Face < MyUsedTypes, face::VertexRef,face::FFAdj, face::Mark, face::BitFlags, face::Normal3f> {};
@ -59,8 +59,8 @@ class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace > >{};
//Delaunay //Delaunay
class MyDelaunayFlip: public vcg::tri::TriEdgeFlip< MyMesh, MyDelaunayFlip > { class MyDelaunayFlip: public vcg::tri::TriEdgeFlip< MyMesh, MyDelaunayFlip > {
public: public:
typedef vcg::tri::TriEdgeFlip< MyMesh, MyDelaunayFlip > TEF; typedef vcg::tri::TriEdgeFlip< MyMesh, MyDelaunayFlip > TEF;
inline MyDelaunayFlip( const TEF::PosType &p, int i,BaseParameterClass *pp) :TEF(p,i,pp){} inline MyDelaunayFlip( const TEF::PosType &p, int i,BaseParameterClass *pp) :TEF(p,i,pp){}
}; };
bool callback(int percent, const char *str) { bool callback(int percent, const char *str) {
@ -71,234 +71,234 @@ bool callback(int percent, const char *str) {
template <class MESH> template <class MESH>
bool NormalTest(typename face::Pos<typename MESH::FaceType> pos) bool NormalTest(typename face::Pos<typename MESH::FaceType> pos)
{ {
//giro intorno al vertice e controllo le normali //giro intorno al vertice e controllo le normali
typename MESH::ScalarType thr = 0.0f; typename MESH::ScalarType thr = 0.0f;
typename MESH::CoordType NdP = vcg::Normal<typename MESH::FaceType>(*pos.f); typename MESH::CoordType NdP = vcg::Normal<typename MESH::FaceType>(*pos.f);
typename MESH::CoordType tmp, oop, soglia = typename MESH::CoordType(thr,thr,thr); typename MESH::CoordType tmp, oop, soglia = typename MESH::CoordType(thr,thr,thr);
face::Pos<typename MESH::FaceType> aux=pos; face::Pos<typename MESH::FaceType> aux=pos;
do{ do{
aux.FlipF(); aux.FlipF();
aux.FlipE(); aux.FlipE();
oop = Abs(tmp - ::vcg::Normal<typename MESH::FaceType>(*pos.f)); oop = Abs(tmp - ::vcg::Normal<typename MESH::FaceType>(*pos.f));
if(oop < soglia )return false; if(oop < soglia )return false;
}while(aux != pos && !aux.IsBorder()); }while(aux != pos && !aux.IsBorder());
return true; return true;
} }
int main(int argc,char ** argv){ int main(int argc,char ** argv){
if(argc<5) if(argc<5)
{ {
printf( printf(
"\n HoleFilling ("__DATE__")\n" "\n HoleFilling ("__DATE__")\n"
"Visual Computing Group I.S.T.I. C.N.R.\n" "Visual Computing Group I.S.T.I. C.N.R.\n"
"Usage: trimesh_hole #algorithm #size filein.ply fileout.ply \n" "Usage: trimesh_hole #algorithm #size filein.ply fileout.ply \n"
"#algorithm: \n" "#algorithm: \n"
" 1) Trivial Ear \n" " 1) Trivial Ear \n"
" 2) Minimum weight Ear \n" " 2) Minimum weight Ear \n"
" 3) Selfintersection Ear \n" " 3) Selfintersection Ear \n"
" 4) Minimum weight \n" " 4) Minimum weight \n"
); );
exit(0); exit(0);
} }
int algorithm = atoi(argv[1]); int algorithm = atoi(argv[1]);
int holeSize = atoi(argv[2]); int holeSize = atoi(argv[2]);
if(algorithm < 0 && algorithm > 4) if(algorithm < 0 && algorithm > 4)
{ {
printf("Error in algorithm's selection %i\n",algorithm); printf("Error in algorithm's selection %i\n",algorithm);
exit(0); exit(0);
} }
MyMesh m; MyMesh m;
if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[3])!=0) if(tri::io::ImporterPLY<MyMesh>::Open(m,argv[3])!=0)
{ {
printf("Error reading file %s\n",argv[2]); printf("Error reading file %s\n",argv[2]);
exit(0); exit(0);
} }
//update the face-face topology //update the face-face topology
tri::UpdateTopology<MyMesh>::FaceFace(m); tri::UpdateTopology<MyMesh>::FaceFace(m);
tri::UpdateNormal<MyMesh>::PerVertexPerFace(m); tri::UpdateNormal<MyMesh>::PerVertexPerFace(m);
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m); tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
assert(tri::Clean<MyMesh>::IsFFAdjacencyConsistent(m)); assert(tri::Clean<MyMesh>::IsFFAdjacencyConsistent(m));
//compute the average of face area //compute the average of face area
float AVG,sumA=0.0f; float AVG,sumA=0.0f;
int numA=0,indice; int numA=0,indice;
indice = m.face.size(); indice = m.face.size();
MyMesh::FaceIterator fi; MyMesh::FaceIterator fi;
for(fi=m.face.begin();fi!=m.face.end();++fi) for(fi=m.face.begin();fi!=m.face.end();++fi)
{ {
sumA += DoubleArea(*fi)/2; sumA += DoubleArea(*fi)/2;
numA++; numA++;
for(int ind =0;ind<3;++ind) for(int ind =0;ind<3;++ind)
fi->V(ind)->InitIMark(); fi->V(ind)->InitIMark();
} }
AVG=sumA/numA; AVG=sumA/numA;
//tri::Hole<MyMesh> holeFiller; //tri::Hole<MyMesh> holeFiller;
switch(algorithm) switch(algorithm)
{ {
case 1: tri::Hole<MyMesh>::EarCuttingFill<tri::TrivialEar<MyMesh> >(m,holeSize,false); break; case 1: tri::Hole<MyMesh>::EarCuttingFill<tri::TrivialEar<MyMesh> >(m,holeSize,false); break;
case 2: tri::Hole<MyMesh>::EarCuttingFill<tri::MinimumWeightEar< MyMesh> >(m,holeSize,false,callback); break; case 2: tri::Hole<MyMesh>::EarCuttingFill<tri::MinimumWeightEar< MyMesh> >(m,holeSize,false,callback); break;
case 3: tri::Hole<MyMesh>::EarCuttingIntersectionFill<tri::SelfIntersectionEar< MyMesh> >(m,holeSize,false); break; case 3: tri::Hole<MyMesh>::EarCuttingIntersectionFill<tri::SelfIntersectionEar< MyMesh> >(m,holeSize,false); break;
case 4: tri::Hole<MyMesh>::MinimumWeightFill(m,holeSize, false); tri::UpdateTopology<MyMesh>::FaceFace(m); break; case 4: tri::Hole<MyMesh>::MinimumWeightFill(m,holeSize, false); tri::UpdateTopology<MyMesh>::FaceFace(m); break;
} }
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m); tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
assert(tri::Clean<MyMesh>::IsFFAdjacencyConsistent(m)); assert(tri::Clean<MyMesh>::IsFFAdjacencyConsistent(m));
printf("\nStart refinig...\n"); printf("\nStart refinig...\n");
/*start refining */ /*start refining */
MyMesh::VertexIterator vi; MyMesh::VertexIterator vi;
MyMesh::FaceIterator f; MyMesh::FaceIterator f;
std::vector<MyMesh::FacePointer> vf; std::vector<MyMesh::FacePointer> vf;
f = m.face.begin(); f = m.face.begin();
f += indice; f += indice;
for(; f != m.face.end();++f) for(; f != m.face.end();++f)
{ {
if(!f->IsD()) if(!f->IsD())
{ {
f->SetS(); f->SetS();
} }
} }
std::vector<MyMesh::FacePointer *> FPP; std::vector<MyMesh::FacePointer *> FPP;
std::vector<MyMesh::FacePointer> added; std::vector<MyMesh::FacePointer> added;
std::vector<MyMesh::FacePointer>::iterator vfit; std::vector<MyMesh::FacePointer>::iterator vfit;
int i=1; int i=1;
printf("\n"); printf("\n");
for(f = m.face.begin();f!=m.face.end();++f) if(!(*f).IsD()) for(f = m.face.begin();f!=m.face.end();++f) if(!(*f).IsD())
{ {
if( f->IsS() ) if( f->IsS() )
{ {
f->V(0)->IsW(); f->V(0)->IsW();
f->V(1)->IsW(); f->V(1)->IsW();
f->V(2)->IsW(); f->V(2)->IsW();
} }
else else
{ {
f->V(0)->ClearW(); f->V(0)->ClearW();
f->V(1)->ClearW(); f->V(1)->ClearW();
f->V(2)->ClearW(); f->V(2)->ClearW();
} }
} }
BaseParameterClass pp; BaseParameterClass pp;
vcg::LocalOptimization<MyMesh> Fs(m,&pp); vcg::LocalOptimization<MyMesh> Fs(m,&pp);
Fs.SetTargetMetric(0.0f); Fs.SetTargetMetric(0.0f);
Fs.Init<MyDelaunayFlip >(); Fs.Init<MyDelaunayFlip >();
Fs.DoOptimization(); Fs.DoOptimization();
do
{
vf.clear();
f = m.face.begin();
f += indice;
for(; f != m.face.end();++f)
{
if(f->IsS())
{
bool test= true;
for(int ind =0;ind<3;++ind)
f->V(ind)->InitIMark();
test = (DoubleArea<MyMesh::FaceType>(*f)/2) > AVG;
if(test)
{
vf.push_back(&(*f));
}
}
}
//info print do
{
vf.clear();
f = m.face.begin();
f += indice;
for(; f != m.face.end();++f)
{
if(f->IsS())
{
bool test= true;
for(int ind =0;ind<3;++ind)
f->V(ind)->InitIMark();
test = (DoubleArea<MyMesh::FaceType>(*f)/2) > AVG;
if(test)
{
vf.push_back(&(*f));
}
}
}
//info print
printf("\r Refining [%d] - > %d",i,int(vf.size())); printf("\r Refining [%d] - > %d",i,int(vf.size()));
i++; i++;
FPP.clear(); FPP.clear();
added.clear(); added.clear();
for(vfit = vf.begin(); vfit!=vf.end();++vfit) for(vfit = vf.begin(); vfit!=vf.end();++vfit)
{ {
FPP.push_back(&(*vfit)); FPP.push_back(&(*vfit));
} }
int toadd= vf.size(); int toadd= vf.size();
MyMesh::FaceIterator f1,f2; MyMesh::FaceIterator f1,f2;
f2 = tri::Allocator<MyMesh>::AddFaces(m,(toadd*2),FPP); f2 = tri::Allocator<MyMesh>::AddFaces(m,(toadd*2),FPP);
MyMesh::VertexIterator vertp = tri::Allocator<MyMesh>::AddVertices(m,toadd); MyMesh::VertexIterator vertp = tri::Allocator<MyMesh>::AddVertices(m,toadd);
std::vector<MyMesh::FacePointer> added; std::vector<MyMesh::FacePointer> added;
added.reserve(toadd); added.reserve(toadd);
vfit=vf.begin(); vfit=vf.begin();
for(int i = 0; i<toadd;++i,f2++,vertp++) for(int i = 0; i<toadd;++i,f2++,vertp++)
{ {
f1=f2; f1=f2;
f2++; f2++;
TriSplit<MyMesh,CenterPoint<MyMesh> >(vf[i],&(*f1),&(*f2),&(*vertp),CenterPoint<MyMesh>() ); TriSplit<MyMesh,CenterPointBarycenter<MyMesh> >::Apply(vf[i],&(*f1),&(*f2),&(*vertp),CenterPointBarycenter<MyMesh>() );
f1->SetS(); f1->SetS();
f2->SetS(); f2->SetS();
for(int itr=0;itr<3;itr++) for(int itr=0;itr<3;itr++)
{ {
f1->V(itr)->SetW(); f1->V(itr)->SetW();
f2->V(itr)->SetW(); f2->V(itr)->SetW();
} }
added.push_back( &(*f1) ); added.push_back( &(*f1) );
added.push_back( &(*f2) ); added.push_back( &(*f2) );
} }
BaseParameterClass pp; BaseParameterClass pp;
vcg::LocalOptimization<MyMesh> FlippingSession(m,&pp); vcg::LocalOptimization<MyMesh> FlippingSession(m,&pp);
FlippingSession.SetTargetMetric(0.0f); FlippingSession.SetTargetMetric(0.0f);
FlippingSession.Init<MyDelaunayFlip >(); FlippingSession.Init<MyDelaunayFlip >();
FlippingSession.DoOptimization(); FlippingSession.DoOptimization();
}while(!vf.empty());
vcg::LocalOptimization<MyMesh> Fiss(m,&pp); }while(!vf.empty());
Fiss.SetTargetMetric(0.0f);
Fiss.Init<MyDelaunayFlip >(); vcg::LocalOptimization<MyMesh> Fiss(m,&pp);
Fiss.DoOptimization(); Fiss.SetTargetMetric(0.0f);
Fiss.Init<MyDelaunayFlip >();
Fiss.DoOptimization();
/*end refining */ /*end refining */
tri::io::ExporterPLY<MyMesh>::Save(m,"PreSmooth.ply",false); tri::io::ExporterPLY<MyMesh>::Save(m,"PreSmooth.ply",false);
int UBIT = MyMesh::VertexType::NewBitFlag(); int UBIT = MyMesh::VertexType::NewBitFlag();
f = m.face.begin(); f = m.face.begin();
f += indice; f += indice;
for(; f != m.face.end();++f) for(; f != m.face.end();++f)
{ {
if(f->IsS()) if(f->IsS())
{ {
for(int ind =0;ind<3;++ind){ for(int ind =0;ind<3;++ind){
if(NormalTest<MyMesh>(face::Pos<MyMesh::FaceType>(&(*f),ind ))) if(NormalTest<MyMesh>(face::Pos<MyMesh::FaceType>(&(*f),ind )))
{ {
f->V(ind)->SetUserBit(UBIT); f->V(ind)->SetUserBit(UBIT);
} }
} }
f->ClearS(); f->ClearS();
} }
} }
for(vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD()) for(vi=m.vert.begin();vi!=m.vert.end();++vi) if(!(*vi).IsD())
{ {
if( vi->IsUserBit(UBIT) ) if( vi->IsUserBit(UBIT) )
{ {
(*vi).SetS(); (*vi).SetS();
vi->ClearUserBit(UBIT); vi->ClearUserBit(UBIT);
} }
} }
tri::Smooth<MyMesh>::VertexCoordLaplacian(m,1,true); tri::Smooth<MyMesh>::VertexCoordLaplacian(m,1,true);
printf("\nCompleted. Saving....\n");
printf("\nCompleted. Saving....\n");
tri::io::ExporterPLY<MyMesh>::Save(m,argv[4],false); tri::io::ExporterPLY<MyMesh>::Save(m,argv[4],false);
return 0; return 0;
} }

View File

@ -882,14 +882,20 @@ struct CenterPointBarycenter : public std::unary_function<typename TRIMESH_TYPE:
template<class TRIMESH_TYPE, class CenterPoint=CenterPointBarycenter <TRIMESH_TYPE> > template<class TRIMESH_TYPE, class CenterPoint=CenterPointBarycenter <TRIMESH_TYPE> >
void TriSplit(typename TRIMESH_TYPE::FacePointer f, class TriSplit
typename TRIMESH_TYPE::FacePointer f1,typename TRIMESH_TYPE::FacePointer f2,
typename TRIMESH_TYPE::VertexPointer vB, CenterPoint Center)
{ {
public:
typedef typename TRIMESH_TYPE::FaceType FaceType;
typedef typename TRIMESH_TYPE::VertexType VertexType;
static void Apply(FaceType *f,
FaceType * f1,FaceType * f2,
VertexType * vB, CenterPoint Center)
{
vB->P() = Center(f); vB->P() = Center(f);
//i tre vertici della faccia da dividere //i tre vertici della faccia da dividere
typename TRIMESH_TYPE::VertexType* V0,*V1,*V2; VertexType *V0,*V1,*V2;
V0 = f->V(0); V0 = f->V(0);
V1 = f->V(1); V1 = f->V(1);
V2 = f->V(2); V2 = f->V(2);
@ -907,49 +913,50 @@ void TriSplit(typename TRIMESH_TYPE::FacePointer f,
if(f->HasFFAdjacency()) if(f->HasFFAdjacency())
{ {
//adiacenza delle facce adiacenti a quelle aggiunte //adiacenza delle facce adiacenti a quelle aggiunte
f->FFp(1)->FFp(f->FFi(1)) = f1; f->FFp(1)->FFp(f->FFi(1)) = f1;
f->FFp(2)->FFp(f->FFi(2)) = f2; f->FFp(2)->FFp(f->FFi(2)) = f2;
//adiacenza ff //adiacenza ff
typename TRIMESH_TYPE::FacePointer FF0,FF1,FF2; FaceType * FF0,*FF1,*FF2;
FF0 = f->FFp(0); FF0 = f->FFp(0);
FF1 = f->FFp(1); FF1 = f->FFp(1);
FF2 = f->FFp(2); FF2 = f->FFp(2);
//Indici di adiacenza ff //Indici di adiacenza ff
char FFi0,FFi1,FFi2; char FFi0,FFi1,FFi2;
FFi0 = f->FFi(0); FFi0 = f->FFi(0);
FFi1 = f->FFi(1); FFi1 = f->FFi(1);
FFi2 = f->FFi(2); FFi2 = f->FFi(2);
//adiacenza della faccia di partenza //adiacenza della faccia di partenza
(*f).FFp(1) = &(*f1); (*f).FFp(1) = &(*f1);
(*f).FFi(1) = 0; (*f).FFi(1) = 0;
(*f).FFp(2) = &(*f2); (*f).FFp(2) = &(*f2);
(*f).FFi(2) = 0; (*f).FFi(2) = 0;
//adiacenza della faccia #1 //adiacenza della faccia #1
(*f1).FFp(0) = f; (*f1).FFp(0) = f;
(*f1).FFi(0) = 1; (*f1).FFi(0) = 1;
(*f1).FFp(1) = FF1; (*f1).FFp(1) = FF1;
(*f1).FFi(1) = FFi1; (*f1).FFi(1) = FFi1;
(*f1).FFp(2) = &(*f2); (*f1).FFp(2) = &(*f2);
(*f1).FFi(2) = 1; (*f1).FFi(2) = 1;
//adiacenza della faccia #2 //adiacenza della faccia #2
(*f2).FFp(0) = f; (*f2).FFp(0) = f;
(*f2).FFi(0) = 2; (*f2).FFi(0) = 2;
(*f2).FFp(1) = &(*f1); (*f2).FFp(1) = &(*f1);
(*f2).FFi(1) = 2; (*f2).FFi(1) = 2;
(*f2).FFp(2) = FF2; (*f2).FFp(2) = FF2;
(*f2).FFi(2) = FFi2; (*f2).FFi(2) = FFi2;
} }
} }
}; // end class TriSplit
} // namespace tri } // namespace tri
} // namespace vcg } // namespace vcg