MROB
EigenFactorPlaneRaw.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  * EigenFactorPlaneRaw.hpp
17  *
18  * Created on: November 16, 2022
19  * Author: Gonzalo Ferrer
20  * g.ferrer@skoltech.ru
21  * Mobile Robotics Lab.
22  */
23 
24 #ifndef EIGENFACTORPLANERAW_HPP_
25 #define EIGENFACTORPLANERAW_HPP_
26 
27 
28 #include "mrob/factor.hpp"
29 #include <unordered_map>
30 #include <deque>
31 #include <Eigen/StdVector>
32 
33 
34 namespace mrob{
35 
55 public:
60  EigenFactorPlaneRaw(Factor::robustFactorType robust_type = Factor::robustFactorType::QUADRATIC);
61  ~EigenFactorPlaneRaw() override = default;
66  void evaluate_residuals() override;
71  void evaluate_jacobians() override;
75  void evaluate_chi2() override;
76 
77  void print() const;
78 
79  MatRefConst get_obs() const
80  {assert(0 && "EigenFactorPlaneRaw:get_obs: method should not be called");return Mat31::Zero();}
81  VectRefConst get_residual() const
82  {assert(0 && "EigenFactorPlaneRaw::get_resigual: method should not be called");return Mat31::Zero();}
83  MatRefConst get_information_matrix() const
84  {assert(0 && "EigenFactorPlaneRaw::get_inform method should not be called");return Mat4::Zero();}
85 
90  MatRefConst get_jacobian([[maybe_unused]] mrob::factor_id_t id = 0) const override;
95  MatRefConst get_hessian(mrob::factor_id_t id = 0) const override;
96 
97 
98  // NEW functions added to the base class factor.hpp
103  VectRefConst get_state(void) const override
104  {return planeEstimation_;}
113  void add_point(const Mat31& p, std::shared_ptr<Node> &node, matData_t &W) override;
117  void add_points_array(const MatX &P, std::shared_ptr<Node> &node, mrob::matData_t &W) override;
122  void add_points_S_matrix(const Mat4 &S, std::shared_ptr<Node> &node, mrob::matData_t &W) override;
131  Mat31 get_mean_point(factor_id_t id);
132 
133 
134 protected:
139  virtual void estimate_plane();
147  void calculate_all_matrices_S(bool reset=false);
160  std::deque<factor_id_t> nodeIds_;
166  std::unordered_map<factor_id_t, uint_t> reverseNodeIds_;
171  std::deque<Mat61, Eigen::aligned_allocator<Mat61>> J_;
176  std::deque<Mat6, Eigen::aligned_allocator<Mat6>> H_;
184  std::deque<Mat4, Eigen::aligned_allocator<Mat4>> S_, Q_;
185  Mat4 accumulatedQ_;//Q matrix of accumulated values for the incremental update of the error.
186 
187  Mat41 planeEstimationUnit_, planeEstimation_;
188  //matData_t planeError_; //this is chi2 scaled by the covariance of point measurement.
189 
190  // subset of pointcloud for the given plane
191  //std::unordered_map<factor_id_t, std::vector<Mat31> > allPlanePoints_;
192  std::deque<std::deque<Mat31, Eigen::aligned_allocator<Mat31>> > allPlanePoints_;
193  std::deque<std::deque<matData_t> > allPointsInformation_;
194  uint_t numberPoints_;
195 
196 
197  matData_t planeError_;
198 
199 public:
200  EIGEN_MAKE_ALIGNED_OPERATOR_NEW // as proposed by Eigen
201 };
202 
203 }
204 #endif /* EigenFactorPlaneRaw_HPP_ */
void add_points_array(const MatX &P, std::shared_ptr< Node > &node, mrob::matData_t &W) override
Definition: EigenFactorPlaneRaw.cpp:117
Mat31 get_mean_point(factor_id_t id)
Definition: EigenFactorPlaneRaw.cpp:187
void evaluate_residuals() override
Definition: EigenFactorPlaneRaw.cpp:42
virtual void estimate_plane()
Definition: EigenFactorPlaneRaw.cpp:131
robustFactorType
Definition: factor.hpp:87
void calculate_all_matrices_Q()
Definition: EigenFactorPlaneRaw.cpp:170
VectRefConst get_state(void) const override
Definition: EigenFactorPlaneRaw.hpp:103
MatRefConst get_hessian(mrob::factor_id_t id=0) const override
Definition: EigenFactorPlaneRaw.cpp:223
std::deque< factor_id_t > nodeIds_
Definition: EigenFactorPlaneRaw.hpp:160
std::deque< Mat4, Eigen::aligned_allocator< Mat4 > > S_
Definition: EigenFactorPlaneRaw.hpp:184
Definition: factor.hpp:221
void evaluate_chi2() override
Definition: EigenFactorPlaneRaw.cpp:81
std::deque< Mat6, Eigen::aligned_allocator< Mat6 > > H_
Definition: EigenFactorPlaneRaw.hpp:176
MatRefConst get_jacobian([[maybe_unused]] mrob::factor_id_t id=0) const override
Definition: EigenFactorPlaneRaw.cpp:216
EigenFactorPlaneRaw(Factor::robustFactorType robust_type=Factor::robustFactorType::QUADRATIC)
Definition: EigenFactorPlaneRaw.cpp:33
VectRefConst get_residual() const
Definition: EigenFactorPlaneRaw.hpp:81
std::deque< Mat61, Eigen::aligned_allocator< Mat61 > > J_
Definition: EigenFactorPlaneRaw.hpp:171
MatRefConst get_obs() const
Definition: EigenFactorPlaneRaw.hpp:79
void add_points_S_matrix(const Mat4 &S, std::shared_ptr< Node > &node, mrob::matData_t &W) override
Definition: EigenFactorPlaneRaw.cpp:125
void evaluate_jacobians() override
Definition: EigenFactorPlaneRaw.cpp:47
void print() const
Definition: EigenFactorPlaneRaw.cpp:194
void add_point(const Mat31 &p, std::shared_ptr< Node > &node, matData_t &W) override
Definition: EigenFactorPlaneRaw.cpp:88
Definition: EigenFactorPlaneRaw.hpp:54
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
void calculate_all_matrices_S(bool reset=false)
Definition: EigenFactorPlaneRaw.cpp:148
std::unordered_map< factor_id_t, uint_t > reverseNodeIds_
Definition: EigenFactorPlaneRaw.hpp:166