diff --git a/.cproject b/.cproject index 3aa628e79..4385a9461 100644 --- a/.cproject +++ b/.cproject @@ -518,6 +518,14 @@ true true + + make + -j5 + ExpressionExample.run + true + true + true + make -j5 @@ -584,7 +592,6 @@ make - tests/testBayesTree.run true false @@ -592,7 +599,6 @@ make - testBinaryBayesNet.run true false @@ -640,7 +646,6 @@ make - testSymbolicBayesNet.run true false @@ -648,7 +653,6 @@ make - tests/testSymbolicFactor.run true false @@ -656,7 +660,6 @@ make - testSymbolicFactorGraph.run true false @@ -672,7 +675,6 @@ make - tests/testBayesTree true false @@ -1008,7 +1010,6 @@ make - testErrors.run true false @@ -1238,46 +1239,6 @@ true true - - make - -j5 - testBTree.run - true - true - true - - - make - -j5 - testDSF.run - true - true - true - - - make - -j5 - testDSFMap.run - true - true - true - - - make - -j5 - testDSFVector.run - true - true - true - - - make - -j5 - testFixedVector.run - true - true - true - make -j2 @@ -1360,6 +1321,7 @@ make + testSimulated2DOriented.run true false @@ -1399,6 +1361,7 @@ make + testSimulated2D.run true false @@ -1406,6 +1369,7 @@ make + testSimulated3D.run true false @@ -1419,6 +1383,46 @@ true true + + make + -j5 + testBTree.run + true + true + true + + + make + -j5 + testDSF.run + true + true + true + + + make + -j5 + testDSFMap.run + true + true + true + + + make + -j5 + testDSFVector.run + true + true + true + + + make + -j5 + testFixedVector.run + true + true + true + make -j5 @@ -1676,7 +1680,6 @@ cpack - -G DEB true false @@ -1684,7 +1687,6 @@ cpack - -G RPM true false @@ -1692,7 +1694,6 @@ cpack - -G TGZ true false @@ -1700,7 +1701,6 @@ cpack - --config CPackSourceConfig.cmake true false @@ -2427,7 +2427,6 @@ make - testGraph.run true false @@ -2435,7 +2434,6 @@ make - testJunctionTree.run true false @@ -2443,7 +2441,6 @@ make - testSymbolicBayesNetB.run true false @@ -2931,6 +2928,7 @@ make + tests/testGaussianISAM2 true false diff --git a/gtsam_unstable/examples/ExpressionExample.cpp b/gtsam_unstable/examples/ExpressionExample.cpp new file mode 100644 index 000000000..00336a319 --- /dev/null +++ b/gtsam_unstable/examples/ExpressionExample.cpp @@ -0,0 +1,98 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file ExpressionExample.cpp + * @brief A structure-from-motion example done with Expressions + * @author Frank Dellaert + * @author Duy-Nguyen Ta + * @date October 1, 2014 + */ + +/** + * This is the Expression version of SFMExample + * See detailed description of headers there, this focuses on explaining the AD part + */ + +// The two new headers that allow using our Automatic Differentiation Expression framework +#include +#include + +// Header order is close to far +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; +using namespace gtsam; + +/* ************************************************************************* */ +int main(int argc, char* argv[]) { + + Cal3_S2::shared_ptr K(new Cal3_S2(50.0, 50.0, 0.0, 50.0, 50.0)); + noiseModel::Isotropic::shared_ptr measurementNoise = noiseModel::Isotropic::Sigma(2, 1.0); // one pixel in u and v + + // Create the set of ground-truth landmarks and poses + vector points = createPoints(); + vector poses = createPoses(); + + // Create a factor graph + NonlinearFactorGraph graph; + + // Specify uncertainty on first pose prior + noiseModel::Diagonal::shared_ptr poseNoise = noiseModel::Diagonal::Sigmas((Vector(6) << Vector3::Constant(0.3), Vector3::Constant(0.1))); + + // Here we don't use a PriorFactor but directly the BADFactor class + // The object x0 is an Expression, and we create a factor wanting it to be equal to poses[0] + Pose3_ x0('x',0); +// graph.push_back(BADFactor(poses[0], x0, poseNoise)); + graph.push_back(PriorFactor(Symbol('x', 0), poses[0], poseNoise)); // add directly to graph + + // Simulated measurements from each camera pose, adding them to the factor graph + for (size_t i = 0; i < poses.size(); ++i) { + for (size_t j = 0; j < points.size(); ++j) { + SimpleCamera camera(poses[i], *K); + Point2 measurement = camera.project(points[j]); + graph.push_back(GenericProjectionFactor(measurement, measurementNoise, Symbol('x', i), Symbol('l', j), K)); + } + } + + // Because the structure-from-motion problem has a scale ambiguity, the problem is still under-constrained + // Here we add a prior on the position of the first landmark. This fixes the scale by indicating the distance + // between the first camera and the first landmark. All other landmark positions are interpreted using this scale. + noiseModel::Isotropic::shared_ptr pointNoise = noiseModel::Isotropic::Sigma(3, 0.1); + graph.push_back(PriorFactor(Symbol('l', 0), points[0], pointNoise)); // add directly to graph + graph.print("Factor Graph:\n"); + + // Create the data structure to hold the initial estimate to the solution + // Intentionally initialize the variables off from the ground truth + Values initialEstimate; + for (size_t i = 0; i < poses.size(); ++i) + initialEstimate.insert(Symbol('x', i), poses[i].compose(Pose3(Rot3::rodriguez(-0.1, 0.2, 0.25), Point3(0.05, -0.10, 0.20)))); + for (size_t j = 0; j < points.size(); ++j) + initialEstimate.insert(Symbol('l', j), points[j].compose(Point3(-0.25, 0.20, 0.15))); + initialEstimate.print("Initial Estimates:\n"); + + /* Optimize the graph and print results */ + Values result = DoglegOptimizer(graph, initialEstimate).optimize(); + result.print("Final results:\n"); + + return 0; +} +/* ************************************************************************* */ +