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 <float.h>
27 
28 #include "ObjectHypothesis.h"
29 #include <Math/Math3d.h>
30 
31 class CKdTree;
32 
33 class CColorICP
34 {
35 public:
37  {
38  float x, y, z, r, g, b, i;
39  };
40 
41  CColorICP();
42 
43  ~CColorICP();
44 
45  // this is the pointcloud in which we search for an object
46  void SetScenePointcloud(std::vector<CPointXYZRGBI> aScenePoints);
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(const std::vector<CPointXYZRGBI>& aObjectPoints,
52  Mat3d& mRotation,
53  Vec3d& vTranslation,
54  const float fBestDistanceUntilNow = FLT_MAX);
55 
56  // set the parameters:
57  // fColorWeight=n: a distance of 1 in color space will be weighted to be equivalent to a distance of n in cartesian space
58  // 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
59  // fConvergenceDelta=n: the algorithm stops when the relative improvement of the distance between the two clouds is less than n
60  // nMaxIterations=n: the algorithm stops after at most n iterations
61  void SetParameters(float fColorWeight = OLP_ICP_COLOR_DISTANCE_WEIGHT,
62  float fCutoffDistance = FLT_MAX,
63  float fConvergenceDelta = 0.01f,
64  int nMaxIterations = 30,
65  int nKdTreeBucketSize = 50); // 50, FLT_MAX, 0.0001f, 50, 50
66 
67  // returns the distances of object points to their nearest neighbour in the scene
68  void GetPointMatchDistances(const std::vector<CPointXYZRGBI>& aObjectPoints,
69  std::vector<float>& aPointMatchDistances);
70  void GetNearestNeighbors(const std::vector<CPointXYZRGBI>& aObjectPoints,
71  std::vector<CColorICP::CPointXYZRGBI>& aNeighbors,
72  std::vector<float>& aPointMatchDistances);
73 
76  static void TransformPointXYZRGBI(CPointXYZRGBI& pPoint, Mat3d mRotation, Vec3d vTranslation);
77 
78 private:
79  void FindNNBruteForce(const float* pPoint, float& fSquaredDistance, float*& pNeighbor);
80 
81  CKdTree* m_pKdTree;
82  int m_nKdTreeBucketSize;
83  std::vector<CPointXYZRGBI> m_aScenePoints;
84  float m_fColorWeight, m_fCutoffDistance, m_fConvergenceDelta;
85  int m_nMaxIterations;
86 
87  int m_nNumScenePoints;
88  float** m_pValues;
89 };
OLP_ICP_COLOR_DISTANCE_WEIGHT
#define OLP_ICP_COLOR_DISTANCE_WEIGHT
Definition: ObjectLearningByPushingDefinitions.h:252
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
ObjectHypothesis.h
CColorICP::CColorICP
CColorICP()
Definition: ColorICP.cpp:36
CColorICP::CPointXYZRGBI::x
float x
Definition: ColorICP.h:38
CColorICP::CPointXYZRGBI::y
float y
Definition: ColorICP.h:38
CColorICP::GetPointMatchDistances
void GetPointMatchDistances(const std::vector< CPointXYZRGBI > &aObjectPoints, std::vector< float > &aPointMatchDistances)
Definition: ColorICP.cpp:279
CColorICP::SetScenePointcloud
void SetScenePointcloud(std::vector< CPointXYZRGBI > aScenePoints)
Definition: ColorICP.cpp:58
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:238
CColorICP::SearchObject
float SearchObject(const std::vector< CPointXYZRGBI > &aObjectPoints, Mat3d &mRotation, Vec3d &vTranslation, const float fBestDistanceUntilNow=FLT_MAX)
Definition: ColorICP.cpp:109
CColorICP::CPointXYZRGBI::g
float g
Definition: ColorICP.h:38
CColorICP::CPointXYZRGBI::i
float i
Definition: ColorICP.h:38
CColorICP::CPointXYZRGBI::r
float r
Definition: ColorICP.h:38
CHypothesisPoint
Definition: ObjectHypothesis.h:166
CColorICP::GetNearestNeighbors
void GetNearestNeighbors(const std::vector< CPointXYZRGBI > &aObjectPoints, std::vector< CColorICP::CPointXYZRGBI > &aNeighbors, std::vector< float > &aPointMatchDistances)
Definition: ColorICP.cpp:305
CColorICP::CPointXYZRGBI
Definition: ColorICP.h:36
CColorICP::CPointXYZRGBI::b
float b
Definition: ColorICP.h:38
CColorICP::~CColorICP
~CColorICP()
Definition: ColorICP.cpp:45
CColorICP::ConvertToXYZRGBI
static CPointXYZRGBI ConvertToXYZRGBI(CHypothesisPoint *pPoint)
Definition: ColorICP.cpp:343
CColorICP::CPointXYZRGBI::z
float z
Definition: ColorICP.h:38
CColorICP
Definition: ColorICP.h:33
CColorICP::TransformPointXYZRGBI
static void TransformPointXYZRGBI(CPointXYZRGBI &pPoint, Mat3d mRotation, Vec3d vTranslation)
Definition: ColorICP.cpp:372
CColorICP::ConvertFromXYZRGBI
static CHypothesisPoint * ConvertFromXYZRGBI(CPointXYZRGBI pPoint)
Definition: ColorICP.cpp:358