Cleaned up a bit. Only a bit.
This commit is contained in:
parent
17f61b2774
commit
391e376be7
|
@ -1,5 +1,3 @@
|
||||||
#ifndef _4PCS_
|
|
||||||
#define _4PCS_
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* VCGLib o o *
|
* VCGLib o o *
|
||||||
* Visual and Computer Graphics Library o o *
|
* Visual and Computer Graphics Library o o *
|
||||||
|
@ -22,6 +20,9 @@
|
||||||
* for more details. *
|
* for more details. *
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#ifndef _AUTOALIGN_4PCS_H_
|
||||||
|
#define _AUTOALIGN_4PCS_H_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
implementation of the 4PCS method from the paper:
|
implementation of the 4PCS method from the paper:
|
||||||
"4-Points Congruent Sets for Robust Pairwise Surface Registration"
|
"4-Points Congruent Sets for Robust Pairwise Surface Registration"
|
||||||
|
@ -29,28 +30,18 @@ D.Aiger, N.Mitra D.Cohen-Or, SIGGRAPH 2008
|
||||||
ps: the name of the variables are out of vcg standard but like the one
|
ps: the name of the variables are out of vcg standard but like the one
|
||||||
used in the paper pseudocode.
|
used in the paper pseudocode.
|
||||||
*/
|
*/
|
||||||
#include <vcg/space/point3.h>
|
|
||||||
#include <vcg/space/point4.h>
|
|
||||||
#include <vcg/space/line3.h>
|
|
||||||
#include <vcg/space/plane3.h>
|
|
||||||
#include <vcg/space/point_matching.h>
|
#include <vcg/space/point_matching.h>
|
||||||
#include <vcg/space/index/grid_static_ptr.h>
|
|
||||||
#include <vcg/complex/algorithms/closest.h>
|
#include <vcg/complex/algorithms/closest.h>
|
||||||
#include <vcg/complex/algorithms/update/bounding.h>
|
|
||||||
|
|
||||||
#include <vcg/simplex/vertex/base.h>
|
|
||||||
#include <vcg/simplex/face/base.h>
|
|
||||||
#include <vcg/complex/complex.h>
|
#include <vcg/complex/complex.h>
|
||||||
#include <vcg/complex/algorithms/stat.h>
|
|
||||||
#include <wrap/io_trimesh/export_ply.h>
|
#include <wrap/io_trimesh/export_ply.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// note: temporary (callback.h should be moved inside vcg)
|
// note: temporary (callback.h should be moved inside vcg)
|
||||||
typedef bool AACb( const int pos,const char * str );
|
typedef bool AACb( const int pos,const char * str );
|
||||||
|
|
||||||
namespace vcg{
|
namespace vcg{
|
||||||
namespace tri{
|
namespace tri{
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
class FourPCS {
|
class FourPCS {
|
||||||
public:
|
public:
|
||||||
|
@ -61,11 +52,8 @@ public:
|
||||||
class PUsedTypes: public vcg::UsedTypes < vcg::Use<PVertex>::template AsVertexType,
|
class PUsedTypes: public vcg::UsedTypes < vcg::Use<PVertex>::template AsVertexType,
|
||||||
vcg::Use<PFace >::template AsFaceType >{};
|
vcg::Use<PFace >::template AsFaceType >{};
|
||||||
|
|
||||||
|
|
||||||
class PVertex : public vcg::Vertex< PUsedTypes,vcg::vertex::BitFlags,vcg::vertex::Coord3f ,vcg::vertex::Mark>{};
|
class PVertex : public vcg::Vertex< PUsedTypes,vcg::vertex::BitFlags,vcg::vertex::Coord3f ,vcg::vertex::Mark>{};
|
||||||
/*same as for the vertes */
|
|
||||||
class PFace : public vcg::Face< PUsedTypes> {};
|
class PFace : public vcg::Face< PUsedTypes> {};
|
||||||
/*the mesh is a container of vertices and a container of faces */
|
|
||||||
class PMesh : public vcg::tri::TriMesh< std::vector<PVertex>, std::vector<PFace> > {};
|
class PMesh : public vcg::tri::TriMesh< std::vector<PVertex>, std::vector<PFace> > {};
|
||||||
|
|
||||||
typedef typename MeshType::ScalarType ScalarType;
|
typedef typename MeshType::ScalarType ScalarType;
|
||||||
|
@ -76,10 +64,11 @@ public:
|
||||||
typedef vcg::GridStaticPtr<typename PMesh::VertexType, ScalarType > GridType;
|
typedef vcg::GridStaticPtr<typename PMesh::VertexType, ScalarType > GridType;
|
||||||
|
|
||||||
/* class for Parameters */
|
/* class for Parameters */
|
||||||
struct Parameters{
|
struct Parameters
|
||||||
|
{
|
||||||
ScalarType delta;
|
ScalarType delta;
|
||||||
int feetsize; // how many points in the neighborhood of each of the 4 points
|
int feetsize; // how many points in the neighborhood of each of the 4 points
|
||||||
ScalarType f; // overlapping estimation
|
ScalarType f; // overlap estimation
|
||||||
int scoreFeet, // how many of the feetsize points must match (max feetsize*4) to try an early interrupt
|
int scoreFeet, // how many of the feetsize points must match (max feetsize*4) to try an early interrupt
|
||||||
scoreAln; // how good must be the alignement to end the process successfully
|
scoreAln; // how good must be the alignement to end the process successfully
|
||||||
|
|
||||||
|
@ -98,9 +87,9 @@ public:
|
||||||
void Init(MeshType &_P,MeshType &_Q);
|
void Init(MeshType &_P,MeshType &_Q);
|
||||||
bool Align( int L, vcg::Matrix44f & result, AACb * cb = NULL ); // main function
|
bool Align( int L, vcg::Matrix44f & result, AACb * cb = NULL ); // main function
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Couple: public std::pair<int,int>{
|
struct Couple: public std::pair<int,int>
|
||||||
|
{
|
||||||
Couple(const int & i, const int & j, float d):std::pair<int,int>(i,j),dist(d){}
|
Couple(const int & i, const int & j, float d):std::pair<int,int>(i,j),dist(d){}
|
||||||
Couple(float d):std::pair<int,int>(0,0),dist(d){}
|
Couple(float d):std::pair<int,int>(0,0),dist(d){}
|
||||||
float dist;
|
float dist;
|
||||||
|
@ -110,7 +99,6 @@ private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* returns the closest point between to segments x1-x2 and x3-x4. */
|
/* returns the closest point between to segments x1-x2 and x3-x4. */
|
||||||
void IntersectionLineLine(const CoordType & x1,const CoordType & x2,const CoordType & x3,const CoordType & x4, CoordType&x)
|
void IntersectionLineLine(const CoordType & x1,const CoordType & x2,const CoordType & x3,const CoordType & x4, CoordType&x)
|
||||||
{
|
{
|
||||||
|
@ -122,7 +110,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
struct CandiType{
|
struct CandiType{
|
||||||
CandiType(){};
|
CandiType(){}
|
||||||
CandiType(FourPoints _p,vcg::Matrix44<ScalarType>_T):p(_p),T(_T){}
|
CandiType(FourPoints _p,vcg::Matrix44<ScalarType>_T):p(_p),T(_T){}
|
||||||
FourPoints p;
|
FourPoints p;
|
||||||
vcg::Matrix44<ScalarType> T;
|
vcg::Matrix44<ScalarType> T;
|
||||||
|
@ -167,13 +155,8 @@ private:
|
||||||
vcg::GridStaticPtr<typename MeshType::VertexType, ScalarType > ugridQ;
|
vcg::GridStaticPtr<typename MeshType::VertexType, ScalarType > ugridQ;
|
||||||
vcg::GridStaticPtr<typename MeshType::VertexType, ScalarType > ugridP;
|
vcg::GridStaticPtr<typename MeshType::VertexType, ScalarType > ugridP;
|
||||||
|
|
||||||
//FILE * f;
|
|
||||||
|
|
||||||
//private:
|
|
||||||
bool SelectCoplanarBase(); // on P
|
bool SelectCoplanarBase(); // on P
|
||||||
bool FindCongruent() ; // of base B, on Q, with approximation delta
|
bool FindCongruent() ; // of base B, on Q, with approximation delta
|
||||||
|
|
||||||
//private:
|
|
||||||
void ComputeR1R2(ScalarType d1,ScalarType d2);
|
void ComputeR1R2(ScalarType d1,ScalarType d2);
|
||||||
|
|
||||||
bool IsTransfCongruent(FourPoints fp,vcg::Matrix44<ScalarType> & mat, float & trerr);
|
bool IsTransfCongruent(FourPoints fp,vcg::Matrix44<ScalarType> & mat, float & trerr);
|
||||||
|
@ -220,21 +203,18 @@ FourPCS<MeshType>:: Init(MeshType &_P,MeshType &_Q){
|
||||||
P = &_P;Q=&_Q;
|
P = &_P;Q=&_Q;
|
||||||
ugridQ.Set(Q->vert.begin(),Q->vert.end());
|
ugridQ.Set(Q->vert.begin(),Q->vert.end());
|
||||||
ugridP.Set(P->vert.begin(),P->vert.end());
|
ugridP.Set(P->vert.begin(),P->vert.end());
|
||||||
int vi;
|
|
||||||
// float areaP = vcg::tri::Stat<MeshType>::ComputeMeshArea(*P);
|
|
||||||
// float areaQ = vcg::tri::Stat<MeshType>::ComputeMeshArea(*Q);
|
|
||||||
|
|
||||||
float ratio = 800 / (float) Q->vert.size();
|
float ratio = 800 / (float) Q->vert.size();
|
||||||
for(vi = 0; vi < Q->vert.size(); ++vi)
|
for(int vi = 0; vi < Q->vert.size(); ++vi)
|
||||||
if(rand()/(float) RAND_MAX < ratio)
|
if(rand()/(float) RAND_MAX < ratio)
|
||||||
mapsub.push_back(vi);
|
mapsub.push_back(vi);
|
||||||
|
|
||||||
for(vi = 0; vi < P->vert.size(); ++vi)
|
for(int vi = 0; vi < P->vert.size(); ++vi)
|
||||||
if(rand()/(float) RAND_MAX < ratio)
|
if(rand()/(float) RAND_MAX < ratio)
|
||||||
subsetP.push_back(&P->vert[vi]);
|
subsetP.push_back(&P->vert[vi]);
|
||||||
|
|
||||||
// estimate neigh distance
|
// estimate neigh distance
|
||||||
float avD = 0.0,dist;
|
float avD = 0.0;
|
||||||
for(int i = 0 ; i < 100; ++i){
|
for(int i = 0 ; i < 100; ++i){
|
||||||
int ri = rand()/(float) RAND_MAX * Q->vert.size() -1;
|
int ri = rand()/(float) RAND_MAX * Q->vert.size() -1;
|
||||||
std::vector< CoordType > samples,d_samples;
|
std::vector< CoordType > samples,d_samples;
|
||||||
|
@ -367,8 +347,7 @@ return true;
|
||||||
|
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
bool
|
bool FourPCS<MeshType>::IsTransfCongruent(FourPoints fp, vcg::Matrix44<ScalarType> & mat, float & trerr){
|
||||||
FourPCS<MeshType>::IsTransfCongruent(FourPoints fp,vcg::Matrix44<ScalarType> & mat, float & trerr){
|
|
||||||
|
|
||||||
std::vector<vcg::Point3<ScalarType> > fix;
|
std::vector<vcg::Point3<ScalarType> > fix;
|
||||||
std::vector<vcg::Point3<ScalarType> > mov;
|
std::vector<vcg::Point3<ScalarType> > mov;
|
||||||
|
@ -390,7 +369,7 @@ FourPCS<MeshType>::IsTransfCongruent(FourPoints fp,vcg::Matrix44<ScalarType> & m
|
||||||
|
|
||||||
trerr = vcg::math::Sqrt(err);
|
trerr = vcg::math::Sqrt(err);
|
||||||
return err < prs.delta* prs.delta*4.0;
|
return err < prs.delta* prs.delta*4.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MeshType>
|
template <class MeshType>
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue