Point Cloud Library (PCL)  1.9.1-dev
gicp.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
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
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 #ifndef PCL_REGISTRATION_IMPL_GICP_HPP_
41 #define PCL_REGISTRATION_IMPL_GICP_HPP_
42 
43 #include <pcl/registration/boost.h>
44 #include <pcl/registration/exceptions.h>
45 
46 ////////////////////////////////////////////////////////////////////////////////////////
47 template <typename PointSource, typename PointTarget>
48 template<typename PointT> void
50  const typename pcl::search::KdTree<PointT>::Ptr kdtree,
51  MatricesVector& cloud_covariances)
52 {
53  if (k_correspondences_ > int (cloud->size ()))
54  {
55  PCL_ERROR ("[pcl::GeneralizedIterativeClosestPoint::computeCovariances] Number or points in cloud (%lu) is less than k_correspondences_ (%lu)!\n", cloud->size (), k_correspondences_);
56  return;
57  }
58 
59  Eigen::Vector3d mean;
60  std::vector<int> nn_indecies; nn_indecies.reserve (k_correspondences_);
61  std::vector<float> nn_dist_sq; nn_dist_sq.reserve (k_correspondences_);
62 
63  // We should never get there but who knows
64  if(cloud_covariances.size () < cloud->size ())
65  cloud_covariances.resize (cloud->size ());
66 
67  MatricesVector::iterator matrices_iterator = cloud_covariances.begin ();
68  for(auto points_iterator = cloud->begin ();
69  points_iterator != cloud->end ();
70  ++points_iterator, ++matrices_iterator)
71  {
72  const PointT &query_point = *points_iterator;
73  Eigen::Matrix3d &cov = *matrices_iterator;
74  // Zero out the cov and mean
75  cov.setZero ();
76  mean.setZero ();
77 
78  // Search for the K nearest neighbours
79  kdtree->nearestKSearch(query_point, k_correspondences_, nn_indecies, nn_dist_sq);
80 
81  // Find the covariance matrix
82  for(int j = 0; j < k_correspondences_; j++) {
83  const PointT &pt = (*cloud)[nn_indecies[j]];
84 
85  mean[0] += pt.x;
86  mean[1] += pt.y;
87  mean[2] += pt.z;
88 
89  cov(0,0) += pt.x*pt.x;
90 
91  cov(1,0) += pt.y*pt.x;
92  cov(1,1) += pt.y*pt.y;
93 
94  cov(2,0) += pt.z*pt.x;
95  cov(2,1) += pt.z*pt.y;
96  cov(2,2) += pt.z*pt.z;
97  }
98 
99  mean /= static_cast<double> (k_correspondences_);
100  // Get the actual covariance
101  for (int k = 0; k < 3; k++)
102  for (int l = 0; l <= k; l++)
103  {
104  cov(k,l) /= static_cast<double> (k_correspondences_);
105  cov(k,l) -= mean[k]*mean[l];
106  cov(l,k) = cov(k,l);
107  }
108 
109  // Compute the SVD (covariance matrix is symmetric so U = V')
110  Eigen::JacobiSVD<Eigen::Matrix3d> svd(cov, Eigen::ComputeFullU);
111  cov.setZero ();
112  Eigen::Matrix3d U = svd.matrixU ();
113  // Reconstitute the covariance matrix with modified singular values using the column // vectors in V.
114  for(int k = 0; k < 3; k++) {
115  Eigen::Vector3d col = U.col(k);
116  double v = 1.; // biggest 2 singular values replaced by 1
117  if(k == 2) // smallest singular value replaced by gicp_epsilon
118  v = gicp_epsilon_;
119  cov+= v * col * col.transpose();
120  }
121  }
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////////////
125 template <typename PointSource, typename PointTarget> void
127 {
128  Eigen::Matrix3d dR_dPhi;
129  Eigen::Matrix3d dR_dTheta;
130  Eigen::Matrix3d dR_dPsi;
131 
132  double phi = x[3], theta = x[4], psi = x[5];
133 
134  double cphi = std::cos(phi), sphi = sin(phi);
135  double ctheta = std::cos(theta), stheta = sin(theta);
136  double cpsi = std::cos(psi), spsi = sin(psi);
137 
138  dR_dPhi(0,0) = 0.;
139  dR_dPhi(1,0) = 0.;
140  dR_dPhi(2,0) = 0.;
141 
142  dR_dPhi(0,1) = sphi*spsi + cphi*cpsi*stheta;
143  dR_dPhi(1,1) = -cpsi*sphi + cphi*spsi*stheta;
144  dR_dPhi(2,1) = cphi*ctheta;
145 
146  dR_dPhi(0,2) = cphi*spsi - cpsi*sphi*stheta;
147  dR_dPhi(1,2) = -cphi*cpsi - sphi*spsi*stheta;
148  dR_dPhi(2,2) = -ctheta*sphi;
149 
150  dR_dTheta(0,0) = -cpsi*stheta;
151  dR_dTheta(1,0) = -spsi*stheta;
152  dR_dTheta(2,0) = -ctheta;
153 
154  dR_dTheta(0,1) = cpsi*ctheta*sphi;
155  dR_dTheta(1,1) = ctheta*sphi*spsi;
156  dR_dTheta(2,1) = -sphi*stheta;
157 
158  dR_dTheta(0,2) = cphi*cpsi*ctheta;
159  dR_dTheta(1,2) = cphi*ctheta*spsi;
160  dR_dTheta(2,2) = -cphi*stheta;
161 
162  dR_dPsi(0,0) = -ctheta*spsi;
163  dR_dPsi(1,0) = cpsi*ctheta;
164  dR_dPsi(2,0) = 0.;
165 
166  dR_dPsi(0,1) = -cphi*cpsi - sphi*spsi*stheta;
167  dR_dPsi(1,1) = -cphi*spsi + cpsi*sphi*stheta;
168  dR_dPsi(2,1) = 0.;
169 
170  dR_dPsi(0,2) = cpsi*sphi - cphi*spsi*stheta;
171  dR_dPsi(1,2) = sphi*spsi + cphi*cpsi*stheta;
172  dR_dPsi(2,2) = 0.;
173 
174  g[3] = matricesInnerProd(dR_dPhi, R);
175  g[4] = matricesInnerProd(dR_dTheta, R);
176  g[5] = matricesInnerProd(dR_dPsi, R);
177 }
178 
179 ////////////////////////////////////////////////////////////////////////////////////////
180 template <typename PointSource, typename PointTarget> void
182  const std::vector<int> &indices_src,
183  const PointCloudTarget &cloud_tgt,
184  const std::vector<int> &indices_tgt,
185  Eigen::Matrix4f &transformation_matrix)
186 {
187  if (indices_src.size () < 4) // need at least 4 samples
188  {
189  PCL_THROW_EXCEPTION (NotEnoughPointsException,
190  "[pcl::GeneralizedIterativeClosestPoint::estimateRigidTransformationBFGS] Need at least 4 points to estimate a transform! Source and target have " << indices_src.size () << " points!");
191  return;
192  }
193  // Set the initial solution
194  Vector6d x = Vector6d::Zero ();
195  x[0] = transformation_matrix (0,3);
196  x[1] = transformation_matrix (1,3);
197  x[2] = transformation_matrix (2,3);
198  x[3] = std::atan2 (transformation_matrix (2,1), transformation_matrix (2,2));
199  x[4] = asin (-transformation_matrix (2,0));
200  x[5] = std::atan2 (transformation_matrix (1,0), transformation_matrix (0,0));
201 
202  // Set temporary pointers
203  tmp_src_ = &cloud_src;
204  tmp_tgt_ = &cloud_tgt;
205  tmp_idx_src_ = &indices_src;
206  tmp_idx_tgt_ = &indices_tgt;
207 
208  // Optimize using forward-difference approximation LM
209  const double gradient_tol = 1e-2;
210  OptimizationFunctorWithIndices functor(this);
212  bfgs.parameters.sigma = 0.01;
213  bfgs.parameters.rho = 0.01;
214  bfgs.parameters.tau1 = 9;
215  bfgs.parameters.tau2 = 0.05;
216  bfgs.parameters.tau3 = 0.5;
217  bfgs.parameters.order = 3;
218 
219  int inner_iterations_ = 0;
220  int result = bfgs.minimizeInit (x);
221  result = BFGSSpace::Running;
222  do
223  {
224  inner_iterations_++;
225  result = bfgs.minimizeOneStep (x);
226  if(result)
227  {
228  break;
229  }
230  result = bfgs.testGradient(gradient_tol);
231  } while(result == BFGSSpace::Running && inner_iterations_ < max_inner_iterations_);
232  if(result == BFGSSpace::NoProgress || result == BFGSSpace::Success || inner_iterations_ == max_inner_iterations_)
233  {
234  PCL_DEBUG ("[pcl::registration::TransformationEstimationBFGS::estimateRigidTransformation]");
235  PCL_DEBUG ("BFGS solver finished with exit code %i \n", result);
236  transformation_matrix.setIdentity();
237  applyState(transformation_matrix, x);
238  }
239  else
240  PCL_THROW_EXCEPTION(SolverDidntConvergeException,
241  "[pcl::" << getClassName () << "::TransformationEstimationBFGS::estimateRigidTransformation] BFGS solver didn't converge!");
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////////////
245 template <typename PointSource, typename PointTarget> inline double
247 {
248  Eigen::Matrix4f transformation_matrix = gicp_->base_transformation_;
249  gicp_->applyState(transformation_matrix, x);
250  double f = 0;
251  int m = static_cast<int> (gicp_->tmp_idx_src_->size ());
252  for (int i = 0; i < m; ++i)
253  {
254  // The last coordinate, p_src[3] is guaranteed to be set to 1.0 in registration.hpp
255  Vector4fMapConst p_src = gicp_->tmp_src_->points[(*gicp_->tmp_idx_src_)[i]].getVector4fMap ();
256  // The last coordinate, p_tgt[3] is guaranteed to be set to 1.0 in registration.hpp
257  Vector4fMapConst p_tgt = gicp_->tmp_tgt_->points[(*gicp_->tmp_idx_tgt_)[i]].getVector4fMap ();
258  Eigen::Vector4f pp (transformation_matrix * p_src);
259  // Estimate the distance (cost function)
260  // The last coordinate is still guaranteed to be set to 1.0
261  Eigen::Vector3d res(pp[0] - p_tgt[0], pp[1] - p_tgt[1], pp[2] - p_tgt[2]);
262  Eigen::Vector3d temp (gicp_->mahalanobis((*gicp_->tmp_idx_src_)[i]) * res);
263  //increment= res'*temp/num_matches = temp'*M*temp/num_matches (we postpone 1/num_matches after the loop closes)
264  f+= double(res.transpose() * temp);
265  }
266  return f/m;
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////////////
270 template <typename PointSource, typename PointTarget> inline void
272 {
273  Eigen::Matrix4f transformation_matrix = gicp_->base_transformation_;
274  gicp_->applyState(transformation_matrix, x);
275  //Zero out g
276  g.setZero ();
277  //Eigen::Vector3d g_t = g.head<3> ();
278  Eigen::Matrix3d R = Eigen::Matrix3d::Zero ();
279  int m = static_cast<int> (gicp_->tmp_idx_src_->size ());
280  for (int i = 0; i < m; ++i)
281  {
282  // The last coordinate, p_src[3] is guaranteed to be set to 1.0 in registration.hpp
283  Vector4fMapConst p_src = gicp_->tmp_src_->points[(*gicp_->tmp_idx_src_)[i]].getVector4fMap ();
284  // The last coordinate, p_tgt[3] is guaranteed to be set to 1.0 in registration.hpp
285  Vector4fMapConst p_tgt = gicp_->tmp_tgt_->points[(*gicp_->tmp_idx_tgt_)[i]].getVector4fMap ();
286 
287  Eigen::Vector4f pp (transformation_matrix * p_src);
288  // The last coordinate is still guaranteed to be set to 1.0
289  Eigen::Vector3d res (pp[0] - p_tgt[0], pp[1] - p_tgt[1], pp[2] - p_tgt[2]);
290  // temp = M*res
291  Eigen::Vector3d temp (gicp_->mahalanobis ((*gicp_->tmp_idx_src_)[i]) * res);
292  // Increment translation gradient
293  // g.head<3> ()+= 2*M*res/num_matches (we postpone 2/num_matches after the loop closes)
294  g.head<3> ()+= temp;
295  // Increment rotation gradient
296  pp = gicp_->base_transformation_ * p_src;
297  Eigen::Vector3d p_src3 (pp[0], pp[1], pp[2]);
298  R+= p_src3 * temp.transpose();
299  }
300  g.head<3> ()*= 2.0/m;
301  R*= 2.0/m;
302  gicp_->computeRDerivative(x, R, g);
303 }
304 
305 ////////////////////////////////////////////////////////////////////////////////////////
306 template <typename PointSource, typename PointTarget> inline void
308 {
309  Eigen::Matrix4f transformation_matrix = gicp_->base_transformation_;
310  gicp_->applyState(transformation_matrix, x);
311  f = 0;
312  g.setZero ();
313  Eigen::Matrix3d R = Eigen::Matrix3d::Zero ();
314  const int m = static_cast<const int> (gicp_->tmp_idx_src_->size ());
315  for (int i = 0; i < m; ++i)
316  {
317  // The last coordinate, p_src[3] is guaranteed to be set to 1.0 in registration.hpp
318  Vector4fMapConst p_src = gicp_->tmp_src_->points[(*gicp_->tmp_idx_src_)[i]].getVector4fMap ();
319  // The last coordinate, p_tgt[3] is guaranteed to be set to 1.0 in registration.hpp
320  Vector4fMapConst p_tgt = gicp_->tmp_tgt_->points[(*gicp_->tmp_idx_tgt_)[i]].getVector4fMap ();
321  Eigen::Vector4f pp (transformation_matrix * p_src);
322  // The last coordinate is still guaranteed to be set to 1.0
323  Eigen::Vector3d res (pp[0] - p_tgt[0], pp[1] - p_tgt[1], pp[2] - p_tgt[2]);
324  // temp = M*res
325  Eigen::Vector3d temp (gicp_->mahalanobis((*gicp_->tmp_idx_src_)[i]) * res);
326  // Increment total error
327  f+= double(res.transpose() * temp);
328  // Increment translation gradient
329  // g.head<3> ()+= 2*M*res/num_matches (we postpone 2/num_matches after the loop closes)
330  g.head<3> ()+= temp;
331  pp = gicp_->base_transformation_ * p_src;
332  Eigen::Vector3d p_src3 (pp[0], pp[1], pp[2]);
333  // Increment rotation gradient
334  R+= p_src3 * temp.transpose();
335  }
336  f/= double(m);
337  g.head<3> ()*= double(2.0/m);
338  R*= 2.0/m;
339  gicp_->computeRDerivative(x, R, g);
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////////////
343 template <typename PointSource, typename PointTarget> inline void
345 {
347  using namespace std;
348  // Difference between consecutive transforms
349  double delta = 0;
350  // Get the size of the target
351  const size_t N = indices_->size ();
352  // Set the mahalanobis matrices to identity
353  mahalanobis_.resize (N, Eigen::Matrix3d::Identity ());
354  // Compute target cloud covariance matrices
355  if ((!target_covariances_) || (target_covariances_->empty ()))
356  {
357  target_covariances_.reset (new MatricesVector);
358  computeCovariances<PointTarget> (target_, tree_, *target_covariances_);
359  }
360  // Compute input cloud covariance matrices
361  if ((!input_covariances_) || (input_covariances_->empty ()))
362  {
364  computeCovariances<PointSource> (input_, tree_reciprocal_, *input_covariances_);
365  }
366 
367  base_transformation_ = Eigen::Matrix4f::Identity();
368  nr_iterations_ = 0;
369  converged_ = false;
370  double dist_threshold = corr_dist_threshold_ * corr_dist_threshold_;
371  std::vector<int> nn_indices (1);
372  std::vector<float> nn_dists (1);
373 
374  pcl::transformPointCloud(output, output, guess);
375 
376  while(!converged_)
377  {
378  size_t cnt = 0;
379  std::vector<int> source_indices (indices_->size ());
380  std::vector<int> target_indices (indices_->size ());
381 
382  // guess corresponds to base_t and transformation_ to t
383  Eigen::Matrix4d transform_R = Eigen::Matrix4d::Zero ();
384  for(size_t i = 0; i < 4; i++)
385  for(size_t j = 0; j < 4; j++)
386  for(size_t k = 0; k < 4; k++)
387  transform_R(i,j)+= double(transformation_(i,k)) * double(guess(k,j));
388 
389  Eigen::Matrix3d R = transform_R.topLeftCorner<3,3> ();
390 
391  for (size_t i = 0; i < N; i++)
392  {
393  PointSource query = output[i];
394  query.getVector4fMap () = transformation_ * query.getVector4fMap ();
395 
396  if (!searchForNeighbors (query, nn_indices, nn_dists))
397  {
398  PCL_ERROR ("[pcl::%s::computeTransformation] Unable to find a nearest neighbor in the target dataset for point %d in the source!\n", getClassName ().c_str (), (*indices_)[i]);
399  return;
400  }
401 
402  // Check if the distance to the nearest neighbor is smaller than the user imposed threshold
403  if (nn_dists[0] < dist_threshold)
404  {
405  Eigen::Matrix3d &C1 = (*input_covariances_)[i];
406  Eigen::Matrix3d &C2 = (*target_covariances_)[nn_indices[0]];
407  Eigen::Matrix3d &M = mahalanobis_[i];
408  // M = R*C1
409  M = R * C1;
410  // temp = M*R' + C2 = R*C1*R' + C2
411  Eigen::Matrix3d temp = M * R.transpose();
412  temp+= C2;
413  // M = temp^-1
414  M = temp.inverse ();
415  source_indices[cnt] = static_cast<int> (i);
416  target_indices[cnt] = nn_indices[0];
417  cnt++;
418  }
419  }
420  // Resize to the actual number of valid correspondences
421  source_indices.resize(cnt); target_indices.resize(cnt);
422  /* optimize transformation using the current assignment and Mahalanobis metrics*/
424  //optimization right here
425  try
426  {
427  rigid_transformation_estimation_(output, source_indices, *target_, target_indices, transformation_);
428  /* compute the delta from this iteration */
429  delta = 0.;
430  for(int k = 0; k < 4; k++) {
431  for(int l = 0; l < 4; l++) {
432  double ratio = 1;
433  if(k < 3 && l < 3) // rotation part of the transform
434  ratio = 1./rotation_epsilon_;
435  else
436  ratio = 1./transformation_epsilon_;
437  double c_delta = ratio*std::abs(previous_transformation_(k,l) - transformation_(k,l));
438  if(c_delta > delta)
439  delta = c_delta;
440  }
441  }
442  }
443  catch (PCLException &e)
444  {
445  PCL_DEBUG ("[pcl::%s::computeTransformation] Optimization issue %s\n", getClassName ().c_str (), e.what ());
446  break;
447  }
448  nr_iterations_++;
449  // Check for convergence
450  if (nr_iterations_ >= max_iterations_ || delta < 1)
451  {
452  converged_ = true;
454  PCL_DEBUG ("[pcl::%s::computeTransformation] Convergence reached. Number of iterations: %d out of %d. Transformation difference: %f\n",
455  getClassName ().c_str (), nr_iterations_, max_iterations_, (transformation_ - previous_transformation_).array ().abs ().sum ());
456  }
457  else
458  PCL_DEBUG ("[pcl::%s::computeTransformation] Convergence failed\n", getClassName ().c_str ());
459  }
461 
462  // Transform the point cloud
464 }
465 
466 template <typename PointSource, typename PointTarget> void
468 {
469  // !!! CAUTION Stanford GICP uses the Z Y X euler angles convention
470  Eigen::Matrix3f R;
471  R = Eigen::AngleAxisf (static_cast<float> (x[5]), Eigen::Vector3f::UnitZ ())
472  * Eigen::AngleAxisf (static_cast<float> (x[4]), Eigen::Vector3f::UnitY ())
473  * Eigen::AngleAxisf (static_cast<float> (x[3]), Eigen::Vector3f::UnitX ());
474  t.topLeftCorner<3,3> ().matrix () = R * t.topLeftCorner<3,3> ().matrix ();
475  Eigen::Vector4f T (static_cast<float> (x[0]), static_cast<float> (x[1]), static_cast<float> (x[2]), 0.0f);
476  t.col (3) += T;
477 }
478 
479 #endif //PCL_REGISTRATION_IMPL_GICP_HPP_
KdTreeReciprocalPtr tree_reciprocal_
A pointer to the spatial search object of the source.
Definition: registration.h:495
Eigen::Matrix4f base_transformation_
base transformation
Definition: gicp.h:272
bool initComputeReciprocal()
Internal computation when reciprocal lookup is needed.
const std::string & getClassName() const
Abstract class get name method.
Definition: registration.h:429
void estimateRigidTransformationBFGS(const PointCloudSource &cloud_src, const std::vector< int > &indices_src, const PointCloudTarget &cloud_tgt, const std::vector< int > &indices_tgt, Eigen::Matrix4f &transformation_matrix)
Estimate a rigid rotation transformation between a source and a target point cloud using an iterative...
Definition: gicp.hpp:181
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:423
std::vector< Eigen::Matrix3d > mahalanobis_
Mahalanobis matrices holder.
Definition: gicp.h:294
const Eigen::Map< const Eigen::Vector4f, Eigen::Aligned > Vector4fMapConst
A base class for all pcl exceptions which inherits from std::runtime_error.
Definition: exceptions.h:64
std::function< void(const pcl::PointCloud< PointSource > &cloud_src, const std::vector< int > &src_indices, const pcl::PointCloud< PointTarget > &cloud_tgt, const std::vector< int > &tgt_indices, Eigen::Matrix4f &transformation_matrix)> rigid_transformation_estimation_
Definition: gicp.h:366
void df(const Vector6d &x, Vector6d &df) override
Definition: gicp.hpp:271
const std::vector< int > * tmp_idx_src_
Temporary pointer to the source dataset indices.
Definition: gicp.h:281
bool searchForNeighbors(const PointSource &query, std::vector< int > &index, std::vector< float > &distance)
Search for the closest nearest neighbor of a given point.
Definition: gicp.h:339
int nr_iterations_
The number of iterations the internal optimization ran for (used internally).
Definition: registration.h:498
const GeneralizedIterativeClosestPoint * gicp_
Definition: gicp.h:359
iterator end()
Definition: point_cloud.h:456
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:154
void fdf(const Vector6d &x, double &f, Vector6d &df) override
Definition: gicp.hpp:307
void computeCovariances(typename pcl::PointCloud< PointT >::ConstPtr cloud, const typename pcl::search::KdTree< PointT >::Ptr tree, MatricesVector &cloud_covariances)
compute points covariances matrices according to the K nearest neighbors.
Definition: gicp.hpp:49
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: gicp.h:103
const PointCloudSource * tmp_src_
Temporary pointer to the source dataset.
Definition: gicp.h:275
std::vector< Eigen::Matrix3d, Eigen::aligned_allocator< Eigen::Matrix3d > > MatricesVector
Definition: gicp.h:92
const std::vector< int > * tmp_idx_tgt_
Temporary pointer to the target dataset indices.
Definition: gicp.h:284
Parameters parameters
Definition: bfgs.h:154
KdTreePtr tree_
A pointer to the spatial search object.
Definition: registration.h:492
Matrix4 previous_transformation_
The previous transformation matrix estimated by the registration method (used internally).
Definition: registration.h:518
Matrix4 transformation_
The transformation matrix estimated by the registration method.
Definition: registration.h:515
int max_iterations_
The maximum number of iterations the internal optimization should run for.
Definition: registration.h:503
Matrix4 final_transformation_
The final transformation matrix estimated by the registration method after N iterations.
Definition: registration.h:512
PointCloudTargetConstPtr target_
The input point cloud dataset target.
Definition: registration.h:509
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Transform< Scalar, 3, Eigen::Affine > &transform, bool copy_all_fields=true)
Apply an affine transform defined by an Eigen Transform.
Definition: transforms.hpp:215
const PointCloudTarget * tmp_tgt_
Temporary pointer to the target dataset.
Definition: gicp.h:278
void applyState(Eigen::Matrix4f &t, const Vector6d &x) const
compute transformation matrix from transformation matrix
Definition: gicp.hpp:467
boost::shared_ptr< KdTree< PointT, Tree > > Ptr
Definition: kdtree.h:78
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void computeTransformation(PointCloudSource &output, const Eigen::Matrix4f &guess) override
Rigid transformation computation method with initial guess.
Definition: gicp.hpp:344
An exception that is thrown when the number of correspondents is not equal to the minimum required...
Definition: exceptions.h:65
double rotation_epsilon_
The epsilon constant for rotation error.
Definition: gicp.h:269
BFGSSpace::Status testGradient(Scalar epsilon)
Definition: bfgs.h:411
An exception that is thrown when the non linear solver didn&#39;t converge.
Definition: exceptions.h:50
MatricesVectorPtr input_covariances_
Input cloud points covariances.
Definition: gicp.h:288
bool converged_
Holds internal convergence state, given user parameters.
Definition: registration.h:548
double transformation_epsilon_
The maximum difference between two consecutive transformations in order to consider convergence (user...
Definition: registration.h:523
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:442
void computeRDerivative(const Vector6d &x, const Eigen::Matrix3d &R, Vector6d &g) const
Computes rotation matrix derivative.
Definition: gicp.hpp:126
double corr_dist_threshold_
The maximum distance threshold between two correspondent points in source <-> target.
Definition: registration.h:539
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:151
iterator begin()
Definition: point_cloud.h:455
const Eigen::Matrix3d & mahalanobis(size_t index) const
Definition: gicp.h:197
A point structure representing Euclidean xyz coordinates, and the RGB color.
BFGSSpace::Status minimizeOneStep(FVectorType &x)
Definition: bfgs.h:331
int nearestKSearch(const PointT &point, int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances) const override
Search for the k-nearest neighbors for the given query point.
Definition: kdtree.hpp:88
BFGSSpace::Status minimizeInit(FVectorType &x)
Definition: bfgs.h:304
MatricesVectorPtr target_covariances_
Target cloud points covariances.
Definition: gicp.h:291
BFGS stands for Broyden–Fletcher–Goldfarb–Shanno (BFGS) method for solving unconstrained nonlinear...
Definition: bfgs.h:113
size_t size() const
Definition: point_cloud.h:461