MROB
factor.hpp
1 /* Copyright (c) 2022, Gonzalo Ferrer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  *
16  * factor.hpp
17  *
18  * Created on: Feb 12, 2018
19  * Author: Gonzalo Ferrer
20  * g.ferrer@skoltech.ru
21  * Mobile Robotics Lab, Skoltech
22  */
23 
24 #ifndef FACTOR_HPP_
25 #define FACTOR_HPP_
26 
27 #include <vector>
28 #include <memory>
29 
30 #include "mrob/matrix_base.hpp"
31 #include "mrob/node.hpp"
32 
33 namespace mrob{
34 
35 class Node;
36 
81 class Factor{
82 public:
87  enum robustFactorType{QUADRATIC = 0, HUBER, CAUCHY, MCCLURE, RANSAC};
88  Factor(uint_t dim, uint_t allNodesDim, robustFactorType factor_type = QUADRATIC, uint_t potNumberNodes = 5);
89  virtual ~Factor();
93  virtual void evaluate_residuals() = 0;
98  virtual void evaluate_jacobians() = 0;
106  virtual void evaluate_chi2() = 0;
111  matData_t get_chi2() const { return chi2_;}
116  virtual void print() const {}
123  virtual MatRefConst get_obs() const = 0;
127  virtual VectRefConst get_residual() const = 0;
128  virtual MatRefConst get_information_matrix() const = 0;
138  virtual MatRefConst get_jacobian([[maybe_unused]] mrob::factor_id_t id = 0) const = 0;
139 
140 
141  factor_id_t get_id() const {return id_;}
142  void set_id(factor_id_t id) {id_ = id;}
143  uint_t get_dim_obs() const {return dim_;}
144  void set_dim_obs(uint_t dim) {dim_ = dim;}
145  uint_t get_all_nodes_dim() const{ return allNodesDim_;}
146  void set_all_nodes_dim(uint_t dim) {allNodesDim_ = dim;}
147  const std::vector<std::shared_ptr<Node> >*
148  get_neighbour_nodes(void) const {return &neighbourNodes_;}
149 
163  matData_t evaluate_robust_weight(matData_t u, matData_t params = 0.0);
164 
165 protected:
166  factor_id_t id_;
171  std::vector<std::shared_ptr<Node> > neighbourNodes_;
172  uint_t dim_;//dimension of the observation
173  uint_t allNodesDim_;//summation of all the nodes that the factor affects
174  matData_t chi2_;
175 
176  // Robust factor weighting the "iteratively weighted LSQ"
177  robustFactorType robust_type_;
178  matData_t robust_weight_; // dp/du 1/u or influence by the inverse of the distance u
179 
188  //matData_t ransac_significance_level_;
189 
190  // variables to declare on child Factor, for instance of dim 6
191  //Mat61 obs_, r_; //and residuals
192  //Mat<Z,N> J_;//Jacobians
193  //Mat6 W_;//inverse of observation covariance (information matrix)
194 
195 };
196 
221 class EigenFactor : public Factor
222 {
223 public:
224  EigenFactor(robustFactorType factor_type = QUADRATIC, uint_t potNumberNodes = 5);
225  virtual ~EigenFactor() = default;
226  virtual VectRefConst get_state() const = 0;
227  virtual void add_point(const Mat31& p, std::shared_ptr<Node> &node, mrob::matData_t &W) = 0;
228  virtual MatRefConst get_hessian(mrob::factor_id_t id = 0) const = 0;
229  virtual void add_points_array(const MatX &P, std::shared_ptr<Node> &node, mrob::matData_t &W) = 0;
230  virtual void add_points_S_matrix(const Mat4 &S, std::shared_ptr<Node> &node, mrob::matData_t &W) = 0;
231 
232 };
233 
234 }
235 
236 #endif /* FACTOR_HPP_ */
virtual VectRefConst get_residual() const =0
virtual void print() const
Definition: factor.hpp:116
robustFactorType
Definition: factor.hpp:87
matData_t evaluate_robust_weight(matData_t u, matData_t params=0.0)
Definition: factor.cpp:42
Definition: factor.hpp:221
virtual void evaluate_jacobians()=0
virtual MatRefConst get_obs() const =0
virtual void evaluate_residuals()=0
matData_t get_chi2() const
Definition: factor.hpp:111
virtual MatRefConst get_jacobian([[maybe_unused]] mrob::factor_id_t id=0) const =0
Special Euclidean (group) in 3d Is the group representing rotations and translations, that is, rigid body transformations. SE3 = {T = [R t] | R SO3 , t Re^3 } [0 1] Associated to the groups of RBT, there is the Lie algebra se3 representing the same transformation in the tangent space around the identity. Particularly, xi =[w , v] Re^6, where w Re^3 represents the rotation and v the translation. We will preserve this order in this class.
Definition: matrix_base.hpp:36
std::vector< std::shared_ptr< Node > > neighbourNodes_
Definition: factor.hpp:171
virtual void evaluate_chi2()=0
Definition: factor.hpp:81