ICP.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <Math/Math3d.h>
27 //Eigen
28 #include <Eigen/Core>
29 
30 #include <float.h>
31 
32 class CKdTree;
33 namespace visionx
34 {
35 
36  class ICP
37  {
38  public:
39  ICP();
40  ~ICP();
41 
42  // this is the pointcloud in which we search for an object
43  void SetScenePointcloud(const std::vector<Eigen::Vector3f>& aScenePoints);
44  // this is the pointcloud of the object we search
45  void SetObjectPointcloud(const std::vector<Eigen::Vector3f>& aObjectPoints);
46 
47  /* Estimate a transformation that fits the object pointcloud into the scene pointcloud
48  * returns the average point distance value (in weighted xyzrgb-space) after the match, and the transformation of the object
49  * fBestDistanceUntilNow=n: if the distance of the new transformation is smaller than 1.25*n, the result is refined more by reducing the fConvergenceDelta parameter (see below) */
50  float SearchObject(Mat3d& mRotation, Vec3d& vTranslation, const float fBestDistanceUntilNow = FLT_MAX);
51 
52  /* Set the parameters:
53  * fCutoffDistance=n: if two corresponding points have a distance of more than n, they are ignored. This is helpful when matching pointclouds with partial overlap
54  * fConvergenceDelta=n: the algorithm stops when the relative improvement of the distance between the two clouds is less than n
55  * nMaxIterations=n: the algorithm stops after at most n iterations */
56  void SetParameters(float fCutoffDistance = FLT_MAX, float fConvergenceDelta = 0.001f, int nMaxIterations = 40, int nKdTreeBucketSize = 50); // 50, FLT_MAX, 0.0001f, 50, 50
57 
58  // returns the distances of object points to their nearest neighbour in the scene
59  void GetPointMatchDistances(std::vector<float>& aPointMatchDistances);
60  void GetNearestNeighbors(std::vector<Eigen::Vector3f>& aNeighbors, std::vector<float>& aPointMatchDistances);
61 
62  private:
63 
64  void FindNNBruteForce(const float* pPoint, float& fSquaredDistance, float*& pNeighbor);
65 
66  CKdTree* m_pKdTree;
67  int m_nKdTreeBucketSize;
68  std::vector<Eigen::Vector3f> m_aScenePoints, m_aObjectPoints;
69  float m_fCutoffDistance, m_fConvergenceDelta;
70  int m_nMaxIterations;
71 
72  int m_nNumScenePoints;
73  float** m_pValues;
74  };
75 }
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ICP::~ICP
~ICP()
Definition: ICP.cpp:45
visionx::ICP::GetNearestNeighbors
void GetNearestNeighbors(std::vector< Eigen::Vector3f > &aNeighbors, std::vector< float > &aPointMatchDistances)
Definition: ICP.cpp:234
visionx::ICP::ICP
ICP()
Definition: ICP.cpp:36
visionx::ICP::SearchObject
float SearchObject(Mat3d &mRotation, Vec3d &vTranslation, const float fBestDistanceUntilNow=FLT_MAX)
Definition: ICP.cpp:103
visionx::ICP::SetScenePointcloud
void SetScenePointcloud(const std::vector< Eigen::Vector3f > &aScenePoints)
Definition: ICP.cpp:57
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
visionx::ICP
Definition: ICP.h:36
visionx::ICP::SetParameters
void SetParameters(float fCutoffDistance=FLT_MAX, float fConvergenceDelta=0.001f, int nMaxIterations=40, int nKdTreeBucketSize=50)
Definition: ICP.cpp:206
visionx::ICP::GetPointMatchDistances
void GetPointMatchDistances(std::vector< float > &aPointMatchDistances)
Definition: ICP.cpp:214
visionx::ICP::SetObjectPointcloud
void SetObjectPointcloud(const std::vector< Eigen::Vector3f > &aObjectPoints)
Definition: ICP.cpp:94