cleanups and comments

This commit is contained in:
alemuntoni 2020-06-01 16:42:53 +02:00
parent fcdf421f47
commit da737ebad7
1 changed files with 31 additions and 21 deletions

View File

@ -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<MyVertex>::AsVertexType, vcg::Use<MyFace>::AsFaceType>{};
struct MyUsedTypes :
public vcg::UsedTypes< vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::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<MyVertex>, std::vector<MyFace> > {};
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<MyVertex>, std::vector<MyFace> >
{};
using namespace vcg;
using namespace std;
@ -58,6 +74,10 @@ int main(int argc,char ** argv)
printf("Usage: trimesh_smooth <filename> <filename>\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<MyMesh>::PerVertexNormalizedPerFace(m1);
vcg::tri::UpdateNormal<MyMesh>::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<MyMesh>(m1,fix);
vcg::AlignPair::A2Grid UG;
@ -109,8 +122,6 @@ int main(int argc,char ** argv)
// 2) Convert the second mesh and sample a <ap.SampleNum> points on it.
//MM(movId)->updateDataMask(MeshModel::MM_FACEMARK);
//m2.face.EnableMark();
std::vector<vcg::AlignPair::A2Vertex> 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<MyMesh>::Matrix(m2, result.Tr, true);
tri::UpdateBounding<MyMesh>::Box(m2);
//result.FixName=fixId;
//result.MovName=movId;
//result.as.Dump(stdout);
//saves the rotated mesh
tri::io::ExporterPLY<MyMesh>::Save(m2 ,"out.ply");
tri::io::ExporterPLY<MyMesh>::Save(m2 ,outputname.c_str());
return 0;
}