FairRoot/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 
37  // constructor
38  // input: M ....... pointer to first model point
39  // M_num ... number of model points
40  // dim ... dimensionality of model points (2 or 3)
41  Icp (double *M,const int32_t M_num,const int32_t dim);
42 
43  // deconstructor
44  virtual ~Icp ();
45 
46  //if correspondences are clear (or given by default), the iterative process can worsen result. disable iterative portion of icp.
48 
49  //return matrices even if no convergence achieved
51 
52  // set subsampling step size of coarse matching (1. stage)
54 
55  // set maximum number of iterations (1. stopping criterion)
57 
58  // set minimum delta of rot/trans parameters (2. stopping criterion)
59  void setMinDeltaParam (double val) { min_delta = val; }
60 
62 
63  // fit template to model yielding R,t (M = R*T + t)
64  // input: T ....... pointer to first template point
65  // T_num ... number of template points
66  // R ....... initial rotation matrix
67  // t ....... initial translation vector
68  // indist .. inlier distance (if <=0: use all points)
69  // output: R ....... final rotation matrix
70  // t ....... final translation vector
71  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
72 
73  //Euclidean fitness score. The lower the better, but if it returns 0, something wrong has happened.
74  double getFitnessScore();
75  double computeFitnessRMSE(const double *T, const Matrix &R,const Matrix &t);
76  double computeFitnessR2(const double *T, const Matrix &R,const Matrix &t);
77  bool hasConverged(){
78  return hasConvergedBool;
79  }
81  return iterations;
82  }
83 
84 private:
85 
86  // iterative fitting
87  bool fitIterate(double *T,const int32_t T_num,Matrix &R,Matrix &t,const std::vector<int32_t> &active);
88 
89  virtual double fitInstant(double *T,const int32_t T_num,Matrix &R,Matrix &t,const std::vector<int32_t> &active) = 0;
90 
91  // inherited classes need to overwrite these functions
92  virtual double fitStep(double *T,const int32_t T_num,Matrix &R,Matrix &t,const std::vector<int32_t> &active) = 0;
93  virtual std::vector<int32_t> getInliers(double *T,const int32_t T_num,const Matrix &R,const Matrix &t,const double indist) = 0;
94 
95 protected:
96 
97  // kd tree of model points
100  double* M_;
101 
102  int32_t dim; // dimensionality of model + template data (2 or 3)
103  int32_t sub_step; // subsampling step size
104  int32_t max_iter; // max number of iterations
107  double min_delta; // min parameter delta
109  double euclidean_fitness; //fitness score for error estimation
114 };
115 
116 #endif // ICP_H
int32_t dim
Definition: icp.h:102
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:56
virtual double fitInstant(double *T, const int32_t T_num, Matrix &R, Matrix &t, const std::vector< int32_t > &active)=0
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
bool checkEventTime
Definition: icp.h:111
bool fitIterate(double *T, const int32_t T_num, Matrix &R, Matrix &t, const std::vector< int32_t > &active)
double * M_
Definition: icp.h:100
double euclidean_fitness
Definition: icp.h:109
void setMinDeltaParam(double val)
Definition: icp.h:59
virtual ~Icp()
virtual std::vector< int32_t > getInliers(double *T, const int32_t T_num, const Matrix &R, const Matrix &t, const double indist)=0
int32_t sub_step
Definition: icp.h:103
virtual double fitStep(double *T, const int32_t T_num, Matrix &R, Matrix &t, const std::vector< int32_t > &active)=0
bool hasConverged()
Definition: icp.h:77
int int32_t
Definition: matrix.h:32
TTree * T
Definition: anaLmdReco.C:32
int32_t T_num
Definition: icp.h:105
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:61
void setSubsamplingStep(int32_t val)
Definition: icp.h:53
Definition: matrix.h:50
kdtree::KDTreeArray M_data
Definition: icp.h:99
kdtree::KDTree * M_tree
Definition: icp.h:98
double current_delta
Definition: icp.h:108
bool giveOutputIfNotConvergedB
Definition: icp.h:112
bool hasConvergedBool
Definition: icp.h:110
TTree * t
Definition: bump_analys.C:13
Definition: icp.h:33
int32_t getInterations()
Definition: icp.h:80
void forceInstantResult(bool val)
Definition: icp.h:47
bool instantForce
Definition: icp.h:113
double min_delta
Definition: icp.h:107
Double_t R
Definition: checkhelixhit.C:61
void giveOutputIfNotConverged(bool val)
Definition: icp.h:50
int32_t max_iter
Definition: icp.h:104
double getFitnessScore()
int32_t iterations
Definition: icp.h:106
double computeFitnessRMSE(const double *T, const Matrix &R, const Matrix &t)