Cleaned up a bit. Only a bit.

This commit is contained in:
Paolo Cignoni 2013-02-28 07:02:20 +00:00
parent 17f61b2774
commit 391e376be7
1 changed files with 123 additions and 144 deletions

View File

@ -1,5 +1,3 @@
#ifndef _4PCS_
#define _4PCS_
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
@ -22,6 +20,9 @@
* for more details. *
* *
****************************************************************************/
#ifndef _AUTOALIGN_4PCS_H_
#define _AUTOALIGN_4PCS_H_
/**
implementation of the 4PCS method from the paper:
"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
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/index/grid_static_ptr.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/algorithms/stat.h>
#include <wrap/io_trimesh/export_ply.h>
// note: temporary (callback.h should be moved inside vcg)
typedef bool AACb( const int pos,const char * str );
namespace vcg{
namespace tri{
namespace tri{
template <class MeshType>
class FourPCS {
public:
@ -61,11 +52,8 @@ public:
class PUsedTypes: public vcg::UsedTypes < vcg::Use<PVertex>::template AsVertexType,
vcg::Use<PFace >::template AsFaceType >{};
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> {};
/*the mesh is a container of vertices and a container of faces */
class PMesh : public vcg::tri::TriMesh< std::vector<PVertex>, std::vector<PFace> > {};
typedef typename MeshType::ScalarType ScalarType;
@ -76,10 +64,11 @@ public:
typedef vcg::GridStaticPtr<typename PMesh::VertexType, ScalarType > GridType;
/* class for Parameters */
struct Parameters{
struct Parameters
{
ScalarType delta;
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
scoreAln; // how good must be the alignement to end the process successfully
@ -98,9 +87,9 @@ public:
void Init(MeshType &_P,MeshType &_Q);
bool Align( int L, vcg::Matrix44f & result, AACb * cb = NULL ); // main function
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(float d):std::pair<int,int>(0,0),dist(d){}
float dist;
@ -110,7 +99,6 @@ private:
/* 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)
{
@ -122,7 +110,7 @@ private:
struct CandiType{
CandiType(){};
CandiType(){}
CandiType(FourPoints _p,vcg::Matrix44<ScalarType>_T):p(_p),T(_T){}
FourPoints p;
vcg::Matrix44<ScalarType> T;
@ -167,13 +155,8 @@ private:
vcg::GridStaticPtr<typename MeshType::VertexType, ScalarType > ugridQ;
vcg::GridStaticPtr<typename MeshType::VertexType, ScalarType > ugridP;
//FILE * f;
//private:
bool SelectCoplanarBase(); // on P
bool FindCongruent() ; // of base B, on Q, with approximation delta
//private:
void ComputeR1R2(ScalarType d1,ScalarType d2);
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;
ugridQ.Set(Q->vert.begin(),Q->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();
for(vi = 0; vi < Q->vert.size(); ++vi)
for(int vi = 0; vi < Q->vert.size(); ++vi)
if(rand()/(float) RAND_MAX < ratio)
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)
subsetP.push_back(&P->vert[vi]);
// estimate neigh distance
float avD = 0.0,dist;
float avD = 0.0;
for(int i = 0 ; i < 100; ++i){
int ri = rand()/(float) RAND_MAX * Q->vert.size() -1;
std::vector< CoordType > samples,d_samples;
@ -367,8 +347,7 @@ return true;
template <class MeshType>
bool
FourPCS<MeshType>::IsTransfCongruent(FourPoints fp,vcg::Matrix44<ScalarType> & mat, float & trerr){
bool FourPCS<MeshType>::IsTransfCongruent(FourPoints fp, vcg::Matrix44<ScalarType> & mat, float & trerr){
std::vector<vcg::Point3<ScalarType> > fix;
std::vector<vcg::Point3<ScalarType> > mov;
@ -390,7 +369,7 @@ FourPCS<MeshType>::IsTransfCongruent(FourPoints fp,vcg::Matrix44<ScalarType> & m
trerr = vcg::math::Sqrt(err);
return err < prs.delta* prs.delta*4.0;
}
}
template <class MeshType>
void