PointToPointWithCov.cpp
Go to the documentation of this file.
1 // kate: replace-tabs off; indent-width 4; indent-mode normal
2 // vim: ts=4:sw=4:noexpandtab
3 /*
4 
5 Copyright (c) 2010--2012,
6 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
7 You can contact the authors at <f dot pomerleau at gmail dot com> and
8 <stephane at magnenat dot net>
9 
10 All rights reserved.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in the
18  documentation and/or other materials provided with the distribution.
19  * Neither the name of the <organization> nor the
20  names of its contributors may be used to endorse or promote products
21  derived from this software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
27 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "ErrorMinimizersImpl.h"
37 #include "PointMatcherPrivate.h"
38 #include "Eigen/SVD"
39 
40 using namespace Eigen;
41 
42 template<typename T>
44  PointToPointErrorMinimizer<T>("PointToPointWithCovErrorMinimizer", availableParameters(), params),
45  sensorStdDev(Parametrizable::get<T>("sensorStdDev"))
46 {
47 }
48 
49 template<typename T>
51 {
52  ErrorElements mPts = mPts_const;
54 
55  this->covMatrix = this->estimateCovariance(mPts, result);
56 
57  return result;
58 }
59 
60 //TODO: rewrite this using ErrorElements struct
61 template<typename T>
63 {
64  const int max_nbr_point = mPts.reading.getNbPoints();
65 
66  Matrix covariance(Matrix::Zero(6,6));
67  Matrix J_hessian(Matrix::Zero(6,6));
68  Matrix d2J_dReadingdX(Matrix::Zero(6, max_nbr_point));
69  Matrix d2J_dReferencedX(Matrix::Zero(6, max_nbr_point));
70 
71  Vector reading_point(Vector::Zero(3));
72  Vector reference_point(Vector::Zero(3));
73  Vector normal(3);
74  Vector reading_direction(Vector::Zero(3));
75  Vector reference_direction(Vector::Zero(3));
76 
77  normal << 1.0, 1.0, 1.0; // Used for point-to-point computation
78 
79  T beta = -asin(transformation(2,0));
80  T alpha = atan2(transformation(2,1), transformation(2,2));
81  T gamma = atan2(transformation(1,0)/cos(beta), transformation(0,0)/cos(beta));
82  T t_x = transformation(0,3);
83  T t_y = transformation(1,3);
84  T t_z = transformation(2,3);
85 
86  Vector tmp_vector_6(Vector::Zero(6));
87 
88  int valid_points_count = 0;
89 
90  //TODO: add missing const
91  for(int i = 0; i < max_nbr_point; ++i)
92  {
93  //if (outlierWeights(0,i) > 0.0)
94  {
95  reading_point = mPts.reading.features.block(0,i,3,1);
96  //int reference_idx = matches.ids(0,i);
97  reference_point = mPts.reference.features.block(0,i,3,1);
98 
99  T reading_range = reading_point.norm();
100  reading_direction = reading_point / reading_range;
101  T reference_range = reference_point.norm();
102  reference_direction = reference_point / reference_range;
103 
104  T n_alpha = normal(2)*reading_direction(1) - normal(1)*reading_direction(2);
105  T n_beta = normal(0)*reading_direction(2) - normal(2)*reading_direction(0);
106  T n_gamma = normal(1)*reading_direction(0) - normal(0)*reading_direction(1);
107 
108  T E = normal(0)*(reading_point(0) - gamma*reading_point(1) + beta*reading_point(2) + t_x - reference_point(0));
109  E += normal(1)*(gamma*reading_point(0) + reading_point(1) - alpha*reading_point(2) + t_y - reference_point(1));
110  E += normal(2)*(-beta*reading_point(0) + alpha*reading_point(1) + reading_point(2) + t_z - reference_point(2));
111 
112  T N_reading = normal(0)*(reading_direction(0) - gamma*reading_direction(1) + beta*reading_direction(2));
113  N_reading += normal(1)*(gamma*reading_direction(0) + reading_direction(1) - alpha*reading_direction(2));
114  N_reading += normal(2)*(-beta*reading_direction(0) + alpha*reading_direction(1) + reading_direction(2));
115 
116  T N_reference = -(normal(0)*reference_direction(0) + normal(1)*reference_direction(1) + normal(2)*reference_direction(2));
117 
118  // update the hessian and d2J/dzdx
119  tmp_vector_6 << normal(0), normal(1), normal(2), reading_range * n_alpha, reading_range * n_beta, reading_range * n_gamma;
120 
121  J_hessian += tmp_vector_6 * tmp_vector_6.transpose();
122 
123  tmp_vector_6 << normal(0) * N_reading, normal(1) * N_reading, normal(2) * N_reading, n_alpha * (E + reading_range * N_reading), n_beta * (E + reading_range * N_reading), n_gamma * (E + reading_range * N_reading);
124 
125  d2J_dReadingdX.block(0,valid_points_count,6,1) = tmp_vector_6;
126 
127  tmp_vector_6 << normal(0) * N_reference, normal(1) * N_reference, normal(2) * N_reference, reference_range * n_alpha * N_reference, reference_range * n_beta * N_reference, reference_range * n_gamma * N_reference;
128 
129  d2J_dReferencedX.block(0,valid_points_count,6,1) = tmp_vector_6;
130 
131  valid_points_count++;
132  } // if (outlierWeights(0,i) > 0.0)
133  }
134 
135  Matrix d2J_dZdX(Matrix::Zero(6, 2 * valid_points_count));
136  d2J_dZdX.block(0,0,6,valid_points_count) = d2J_dReadingdX.block(0,0,6,valid_points_count);
137  d2J_dZdX.block(0,valid_points_count,6,valid_points_count) = d2J_dReferencedX.block(0,0,6,valid_points_count);
138 
139  Matrix inv_J_hessian = J_hessian.inverse();
140 
141  covariance = d2J_dZdX * d2J_dZdX.transpose();
142  covariance = inv_J_hessian * covariance * inv_J_hessian;
143 
144  return (sensorStdDev * sensorStdDev) * covariance;
145 }
146 
147 template<typename T>
149 {
150  return covMatrix;
151 }
152 
PointToPointWithCovErrorMinimizer::estimateCovariance
Matrix estimateCovariance(const ErrorElements &mPts, const TransformationParameters &transformation)
Definition: PointToPointWithCov.cpp:62
PointToPointWithCovErrorMinimizer::PointToPointWithCovErrorMinimizer
PointToPointWithCovErrorMinimizer(const Parameters &params=Parameters())
Definition: PointToPointWithCov.cpp:43
PointToPointErrorMinimizer::Matrix
PointMatcher< T >::Matrix Matrix
Definition: PointToPoint.h:54
PointToPointWithCovErrorMinimizer::getCovariance
virtual Matrix getCovariance() const
If not redefined by child class, return zero matrix.
Definition: PointToPointWithCov.cpp:148
PointMatcherPrivate.h
ErrorMinimizersImpl.h
PointToPointWithCovErrorMinimizer::compute
virtual TransformationParameters compute(const ErrorElements &mPts)
Find the transformation that minimizes the error given matched pair of points. This function most be ...
Definition: PointToPointWithCov.cpp:50
mp2p_icp::covariance
mrpt::math::CMatrixDouble66 covariance(const Pairings &finalPairings, const mrpt::poses::CPose3D &finalAlignSolution, const CovarianceParameters &p)
Definition: covariance.cpp:22
PointMatcher::ErrorMinimizer::ErrorElements
A structure holding data ready for minimization. The data are "normalized", for instance there are no...
Definition: PointMatcher.h:530
PointMatcher::ErrorMinimizer::ErrorElements::reading
DataPoints reading
reading point cloud
Definition: PointMatcher.h:532
PointMatcher::DataPoints::getNbPoints
unsigned getNbPoints() const
Return the number of points contained in the point cloud.
Definition: pointmatcher/DataPoints.cpp:158
PointMatcher::DataPoints::features
Matrix features
features of points in the cloud
Definition: PointMatcher.h:331
PointMatcher::ErrorMinimizer::ErrorElements::reference
DataPoints reference
reference point cloud
Definition: PointMatcher.h:533
PointToPointErrorMinimizer::Vector
PointMatcher< T >::Vector Vector
Definition: PointToPoint.h:53
PointMatcherSupport::Parametrizable
The superclass of classes that are constructed using generic parameters. This class provides the para...
Definition: Parametrizable.h:98
PointMatcherSupport::get
const M::mapped_type & get(const M &m, const typename M::key_type &k)
Definition: Bibliography.cpp:57
PointToPointErrorMinimizer::TransformationParameters
PointMatcher< T >::TransformationParameters TransformationParameters
Definition: PointToPoint.h:48
PointToPointErrorMinimizer::compute_in_place
TransformationParameters compute_in_place(ErrorElements &mPts)
Definition: PointToPoint.cpp:62
PointToPointErrorMinimizer
Definition: PointToPoint.h:42
PointToPointWithCovErrorMinimizer
Definition: PointToPointWithCov.h:43
PointToPointWithCovErrorMinimizer::Matrix
PointMatcher< T >::Matrix Matrix
Definition: PointToPointWithCov.h:50
PointToPointErrorMinimizer::Parameters
Parametrizable::Parameters Parameters
Definition: PointToPoint.h:45
PointMatcher::TransformationParameters
Matrix TransformationParameters
A matrix holding the parameters a transformation.
Definition: PointMatcher.h:182


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:59