PointToPlaneWithCov.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 <iostream>
37 
38 #include "Eigen/SVD"
39 
40 #include "ErrorMinimizersImpl.h"
41 #include "PointMatcherPrivate.h"
42 #include "Functions.h"
43 
44 using namespace Eigen;
45 using namespace std;
46 
52 
53 template<typename T>
56  sensorStdDev(Parametrizable::get<T>("sensorStdDev"))
57 {
58 }
59 
60 template<typename T>
62 {
63  ErrorElements mPts = mPts_const;
65 
66  this->covMatrix = this->estimateCovariance(mPts, out);
67 
68  return out;
69 }
70 
71 template<typename T>
74 {
75  const int max_nbr_point = mPts.reading.getNbPoints();
76 
77  Matrix covariance(Matrix::Zero(6,6));
78  Matrix J_hessian(Matrix::Zero(6,6));
79  Matrix d2J_dReadingdX(Matrix::Zero(6, max_nbr_point));
80  Matrix d2J_dReferencedX(Matrix::Zero(6, max_nbr_point));
81 
82  Vector reading_point(Vector::Zero(3));
83  Vector reference_point(Vector::Zero(3));
84  Vector normal(3);
85  Vector reading_direction(Vector::Zero(3));
86  Vector reference_direction(Vector::Zero(3));
87 
88  //TODO: should be constView
89  Matrix normals = mPts.reference.getDescriptorViewByName("normals");
90 
91  if (normals.rows() < 3) // Make sure there are normals in DataPoints
92  return std::numeric_limits<T>::max() * Matrix::Identity(6,6);
93 
94  T beta = -asin(transformation(2,0));
95  T alpha = atan2(transformation(2,1), transformation(2,2));
96  T gamma = atan2(transformation(1,0)/cos(beta), transformation(0,0)/cos(beta));
97  T t_x = transformation(0,3);
98  T t_y = transformation(1,3);
99  T t_z = transformation(2,3);
100 
101  Vector tmp_vector_6(Vector::Zero(6));
102 
103  int valid_points_count = 0;
104 
105  //TODO: add missing const
106  for(int i = 0; i < max_nbr_point; ++i)
107  {
108  //if (outlierWeights(0,i) > 0.0)
109  {
110  reading_point = mPts.reading.features.block(0,i,3,1);
111  //int reference_idx = matches.ids(0,i);
112  reference_point = mPts.reference.features.block(0,i,3,1);
113 
114  normal = normals.block(0,i,3,1);
115 
116  T reading_range = reading_point.norm();
117  reading_direction = reading_point / reading_range;
118  T reference_range = reference_point.norm();
119  reference_direction = reference_point / reference_range;
120 
121  T n_alpha = normal(2)*reading_direction(1) - normal(1)*reading_direction(2);
122  T n_beta = normal(0)*reading_direction(2) - normal(2)*reading_direction(0);
123  T n_gamma = normal(1)*reading_direction(0) - normal(0)*reading_direction(1);
124 
125  T E = normal(0)*(reading_point(0) - gamma*reading_point(1) + beta*reading_point(2) + t_x - reference_point(0));
126  E += normal(1)*(gamma*reading_point(0) + reading_point(1) - alpha*reading_point(2) + t_y - reference_point(1));
127  E += normal(2)*(-beta*reading_point(0) + alpha*reading_point(1) + reading_point(2) + t_z - reference_point(2));
128 
129  T N_reading = normal(0)*(reading_direction(0) - gamma*reading_direction(1) + beta*reading_direction(2));
130  N_reading += normal(1)*(gamma*reading_direction(0) + reading_direction(1) - alpha*reading_direction(2));
131  N_reading += normal(2)*(-beta*reading_direction(0) + alpha*reading_direction(1) + reading_direction(2));
132 
133  T N_reference = -(normal(0)*reference_direction(0) + normal(1)*reference_direction(1) + normal(2)*reference_direction(2));
134 
135  // update the hessian and d2J/dzdx
136  tmp_vector_6 << normal(0), normal(1), normal(2), reading_range * n_alpha, reading_range * n_beta, reading_range * n_gamma;
137 
138  J_hessian += tmp_vector_6 * tmp_vector_6.transpose();
139 
140  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);
141 
142  d2J_dReadingdX.block(0,valid_points_count,6,1) = tmp_vector_6;
143 
144  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;
145 
146  d2J_dReferencedX.block(0,valid_points_count,6,1) = tmp_vector_6;
147 
148  valid_points_count++;
149  } // if (outlierWeights(0,i) > 0.0)
150  }
151 
152  Matrix d2J_dZdX(Matrix::Zero(6, 2 * valid_points_count));
153  d2J_dZdX.block(0,0,6,valid_points_count) = d2J_dReadingdX.block(0,0,6,valid_points_count);
154  d2J_dZdX.block(0,valid_points_count,6,valid_points_count) = d2J_dReferencedX.block(0,0,6,valid_points_count);
155 
156  Matrix inv_J_hessian = J_hessian.inverse();
157 
158  covariance = d2J_dZdX * d2J_dZdX.transpose();
159  covariance = inv_J_hessian * covariance * inv_J_hessian;
160 
161  return (sensorStdDev * sensorStdDev) * covariance;
162 }
163 
164 
165 template<typename T>
167 {
168  return covMatrix;
169 }
170 
PointToPlaneWithCovErrorMinimizer::compute
virtual TransformationParameters compute(const ErrorElements &mPts)
Find the transformation that minimizes the error given matched pair of points. This function most be ...
Definition: PointToPlaneWithCov.cpp:61
PointToPlaneErrorMinimizer::Vector
PointMatcher< T >::Vector Vector
Definition: PointToPlane.h:56
PointToPlaneWithCovErrorMinimizer::getCovariance
virtual Matrix getCovariance() const
If not redefined by child class, return zero matrix.
Definition: PointToPlaneWithCov.cpp:166
build_map.T
T
Definition: build_map.py:34
PointToPlaneErrorMinimizer::TransformationParameters
PointMatcher< T >::TransformationParameters TransformationParameters
Definition: PointToPlane.h:55
PointMatcherPrivate.h
PointToPlaneWithCovErrorMinimizer::PointToPlaneWithCovErrorMinimizer
PointToPlaneWithCovErrorMinimizer(const Parameters &params=Parameters())
Definition: PointToPlaneWithCov.cpp:54
ParametersDoc
Parametrizable::ParametersDoc ParametersDoc
Definition: PointToPlaneWithCov.cpp:51
PointToPlaneErrorMinimizer::Matrix
PointMatcher< T >::Matrix Matrix
Definition: PointToPlane.h:57
ErrorMinimizersImpl.h
PointToPlaneWithCovErrorMinimizer::estimateCovariance
Matrix estimateCovariance(const ErrorElements &mPts, const TransformationParameters &transformation)
Definition: PointToPlaneWithCov.cpp:73
Parameters
Parametrizable::Parameters Parameters
Definition: PointToPlaneWithCov.cpp:49
PointMatcher::ErrorMinimizer::ErrorElements
A structure holding data ready for minimization. The data are "normalized", for instance there are no...
Definition: PointMatcher.h:534
ParameterDoc
Parametrizable::ParameterDoc ParameterDoc
Definition: PointToPlaneWithCov.cpp:50
PointMatcherSupport::Parametrizable::ParametersDoc
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
Definition: Parametrizable.h:187
PointToPlaneErrorMinimizer
Definition: PointToPlane.h:42
align_sequence.params
params
Definition: align_sequence.py:13
PointMatcher::Matrix
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dense matrix over ScalarType.
Definition: PointMatcher.h:169
PointMatcher::ErrorMinimizer::ErrorElements::reading
DataPoints reading
reading point cloud
Definition: PointMatcher.h:536
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:537
PointToPlaneWithCovErrorMinimizer
Definition: PointToPlaneWithCov.h:43
PointToPlaneErrorMinimizer::Parameters
Parametrizable::Parameters Parameters
Definition: PointToPlane.h:46
PointToPlaneErrorMinimizer::compute_in_place
TransformationParameters compute_in_place(ErrorElements &mPts)
Definition: PointToPlane.cpp:172
PointMatcherSupport::Parametrizable
The superclass of classes that are constructed using generic parameters. This class provides the para...
Definition: Parametrizable.h:141
std
PointMatcherSupport::get
const M::mapped_type & get(const M &m, const typename M::key_type &k)
Definition: Bibliography.cpp:57
PointMatcherSupport::Parametrizable::ParameterDoc
The documentation of a parameter.
Definition: Parametrizable.h:160
build_map.transformation
transformation
Definition: build_map.py:37
Functions.h
Parametrizable
PointMatcherSupport::Parametrizable Parametrizable
Definition: PointToPlaneWithCov.cpp:47
PointMatcher::DataPoints::getDescriptorViewByName
ConstView getDescriptorViewByName(const std::string &name) const
Get a const view on a descriptor by name, throw an exception if it does not exist.
Definition: pointmatcher/DataPoints.cpp:555
P
PointMatcherSupport::Parametrizable P
Definition: PointToPlaneWithCov.cpp:48
PointMatcherSupport::Parametrizable::Parameters
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
Definition: Parametrizable.h:199
PointMatcher::TransformationParameters
Matrix TransformationParameters
A matrix holding the parameters a transformation.
Definition: PointMatcher.h:182


libpointmatcher
Author(s):
autogenerated on Mon Sep 16 2024 02:24:10