vcglib/apps/sample/trimesh_hole/trimesh_hole.cpp

94 lines
2.2 KiB
C++
Raw Normal View History

2006-11-22 14:42:06 +01:00
#include <vector>
#include<vcg/simplex/vertexplus/base.h>
#include<vcg/simplex/faceplus/base.h>
#include<vcg/simplex/face/topology.h>
#include<vcg/complex/trimesh/base.h>
// topology computation
#include<vcg/complex/trimesh/update/topology.h>
#include <vcg/complex/trimesh/update/flag.h>
2006-11-29 16:17:39 +01:00
#include <vcg/complex/trimesh/update/normal.h>
2006-11-22 14:42:06 +01:00
// half edge iterators
#include<vcg/simplex/face/pos.h>
// input output
#include <wrap/io_trimesh/import_ply.h>
#include <wrap/io_trimesh/export_ply.h>
#include<vcg/complex/trimesh/hole.h>
using namespace vcg;
class MyEdge; // dummy prototype never used
class MyFace;
class MyVertex;
class MyVertex : public VertexSimp2< MyVertex, MyEdge, MyFace, vert::Coord3f, vert::BitFlags, vert::Normal3f >{};
class MyFace : public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,face::FFAdj, face::Mark, face::BitFlags, face::Normal3f > {};
class MyMesh : public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace > >{};
int main(int argc,char ** argv){
if(argc<4)
{
printf(
"\n HoleFilling ("__DATE__")\n"
"Visual Computing Group I.S.T.I. C.N.R.\n"
2006-11-29 16:17:39 +01:00
"Usage: trimesh_hole #algorithm filein.ply fileout.ply \n"
2006-11-22 14:42:06 +01:00
"#algorithm: \n"
" 1) Trivial Ear \n"
" 2) Leipa Ear \n"
" 3) Selfintersection Ear \n"
2006-11-29 16:17:39 +01:00
" 4) Minimum weight \n"
2006-11-22 14:42:06 +01:00
);
exit(0);
}
2006-11-22 15:38:16 +01:00
2006-11-22 14:42:06 +01:00
int algorithm = atoi(argv[1]);
if(algorithm < 0 && algorithm > 4)
{
2006-11-29 16:17:39 +01:00
printf("Error in algorithm's selection\n",algorithm);
2006-11-22 14:42:06 +01:00
exit(0);
}
MyMesh m;
if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[2])!=0)
{
printf("Error reading file %s\n",argv[2]);
exit(0);
}
//update the face-face topology
vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
2006-11-29 16:17:39 +01:00
vcg::tri::UpdateNormals<MyMesh>::PerVertex(m);
2006-11-22 14:42:06 +01:00
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
2006-11-29 16:17:39 +01:00
vcg::tri::Hole<MyMesh> holeFiller;
2006-11-22 14:42:06 +01:00
switch(algorithm)
{
case 1:
2006-11-29 16:17:39 +01:00
holeFiller.EarCuttingFill<vcg::tri::TrivialEar<MyMesh> >(m,50,false);
2006-11-22 14:42:06 +01:00
break;
case 2:
2006-11-29 16:17:39 +01:00
holeFiller.EarCuttingFill<vcg::tri::MinimumWeightEar< MyMesh> >(m,500,false);
2006-11-22 14:42:06 +01:00
break;
case 3:
2006-11-29 16:17:39 +01:00
holeFiller.EarCuttingIntersectionFill<vcg::tri::SelfIntersectionEar< MyMesh> >(m,500,false);
2006-11-22 14:42:06 +01:00
break;
case 4:
2006-11-29 16:17:39 +01:00
holeFiller.MinimumWeightFill(m, false);
2006-11-22 14:42:06 +01:00
break;
}
vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[3],false);
return 0;
}