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 <float.h>
29 
30 #include <Eigen/Core>
31 
32 class CKdTree;
33 
34 namespace visionx
35 {
36 
37  class ICP
38  {
39  public:
40  ICP();
41  ~ICP();
42 
43  // this is the pointcloud in which we search for an object
44  void SetScenePointcloud(const std::vector<Eigen::Vector3f>& aScenePoints);
45  // this is the pointcloud of the object we search
46  void SetObjectPointcloud(const std::vector<Eigen::Vector3f>& aObjectPoints);
47 
48  /* Estimate a transformation that fits the object pointcloud into the scene pointcloud
49  * returns the average point distance value (in weighted xyzrgb-space) after the match, and the transformation of the object
50  * 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) */
51  float SearchObject(Mat3d& mRotation,
52  Vec3d& vTranslation,
53  const float fBestDistanceUntilNow = FLT_MAX);
54 
55  /* Set the parameters:
56  * 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
57  * fConvergenceDelta=n: the algorithm stops when the relative improvement of the distance between the two clouds is less than n
58  * nMaxIterations=n: the algorithm stops after at most n iterations */
59  void SetParameters(float fCutoffDistance = FLT_MAX,
60  float fConvergenceDelta = 0.001f,
61  int nMaxIterations = 40,
62  int nKdTreeBucketSize = 50); // 50, FLT_MAX, 0.0001f, 50, 50
63 
64  // returns the distances of object points to their nearest neighbour in the scene
65  void GetPointMatchDistances(std::vector<float>& aPointMatchDistances);
66  void GetNearestNeighbors(std::vector<Eigen::Vector3f>& aNeighbors,
67  std::vector<float>& aPointMatchDistances);
68 
69  private:
70  void FindNNBruteForce(const float* pPoint, float& fSquaredDistance, float*& pNeighbor);
71 
72  CKdTree* m_pKdTree;
73  int m_nKdTreeBucketSize;
74  std::vector<Eigen::Vector3f> m_aScenePoints, m_aObjectPoints;
75  float m_fCutoffDistance, m_fConvergenceDelta;
76  int m_nMaxIterations;
77 
78  int m_nNumScenePoints;
79  float** m_pValues;
80  };
81 } // namespace visionx
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
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:255
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:107
visionx::ICP::SetScenePointcloud
void SetScenePointcloud(const std::vector< Eigen::Vector3f > &aScenePoints)
Definition: ICP.cpp:58
visionx::ICP
Definition: ICP.h:37
visionx::ICP::SetParameters
void SetParameters(float fCutoffDistance=FLT_MAX, float fConvergenceDelta=0.001f, int nMaxIterations=40, int nKdTreeBucketSize=50)
Definition: ICP.cpp:222
visionx::ICP::GetPointMatchDistances
void GetPointMatchDistances(std::vector< float > &aPointMatchDistances)
Definition: ICP.cpp:234
visionx::ICP::SetObjectPointcloud
void SetObjectPointcloud(const std::vector< Eigen::Vector3f > &aObjectPoints)
Definition: ICP.cpp:96