default_convergence_criteria.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2012-, Open Perception, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the copyright holder(s) nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id$
00037  *
00038  */
00039 
00040 #ifndef PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_H_
00041 #define PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_H_
00042 
00043 #include <pcl/registration/eigen.h>
00044 #include <pcl/correspondence.h>
00045 #include <pcl/registration/convergence_criteria.h>
00046 
00047 namespace pcl
00048 {
00049   namespace registration
00050   {
00064     template <typename Scalar = float>
00065     class DefaultConvergenceCriteria : public ConvergenceCriteria
00066     {
00067       public:
00068         typedef boost::shared_ptr<DefaultConvergenceCriteria<Scalar> > Ptr;
00069         typedef boost::shared_ptr<const DefaultConvergenceCriteria<Scalar> > ConstPtr;
00070 
00071         typedef Eigen::Matrix<Scalar, 4, 4> Matrix4;
00072 
00073         enum ConvergenceState
00074         {
00075           CONVERGENCE_CRITERIA_NOT_CONVERGED,
00076           CONVERGENCE_CRITERIA_ITERATIONS,
00077           CONVERGENCE_CRITERIA_TRANSFORM,
00078           CONVERGENCE_CRITERIA_ABS_MSE,
00079           CONVERGENCE_CRITERIA_REL_MSE,
00080           CONVERGENCE_CRITERIA_NO_CORRESPONDENCES
00081         };
00082 
00094         DefaultConvergenceCriteria (const int &iterations, const Matrix4 &transform, const pcl::Correspondences &correspondences)
00095           : iterations_ (iterations)
00096           , transformation_ (transform)
00097           , correspondences_ (correspondences)
00098           , correspondences_prev_mse_ (std::numeric_limits<double>::max ())
00099           , correspondences_cur_mse_ (std::numeric_limits<double>::max ())
00100           , max_iterations_ (100)                 // 100 iterations
00101           , failure_after_max_iter_ (false)
00102           , rotation_threshold_ (0.99999)         // 0.256 degrees
00103           , translation_threshold_ (3e-4 * 3e-4)  // 0.0003 meters
00104           , mse_threshold_relative_ (0.00001)     // 0.001% of the previous MSE (relative error)
00105           , mse_threshold_absolute_ (1e-12)       // MSE (absolute error)
00106           , iterations_similar_transforms_ (0)
00107           , max_iterations_similar_transforms_ (0)
00108           , convergence_state_ (CONVERGENCE_CRITERIA_NOT_CONVERGED)
00109         {
00110         }
00111       
00113         virtual ~DefaultConvergenceCriteria () {}
00114 
00119         inline void
00120         setMaximumIterationsSimilarTransforms (const int nr_iterations) { max_iterations_similar_transforms_ = nr_iterations; }
00121 
00125         inline int
00126         getMaximumIterationsSimilarTransforms () const { return (max_iterations_similar_transforms_); }
00127 
00131         inline void
00132         setMaximumIterations (const int nr_iterations) { max_iterations_ = nr_iterations; }
00133 
00135         inline int
00136         getMaximumIterations () const { return (max_iterations_); }
00137 
00141         inline void
00142         setFailureAfterMaximumIterations (const bool failure_after_max_iter) { failure_after_max_iter_ = failure_after_max_iter; }
00143 
00145         inline bool
00146         getFailureAfterMaximumIterations () const { return (failure_after_max_iter_); }
00147 
00151         inline void
00152         setRotationThreshold (const double threshold) { rotation_threshold_ = threshold; }
00153 
00156         inline double
00157         getRotationThreshold () const { return (rotation_threshold_); }
00158 
00162         inline void
00163         setTranslationThreshold (const double threshold) { translation_threshold_ = threshold; }
00164 
00167         inline double
00168         getTranslationThreshold () const { return (translation_threshold_); }
00169 
00173         inline void
00174         setRelativeMSE (const double mse_relative) { mse_threshold_relative_ = mse_relative; }
00175 
00177         inline double
00178         getRelativeMSE () const { return (mse_threshold_relative_); }
00179 
00183         inline void
00184         setAbsoluteMSE (const double mse_absolute) { mse_threshold_absolute_ = mse_absolute; }
00185 
00187         inline double
00188         getAbsoluteMSE () const { return (mse_threshold_absolute_); }
00189 
00190 
00192         virtual bool
00193         hasConverged ();
00194 
00196         ConvergenceState
00197         getConvergenceState ()
00198         {
00199           return (convergence_state_);
00200         }
00201 
00207         inline void
00208         setConvergenceState(ConvergenceState c)
00209         {
00210           convergence_state_ = c;
00211         }
00212 
00213       protected:
00214 
00218         inline double
00219         calculateMSE (const pcl::Correspondences &correspondences) const
00220         {
00221           double mse = 0;
00222           for (size_t i = 0; i < correspondences.size (); ++i)
00223             mse += correspondences[i].distance;
00224           mse /= double (correspondences.size ());
00225           return (mse);
00226         }
00227 
00229         const int &iterations_;
00230 
00232         const Matrix4 &transformation_;
00233 
00235         const pcl::Correspondences &correspondences_;
00236 
00238         double correspondences_prev_mse_;
00239 
00241         double correspondences_cur_mse_;
00242 
00244         int max_iterations_;
00245 
00247         bool failure_after_max_iter_;
00248 
00250         double rotation_threshold_;
00251 
00253         double translation_threshold_;
00254 
00256         double mse_threshold_relative_;
00257 
00259         double mse_threshold_absolute_;
00260 
00263         int iterations_similar_transforms_;
00264 
00267         int max_iterations_similar_transforms_;
00268 
00270         ConvergenceState convergence_state_;
00271 
00272       public:
00273         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00274      };
00275   }
00276 }
00277 
00278 #include <pcl/registration/impl/default_convergence_criteria.hpp>
00279 
00280 #endif    // PCL_REGISTRATION_DEFAULT_CONVERGENCE_CRITERIA_H_
00281 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:23:21