MROB
factor_graph.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_graph.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_GRAPH_HPP_
25 #define FACTOR_GRAPH_HPP_
26 
27 //#include <unordered_map>
28 #include <deque>// for long allocations
29 
30 #include "mrob/factor.hpp"
31 #include "mrob/node.hpp"
32 
33 namespace mrob{
57 class FGraph{
58 public:
59  FGraph();
60  virtual ~FGraph();
74  factor_id_t add_factor(std::shared_ptr<Factor> &factor);
81  factor_id_t add_eigen_factor(std::shared_ptr<EigenFactor> &factor);
85  factor_id_t add_node(std::shared_ptr<Node> &node);
86 
90  std::shared_ptr<Node>& get_node(factor_id_t key);
91 
95  std::shared_ptr<Factor>& get_factor(factor_id_t key);
99  std::shared_ptr<EigenFactor>& get_eigen_factor(factor_id_t key);
100  void print(bool complete = false) const;
101 
102 
106  factor_id_t number_nodes() {return nodes_.size();};
107  factor_id_t number_factors() {return factors_.size();};
108  uint_t get_dimension_state() {return stateDim_;};
109  uint_t get_dimension_obs() {return obsDim_;};
110 
111  //TODO serialization
112  void save_graph() const;
113  void load_graph();
114 
115 protected:
126  //All nodes in the system. The index Id corresponds to the position in this vector
127  std::deque<std::shared_ptr<Node> > nodes_;
128  // Only active nodes, here the index does not guarantee anything.
129  std::deque<std::shared_ptr<Node> > active_nodes_;
130 
131  //std::unordered_set<std::shared_ptr<Factor> > factors_;
132  std::deque<std::shared_ptr<Factor> > factors_; // no specific order needed
133 
134  // This requires a special list for the factors
135  std::deque<std::shared_ptr<EigenFactor> > eigen_factors_;
136 
141  uint_t stateDim_, obsDim_;
142 };
143 
144 
145 
146 }
147 
148 #endif /* FACTOR_Graph_HPP_ */
std::shared_ptr< EigenFactor > & get_eigen_factor(factor_id_t key)
Definition: factor_graph.cpp:89
factor_id_t number_nodes()
Definition: factor_graph.hpp:106
factor_id_t add_factor(std::shared_ptr< Factor > &factor)
Definition: factor_graph.cpp:41
uint_t stateDim_
Definition: factor_graph.hpp:141
Definition: factor_graph.hpp:57
std::shared_ptr< Node > & get_node(factor_id_t key)
Definition: factor_graph.cpp:76
std::shared_ptr< Factor > & get_factor(factor_id_t key)
Definition: factor_graph.cpp:82
factor_id_t add_node(std::shared_ptr< Node > &node)
Definition: factor_graph.cpp:57
factor_id_t add_eigen_factor(std::shared_ptr< EigenFactor > &factor)
Definition: factor_graph.cpp:49
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::deque< std::shared_ptr< Node > > nodes_
Definition: factor_graph.hpp:127