24 #include<vcg/complex/complex.h>
25 #include<wrap/io_trimesh/import.h>
26 #include<wrap/io_trimesh/export.h>
27 #include<vcg/complex/algorithms/update/topology.h>
28 #include<vcg/complex/algorithms/update/normal.h>
29 #include<vcg/complex/algorithms/update/color.h>
30 #include<vcg/complex/algorithms/inertia.h>
31 #include<vcg/complex/algorithms/point_sampling.h>
32 #include<vcg/complex/algorithms/ransac_matching.h>
35 #include<vcg/space/index/kdtree/kdtree.h>
36 #include<vcg/space/point_matching.h>
40 class MyVertex;
class MyEdge;
class MyFace;
41 struct MyUsedTypes :
public UsedTypes<Use<MyVertex> ::AsVertexType,
42 Use<MyEdge> ::AsEdgeType,
43 Use<MyFace> ::AsFaceType>{};
45 class MyVertex :
public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Color4b, vertex::Qualityf, vertex::BitFlags >{};
46 class MyFace :
public Face< MyUsedTypes, face::FFAdj, face::Color4b, face::Normal3f, face::VertexRef, face::BitFlags > {};
47 class MyEdge :
public Edge< MyUsedTypes, edge::VertexRef, edge::VEAdj, edge::EEAdj, edge::BitFlags> {};
49 class MyMesh :
public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
52 int main(
int argc,
char **argv )
54 setvbuf(stdout, NULL, _IONBF, 0);
57 printf(
"Usage alignmeshmesh <meshfilename2.ply> <meshfilename2.ply>\n");
63 tri::io::Importer<MyMesh>::Open(fixM,argv[1]);
64 printf(
"Mesh0 has %i vert and %i faces\n", fixM.VN(), fixM.FN() );
65 tri::io::Importer<MyMesh>::Open(movM,argv[2]);
66 printf(
"Mesh1 has %i vert and %i faces\n", movM.VN(), movM.FN() );
68 math::MarsenneTwisterRNG rnd;
73 Point3f delta = math::GeneratePointInUnitBallUniform<float>(rnd) * fixM.bbox.Diag();
75 Point3f axis = math::GeneratePointOnUnitSphereUniform<float>(rnd);
76 float angle = rnd.generate01() * M_PI;
77 Matrix44f rot; rot.SetRotateRad(angle,axis);
79 tri::io::ExporterPLY<MyMesh>::Save(movM,
"out.ply");
80 int randSeed = clock();
82 RansacFramework<MyMesh,BaseFeatureSet<MyMesh> > Ran;
83 RansacFramework<MyMesh,BaseFeatureSet<MyMesh> >::Param pp;
84 BaseFeatureSet<MyMesh>::Param fpp;
85 pp.samplingRadiusPerc=0.008;
87 pp.inlierRatioThr = 0.5;
89 pp.maxMatchingFeatureNum = 500;
90 fpp.featureSampleRatio=0.5;
91 std::vector<RansacFramework<MyMesh,BaseFeatureSet<MyMesh> >::Candidate> cVec;
118 Ran.Init(fixM,movM,pp,fpp);
120 Ran.Process_SearchEvaluateTriple(cVec,pp);
123 printf(
"Completed Search (%5.2f init %5.2f search)\n",
float(t1-t0)/CLOCKS_PER_SEC,
float(t2-t1)/CLOCKS_PER_SEC);
128 tri::io::ExporterPLY<MyMesh>::Save(out0,
"out0.ply");
131 Ran.DumpInlier(inlierMesh0,cVec[0],pp);
132 tri::io::ExporterPLY<MyMesh>::Save(inlierMesh0,
"inlier0.ply");
136 tri::io::ExporterPLY<MyMesh>::Save(out1,
"out1.ply");
139 Ran.DumpInlier(inlierMesh1,cVec[1],pp);
140 tri::io::ExporterPLY<MyMesh>::Save(inlierMesh1,
"inlier1.ply");