UnaryExpression

release/4.3a0
dellaert 2014-09-21 17:43:47 +02:00
parent b89f65cccc
commit 6a5e4191a3
1 changed files with 35 additions and 6 deletions

View File

@ -19,6 +19,7 @@
#include <gtsam/nonlinear/NonlinearFactor.h> #include <gtsam/nonlinear/NonlinearFactor.h>
#include <gtsam/geometry/Pose3.h> #include <gtsam/geometry/Pose3.h>
#include <gtsam/geometry/Cal3_S2.h> #include <gtsam/geometry/Cal3_S2.h>
#include <gtsam/geometry/PinholeCamera.h>
#include <gtsam/slam/GeneralSFMFactor.h> #include <gtsam/slam/GeneralSFMFactor.h>
#include <gtsam/inference/Key.h> #include <gtsam/inference/Key.h>
#include <gtsam/base/Testable.h> #include <gtsam/base/Testable.h>
@ -71,6 +72,34 @@ public:
} }
}; };
//-----------------------------------------------------------------------------
/// Unary Expression
template<class T, class E>
class UnaryExpression {
public:
typedef T (*function)(const typename E::type&);
private:
const E expression_;
function f_;
public:
typedef T type;
/// Constructor with a single key
UnaryExpression(function f, const E& expression) :
expression_(expression), f_(f) {
}
T value(const Values& values) const {
return f_(expression_.value(values));
}
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// Binary Expression /// Binary Expression
template<class T, class E1, class E2> template<class T, class E1, class E2>
@ -106,10 +135,8 @@ Point3 transformTo(const Pose3& x, const Point3& p) {
return x.transform_to(p); return x.transform_to(p);
} }
/// Expression version of project Point2 project(const Point3& p) {
template<class E> return PinholeCamera<Cal3_S2>::project_to_camera(p);
LeafExpression<Point2> project(const E& p) {
return LeafExpression<Point2>(0);
} }
/// Expression version of uncalibrate /// Expression version of uncalibrate
@ -206,8 +233,10 @@ TEST(BAD, test) {
// Create expression tree // Create expression tree
typedef BinaryExpression<Point3, LeafExpression<Pose3>, LeafExpression<Point3> > Binary1; typedef BinaryExpression<Point3, LeafExpression<Pose3>, LeafExpression<Point3> > Binary1;
Binary1 p_cam = Binary1(transformTo, x, p); Binary1 p_cam(transformTo, x, p);
LeafExpression<Point2> projection = project(p_cam);
typedef UnaryExpression<Point2, Binary1> Unary1;
Unary1 projection(project, p_cam);
LeafExpression<Point2> uv_hat = uncalibrate(K, projection); LeafExpression<Point2> uv_hat = uncalibrate(K, projection);
// Create factor // Create factor