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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
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
|
|
|
#include "VSLAMFactor.h"
|
2009-11-11 06:49:22 +08:00
|
|
|
#include "NonlinearFactorGraph.h"
|
|
|
|
|
#include "FactorGraph-inl.h"
|
2009-11-11 04:19:00 +08:00
|
|
|
#include "VSLAMConfig.h"
|
2009-11-17 09:19:55 +08:00
|
|
|
#include "Testable.h"
|
2009-11-11 04:19:00 +08:00
|
|
|
|
2009-11-11 06:49:22 +08:00
|
|
|
namespace gtsam{
|
2009-11-11 04:19:00 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Non-linear factor graph for visual SLAM
|
|
|
|
|
*/
|
2009-12-10 03:11:45 +08:00
|
|
|
class VSLAMGraph : public gtsam::NonlinearFactorGraph<VSLAMConfig>{
|
2009-11-11 04:19:00 +08:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/** default constructor is empty graph */
|
|
|
|
|
VSLAMGraph() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* print out graph
|
|
|
|
|
*/
|
|
|
|
|
void print(const std::string& s = "") const {
|
|
|
|
|
gtsam::NonlinearFactorGraph<VSLAMConfig>::print(s);
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-17 09:19:55 +08:00
|
|
|
/**
|
|
|
|
|
* equals
|
|
|
|
|
*/
|
2009-12-10 03:11:45 +08:00
|
|
|
bool equals(const VSLAMGraph& p, double tol=1e-9) const {
|
|
|
|
|
return gtsam::NonlinearFactorGraph<VSLAMConfig>::equals(p, tol);
|
|
|
|
|
}
|
2009-11-13 14:18:27 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a constraint on a landmark (for now, *must* be satisfied in any Config)
|
|
|
|
|
* @param j index of landmark
|
|
|
|
|
* @param p to which point to constrain it to
|
|
|
|
|
*/
|
|
|
|
|
void addLandmarkConstraint(int j, const Point3& p = Point3());
|
2009-11-17 09:19:55 +08:00
|
|
|
|
2009-11-18 01:19:54 +08:00
|
|
|
/**
|
|
|
|
|
* Add a constraint on a camera (for now, *must* be satisfied in any Config)
|
|
|
|
|
* @param j index of camera
|
|
|
|
|
* @param p to which pose to constrain it to
|
|
|
|
|
*/
|
|
|
|
|
void addCameraConstraint(int j, const Pose3& p = Pose3());
|
|
|
|
|
|
2009-11-17 09:19:55 +08:00
|
|
|
private:
|
|
|
|
|
/** Serialization function */
|
|
|
|
|
friend class boost::serialization::access;
|
|
|
|
|
template<class Archive>
|
2009-12-10 03:11:45 +08:00
|
|
|
void serialize(Archive & ar, const unsigned int version) {}
|
2009-11-11 04:19:00 +08:00
|
|
|
};
|
2009-11-11 06:49:22 +08:00
|
|
|
|
|
|
|
|
} // namespace gtsam
|