MROB
EigenFactorPlane.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  * EigenFactorPlane.hpp
17  *
18  * Created on: Aug 16, 2019
19  * Created on: July 10, 2021 (for real)
20  * Author: Gonzalo Ferrer
21  * g.ferrer@skoltech.ru
22  * Mobile Robotics Lab.
23  */
24 
25 #ifndef EIGENFACTORPLANE_HPP_
26 #define EIGENFACTORPLANE_HPP_
27 
28 
29 #include "mrob/factor.hpp"
30 #include <unordered_map>
31 #include <deque>
32 #include <Eigen/StdVector>
33 
34 
35 namespace mrob{
36 
56 public:
61  EigenFactorPlane(Factor::robustFactorType robust_type = Factor::robustFactorType::QUADRATIC);
62  ~EigenFactorPlane() override = default;
67  void evaluate_residuals() override;
72  void evaluate_jacobians() override;
76  void evaluate_chi2() override;
77 
78  void print() const;
79 
80  MatRefConst get_obs() const
81  {assert(0 && "EigenFactorPlane:get_obs: method should not be called");return Mat31::Zero();}
82  VectRefConst get_residual() const
83  {assert(0 && "EigenFactorPlane::get_resigual: method should not be called");return Mat31::Zero();}
84  MatRefConst get_information_matrix() const
85  {assert(0 && "EigenFactorPlane::get_inform method should not be called");return Mat4::Zero();}
86 
91  MatRefConst get_jacobian([[maybe_unused]] mrob::factor_id_t id = 0) const override;
96  MatRefConst get_hessian(mrob::factor_id_t id = 0) const override;
97 
98 
99  // NEW functions added to the base class factor.hpp
104  VectRefConst get_state(void) const override
105  {return planeEstimation_;}
114  void add_point(const Mat31& p, std::shared_ptr<Node> &node, matData_t &W) override;
118  void add_points_array(const MatX &P, std::shared_ptr<Node> &node, mrob::matData_t &W) override;
123  void add_points_S_matrix(const Mat4 &S, std::shared_ptr<Node> &node, mrob::matData_t &W) override;
132  Mat31 get_mean_point(factor_id_t id);
133 
134 
135 protected:
140  virtual void estimate_plane();
162  std::deque<factor_id_t> nodeIds_;
168  std::unordered_map<factor_id_t, uint_t> reverseNodeIds_;
173  std::deque<Mat61, Eigen::aligned_allocator<Mat61>> J_;
178  std::deque<Mat6, Eigen::aligned_allocator<Mat6>> H_;
186  std::deque<Mat4, Eigen::aligned_allocator<Mat4>> S_, Q_;
187  Mat4 accumulatedQ_;//Q matrix of accumulated values for the incremental update of the error.
188 
189  Mat41 planeEstimation_, planeEstimationCenter_;
190  //matData_t planeError_; //this is chi2 scaled by the covariance of point measurement.
191 
192  // subset of pointcloud for the given plane
193  //std::unordered_map<factor_id_t, std::vector<Mat31> > allPlanePoints_;
194  std::deque<std::deque<Mat31, Eigen::aligned_allocator<Mat31>> > allPlanePoints_;
195  std::deque<std::deque<matData_t> > allPointsInformation_;
196  uint_t numberPoints_;
197 
198  matData_t planeError_;
199 
200  Mat4 Tcenter_; // Used to move the Q matrix close to have a d~0, to avoid scale
201 
202 public:
203  EIGEN_MAKE_ALIGNED_OPERATOR_NEW // as proposed by Eigen
204 };
205 
206 }
207 #endif /* EigenFactorPlane_HPP_ */
std::deque< Mat6, Eigen::aligned_allocator< Mat6 > > H_
Definition: EigenFactorPlane.hpp:178
void evaluate_jacobians() override
Definition: EigenFactorPlane.cpp:48
void evaluate_chi2() override
Definition: EigenFactorPlane.cpp:85
robustFactorType
Definition: factor.hpp:87
void add_points_S_matrix(const Mat4 &S, std::shared_ptr< Node > &node, mrob::matData_t &W) override
Definition: EigenFactorPlane.cpp:129
VectRefConst get_residual() const
Definition: EigenFactorPlane.hpp:82
std::deque< factor_id_t > nodeIds_
Definition: EigenFactorPlane.hpp:162
Definition: factor.hpp:221
std::deque< Mat4, Eigen::aligned_allocator< Mat4 > > S_
Definition: EigenFactorPlane.hpp:186
VectRefConst get_state(void) const override
Definition: EigenFactorPlane.hpp:104
void calculate_all_matrices_S()
Definition: EigenFactorPlane.cpp:159
std::unordered_map< factor_id_t, uint_t > reverseNodeIds_
Definition: EigenFactorPlane.hpp:168
MatRefConst get_obs() const
Definition: EigenFactorPlane.hpp:80
Mat31 get_mean_point(factor_id_t id)
Definition: EigenFactorPlane.cpp:198
std::deque< Mat61, Eigen::aligned_allocator< Mat61 > > J_
Definition: EigenFactorPlane.hpp:173
void evaluate_residuals() override
Definition: EigenFactorPlane.cpp:43
virtual void estimate_plane()
Definition: EigenFactorPlane.cpp:135
void add_point(const Mat31 &p, std::shared_ptr< Node > &node, matData_t &W) override
Definition: EigenFactorPlane.cpp:92
EigenFactorPlane(Factor::robustFactorType robust_type=Factor::robustFactorType::QUADRATIC)
Definition: EigenFactorPlane.cpp:33
void print() const
Definition: EigenFactorPlane.cpp:205
Definition: EigenFactorPlane.hpp:55
MatRefConst get_hessian(mrob::factor_id_t id=0) const override
Definition: EigenFactorPlane.cpp:234
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
MatRefConst get_jacobian([[maybe_unused]] mrob::factor_id_t id=0) const override
Definition: EigenFactorPlane.cpp:227
void calculate_all_matrices_Q()
Definition: EigenFactorPlane.cpp:181
void add_points_array(const MatX &P, std::shared_ptr< Node > &node, mrob::matData_t &W) override
Definition: EigenFactorPlane.cpp:121