A minimal traits example

release/4.3a0
Frank Dellaert 2016-02-16 10:23:02 -08:00
parent c11592e08f
commit a283938b47
1 changed files with 29 additions and 0 deletions

View File

@ -462,6 +462,35 @@ TEST( NonlinearOptimizer, logfile )
// EXPECT(actual.str()==expected.str()); // EXPECT(actual.str()==expected.str());
} }
/* ************************************************************************* */
// Minimal traits example
struct MyType : public Vector3 {
using Vector3::Vector3;
};
namespace gtsam {
template <>
struct traits<MyType> {
static bool Equals(const MyType&, const MyType&, double tol) {return true;}
static void Print(const MyType&, const string&) {}
static int GetDimension(const MyType&) { return 3;}
static MyType Retract(const MyType&, const Vector3&) {return MyType();}
static Vector3 Local(const MyType&, const MyType&) {return Vector3();}
};
}
TEST(NonlinearOptimizer, Traits) {
NonlinearFactorGraph fg;
fg += PriorFactor<MyType>(0, MyType(0, 0, 0), noiseModel::Isotropic::Sigma(3, 1));
Values init;
init.insert(0, MyType(0,0,0));
LevenbergMarquardtOptimizer optimizer(fg, init);
Values actual = optimizer.optimize();
EXPECT(assert_equal(init, actual));
}
/* ************************************************************************* */ /* ************************************************************************* */
int main() { int main() {
TestResult tr; TestResult tr;