gtsam  4.0.0
gtsam
LabeledSymbol.h
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 
20 #pragma once
21 
22 #include <gtsam/inference/Symbol.h>
23 
24 namespace gtsam {
25 
34 class GTSAM_EXPORT LabeledSymbol {
35 protected:
36  unsigned char c_, label_;
37  std::uint64_t j_;
38 
39 public:
41  LabeledSymbol();
42 
44  LabeledSymbol(const LabeledSymbol& key);
45 
47  LabeledSymbol(unsigned char c, unsigned char label, std::uint64_t j);
48 
51 
53  operator gtsam::Key() const;
54 
55  // Testable Requirements
56  void print(const std::string& s = "") const;
57 
58  bool equals(const LabeledSymbol& expected, double tol = 0.0) const {
59  return (*this) == expected;
60  }
61 
63  gtsam::Key key() const { return (gtsam::Key) *this; }
64 
66  inline unsigned char label() const { return label_; }
67 
69  inline unsigned char chr() const { return c_; }
70 
72  inline size_t index() const { return j_; }
73 
75  operator std::string() const;
76 
78  bool operator<(const LabeledSymbol& comp) const;
79  bool operator==(const LabeledSymbol& comp) const;
80  bool operator==(gtsam::Key comp) const;
81  bool operator!=(const LabeledSymbol& comp) const;
82  bool operator!=(gtsam::Key comp) const;
83 
90  // Checks only the type
91  static boost::function<bool(gtsam::Key)> TypeTest(unsigned char c);
92 
93  // Checks only the robot ID (label_)
94  static boost::function<bool(gtsam::Key)> LabelTest(unsigned char label);
95 
96  // Checks both type and the robot ID
97  static boost::function<bool(gtsam::Key)> TypeLabelTest(unsigned char c, unsigned char label);
98 
99  // Converts to upper/lower versions of labels
100  LabeledSymbol upper() const { return LabeledSymbol(c_, toupper(label_), j_); }
101  LabeledSymbol lower() const { return LabeledSymbol(c_, tolower(label_), j_); }
102 
103  // Create a new symbol with a different value
104  LabeledSymbol newChr(unsigned char c) const { return LabeledSymbol(c, label_, j_); }
105  LabeledSymbol newLabel(unsigned char label) const { return LabeledSymbol(c_, label, j_); }
106 
107 private:
108 
110  friend class boost::serialization::access;
111  template<class ARCHIVE>
112  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
113  ar & BOOST_SERIALIZATION_NVP(c_);
114  ar & BOOST_SERIALIZATION_NVP(label_);
115  ar & BOOST_SERIALIZATION_NVP(j_);
116  }
117 }; // \class LabeledSymbol
118 
120 inline Key mrsymbol(unsigned char c, unsigned char label, size_t j) {
121  return (Key)LabeledSymbol(c,label,j);
122 }
123 
125 inline unsigned char mrsymbolChr(Key key) { return LabeledSymbol(key).chr(); }
126 
128 inline unsigned char mrsymbolLabel(Key key) { return LabeledSymbol(key).label(); }
129 
131 inline size_t mrsymbolIndex(Key key) { return LabeledSymbol(key).index(); }
132 
134 template<> struct traits<LabeledSymbol> : public Testable<LabeledSymbol> {};
135 
136 } // \namespace gtsam
137 
Customized version of gtsam::Symbol for multi-robot use.
Definition: LabeledSymbol.h:34
unsigned char chr() const
Retrieve key character.
Definition: LabeledSymbol.h:69
unsigned char label() const
Retrieve label character.
Definition: LabeledSymbol.h:66
unsigned char mrsymbolChr(Key key)
Return the character portion of a symbol key.
Definition: LabeledSymbol.h:125
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
unsigned char mrsymbolLabel(Key key)
Return the label portion of a symbol key.
Definition: LabeledSymbol.h:128
Template to create a binary predicate.
Definition: Testable.h:110
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
Key mrsymbol(unsigned char c, unsigned char label, size_t j)
Create a symbol key from a character, label and index, i.e.
Definition: LabeledSymbol.h:120
size_t mrsymbolIndex(Key key)
Return the index portion of a symbol key.
Definition: LabeledSymbol.h:131
bool operator!=(const Matrix &A, const Matrix &B)
inequality
Definition: Matrix.h:109
size_t index() const
Retrieve key index.
Definition: LabeledSymbol.h:72
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::Key key() const
return the integer version
Definition: LabeledSymbol.h:63
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition: Matrix.h:102