22#include <gtsam/constrained/QcqpProblem.h>
23#include <gtsam/constrained/QpCost.h>
52 static_assert(std::is_same_v<T, Pose2> || std::is_same_v<T, Pose3>,
53 "KnownLandmarkFactor supports only Pose2 and Pose3");
57 using Point =
typename T::Translation;
69 : Base(model,
key), wL_(wL), measured_kP_(measured_kP) {}
71 NonlinearFactor::shared_ptr
clone()
const override {
72 return std::make_shared<This>(*
this);
76 double tol = 1e-9)
const override {
77 const auto* e =
dynamic_cast<const This*
>(&expected);
85 const Point predicted_kP = wTk.transformTo(wL_, H);
86 return predicted_kP - measured_kP_;
106 static_assert(std::is_same_v<T, Pose2> || std::is_same_v<T, Pose3>,
107 "KnownLandmarkFactor2 supports only Pose2 and Pose3");
111 using Point =
typename T::Translation;
123 : Base(model,
key), wL_(wL), measured_kP_(measured_kP) {}
125 NonlinearFactor::shared_ptr
clone()
const override {
126 return std::make_shared<This>(*
this);
130 double tol = 1e-9)
const override {
131 const auto* e =
dynamic_cast<const This*
>(&expected);
139 const Point predicted_kP = kTw.transformFrom(wL_, H);
140 return predicted_kP - measured_kP_;
145 NonlinearEqualityConstraints* constraints,
146 size_t columnDimension = 1)
const override {
147 if (columnDimension != 1) {
148 throw std::invalid_argument(
149 "KnownLandmarkFactor2::qcqpFactors only supports column dimension "
153 throw std::invalid_argument(
154 "KnownLandmarkFactor2::qcqpFactors costs is null");
156 if (!this->noiseModel_ ||
157 std::dynamic_pointer_cast<noiseModel::Robust>(this->noiseModel_) ||
158 this->noiseModel_->isConstrained()) {
159 throw std::runtime_error(
160 "KnownLandmarkFactor2::qcqpFactors requires a non-null, "
161 "non-robust/non-hard quadratic noise model");
164 constexpr int PointDim = Point::RowsAtCompileTime;
165 constexpr int N = T::LieAlgebra::RowsAtCompileTime;
166 constexpr int LiftedDim = 1 + PointDim *
N;
167 static_assert(
N == PointDim ||
N == PointDim + 1,
168 "Unsupported transform and point dimensions");
170 Matrix B = Matrix::Zero(PointDim, LiftedDim);
171 B.col(0) = -measured_kP_;
172 for (
int column = 0; column <
N; ++column) {
173 const double coefficient = column < PointDim ? wL_(column) : 1.0;
174 B.block(0, 1 + column * PointDim, PointDim, PointDim)
176 .setConstant(coefficient);
179 const Matrix whitenedB = this->noiseModel_->Whiten(B);
180 const Matrix Q = whitenedB.transpose() * whitenedB;
182 InsertQcqpConstraints<T, 1>(this->
key(), constraints);
3D Pose manifold SO(3) x R^3 and group SE(3)
Base class for noise model factors with N variables.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
This class stores a dense matrix and allows it to be accessed as a collection of blocks.
Definition SymmetricBlockMatrix.h:80
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition FactorGraph.h:147
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
static constexpr auto N
Definition NoiseModelFactorN.h:158
Key key() const
Definition NoiseModelFactorN.h:307
Nonlinear factor base class.
Definition NonlinearFactor.h:70
Definition NonlinearFactorGraph.h:57
NonlinearFactor::shared_ptr clone() const override
Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.
Definition KnownLandmarkFactor.h:71
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Check if two factors are equal.
Definition KnownLandmarkFactor.h:75
Vector evaluateError(const T &wTk, OptionalMatrixType H) const override
Evaluate the conventional world-from-k prediction minus measured_kP.
Definition KnownLandmarkFactor.h:84
KnownLandmarkFactor(Key key, const Point &wL, const Point &measured_kP, const SharedNoiseModel &model)
Construct from a key, world landmark, frame-k measurement, and noise model.
Definition KnownLandmarkFactor.h:67
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Check if two factors are equal.
Definition KnownLandmarkFactor.h:129
KnownLandmarkFactor2(Key key, const Point &wL, const Point &measured_kP, const SharedNoiseModel &model)
Construct from a key, world landmark, frame-k measurement, and noise model.
Definition KnownLandmarkFactor.h:121
Vector evaluateError(const T &kTw, OptionalMatrixType H) const override
Evaluate the k-from-world prediction minus measured_kP.
Definition KnownLandmarkFactor.h:138
NonlinearFactor::shared_ptr clone() const override
Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.
Definition KnownLandmarkFactor.h:125
void qcqpFactors(NonlinearFactorGraph *costs, NonlinearEqualityConstraints *constraints, size_t columnDimension=1) const override
Add the exact D=1 homogeneous known-landmark cost to a QCQP.
Definition KnownLandmarkFactor.h:144