1 /******************************************************************************
2  * Authors:  Johannes Mikulasch                                               *
3  * License:  Copyright (c) 2013 Laurent Kneip, ANU. All rights reserved.      *
4  *                                                                            *
5  * Redistribution and use in source and binary forms, with or without         *
6  * modification, are permitted provided that the following conditions         *
7  * are met:                                                                   *
8  * * Redistributions of source code must retain the above copyright           *
9  *   notice, this list of conditions and the following disclaimer.            *
10  * * Redistributions in binary form must reproduce the above copyright        *
11  *   notice, this list of conditions and the following disclaimer in the      *
12  *   documentation and/or other materials provided with the distribution.     *
13  * * Neither the name of ANU nor the names of its contributors may be         *
14  *   used to endorse or promote products derived from this software without   *
15  *   specific prior written permission.                                       *
16  *                                                                            *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"*
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  *
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
20  * ARE DISCLAIMED. IN NO EVENT SHALL ANU OR THE CONTRIBUTORS BE LIABLE        *
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
24  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT         *
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY  *
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF     *
27  * SUCH DAMAGE.                                                               *
28  ******************************************************************************/
29 
30 //Note: has been derived from Ransac which has been derived from ROS
31 
32 /**
33  * \file Lmeds.hpp
34  * \brief Implementation of the Lmeds algorithm
35  */
36 
37 #ifndef OPENGV_SAC_LMEDS_HPP_
38 #define OPENGV_SAC_LMEDS_HPP_
39 
40 #include <vector>
41 #include <opengv/sac/SampleConsensus.hpp>
42 #include <cstdio>
43 
44 /**
45  * \brief The namespace of this library.
46  */
47 namespace opengv
48 {
49 /**
50  * \brief The namespace for the sample consensus methods.
51  */
52 namespace sac
53 {
54 
55 /**
56  * The LMedS (Least Median of Squares) sample consensus method
57  */
58 template<typename PROBLEM_T>
59 class Lmeds : public SampleConsensus<PROBLEM_T>
60 {
61 public:
62   /** A child of SampleConsensusProblem */
63   typedef PROBLEM_T problem_t;
64   /** The model we trying to fit */
65   typedef typename problem_t::model_t model_t;
66 
67   using SampleConsensus<problem_t>::max_iterations_;
68   using SampleConsensus<problem_t>::threshold_;
69   using SampleConsensus<problem_t>::iterations_;
70   using SampleConsensus<problem_t>::sac_model_;
71   using SampleConsensus<problem_t>::model_;
72   using SampleConsensus<problem_t>::model_coefficients_;
73   using SampleConsensus<problem_t>::inliers_;
74   using SampleConsensus<problem_t>::probability_;
75 
76   /**
77    * \brief Constructor.
78    */
79   Lmeds(
80       int maxIterations = 1000,
81       double threshold = 1.0,
82       double probability = 0.99);
83   /**
84    * \brief Destructor.
85    */
86   virtual ~Lmeds();
87 
88   /**
89    * \brief Fit the model.
90    */
91   bool computeModel( int debug_verbosity_level = 0 );
92 };
93 
94 } // namespace sac
95 } // namespace opengv
96 
97 #include "implementation/Lmeds.hpp"
98 
99 #endif /* OPENGV_SAC_LMEDS_HPP_ */
100