22#include <gtsam/slam/KarcherMeanFactor.h>
28template <
class T,
class ALLOC>
29T FindKarcherMeanImpl(
const vector<T, ALLOC>& rotations) {
32 NonlinearFactorGraph graph;
33 static const Key kKey(0);
34 for (
const auto& R : rotations) {
35 graph.addPrior<T>(kKey, R);
38 initial.insert<T>(kKey, T());
39 auto result = GaussNewtonOptimizer(graph, initial).optimize();
40 return result.at<T>(kKey);
44 typename =
typename std::enable_if< std::is_same<gtsam::Rot3, T>::value >::type >
45T FindKarcherMean(
const std::vector<T>& rotations) {
46 return FindKarcherMeanImpl(rotations);
50T FindKarcherMean(
const std::vector<T, Eigen::aligned_allocator<T>>& rotations) {
51 return FindKarcherMeanImpl(rotations);
55T FindKarcherMean(std::initializer_list<T>&& rotations) {
56 return FindKarcherMeanImpl(std::vector<T, Eigen::aligned_allocator<T> >(rotations));
60template <
typename CONTAINER>
62 boost::optional<double> beta)
65 throw std::invalid_argument(
66 "KarcherMeanFactor needs dimension for dynamic types.");
70 Matrix A = Matrix::Identity(d, d);
71 if (beta) A *= std::sqrt(*beta);
72 std::map<Key, Matrix> terms;
77 boost::make_shared<JacobianFactor>(terms, Vector::Zero(d));
Factor Graph consisting of non-linear factors.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:125
Nonlinear factor base class.
Definition: NonlinearFactor.h:43
KarcherMeanFactor(const CONTAINER &keys, int d=D, boost::optional< double > beta=boost::none)
Construct from given keys.
Definition: KarcherMeanFactor-inl.h:61