TransferFactor.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * GTSAM Copyright 2010-2024, Georgia Tech Research Corporation,
3  * Atlanta, Georgia 30332-0415
4  * All Rights Reserved
5  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
6  * See LICENSE for the license information
7  * -------------------------------------------------------------------------- */
8 
9 /*
10  * @file TransferFactor.h
11  * @brief TransferFactor class
12  * @author Frank Dellaert
13  * @date October 24, 2024
14  */
15 
16 #pragma once
17 
22 
23 namespace gtsam {
24 
32 template <typename F>
33 class TransferFactor : public NoiseModelFactorN<F, F> {
35  std::vector<std::tuple<Point2, Point2, Point2>>
37 
38  public:
53  const Point2& pc, const SharedNoiseModel& model = nullptr)
55  key1_(key1),
56  key2_(key2),
57  triplets_({std::make_tuple(pa, pb, pc)}) {}
58 
70  const std::vector<std::tuple<Point2, Point2, Point2>>& triplets,
71  const SharedNoiseModel& model = nullptr)
73  key1_(key1),
74  key2_(key2),
75  triplets_(triplets) {}
76 
77  // Create Matrix3 objects based on EdgeKey configurations
78  std::pair<Matrix3, Matrix3> getMatrices(const F& F1, const F& F2) const {
79  // Fill Fca and Fcb based on EdgeKey configurations
80  if (key1_.i() == key2_.i()) {
81  return {F1.matrix(), F2.matrix()};
82  } else if (key1_.i() == key2_.j()) {
83  return {F1.matrix(), F2.matrix().transpose()};
84  } else if (key1_.j() == key2_.i()) {
85  return {F1.matrix().transpose(), F2.matrix()};
86  } else if (key1_.j() == key2_.j()) {
87  return {F1.matrix().transpose(), F2.matrix().transpose()};
88  } else {
89  throw std::runtime_error(
90  "TransferFactor: invalid EdgeKey configuration.");
91  }
92  }
93 
95  Vector evaluateError(const F& F1, const F& F2,
96  OptionalMatrixType H1 = nullptr,
97  OptionalMatrixType H2 = nullptr) const override {
98  std::function<Vector(const F&, const F&)> transfer = [&](const F& F1,
99  const F& F2) {
100  Vector errors(2 * triplets_.size());
101  size_t idx = 0;
102  auto [Fca, Fcb] = getMatrices(F1, F2);
103  for (const auto& tuple : triplets_) {
104  const auto& [pa, pb, pc] = tuple;
105  Point2 transferredPoint = EpipolarTransfer(Fca, pa, Fcb, pb);
106  Vector2 error = transferredPoint - pc;
107  errors.segment<2>(idx) = error;
108  idx += 2;
109  }
110  return errors;
111  };
112  if (H1) *H1 = numericalDerivative21<Vector, F, F>(transfer, F1, F2);
113  if (H2) *H2 = numericalDerivative22<Vector, F, F>(transfer, F1, F2);
114  return transfer(F1, F2);
115  }
116 };
117 
118 } // namespace gtsam
gtsam::TransferFactor::triplets_
std::vector< std::tuple< Point2, Point2, Point2 > > triplets_
Point triplets.
Definition: TransferFactor.h:36
gtsam::NoiseModelFactor::error
double error(const Values &c) const override
Definition: NonlinearFactor.cpp:136
gtsam::EpipolarTransfer
Point2 EpipolarTransfer(const Matrix3 &Fca, const Point2 &pa, const Matrix3 &Fcb, const Point2 &pb)
Transfer projections from cameras a and b to camera c.
Definition: FundamentalMatrix.cpp:15
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:38
numericalDerivative.h
Some functions to compute numerical derivatives.
make_tuple
tuple make_tuple()
Definition: cast.h:1383
gtsam::EdgeKey::i
std::uint32_t i() const
Retrieve high 32 bits.
Definition: EdgeKey.h:52
gtsam::TransferFactor::TransferFactor
TransferFactor(EdgeKey key1, EdgeKey key2, const Point2 &pa, const Point2 &pb, const Point2 &pc, const SharedNoiseModel &model=nullptr)
Constructor for a single triplet of points.
Definition: TransferFactor.h:52
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:431
gtsam::TransferFactor::TransferFactor
TransferFactor(EdgeKey key1, EdgeKey key2, const std::vector< std::tuple< Point2, Point2, Point2 >> &triplets, const SharedNoiseModel &model=nullptr)
Constructor that accepts a vector of point triplets.
Definition: TransferFactor.h:68
gtsam::TransferFactor::key1_
EdgeKey key1_
Definition: TransferFactor.h:34
Vector2
Definition: test_operator_overloading.cpp:18
gtsam::Point2
Vector2 Point2
Definition: Point2.h:32
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::NoiseModelFactorN< F, F >::key1
Key key1() const
Definition: NonlinearFactor.h:731
gtsam::symbol_shorthand::F
Key F(std::uint64_t j)
Definition: inference/Symbol.h:153
gtsam::TransferFactor
Definition: TransferFactor.h:33
F1
const Matrix26 F1
Definition: testRegularImplicitSchurFactor.cpp:37
pc
int RealScalar int RealScalar int RealScalar * pc
Definition: level1_cplx_impl.h:119
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
NonlinearFactor.h
Non-linear factor base classes.
gtsam::NoiseModelFactorN< F, F >::key2
Key key2() const
Definition: NonlinearFactor.h:735
gtsam::EdgeKey
Definition: EdgeKey.h:25
gtsam::TransferFactor::getMatrices
std::pair< Matrix3, Matrix3 > getMatrices(const F &F1, const F &F2) const
Definition: TransferFactor.h:78
gtsam
traits
Definition: SFMdata.h:40
gtsam::TransferFactor::key2_
EdgeKey key2_
the two EdgeKeys
Definition: TransferFactor.h:34
FundamentalMatrix.h
tuple
Definition: pytypes.h:2077
gtsam::EdgeKey::j
std::uint32_t j() const
Retrieve low 32 bits.
Definition: EdgeKey.h:55
EdgeKey.h
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:55
gtsam::TransferFactor::evaluateError
Vector evaluateError(const F &F1, const F &F2, OptionalMatrixType H1=nullptr, OptionalMatrixType H2=nullptr) const override
vector of errors returns 2*N vector
Definition: TransferFactor.h:95


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:42:30