HybridFactorGraph.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010-2022, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
21 
22 namespace gtsam {
23 
24 /* ************************************************************************* */
25 std::set<DiscreteKey> HybridFactorGraph::discreteKeys() const {
26  std::set<DiscreteKey> keys;
27  for (auto& factor : factors_) {
28  if (auto p = std::dynamic_pointer_cast<DiscreteFactor>(factor)) {
29  for (const DiscreteKey& key : p->discreteKeys()) {
30  keys.insert(key);
31  }
32  }
33  if (auto p = std::dynamic_pointer_cast<HybridFactor>(factor)) {
34  for (const DiscreteKey& key : p->discreteKeys()) {
35  keys.insert(key);
36  }
37  }
38  }
39  return keys;
40 }
41 
42 /* ************************************************************************* */
44  KeySet keys;
45  std::set<DiscreteKey> key_set = discreteKeys();
46  std::transform(key_set.begin(), key_set.end(),
47  std::inserter(keys, keys.begin()),
48  [](const DiscreteKey& k) { return k.first; });
49  return keys;
50 }
51 
52 /* ************************************************************************* */
53 std::unordered_map<Key, DiscreteKey> HybridFactorGraph::discreteKeyMap() const {
54  std::unordered_map<Key, DiscreteKey> result;
55  for (const DiscreteKey& k : discreteKeys()) {
56  result[k.first] = k;
57  }
58  return result;
59 }
60 
61 /* ************************************************************************* */
63  KeySet keys;
64  for (auto& factor : factors_) {
65  if (auto p = std::dynamic_pointer_cast<HybridFactor>(factor)) {
66  for (const Key& key : p->continuousKeys()) {
67  keys.insert(key);
68  }
69  } else if (auto p = std::dynamic_pointer_cast<GaussianFactor>(factor)) {
70  keys.insert(p->keys().begin(), p->keys().end());
71  }
72  }
73  return keys;
74 }
75 
76 /* ************************************************************************* */
77 
78 } // namespace gtsam
gtsam::HybridFactorGraph::discreteKeys
std::set< DiscreteKey > discreteKeys() const
Get all the discrete keys in the factor graph.
Definition: HybridFactorGraph.cpp:25
gtsam::FactorGraph< Factor >::factors_
FastVector< sharedFactor > factors_
Definition: FactorGraph.h:92
gtsam::HybridFactorGraph::continuousKeySet
const KeySet continuousKeySet() const
Get all the continuous keys in the factor graph.
Definition: HybridFactorGraph.cpp:62
gtsam::HybridFactorGraph::discreteKeyMap
std::unordered_map< Key, DiscreteKey > discreteKeyMap() const
Get a map from Key to corresponding DiscreteKey.
Definition: HybridFactorGraph.cpp:53
gtsam::FastSet< Key >
result
Values result
Definition: OdometryOptimize.cpp:8
gtsam::FactorGraph< Factor >::keys
KeySet keys() const
Definition: FactorGraph-inst.h:85
gtsam::HybridFactorGraph::discreteKeySet
KeySet discreteKeySet() const
Get all the discrete keys in the factor graph, as a set.
Definition: HybridFactorGraph.cpp:43
transform
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25
key
const gtsam::Symbol key('X', 0)
HybridFactorGraph.h
Factor graph with utilities for hybrid factors.
gtsam
traits
Definition: chartTesting.h:28
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97


gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:01:00