align_pair sample working
This commit is contained in:
parent
5b6d6ec767
commit
fcdf421f47
|
@ -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
|
||||
|
|
|
@ -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 <vcg/complex/complex.h>
|
||||
|
||||
typedef double Scalarm;
|
||||
typedef vcg::Point2<Scalarm> Point2m;
|
||||
typedef vcg::Point3<Scalarm> Point3m;
|
||||
typedef vcg::Point4<Scalarm> Point4m;
|
||||
typedef vcg::Plane3<Scalarm> Plane3m;
|
||||
typedef vcg::Segment2<Scalarm> Segment2m;
|
||||
typedef vcg::Segment3<Scalarm> Segment3m;
|
||||
typedef vcg::Box3<Scalarm> Box3m;
|
||||
typedef vcg::Matrix44<Scalarm> Matrix44m;
|
||||
typedef vcg::Matrix33<Scalarm> Matrix33m;
|
||||
typedef vcg::Shot<Scalarm> Shotm;
|
||||
typedef vcg::Similarity<Scalarm> Similaritym;
|
||||
|
||||
namespace vcg
|
||||
{
|
||||
namespace vertex
|
||||
{
|
||||
template <class T> class Coord3m: public Coord<vcg::Point3<Scalarm>, T> {
|
||||
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3m"));T::Name(name);}
|
||||
};
|
||||
|
||||
template <class T> class Normal3m: public Normal<vcg::Point3<Scalarm>, T> {
|
||||
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3m"));T::Name(name);}
|
||||
};
|
||||
|
||||
template <class T> class CurvatureDirmOcf: public CurvatureDirOcf<CurvatureDirTypeOcf<Scalarm>, T> {
|
||||
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDirmOcf"));T::Name(name);}
|
||||
};
|
||||
|
||||
template <class T> class RadiusmOcf: public RadiusOcf<Scalarm, T> {
|
||||
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("RadiusmOcf"));T::Name(name);}
|
||||
};
|
||||
|
||||
}//end namespace vertex
|
||||
namespace face
|
||||
{
|
||||
template <class T> class Normal3m: public NormalAbs<vcg::Point3<Scalarm>, T> {
|
||||
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3m"));T::Name(name);}
|
||||
};
|
||||
|
||||
template <class T> class CurvatureDirmOcf: public CurvatureDirOcf<CurvatureDirOcfBaseType<Scalarm>, T> {
|
||||
public: static void Name(std::vector<std::string> & 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<CVertexO>::AsVertexType,
|
||||
vcg::Use<CEdgeO >::AsEdgeType,
|
||||
vcg::Use<CFaceO >::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<CUsedTypesO,
|
||||
vcg::edge::BitFlags, /* 4b */
|
||||
vcg::edge::EVAdj,
|
||||
vcg::edge::EEAdj
|
||||
>{
|
||||
};
|
||||
|
||||
// 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<CVertexO>, vcg::face::vector_ocf<CFaceO> >
|
||||
{
|
||||
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
|
|
@ -36,7 +36,14 @@ This file contain a minimal example of the library
|
|||
#include <wrap/io_trimesh/import.h>
|
||||
#include <wrap/io_trimesh/export_ply.h>
|
||||
|
||||
#include "my_mesh.h"
|
||||
class MyFace;
|
||||
class MyVertex;
|
||||
|
||||
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> > {};
|
||||
|
||||
using namespace vcg;
|
||||
using namespace std;
|
||||
|
@ -62,28 +69,30 @@ int main(int argc,char ** argv)
|
|||
}
|
||||
|
||||
//open second mesh
|
||||
err = tri::io::Importer<MyMesh>::Open(m1,argv[2]);
|
||||
err = tri::io::Importer<MyMesh>::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<MyMesh>::ErrorMsg(err));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
vcg::tri::UpdateNormal<MyMesh>::PerVertexNormalizedPerFace(m1);
|
||||
vcg::tri::UpdateNormal<MyMesh>::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<MyMesh>(m1,fix);
|
||||
|
||||
vcg::AlignPair::A2Grid UG;
|
||||
|
@ -101,7 +110,7 @@ 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();
|
||||
//m2.face.EnableMark();
|
||||
std::vector<vcg::AlignPair::A2Vertex> 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<MyMesh>::Matrix(m2, m2.Tr, true);
|
||||
tri::UpdatePosition<MyMesh>::Matrix(m2, result.Tr, true);
|
||||
tri::UpdateBounding<MyMesh>::Box(m2);
|
||||
m2.Tr.SetIdentity();
|
||||
|
||||
//result.FixName=fixId;
|
||||
//result.MovName=movId;
|
||||
|
|
|
@ -2,9 +2,6 @@ include(../common.pri)
|
|||
|
||||
TARGET = trimesh_align_pair
|
||||
|
||||
HEADERS += \
|
||||
my_mesh.h
|
||||
|
||||
SOURCES += \
|
||||
trimesh_align_pair.cpp \
|
||||
../../../wrap/ply/plylib.cpp
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define VCG_ALIGN_PAIR_H
|
||||
|
||||
#include <ctime>
|
||||
#include <stdio.h>
|
||||
#include <vcg/math/histogram.h>
|
||||
#include <vcg/math/matrix44.h>
|
||||
#include <vcg/math/random_generator.h>
|
||||
|
@ -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<Point3d> &pfix, // vertici corrispondenti su src (rossi)
|
||||
std::vector<Point3d> &nfix, // normali corrispondenti su src (rossi)
|
||||
std::vector<Point3d> &opmov, // vertici scelti su trg (verdi) prima della trasformazione in ingresso (Original Point Target)
|
||||
std::vector<Point3d> &onmov, // normali scelti su trg (verdi)
|
||||
const Matrix44d &in, // starting transformation that matches mov points to fix mesh
|
||||
Matrix44d &out, // computed transformation
|
||||
std::vector<Point3d> &pfix, // (red) corresponding vertices on src
|
||||
std::vector<Point3d> &nfix, // (red) corresponding normals on src
|
||||
std::vector<Point3d> &opmov, // chosen vertices on trg (verdi) before the input transormation (Original Point Target)
|
||||
std::vector<Point3d> &onmov, // chosen normals on trg (verdi)
|
||||
Histogramf &h,
|
||||
Stat &as)
|
||||
{
|
||||
std::vector<char> 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<char> 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<Point3d> pmov; // vertici scelti dopo la trasf iniziale
|
||||
std::vector<Point3d> 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 <ReduceFactor> 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 <MovVert> e <MovNorm> con i coordinate e normali presi dal vettore di vertici mov
|
||||
della mesh da muovere trasformata secondo la matrice <In>
|
||||
Calcola anche il nuovo bounding box di tali vertici trasformati.
|
||||
* Function called by Align at every cycle.
|
||||
* It fills the <MovVert> and <MovNorm> vectors with the coordinates and normals
|
||||
* taken from the the vertex vector "mov" of the mesh to move according to the
|
||||
* matrix <In>.
|
||||
* It computes also the new bounding box of the transformed vertices
|
||||
*/
|
||||
inline bool initMov(
|
||||
std::vector< Point3d > &movvert,
|
||||
|
|
Loading…
Reference in New Issue