diff --git a/apps/sample/common.pri b/apps/sample/common.pri index 6cb16b15..070301f5 100644 --- a/apps/sample/common.pri +++ b/apps/sample/common.pri @@ -8,7 +8,7 @@ INCLUDEPATH += \ ../../../eigenlib -CONFIG += console c++11 +CONFIG += c++11 TEMPLATE = app # Mac specific Config required to avoid to make application bundles diff --git a/apps/sample/trimesh_align_pair/my_mesh.h b/apps/sample/trimesh_align_pair/my_mesh.h deleted file mode 100644 index 14a604ce..00000000 --- a/apps/sample/trimesh_align_pair/my_mesh.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -* VCGLib o o * -* Visual and Computer Graphics Library o o * -* _ O _ * -* Copyright(C) 2004-2016 \/)\/ * -* Visual Computing Lab /\/| * -* ISTI - Italian National Research Council | * -* \ * -* All rights reserved. * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation; either version 2 of the License, or * -* (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * -* for more details. * -* * -****************************************************************************/ -#ifndef MY_MESH_H -#define MY_MESH_H - -#include - -typedef double Scalarm; -typedef vcg::Point2 Point2m; -typedef vcg::Point3 Point3m; -typedef vcg::Point4 Point4m; -typedef vcg::Plane3 Plane3m; -typedef vcg::Segment2 Segment2m; -typedef vcg::Segment3 Segment3m; -typedef vcg::Box3 Box3m; -typedef vcg::Matrix44 Matrix44m; -typedef vcg::Matrix33 Matrix33m; -typedef vcg::Shot Shotm; -typedef vcg::Similarity Similaritym; - -namespace vcg -{ - namespace vertex - { - template class Coord3m: public Coord, T> { - public: static void Name(std::vector & name){name.push_back(std::string("Coord3m"));T::Name(name);} - }; - - template class Normal3m: public Normal, T> { - public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} - }; - - template class CurvatureDirmOcf: public CurvatureDirOcf, T> { - public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirmOcf"));T::Name(name);} - }; - - template class RadiusmOcf: public RadiusOcf { - public: static void Name(std::vector & name){name.push_back(std::string("RadiusmOcf"));T::Name(name);} - }; - - }//end namespace vertex - namespace face - { - template class Normal3m: public NormalAbs, T> { - public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} - }; - - template class CurvatureDirmOcf: public CurvatureDirOcf, T> { - public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirdOcf"));T::Name(name);} - }; - - }//end namespace face -}//end namespace vcg - -// Forward declarations needed for creating the used types -class CVertexO; -class CEdgeO; -class CFaceO; - -// Declaration of the semantic of the used types -class CUsedTypesO: public vcg::UsedTypes < vcg::Use::AsVertexType, - vcg::Use::AsEdgeType, - vcg::Use::AsFaceType >{}; - - -// The Main Vertex Class -// Most of the attributes are optional and must be enabled before use. -// Each vertex needs 40 byte, on 32bit arch. and 44 byte on 64bit arch. - -class CVertexO : public vcg::Vertex< CUsedTypesO, - vcg::vertex::InfoOcf, /* 4b */ - vcg::vertex::Coord3m, /* 12b */ - vcg::vertex::BitFlags, /* 4b */ - vcg::vertex::Normal3m, /* 12b */ - vcg::vertex::Qualityf, /* 4b */ - vcg::vertex::Color4b, /* 4b */ - vcg::vertex::VFAdjOcf, /* 0b */ - vcg::vertex::MarkOcf, /* 0b */ - vcg::vertex::TexCoordfOcf, /* 0b */ - vcg::vertex::CurvaturefOcf, /* 0b */ - vcg::vertex::CurvatureDirmOcf, /* 0b */ - vcg::vertex::RadiusmOcf /* 0b */ ->{ -}; - - -// The Main Edge Class -class CEdgeO : public vcg::Edge{ -}; - -// Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch. -class CFaceO : public vcg::Face< CUsedTypesO, - vcg::face::InfoOcf, /* 4b */ - vcg::face::VertexRef, /*12b */ - vcg::face::BitFlags, /* 4b */ - vcg::face::Normal3m, /*12b */ - vcg::face::QualityfOcf, /* 0b */ - vcg::face::MarkOcf, /* 0b */ - vcg::face::Color4bOcf, /* 0b */ - vcg::face::FFAdjOcf, /* 0b */ - vcg::face::VFAdjOcf, /* 0b */ - vcg::face::CurvatureDirmOcf, /* 0b */ - vcg::face::WedgeTexCoordfOcf /* 0b */ -> {}; - - -class MyMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > -{ -public : - int sfn; //The number of selected faces. - int svn; //The number of selected vertices. - - int pvn; //the number of the polygonal vertices - int pfn; //the number of the polygonal faces - - Matrix44m Tr; // Usually it is the identity. It is applied in rendering and filters can or cannot use it. (most of the filter will ignore this) - - const Box3m &trBB() - { - static Box3m bb; - bb.SetNull(); - bb.Add(Tr,bbox); - return bb; - } -}; - -#endif // MY_MESH_H diff --git a/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp b/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp index c9876c76..3073797d 100644 --- a/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp +++ b/apps/sample/trimesh_align_pair/trimesh_align_pair.cpp @@ -36,7 +36,14 @@ This file contain a minimal example of the library #include #include -#include "my_mesh.h" +class MyFace; +class MyVertex; + +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 > {}; using namespace vcg; using namespace std; @@ -62,28 +69,30 @@ int main(int argc,char ** argv) } //open second mesh - err = tri::io::Importer::Open(m1,argv[2]); + err = tri::io::Importer::Open(m2,argv[2]); if(err) { // all the importers return 0 in case of success printf("Error in reading %s: '%s'\n", argv[2], tri::io::Importer::ErrorMsg(err)); exit(-1); } + vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(m1); + vcg::tri::UpdateNormal::PerVertexNormalizedPerFace(m2); + ////PARAMS /////TODO - vcg::Matrix44d MovM; 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::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(); + //m1.face.EnableMark(); aa.convertMesh(m1,fix); vcg::AlignPair::A2Grid UG; @@ -101,7 +110,7 @@ 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(); + //m2.face.EnableMark(); std::vector tmpmv; aa.convertVertex(m2.vert,tmpmv); aa.sampleMovVert(tmpmv, ap.SampleNum, ap.SampleMode); @@ -110,14 +119,13 @@ int main(int argc,char ** argv) aa.fix=&fix; aa.ap = ap; - vcg::Matrix44d In=MovM; + vcg::Matrix44d In; + In.SetIdentity(); // Perform the ICP algorithm aa.align(In,UG,VG,result); - m2.Tr = result.Tr; - tri::UpdatePosition::Matrix(m2, m2.Tr, true); + tri::UpdatePosition::Matrix(m2, result.Tr, true); tri::UpdateBounding::Box(m2); - m2.Tr.SetIdentity(); //result.FixName=fixId; //result.MovName=movId; diff --git a/apps/sample/trimesh_align_pair/trimesh_align_pair.pro b/apps/sample/trimesh_align_pair/trimesh_align_pair.pro index 81c0969c..0fba0c03 100644 --- a/apps/sample/trimesh_align_pair/trimesh_align_pair.pro +++ b/apps/sample/trimesh_align_pair/trimesh_align_pair.pro @@ -2,9 +2,6 @@ include(../common.pri) TARGET = trimesh_align_pair -HEADERS += \ - my_mesh.h - SOURCES += \ trimesh_align_pair.cpp \ ../../../wrap/ply/plylib.cpp diff --git a/vcg/complex/algorithms/align_pair.h b/vcg/complex/algorithms/align_pair.h index 42bd7df6..51746ab6 100644 --- a/vcg/complex/algorithms/align_pair.h +++ b/vcg/complex/algorithms/align_pair.h @@ -24,6 +24,7 @@ #define VCG_ALIGN_PAIR_H #include +#include #include #include #include @@ -643,22 +644,22 @@ in inline bool align( A2Grid &u, A2GridVert &uv, - const Matrix44d &in, // trasformazione Iniziale che porta i punti di mov su fix - Matrix44d &out, // trasformazione calcolata - std::vector &pfix, // vertici corrispondenti su src (rossi) - std::vector &nfix, // normali corrispondenti su src (rossi) - std::vector &opmov, // vertici scelti su trg (verdi) prima della trasformazione in ingresso (Original Point Target) - std::vector &onmov, // normali scelti su trg (verdi) + const Matrix44d &in, // starting transformation that matches mov points to fix mesh + Matrix44d &out, // computed transformation + std::vector &pfix, // (red) corresponding vertices on src + std::vector &nfix, // (red) corresponding normals on src + std::vector &opmov, // chosen vertices on trg (verdi) before the input transormation (Original Point Target) + std::vector &onmov, // chosen normals on trg (verdi) Histogramf &h, Stat &as) { - std::vector beyondCntVec; // vettore per marcare i movvert che sicuramente non si devono usare - // ogni volta che un vertice si trova a distanza oltre max dist viene incrementato il suo contatore; - // i movvert che sono stati scartati piu' di MaxCntDist volte non si guardano piu'; + std::vector beyondCntVec; // flag vector to set the movverts that we should not use + // every time that a vertex is at a distance beyound max dist, its counter is incremented; + // movverts that has been discarded more than MaxCntDist times will not be considered anymore const int maxBeyondCnt = 3; std::vector< Point3d > movvert; std::vector< Point3d > movnorm; - std::vector pmov; // vertici scelti dopo la trasf iniziale + std::vector pmov; // vertices chosen after the transformation status = SUCCESS; int tt0 = clock(); @@ -746,7 +747,7 @@ in } } // End for each pmov int tts1 = clock(); - //printf("Found %d pairs\n",(int)pfix.size()); + printf("Found %d pairs\n",(int)pfix.size()); if (!choosePoints(pfix, nfix, pmov, opmov, ap.PassHiFilter, h)) { if (int(pfix.size()) < ap.MinPointNum){ status = TOO_FEW_POINTS; @@ -778,8 +779,8 @@ in //} //printf("Distance %f -> %f\n",sum_before/double(pfix.size()),sum_after/double(pfix.size()) ) ; - // le passate successive utilizzano quindi come trasformazione iniziale questa appena trovata. - // Nei prossimi cicli si parte da questa matrice come iniziale. + // the following tuns will use as a initial transformation, the one that has been just found. + // in the next loops the starting matrix will be this one. out = newout * out; assert(pfix.size() == pmov.size()); @@ -798,6 +799,7 @@ in // We use 5 times the percentile of the found points. if (ap.ReduceFactorPerc<1) startMinDist = std::max(ap.MinDistAbs*ap.MinMinDistPerc, std::min(startMinDist, 5.0*h.Percentile(float(ap.ReduceFactorPerc)))); + //as.dump(stderr); } while ( nc <= ap.MaxIterNum && h.Percentile(.5) > ap.TrgDistAbs && @@ -826,10 +828,11 @@ in } /* - Funzione chiamata dalla Align ad ogni ciclo - Riempie i vettori e con i coordinate e normali presi dal vettore di vertici mov - della mesh da muovere trasformata secondo la matrice - Calcola anche il nuovo bounding box di tali vertici trasformati. + * Function called by Align at every cycle. + * It fills the and vectors with the coordinates and normals + * taken from the the vertex vector "mov" of the mesh to move according to the + * matrix . + * It computes also the new bounding box of the transformed vertices */ inline bool initMov( std::vector< Point3d > &movvert,