PandaRoot
icp.h
Go to the documentation of this file.
1 /*
2 Copyright 2011. All rights reserved.
3 Institute of Measurement and Control Systems
4 Karlsruhe Institute of Technology, Germany
5 
6 Authors: Andreas Geiger
7 
8 libicp is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or any later version.
11 
12 libicp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14 PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License along with
17 libicp; if not, write to the Free Software Foundation, Inc., 51 Franklin
18 Street, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20 
21 #ifndef ICP_H
22 #define ICP_H
23 
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <iostream>
28 #include <vector>
29 
30 #include "matrix.h"
31 #include "kdtree.h"
32 
33 class Icp {
34 
35  public:
36  // constructor
37  // input: M ....... pointer to first model point
38  // M_num ... number of model points
39  // dim ... dimensionality of model points (2 or 3)
40  Icp(double *M, const int32_t M_num, const int32_t dim);
41 
42  // deconstructor
43  virtual ~Icp();
44 
45  // if correspondences are clear (or given by default), the iterative process can worsen result. disable iterative portion of icp.
46  void forceInstantResult(bool val) { instantForce = val; }
47 
48  // return matrices even if no convergence achieved
50 
51  // set subsampling step size of coarse matching (1. stage)
52  void setSubsamplingStep(int32_t val) { sub_step = val; }
53 
54  // set maximum number of iterations (1. stopping criterion)
55  void setMaxIterations(int32_t val) { max_iter = val; }
56 
57  // set minimum delta of rot/trans parameters (2. stopping criterion)
58  void setMinDeltaParam(double val) { min_delta = val; }
59 
60  void setEventTimeCheck(bool val) { checkEventTime = val; }
61 
62  // fit template to model yielding R,t (M = R*T + t)
63  // input: T ....... pointer to first template point
64  // T_num ... number of template points
65  // R ....... initial rotation matrix
66  // t ....... initial translation vector
67  // indist .. inlier distance (if <=0: use all points)
68  // output: R ....... final rotation matrix
69  // t ....... final translation vector
70  double fit(double *T, const int32_t T_num, Matrix &R, Matrix &t, const double indist); // returns delta between the last two transfomartion matrices before termination
71 
72  // Euclidean fitness score. The lower the better, but if it returns 0, something wrong has happened.
73  double getFitnessScore();
74  double computeFitnessRMSE(const double *T, const Matrix &R, const Matrix &t);
75  double computeFitnessR2(const double *T, const Matrix &R, const Matrix &t);
76  bool hasConverged() { return hasConvergedBool; }
78 
79  private:
80  // iterative fitting
81  bool fitIterate(double *T, const int32_t T_num, Matrix &R, Matrix &t, const std::vector<int32_t> &active);
82 
83  virtual double fitInstant(double *T, const int32_t T_num, Matrix &R, Matrix &t, const std::vector<int32_t> &active) = 0;
84 
85  // inherited classes need to overwrite these functions
86  virtual double fitStep(double *T, const int32_t T_num, Matrix &R, Matrix &t, const std::vector<int32_t> &active) = 0;
87  virtual std::vector<int32_t> getInliers(double *T, const int32_t T_num, const Matrix &R, const Matrix &t, const double indist) = 0;
88 
89  protected:
90  // kd tree of model points
93  double *M_;
94 
95  int32_t dim; // dimensionality of model + template data (2 or 3)
96  int32_t sub_step; // subsampling step size
97  int32_t max_iter; // max number of iterations
100  double min_delta; // min parameter delta
102  double euclidean_fitness; // fitness score for error estimation
107 };
108 
109 #endif // ICP_H
int32_t dim
Definition: icp.h:95
boost::multi_array< double, 2 > KDTreeArray
Definition: kdtree.h:20
double computeFitnessR2(const double *T, const Matrix &R, const Matrix &t)
void setMaxIterations(int32_t val)
Definition: icp.h:55
bool checkEventTime
Definition: icp.h:104
double * M_
Definition: icp.h:93
double euclidean_fitness
Definition: icp.h:102
void setMinDeltaParam(double val)
Definition: icp.h:58
virtual ~Icp()
int32_t sub_step
Definition: icp.h:96
bool hasConverged()
Definition: icp.h:76
int int32_t
Definition: matrix.h:32
int32_t T_num
Definition: icp.h:98
Icp(double *M, const int32_t M_num, const int32_t dim)
double fit(double *T, const int32_t T_num, Matrix &R, Matrix &t, const double indist)
void setEventTimeCheck(bool val)
Definition: icp.h:60
void setSubsamplingStep(int32_t val)
Definition: icp.h:52
Definition: matrix.h:50
kdtree::KDTreeArray M_data
Definition: icp.h:92
kdtree::KDTree * M_tree
Definition: icp.h:91
double current_delta
Definition: icp.h:101
bool giveOutputIfNotConvergedB
Definition: icp.h:105
bool hasConvergedBool
Definition: icp.h:103
Definition: icp.h:33
int32_t getInterations()
Definition: icp.h:77
void forceInstantResult(bool val)
Definition: icp.h:46
bool instantForce
Definition: icp.h:106
double min_delta
Definition: icp.h:100
void giveOutputIfNotConverged(bool val)
Definition: icp.h:49
int32_t max_iter
Definition: icp.h:97
double getFitnessScore()
int32_t iterations
Definition: icp.h:99
double computeFitnessRMSE(const double *T, const Matrix &R, const Matrix &t)