TypedLabeledSymbols now convert properly to Symbols, so they can be used to add a runtime label to a TypedKey to express "Pose 1 of robot A"
parent
31999ecb1f
commit
d0aed559b5
14
cpp/Key.h
14
cpp/Key.h
|
@ -111,13 +111,13 @@ namespace gtsam {
|
|||
|
||||
/**
|
||||
* Encoding two numbers into a single size_t for conversion to Symbol
|
||||
* Stores the label in the upper bits of the index
|
||||
*
|
||||
* STILL IN TESTING - DO NOT USE!!
|
||||
* Stores the label in the upper bytes of the index
|
||||
*/
|
||||
size_t encode() {
|
||||
//short label = label_;
|
||||
return this->j_; // + (label << 32);
|
||||
size_t encode() const {
|
||||
short label = (short) label_; //bound size of label to 2 bytes
|
||||
size_t shift = (sizeof(size_t)-sizeof(short)) * 8;
|
||||
size_t modifier = ((size_t) label) << shift;
|
||||
return this->j_ + modifier;
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,7 +184,7 @@ namespace gtsam {
|
|||
|
||||
/** Casting constructor from TypedLabeledSymbol */
|
||||
template<class T, char C, typename L>
|
||||
Symbol(const TypedLabeledSymbol<T,C, L>& symbol): c_(C), j_(symbol.encode()) {}
|
||||
Symbol(const TypedLabeledSymbol<T,C,L>& symbol): c_(C), j_(symbol.encode()) {}
|
||||
|
||||
/** "Magic" key casting constructor from string */
|
||||
#ifdef GTSAM_MAGIC_KEY
|
||||
|
|
|
@ -54,27 +54,29 @@ TEST ( TypedLabledSymbol, basic_operations ) {
|
|||
CHECK(key5 < key6);
|
||||
}
|
||||
|
||||
/* ************************************************************************* *
|
||||
/* ************************************************************************* */
|
||||
TEST ( TypedLabledSymbol, encoding ) {
|
||||
typedef TypedLabeledSymbol<Pose3, 'x', char> RobotKey;
|
||||
|
||||
cout << "short : " << sizeof(short) << " size_t: " << sizeof(size_t) << endl;
|
||||
cout << "unsigned int : " << sizeof(unsigned int) << endl;
|
||||
|
||||
RobotKey key1(37, 'A');
|
||||
|
||||
size_t index = key1.index();
|
||||
size_t modifier = 65;
|
||||
modifier = modifier << sizeof(size_t) * 4;
|
||||
index += modifier;
|
||||
cout << "index: " << index << " modifier: " << modifier << endl;
|
||||
// Note: calculations done in test due to possible differences between machines
|
||||
// take the upper two bytes for the label
|
||||
short label = key1.label();
|
||||
|
||||
// find the shift necessary
|
||||
size_t shift = (sizeof(size_t)-sizeof(short)) * 8;
|
||||
size_t modifier = label;
|
||||
modifier = modifier << shift;
|
||||
size_t index = key1.index() + modifier;
|
||||
|
||||
// short encoded = 65;
|
||||
// size_t modifier = encoded << 32;
|
||||
// size_t index = 37 + encoded;
|
||||
// Symbol act(key1), exp('x', index);
|
||||
// CHECK(assert_equal(exp, act));
|
||||
// check index encoding
|
||||
Symbol act1(key1), exp('x', index);
|
||||
CHECK(assert_equal(exp, act1));
|
||||
|
||||
// check casting
|
||||
Symbol act2 = (Symbol) key1;
|
||||
CHECK(assert_equal(exp, act2));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue