vcglib/apps/sample/trimesh_hole/trimesh_hole.cpp

126 lines
3.6 KiB
C++
Raw Normal View History

2006-11-22 14:42:06 +01:00
#include <vector>
2006-12-01 09:25:53 +01:00
#include <iostream>
2006-11-22 14:42:06 +01:00
#include<vcg/simplex/vertexplus/base.h>
#include<vcg/simplex/faceplus/base.h>
#include<vcg/simplex/face/topology.h>
#include<vcg/complex/trimesh/base.h>
#include <vcg/complex/local_optimization.h>
2007-01-15 13:46:25 +01:00
//#include <relaxation.h>
#include<vcg/complex/local_optimization/tri_edge_flip.h>
2006-11-22 14:42:06 +01:00
// 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>
2006-12-01 09:25:53 +01:00
#include<vcg/complex/trimesh/hole.h>
2006-11-22 14:42:06 +01:00
// input output
#include <wrap/io_trimesh/import_ply.h>
#include <wrap/io_trimesh/export_ply.h>
2006-12-01 09:25:53 +01:00
2006-11-22 14:42:06 +01:00
using namespace vcg;
2006-12-01 09:25:53 +01:00
using namespace std;
2006-11-22 14:42:06 +01:00
class MyEdge; // dummy prototype never used
class MyFace;
class MyVertex;
2007-01-15 13:46:25 +01:00
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> {};
2006-11-22 14:42:06 +01:00
2006-12-01 09:25:53 +01:00
class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace > >{};
2007-01-15 13:46:25 +01:00
/*
//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){}
};
2007-01-15 13:46:25 +01:00
//*/
2006-12-01 09:25:53 +01:00
bool callback(int percent, const char *str) {
cout << "str: " << str << " " << percent << "%\r";
2006-12-01 09:25:53 +01:00
return true;
}
2006-11-22 14:42:06 +01:00
int main(int argc,char ** argv){
if(argc<5)
2006-11-22 14:42:06 +01:00
{
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"
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]);
int holeSize = atoi(argv[2]);
2006-11-22 14:42:06 +01:00
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(tri::io::ImporterPLY<MyMesh>::Open(m,argv[3])!=0)
2006-11-22 14:42:06 +01:00
{
printf("Error reading file %s\n",argv[2]);
exit(0);
}
//update the face-face topology
2006-12-01 09:25:53 +01:00
tri::UpdateTopology<MyMesh>::FaceFace(m);
tri::UpdateNormals<MyMesh>::PerVertexPerFace(m);
2006-11-22 14:42:06 +01:00
tri::UpdateFlags<MyMesh>::FaceBorderFromFF(m);
assert(tri::Clean<MyMesh>::IsFFAdjacencyConsistent(m));
2007-01-15 13:46:25 +01:00
2006-11-22 14:42:06 +01:00
tri::Hole<MyMesh> holeFiller;
2006-11-22 14:42:06 +01:00
switch(algorithm)
{
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 3: tri::Hole<MyMesh>::EarCuttingIntersectionFill<tri::SelfIntersectionEar< MyMesh> >(m,holeSize,false); break;
case 4: tri::Hole<MyMesh>::MinimumWeightFill(m, false); break;
2006-11-22 14:42:06 +01:00
}
2007-01-15 13:46:25 +01:00
printf("\nCompleted. Saving...\n");
assert(tri::Clean<MyMesh>::IsFFAdjacencyConsistent(m));
tri::io::ExporterPLY<MyMesh>::Save(m,argv[4],false);
2007-01-15 13:46:25 +01:00
printf("\nStart flipping...\n");
vcg::LocalOptimization<MyMesh> FlippingSession(m);
2007-01-15 13:46:25 +01:00
FlippingSession.SetTargetMetric(-0.000000000001f);//
FlippingSession.Init<MyTriEdgeFlip >();
FlippingSession.DoOptimization();
2007-01-15 13:46:25 +01:00
tri::io::ExporterPLY<MyMesh>::Save(m,"out2.ply",vcg::tri::io::Mask::IOM_VERTCOLOR);
2006-11-22 14:42:06 +01:00
return 0;
}