diff --git a/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp b/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp index 3073797d..b7903151 100644 --- a/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp +++ b/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp @@ -23,9 +23,14 @@ /*! \file trimesh_align_pair.cpp \ingroup code_sample -\brief the minimal example of using the lib +\brief the minimal example for aligning two meshes -This file contain a minimal example of the library +This file contain a minimal example for aligning two meshs. + +Example call: +./trimesh_align_pair mesh1.ply mesh2.ply output.ply + +output.ply will contain mesh2.ply rotated in order to be aligned to mesh1.ply */ @@ -39,11 +44,22 @@ This file contain a minimal example of the library class MyFace; class MyVertex; -struct MyUsedTypes : public vcg::UsedTypes< vcg::Use::AsVertexType, vcg::Use::AsFaceType>{}; +struct MyUsedTypes : + public vcg::UsedTypes< vcg::Use::AsVertexType, + vcg::Use::AsFaceType> +{}; -class MyVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3d, vcg::vertex::Normal3d, vcg::vertex::Color4b, vcg::vertex::BitFlags >{}; -class MyFace : public vcg::Face < MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3d, vcg::face::FFAdj, vcg::face::Mark, vcg::face::BitFlags > {}; -class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector > {}; +class MyVertex : + public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3d, vcg::vertex::Normal3d, vcg::vertex::Color4b, vcg::vertex::BitFlags> +{}; + +class MyFace : + public vcg::Face < MyUsedTypes, vcg::face::VertexRef, vcg::face::Normal3d, vcg::face::FFAdj, vcg::face::Mark, vcg::face::BitFlags > +{}; + +class MyMesh : + public vcg::tri::TriMesh< std::vector, std::vector > +{}; using namespace vcg; using namespace std; @@ -58,6 +74,10 @@ int main(int argc,char ** argv) printf("Usage: trimesh_smooth \n"); return 0; } + std::string outputname = "output.ply"; + if (argc == 4){ + outputname = std::string(argv[3]); + } MyMesh m1, m2; @@ -75,24 +95,17 @@ int main(int argc,char ** argv) exit(-1); } + //update normals vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(m1); vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(m2); ////PARAMS - /////TODO vcg::AlignPair::Result result; vcg::AlignPair::Param ap; - - //MovM - //vcg::Matrix44d FixM=vcg::Matrix44d::Construct(m1.Tr); - //MovM=vcg::Matrix44d::Construct(m2.Tr); - //MovM = Inverse(FixM) * MovM; - vcg::AlignPair::A2Mesh fix; vcg::AlignPair aa; // 1) Convert fixed mesh and put it into the grid. - //m1.face.EnableMark(); aa.convertMesh(m1,fix); vcg::AlignPair::A2Grid UG; @@ -109,8 +122,6 @@ int main(int argc,char ** argv) // 2) Convert the second mesh and sample a points on it. - //MM(movId)->updateDataMask(MeshModel::MM_FACEMARK); - //m2.face.EnableMark(); std::vector tmpmv; aa.convertVertex(m2.vert,tmpmv); aa.sampleMovVert(tmpmv, ap.SampleNum, ap.SampleMode); @@ -119,20 +130,19 @@ int main(int argc,char ** argv) aa.fix=&fix; aa.ap = ap; + //use identity as first matrix vcg::Matrix44d In; In.SetIdentity(); + // Perform the ICP algorithm aa.align(In,UG,VG,result); + //rotate m2 using the resulting transformation tri::UpdatePosition::Matrix(m2, result.Tr, true); tri::UpdateBounding::Box(m2); - //result.FixName=fixId; - //result.MovName=movId; - //result.as.Dump(stdout); - //saves the rotated mesh - tri::io::ExporterPLY::Save(m2 ,"out.ply"); + tri::io::ExporterPLY::Save(m2 ,outputname.c_str()); return 0; }