ColorICP.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 
28 #include <float.h>
29 
30 #include "ObjectHypothesis.h"
31 
32 class CKdTree;
33 
34 
35 
36 class CColorICP
37 {
38 public:
39 
41  {
42  float x, y, z, r, g, b, i;
43  };
44 
45  CColorICP();
46 
47  ~CColorICP();
48 
49  // this is the pointcloud in which we search for an object
50  void SetScenePointcloud(std::vector<CPointXYZRGBI> aScenePoints);
51 
52  // estimate a transformation that fits the object pointcloud into the scene pointcloud
53  // returns the average point distance value (in weighted xyzrgb-space) after the match, and the transformation of the object
54  // 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)
55  float SearchObject(const std::vector<CPointXYZRGBI>& aObjectPoints, Mat3d& mRotation, Vec3d& vTranslation, const float fBestDistanceUntilNow = FLT_MAX);
56 
57  // set the parameters:
58  // fColorWeight=n: a distance of 1 in color space will be weighted to be equivalent to a distance of n in cartesian space
59  // 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
60  // fConvergenceDelta=n: the algorithm stops when the relative improvement of the distance between the two clouds is less than n
61  // nMaxIterations=n: the algorithm stops after at most n iterations
62  void SetParameters(float fColorWeight = OLP_ICP_COLOR_DISTANCE_WEIGHT, float fCutoffDistance = FLT_MAX, float fConvergenceDelta = 0.01f, int nMaxIterations = 30, 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(const std::vector<CPointXYZRGBI>& aObjectPoints, std::vector<float>& aPointMatchDistances);
66  void GetNearestNeighbors(const std::vector<CPointXYZRGBI>& aObjectPoints, std::vector<CColorICP::CPointXYZRGBI>& aNeighbors, std::vector<float>& aPointMatchDistances);
67 
70  static void TransformPointXYZRGBI(CPointXYZRGBI& pPoint, Mat3d mRotation, Vec3d vTranslation);
71 
72 private:
73 
74  void FindNNBruteForce(const float* pPoint, float& fSquaredDistance, float*& pNeighbor);
75 
76  CKdTree* m_pKdTree;
77  int m_nKdTreeBucketSize;
78  std::vector<CPointXYZRGBI> m_aScenePoints;
79  float m_fColorWeight, m_fCutoffDistance, m_fConvergenceDelta;
80  int m_nMaxIterations;
81 
82  int m_nNumScenePoints;
83  float** m_pValues;
84 };
85 
OLP_ICP_COLOR_DISTANCE_WEIGHT
#define OLP_ICP_COLOR_DISTANCE_WEIGHT
Definition: ObjectLearningByPushingDefinitions.h:238
ObjectHypothesis.h
CColorICP::CColorICP
CColorICP()
Definition: ColorICP.cpp:38
CColorICP::CPointXYZRGBI::x
float x
Definition: ColorICP.h:42
CColorICP::CPointXYZRGBI::y
float y
Definition: ColorICP.h:42
CColorICP::GetPointMatchDistances
void GetPointMatchDistances(const std::vector< CPointXYZRGBI > &aObjectPoints, std::vector< float > &aPointMatchDistances)
Definition: ColorICP.cpp:272
CColorICP::SetScenePointcloud
void SetScenePointcloud(std::vector< CPointXYZRGBI > aScenePoints)
Definition: ColorICP.cpp:63
CColorICP::SetParameters
void SetParameters(float fColorWeight=OLP_ICP_COLOR_DISTANCE_WEIGHT, float fCutoffDistance=FLT_MAX, float fConvergenceDelta=0.01f, int nMaxIterations=30, int nKdTreeBucketSize=50)
Definition: ColorICP.cpp:233
CColorICP::SearchObject
float SearchObject(const std::vector< CPointXYZRGBI > &aObjectPoints, Mat3d &mRotation, Vec3d &vTranslation, const float fBestDistanceUntilNow=FLT_MAX)
Definition: ColorICP.cpp:116
CColorICP::CPointXYZRGBI::g
float g
Definition: ColorICP.h:42
CColorICP::CPointXYZRGBI::i
float i
Definition: ColorICP.h:42
CColorICP::CPointXYZRGBI::r
float r
Definition: ColorICP.h:42
CHypothesisPoint
Definition: ObjectHypothesis.h:171
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
CColorICP::GetNearestNeighbors
void GetNearestNeighbors(const std::vector< CPointXYZRGBI > &aObjectPoints, std::vector< CColorICP::CPointXYZRGBI > &aNeighbors, std::vector< float > &aPointMatchDistances)
Definition: ColorICP.cpp:299
CColorICP::CPointXYZRGBI
Definition: ColorICP.h:40
CColorICP::CPointXYZRGBI::b
float b
Definition: ColorICP.h:42
CColorICP::~CColorICP
~CColorICP()
Definition: ColorICP.cpp:49
CColorICP::ConvertToXYZRGBI
static CPointXYZRGBI ConvertToXYZRGBI(CHypothesisPoint *pPoint)
Definition: ColorICP.cpp:335
CColorICP::CPointXYZRGBI::z
float z
Definition: ColorICP.h:42
CColorICP
Definition: ColorICP.h:36
CColorICP::TransformPointXYZRGBI
static void TransformPointXYZRGBI(CPointXYZRGBI &pPoint, Mat3d mRotation, Vec3d vTranslation)
Definition: ColorICP.cpp:365
CColorICP::ConvertFromXYZRGBI
static CHypothesisPoint * ConvertFromXYZRGBI(CPointXYZRGBI pPoint)
Definition: ColorICP.cpp:350