MROB
plane.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  * plane.hpp
17  *
18  * Created on: Feb 1, 2019
19  * Author: Gonzalo Ferrer
20  * g.ferrer@skoltech.ru
21  * Mobile Robotics Lab, Skoltech
22  */
23 
24 #ifndef PLANE_HPP_
25 #define PLANE_HPP_
26 
27 
28 #include <vector>
29 #include <memory>
30 #include "mrob/SE3.hpp"
31 #include <Eigen/StdVector>
32 
33 
34 
35 namespace mrob{
36 
45 class Plane{
46  public:
47  Plane(uint_t timeLength);
48  ~Plane();
49 
50  void reserve(uint_t d, uint_t t);//XXX not used
51  Mat41 get_plane(void) {return planeEstimation_;};
56  void push_back_point(Mat31 &point, uint_t t);
57  std::vector<Mat31>& get_points(uint_t t);
58  uint_t get_number_points(uint_t t) {return allPlanePoints_[t].size();};
59  uint_t get_total_number_points() {return numberPoints_;};
60  void clear_points();
61  void set_trajectory(const std::shared_ptr<const std::vector<SE3>> &trajectory) {trajectory_ = trajectory;};
62 
67  double estimate_plane();
75  double estimate_plane_incrementally(uint_t t);
79  double get_error() const {return lambda_;};
84  double get_error_incremental(uint_t t) const;
85 
93  void calculate_all_matrices_S(bool reset=false);
102  Mat31 get_mean_point(uint_t t);
115  Mat61 calculate_gradient(uint_t t);
116 
122  Mat6 calculate_hessian(uint_t t);
123 
124 
125  void reset();
126  void print() const;
127 
128 
129  protected:
130  // max index of time, or trajectory length
131  uint_t timeLength_;
132  //std::vector<uint_t> timeIndex_;// not used now, but it would be useful for non-consecutive obs
133 
134  // Overparametrized plane, as a transformation in SE3 TODO needed?
135  //SE3 plane_;
136  Mat41 planeEstimation_;
137  double lambda_ {};
138  bool isPlaneEstimated_;// XXX used or deprecated?
139 
140  // subset of pointcloud for the given plane
141  std::vector< std::vector<Mat31> > allPlanePoints_;
142  uint_t numberPoints_;
143 
144  // Transformations. We shared it across all planes that need it.
145  std::shared_ptr<const std::vector<SE3>> trajectory_;
146 
147  // gradient calculation Q
148  // This container is aligned since we use cpp17 (o.w. it would not be)
149  std::vector<Mat4, Eigen::aligned_allocator<Mat4> > matrixS_, matrixQ_;
150  Mat4 accumulatedQ_;//Q matrix of accumulated values for the incremental update of the error.
151 
152  // Store last gradients calculated (for Hessian)
153  std::vector<Mat4, Eigen::aligned_allocator<Mat4> > gradQ_, lieGenerativeMatrices_;
154 
155  public:
156  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
157 };
158 }
159 
160 
161 #endif /* PLANE_HPP_ */
double estimate_plane_incrementally(uint_t t)
Definition: plane.cpp:148
void calculate_all_matrices_S(bool reset=false)
Definition: plane.cpp:170
Mat31 get_mean_point(uint_t t)
Definition: plane.cpp:190
double get_error_incremental(uint_t t) const
Definition: plane.cpp:158
void calculate_all_matrices_Q()
Definition: plane.cpp:196
Mat61 calculate_gradient(uint_t t)
Definition: plane.cpp:207
double get_error() const
Definition: plane.hpp:79
void push_back_point(Mat31 &point, uint_t t)
Definition: plane.cpp:98
Definition: plane.hpp:45
Mat6 calculate_hessian(uint_t t)
Definition: plane.cpp:282
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
double estimate_plane()
Definition: plane.cpp:123