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"

release/4.3a0
Alex Cunningham 2010-02-10 14:39:58 +00:00
parent 31999ecb1f
commit d0aed559b5
2 changed files with 23 additions and 21 deletions

View File

@ -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

View File

@ -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));
}