38 using namespace gtsam;
52 for (
const auto &edge : relativeTranslations) {
55 if (key1 != key2 && edge.measured().equals(
Unit3(0.0, 0.0, 0.0))) {
56 sameTranslationDSF.
merge(key1, key2);
59 return sameTranslationDSF;
68 std::vector<BinaryMeasurement<T>> newEdges;
69 for (
const auto &edge :
edges) {
72 if (key1 == key2)
continue;
73 newEdges.emplace_back(key1, key2, edge.measured(), edge.noiseModel());
86 for (
const auto &optimizedAndDuplicateKeys : sameTranslationDSFMap.
sets()) {
87 Key optimizedKey = optimizedAndDuplicateKeys.first;
88 std::set<Key> duplicateKeys = optimizedAndDuplicateKeys.second;
90 for (
const Key duplicateKey : duplicateKeys) {
91 if (final_result.
exists(duplicateKey))
continue;
93 final_result.
at<
Point3>(optimizedKey));
104 for (
auto edge : relativeTranslations) {
106 edge.measured(), edge.noiseModel());
117 auto edge = relativeTranslations.begin();
118 if (edge == relativeTranslations.end())
return;
123 if (betweenTranslations.empty()) {
125 edge->key2(), scale * edge->measured().point3(), edge->noiseModel());
130 for (
auto prior_edge : betweenTranslations) {
132 prior_edge.key1(), prior_edge.key2(), prior_edge.measured(),
133 prior_edge.noiseModel());
140 std::mt19937 *
rng,
const Values &initialValues)
const {
141 uniform_real_distribution<double> randomVal(-1, 1);
151 j,
Point3(randomVal(*rng), randomVal(*rng), randomVal(*rng)));
157 for (
auto edge : relativeTranslations) {
162 for (
auto edge : betweenTranslations) {
172 const Values &initialValues)
const {
173 return initializeRandomly(relativeTranslations, betweenTranslations,
180 const Values &initialValues)
const {
187 const std::vector<BinaryMeasurement<Point3>> nonzeroBetweenTranslations =
195 addPrior(nonzeroRelativeTranslations, scale, nonzeroBetweenTranslations,
200 nonzeroRelativeTranslations, nonzeroBetweenTranslations, initialValues);
204 if (initial.
empty() && !sameTranslationDSFMap.
sets().empty()) {
205 for (
const auto &optimizedAndDuplicateKeys : sameTranslationDSFMap.
sets()) {
206 Key optimizedKey = optimizedAndDuplicateKeys.first;
217 const Values &poses,
const vector<KeyPair> &
edges) {
220 for (
auto edge : edges) {
225 const Unit3 w_aZb(Tb - Ta);
226 relativeTranslations.emplace_back(a, b, w_aZb, edgeNoiseModel);
228 return relativeTranslations;
vector< MFAS::KeyPair > edges
static std::mt19937 kRandomNumberGenerator(42)
const Point3 & translation(OptionalJacobian< 3, 6 > Hself={}) const
get translation
Values initializeRandomly(const std::vector< BinaryMeasurement< Unit3 >> &relativeTranslations, const std::vector< BinaryMeasurement< Point3 >> &betweenTranslations, std::mt19937 *rng, const Values &initialValues=Values()) const
Create random initial translations.
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
A non-templated config holding any types of Manifold-group elements.
Factor Graph consisting of non-linear factors.
void merge(const KEY &x, const KEY &y)
Merge two sets.
std::vector< BinaryMeasurement< Unit3 > > TranslationEdges
const ValueType at(Key j) const
Values run(const TranslationEdges &relativeTranslations, const double scale=1.0, const std::vector< BinaryMeasurement< Point3 >> &betweenTranslations={}, const Values &initialValues=Values()) const
Build and optimize factor graph.
NonlinearFactorGraph graph
std::vector< BinaryMeasurement< T > > removeSameTranslationNodes(const std::vector< BinaryMeasurement< T >> &edges, const DSFMap< Key > &sameTranslationDSFMap)
static TranslationEdges SimulateMeasurements(const Values &poses, const std::vector< KeyPair > &edges)
Simulate translation direction measurements.
Values addSameTranslationNodes(const Values &result, const DSFMap< Key > &sameTranslationDSFMap)
Represents a 3D point on a unit sphere.
DSFMap< Key > getSameTranslationDSFMap(const std::vector< BinaryMeasurement< Unit3 >> &relativeTranslations)
const Symbol key1('v', 1)
void addPrior(const std::vector< BinaryMeasurement< Unit3 >> &relativeTranslations, const double scale, const std::vector< BinaryMeasurement< Point3 >> &betweenTranslations, NonlinearFactorGraph *graph, const SharedNoiseModel &priorNoiseModel=noiseModel::Isotropic::Sigma(3, 0.01)) const
Add 3 factors to the graph:
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
NonlinearFactorGraph buildGraph(const std::vector< BinaryMeasurement< Unit3 >> &relativeTranslations) const
Build the factor graph to do the optimization.
Binary factor for a relative translation direction measurement.
Non-linear factor base classes.
static double scale(double x, double a, double b, double t1, double t2)
Scale x from [a, b] to [t1, t2].
std::map< KEY, Set > sets() const
return all sets, i.e. a partition of all elements
void insert(Key j, const Value &val)
Allow for arbitrary type in DSF.
Recovering translations in an epipolar graph when rotations are given.
KEY find(const KEY &key) const
Given key, find the representative key for the set in which it lives.
std::uint64_t Key
Integer nonlinear key type.
noiseModel::Base::shared_ptr SharedNoiseModel
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)
graph addPrior(1, Pose2(0, 0, 0), priorNoise)
const Symbol key2('v', 2)