00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include<vcg/complex/complex.h>
00025 #include<wrap/io_trimesh/import.h>
00026 #include<wrap/io_trimesh/export.h>
00027 #include<vcg/complex/algorithms/update/topology.h>
00028 #include<vcg/complex/algorithms/update/normal.h>
00029 #include<vcg/complex/algorithms/update/color.h>
00030 #include<vcg/complex/algorithms/inertia.h>
00031 #include<vcg/complex/algorithms/point_sampling.h>
00032 #include<vcg/complex/algorithms/ransac_matching.h>
00033
00034
00035 #include<vcg/space/index/kdtree/kdtree.h>
00036 #include<vcg/space/point_matching.h>
00037
00038 using namespace vcg;
00039
00040 class MyVertex; class MyEdge; class MyFace;
00041 struct MyUsedTypes : public UsedTypes<Use<MyVertex> ::AsVertexType,
00042 Use<MyEdge> ::AsEdgeType,
00043 Use<MyFace> ::AsFaceType>{};
00044
00045 class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Color4b, vertex::Qualityf, vertex::BitFlags >{};
00046 class MyFace : public Face< MyUsedTypes, face::FFAdj, face::Color4b, face::Normal3f, face::VertexRef, face::BitFlags > {};
00047 class MyEdge : public Edge< MyUsedTypes, edge::VertexRef, edge::VEAdj, edge::EEAdj, edge::BitFlags> {};
00048
00049 class MyMesh : public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
00050
00051
00052 int main( int argc, char **argv )
00053 {
00054 setvbuf(stdout, NULL, _IONBF, 0);
00055 if(argc<3)
00056 {
00057 printf("Usage alignmeshmesh <meshfilename2.ply> <meshfilename2.ply>\n");
00058 return -1;
00059 }
00060
00061 MyMesh fixM,movM;
00062
00063 tri::io::Importer<MyMesh>::Open(fixM,argv[1]);
00064 printf( "Mesh0 has %i vert and %i faces\n", fixM.VN(), fixM.FN() );
00065 tri::io::Importer<MyMesh>::Open(movM,argv[2]);
00066 printf( "Mesh1 has %i vert and %i faces\n", movM.VN(), movM.FN() );
00067
00068 math::MarsenneTwisterRNG rnd;
00069
00070 tri::UpdateBounding<MyMesh>::Box(fixM);
00071 tri::UpdateBounding<MyMesh>::Box(movM);
00072
00073 Point3f delta = math::GeneratePointInUnitBallUniform<float>(rnd) * fixM.bbox.Diag();
00074 tri::UpdatePosition<MyMesh>::Translate(movM,delta);
00075 Point3f axis = math::GeneratePointOnUnitSphereUniform<float>(rnd);
00076 float angle = rnd.generate01() * M_PI;
00077 Matrix44f rot; rot.SetRotateRad(angle,axis);
00078 tri::UpdatePosition<MyMesh>::Matrix(movM,rot);
00079 tri::io::ExporterPLY<MyMesh>::Save(movM,"out.ply");
00080 int randSeed = clock();
00081
00082 RansacFramework<MyMesh,BaseFeatureSet<MyMesh> > Ran;
00083 RansacFramework<MyMesh,BaseFeatureSet<MyMesh> >::Param pp;
00084 BaseFeatureSet<MyMesh>::Param fpp;
00085 pp.samplingRadiusPerc=0.008;
00086 pp.evalSize=50;
00087 pp.inlierRatioThr = 0.5;
00088 pp.iterMax = 100;
00089 pp.maxMatchingFeatureNum = 500;
00090 fpp.featureSampleRatio=0.5;
00091 std::vector<RansacFramework<MyMesh,BaseFeatureSet<MyMesh> >::Candidate> cVec;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 int t0=clock();
00118 Ran.Init(fixM,movM,pp,fpp);
00119 int t1=clock();
00120 Ran.Process_SearchEvaluateTriple(cVec,pp);
00121 int t2=clock();
00122
00123 printf("Completed Search (%5.2f init %5.2f search)\n",float(t1-t0)/CLOCKS_PER_SEC, float(t2-t1)/CLOCKS_PER_SEC);
00124
00125
00126 MyMesh out0; tri::Append<MyMesh,MyMesh>::MeshCopy(out0,movM);
00127 tri::UpdatePosition<MyMesh>::Matrix(out0,cVec[0].Tr);
00128 tri::io::ExporterPLY<MyMesh>::Save(out0,"out0.ply");
00129
00130 MyMesh inlierMesh0;
00131 Ran.DumpInlier(inlierMesh0,cVec[0],pp);
00132 tri::io::ExporterPLY<MyMesh>::Save(inlierMesh0,"inlier0.ply");
00133
00134 MyMesh out1; tri::Append<MyMesh,MyMesh>::MeshCopy(out1,movM);
00135 tri::UpdatePosition<MyMesh>::Matrix(out1,cVec[1].Tr);
00136 tri::io::ExporterPLY<MyMesh>::Save(out1,"out1.ply");
00137
00138 MyMesh inlierMesh1;
00139 Ran.DumpInlier(inlierMesh1,cVec[1],pp);
00140 tri::io::ExporterPLY<MyMesh>::Save(inlierMesh1,"inlier1.ply");
00141
00142 return 0;
00143 }
00144