HybridFactor.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, 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 
19 
20 namespace gtsam {
21 
22 /* ************************************************************************ */
23 KeyVector CollectKeys(const KeyVector &continuousKeys,
24  const DiscreteKeys &discreteKeys) {
25  KeyVector allKeys;
26  std::copy(continuousKeys.begin(), continuousKeys.end(),
27  std::back_inserter(allKeys));
28  std::transform(discreteKeys.begin(), discreteKeys.end(),
29  std::back_inserter(allKeys),
30  [](const DiscreteKey &k) { return k.first; });
31  return allKeys;
32 }
33 
34 /* ************************************************************************ */
35 KeyVector CollectKeys(const KeyVector &keys1, const KeyVector &keys2) {
36  KeyVector allKeys;
37  std::copy(keys1.begin(), keys1.end(), std::back_inserter(allKeys));
38  std::copy(keys2.begin(), keys2.end(), std::back_inserter(allKeys));
39  return allKeys;
40 }
41 
42 /* ************************************************************************ */
44  const DiscreteKeys &key2) {
45  DiscreteKeys allKeys;
46  std::copy(key1.begin(), key1.end(), std::back_inserter(allKeys));
47  std::copy(key2.begin(), key2.end(), std::back_inserter(allKeys));
48  return allKeys;
49 }
50 
51 /* ************************************************************************ */
53  : Base(keys), isContinuous_(true), continuousKeys_(keys) {}
54 
55 /* ************************************************************************ */
58  : Base(CollectKeys(continuousKeys, discreteKeys)),
59  isDiscrete_((continuousKeys.size() == 0) && (discreteKeys.size() != 0)),
60  isContinuous_((continuousKeys.size() != 0) && (discreteKeys.size() == 0)),
61  isHybrid_((continuousKeys.size() != 0) && (discreteKeys.size() != 0)),
62  discreteKeys_(discreteKeys),
63  continuousKeys_(continuousKeys) {}
64 
65 /* ************************************************************************ */
68  isDiscrete_(true),
70  continuousKeys_({}) {}
71 
72 /* ************************************************************************ */
73 bool HybridFactor::equals(const HybridFactor &lf, double tol) const {
74  const This *e = dynamic_cast<const This *>(&lf);
75  return e != nullptr && Base::equals(*e, tol) &&
79 }
80 
81 /* ************************************************************************ */
82 void HybridFactor::print(const std::string &s,
83  const KeyFormatter &formatter) const {
84  std::cout << (s.empty() ? "" : s + "\n");
85  if (isContinuous_) std::cout << "Continuous ";
86  if (isDiscrete_) std::cout << "Discrete ";
87  if (isHybrid_) std::cout << "Hybrid ";
88  std::cout << "[";
89  for (size_t c = 0; c < continuousKeys_.size(); c++) {
90  std::cout << formatter(continuousKeys_.at(c));
91  if (c < continuousKeys_.size() - 1) {
92  std::cout << " ";
93  } else {
94  std::cout << (discreteKeys_.size() > 0 ? "; " : "");
95  }
96  }
97  for (size_t d = 0; d < discreteKeys_.size(); d++) {
98  std::cout << formatter(discreteKeys_.at(d).first);
99  if (d < discreteKeys_.size() - 1) {
100  std::cout << " ";
101  }
102  }
103  std::cout << "]";
104 }
105 
106 } // namespace gtsam
size_t size() const
Definition: Factor.h:159
const DiscreteKeys & discreteKeys() const
Return the discrete keys for this factor.
Definition: HybridFactor.h:129
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
const KeyVector & continuousKeys() const
Return only the continuous keys for this factor.
Definition: HybridFactor.h:132
const KeyFormatter & formatter
void print(const std::string &s="HybridFactor\, const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
const Symbol key1('v', 1)
virtual bool equals(const HybridFactor &lf, double tol=1e-9) const
equals
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25
HybridFactor()=default
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
KeyVector continuousKeys_
Record continuous keys for book-keeping.
Definition: HybridFactor.h:62
traits
Definition: chartTesting.h:28
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
const G double tol
Definition: Group.h:86
const KeyVector keys
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
DiscreteKeys discreteKeys_
Definition: HybridFactor.h:60
DiscreteKeys CollectDiscreteKeys(const DiscreteKeys &key1, const DiscreteKeys &key2)
KeyVector CollectKeys(const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys)
const Symbol key2('v', 2)
bool equals(const This &other, double tol=1e-9) const
check equality
Definition: Factor.cpp:42
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:20