#include #include #include #include #include #include #include //#include #include // topology computation #include #include #include // half edge iterators #include #include // input output #include #include using namespace vcg; using namespace std; class MyEdge; // dummy prototype never used class MyFace; class MyVertex; class MyVertex : public VertexSimp2< MyVertex, MyEdge, MyFace, vert::Coord3f, vert::BitFlags, vert::Normal3f, vert::Mark, vert::Color4b >{}; class MyFace : public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,face::FFAdj, face::Mark, face::BitFlags, face::Normal3f> {}; class MyMesh : public tri::TriMesh< vector, vector >{}; /* //for coplanar mesh class MyTriEdgeFlip: public vcg::tri::PlanarEdgeFlip< MyMesh, MyTriEdgeFlip > { public: typedef vcg::tri::PlanarEdgeFlip< MyMesh, MyTriEdgeFlip > TEF; inline MyTriEdgeFlip( const TEF::PosType &p, int i) :TEF(p,i){} }; /*/ //Delaunay class MyTriEdgeFlip: public vcg::tri::TriEdgeFlip< MyMesh, MyTriEdgeFlip > { public: typedef vcg::tri::TriEdgeFlip< MyMesh, MyTriEdgeFlip > TEF; inline MyTriEdgeFlip( const TEF::PosType &p, int i) :TEF(p,i){} }; //*/ bool callback(int percent, const char *str) { cout << "str: " << str << " " << percent << "%\r"; return true; } int main(int argc,char ** argv){ if(argc<5) { printf( "\n HoleFilling ("__DATE__")\n" "Visual Computing Group I.S.T.I. C.N.R.\n" "Usage: trimesh_hole #algorithm #size filein.ply fileout.ply \n" "#algorithm: \n" " 1) Trivial Ear \n" " 2) Minimum weight Ear \n" " 3) Selfintersection Ear \n" " 4) Minimum weight \n" ); exit(0); } int algorithm = atoi(argv[1]); int holeSize = atoi(argv[2]); if(algorithm < 0 && algorithm > 4) { printf("Error in algorithm's selection\n",algorithm); exit(0); } MyMesh m; if(tri::io::ImporterPLY::Open(m,argv[3])!=0) { printf("Error reading file %s\n",argv[2]); exit(0); } //update the face-face topology tri::UpdateTopology::FaceFace(m); tri::UpdateNormals::PerVertexPerFace(m); tri::UpdateFlags::FaceBorderFromFF(m); assert(tri::Clean::IsFFAdjacencyConsistent(m)); tri::Hole holeFiller; switch(algorithm) { case 1: tri::Hole::EarCuttingFill >(m,holeSize,false); break; case 2: tri::Hole::EarCuttingFill >(m,holeSize,false,callback); break; case 3: tri::Hole::EarCuttingIntersectionFill >(m,holeSize,false); break; case 4: tri::Hole::MinimumWeightFill(m,holeSize, false); break; } printf("\nCompleted. Saving...\n"); assert(tri::Clean::IsFFAdjacencyConsistent(m)); tri::io::ExporterPLY::Save(m,argv[4],false); printf("\nStart flipping...\n"); vcg::LocalOptimization FlippingSession(m); FlippingSession.SetTargetMetric(-0.000000000001f);// FlippingSession.Init(); FlippingSession.DoOptimization(); tri::io::ExporterPLY::Save(m,"out2.ply",vcg::tri::io::Mask::IOM_VERTCOLOR); return 0; }