2009-11-11 04:19:00 +08:00
|
|
|
/**
|
|
|
|
|
* @file VSLAMGraph.h
|
|
|
|
|
* @brief A factor graph for the VSLAM problem
|
|
|
|
|
* @author Alireza Fathi
|
|
|
|
|
* @author Carlos Nieto
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
|
|
#include "VSLAMGraph.h"
|
2009-11-11 13:14:03 +08:00
|
|
|
#include "NonlinearFactorGraph-inl.h"
|
|
|
|
|
#include "NonlinearOptimizer-inl.h"
|
2009-11-13 14:18:27 +08:00
|
|
|
#include "NonlinearEquality.h"
|
2009-11-11 04:19:00 +08:00
|
|
|
|
|
|
|
|
using namespace std;
|
2009-11-13 14:18:27 +08:00
|
|
|
|
|
|
|
|
namespace gtsam {
|
2009-11-11 04:19:00 +08:00
|
|
|
|
2009-11-11 13:14:03 +08:00
|
|
|
// explicit instantiation so all the code is there and we can link with it
|
|
|
|
|
template class FactorGraph<VSLAMFactor>;
|
|
|
|
|
template class NonlinearFactorGraph<VSLAMConfig>;
|
|
|
|
|
template class NonlinearOptimizer<VSLAMGraph,VSLAMConfig>;
|
|
|
|
|
|
2009-11-11 04:19:00 +08:00
|
|
|
/* ************************************************************************* */
|
2009-11-13 14:18:27 +08:00
|
|
|
bool compareLandmark(const std::string& key,
|
|
|
|
|
const VSLAMConfig& feasible,
|
|
|
|
|
const VSLAMConfig& input) {
|
|
|
|
|
int j = atoi(key.substr(1, key.size() - 1).c_str());
|
|
|
|
|
return feasible.landmarkPoint(j).equals(input.landmarkPoint(j));
|
|
|
|
|
}
|
2009-11-11 04:19:00 +08:00
|
|
|
|
2009-11-13 14:18:27 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
void VSLAMGraph::addLandmarkConstraint(int j, const gtsam::Point3& p) {
|
Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just says something like
if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
2010-01-14 06:25:03 +08:00
|
|
|
typedef NonlinearEquality<VSLAMConfig,VSLAMConfig::PointKey,Point3> NLE;
|
|
|
|
|
boost::shared_ptr<NLE> factor(new NLE(j, p));
|
2009-11-13 14:18:27 +08:00
|
|
|
push_back(factor);
|
2009-11-11 04:19:00 +08:00
|
|
|
}
|
|
|
|
|
|
2009-11-18 01:19:54 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
bool compareCamera(const std::string& key,
|
|
|
|
|
const VSLAMConfig& feasible,
|
|
|
|
|
const VSLAMConfig& input) {
|
|
|
|
|
int j = atoi(key.substr(1, key.size() - 1).c_str());
|
|
|
|
|
return feasible.cameraPose(j).equals(input.cameraPose(j));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
|
void VSLAMGraph::addCameraConstraint(int j, const gtsam::Pose3& p) {
|
Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just says something like
if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
2010-01-14 06:25:03 +08:00
|
|
|
typedef NonlinearEquality<VSLAMConfig,VSLAMConfig::PoseKey,Pose3> NLE;
|
|
|
|
|
boost::shared_ptr<NLE> factor(new NLE(j,p));
|
2009-11-18 01:19:54 +08:00
|
|
|
push_back(factor);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-11 04:19:00 +08:00
|
|
|
/* ************************************************************************* */
|
|
|
|
|
|
2009-11-11 06:49:22 +08:00
|
|
|
} // namespace gtsam
|
|
|
|
|
|