gtsam
Loading...
Searching...
No Matches
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
19
20#pragma once
21
22#include <gtsam/base/Testable.h>
24
25#include <functional>
26
27namespace gtsam {
28
37class GTSAM_EXPORT LabeledSymbol {
38 protected:
39 unsigned char c_, label_;
40 std::uint64_t j_;
41
42 public:
45
48
51
53 LabeledSymbol(unsigned char c, unsigned char label, std::uint64_t j);
54
57
61
63 void print(const std::string& s = "") const;
64
66 bool equals(const LabeledSymbol& expected, double tol = 0.0) const {
67 return (*this) == expected;
68 }
69
73
75 operator Key() const;
76
78 Key key() const { return (Key) * this; }
79
81 inline unsigned char label() const { return label_; }
82
84 inline unsigned char chr() const { return c_; }
85
87 inline std::uint64_t index() const { return j_; }
88
90 operator std::string() const;
91
93 friend GTSAM_EXPORT std::ostream& operator<<(std::ostream&,
94 const LabeledSymbol&);
95
99
100 bool operator<(const LabeledSymbol& comp) const;
101 bool operator==(const LabeledSymbol& comp) const;
102 bool operator==(Key comp) const;
103 bool operator!=(const LabeledSymbol& comp) const;
104 bool operator!=(Key comp) const;
105
113
115 static std::function<bool(Key)> TypeTest(unsigned char c);
116
118 static std::function<bool(Key)> LabelTest(unsigned char label);
119
121 static std::function<bool(Key)> TypeLabelTest(unsigned char c,
122 unsigned char label);
123
127
129 LabeledSymbol upper() const { return LabeledSymbol(c_, toupper(label_), j_); }
130 LabeledSymbol lower() const { return LabeledSymbol(c_, tolower(label_), j_); }
131
133 LabeledSymbol newChr(unsigned char c) const {
134 return LabeledSymbol(c, label_, j_);
135 }
136
138 LabeledSymbol newLabel(unsigned char label) const {
139 return LabeledSymbol(c_, label, j_);
140 }
141
143
144 private:
145#if GTSAM_ENABLE_BOOST_SERIALIZATION
147 friend class boost::serialization::access;
148 template <class ARCHIVE>
149 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
150 ar& BOOST_SERIALIZATION_NVP(c_);
151 ar& BOOST_SERIALIZATION_NVP(label_);
152 ar& BOOST_SERIALIZATION_NVP(j_);
153 }
154#endif
155}; // \class LabeledSymbol
156
158inline Key mrsymbol(unsigned char c, unsigned char label, std::uint64_t j) {
159 return (Key)LabeledSymbol(c, label, j);
160}
161
163inline unsigned char mrsymbolChr(Key key) { return LabeledSymbol(key).chr(); }
164
166inline unsigned char mrsymbolLabel(Key key) {
167 return LabeledSymbol(key).label();
168}
169
171inline std::uint64_t mrsymbolIndex(Key key) {
172 return LabeledSymbol(key).index();
173}
174
176template <>
177struct traits<LabeledSymbol> : public Testable<LabeledSymbol> {};
178
179} // namespace gtsam
Concept check for values that can be used in unit tests.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
unsigned char mrsymbolChr(Key key)
Return the character portion of a symbol key.
Definition LabeledSymbol.h:163
std::uint64_t mrsymbolIndex(Key key)
Return the index portion of a symbol key.
Definition LabeledSymbol.h:171
unsigned char mrsymbolLabel(Key key)
Return the label portion of a symbol key.
Definition LabeledSymbol.h:166
Key mrsymbol(unsigned char c, unsigned char label, std::uint64_t j)
Create a symbol key from a character, label and index, i.e. xA5.
Definition LabeledSymbol.h:158
bool operator!=(const Matrix &A, const Matrix &B)
inequality
Definition Matrix.h:107
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
bool operator==(const Matrix &A, const Matrix &B)
equality is just equal_with_abs_tol 1e-9
Definition Matrix.h:100
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
Customized version of gtsam::Symbol for multi-robot use.
Definition LabeledSymbol.h:37
void print(const std::string &s="") const
Prints the LabeledSymbol with an optional prefix string.
Definition LabeledSymbol.cpp:69
Key key() const
return the integer version
Definition LabeledSymbol.h:78
LabeledSymbol()
Default constructor.
Definition LabeledSymbol.cpp:28
LabeledSymbol newChr(unsigned char c) const
Create a new symbol with a different character.
Definition LabeledSymbol.h:133
std::uint64_t index() const
Retrieve key index.
Definition LabeledSymbol.h:87
LabeledSymbol upper() const
Converts to upper/lower versions of labels.
Definition LabeledSymbol.h:129
unsigned char chr() const
Retrieve key character.
Definition LabeledSymbol.h:84
unsigned char label() const
Retrieve label character.
Definition LabeledSymbol.h:81
bool equals(const LabeledSymbol &expected, double tol=0.0) const
Checks if this LabeledSymbol is equal to another, tolerance is ignored.
Definition LabeledSymbol.h:66
LabeledSymbol newLabel(unsigned char label) const
Create a new symbol with a different label.
Definition LabeledSymbol.h:138