Go to the documentation of this file.
35 template <
class CAMERA>
36 class CameraSet :
public std::vector<CAMERA, Eigen::aligned_allocator<CAMERA>> {
38 using Base = std::vector<CAMERA, typename Eigen::aligned_allocator<CAMERA>>;
45 typedef typename CAMERA::MeasurementVector
ZVector;
53 size_t m = predicted.size();
55 throw std::runtime_error(
"CameraSet::errors: size mismatch");
78 using FBlocks = std::vector<MatrixZD, Eigen::aligned_allocator<MatrixZD>>;
85 virtual void print(
const std::string&
s =
"")
const {
86 std::cout <<
s <<
"CameraSet, cameras = \n";
87 for (
size_t k = 0; k < this->
size(); ++k) this->at(k).print(
s);
92 if (this->
size() != p.size())
return false;
93 bool camerasAreEqual =
true;
94 for (
size_t i = 0;
i < this->
size();
i++) {
95 if (this->at(
i).equals(
p.at(
i),
tol) ==
false) camerasAreEqual =
false;
98 return camerasAreEqual;
107 template <
class POINT>
114 size_t m = this->
size();
120 if (Fs) Fs->resize(
m);
123 for (
size_t i = 0;
i <
m;
i++) {
127 if (Fs) (*Fs)[
i] = Fi;
140 template <
class POINT,
class... OptArgs>
142 const POINT&
point, OptArgs&...
args)
const {
148 template <
class POINT>
159 template <
class POINT,
class... OptArgs,
typename =
std::enable_if_t<
sizeof...(OptArgs)!=0>>
161 OptArgs&...
args)
const {
180 size_t m = Fs.size();
184 size_t M1 = ND *
m + 1;
185 std::vector<DenseIndex> dims(
m + 1);
186 std::fill(dims.begin(), dims.end() - 1, ND);
191 for (
size_t i = 0;
i <
m;
i++) {
194 const auto FiT = Fi.transpose();
211 FiT * (Fi - Ei_P *
E.block(
ZDim *
i, 0,
ZDim,
N).transpose() * Fi));
214 for (
size_t j =
i + 1;
j <
m;
j++) {
220 -FiT * (Ei_P *
E.block(
ZDim *
j, 0,
ZDim,
N).transpose() * Fj));
225 return augmentedHessian;
241 template <
int N,
int ND,
int NDD>
248 size_t nrNonuniqueKeys = jacobianKeys.size();
249 size_t nrUniqueKeys = hessianKeys.size();
255 std::vector<DenseIndex> dims(nrUniqueKeys + 1);
256 std::fill(dims.begin(), dims.end() - 1, NDD);
261 if (nrUniqueKeys == nrNonuniqueKeys) {
268 std::vector<DenseIndex> nonuniqueDims(nrNonuniqueKeys + 1);
269 std::fill(nonuniqueDims.begin(), nonuniqueDims.end() - 1, NDD);
270 nonuniqueDims.back() = 1;
276 std::map<Key, size_t> keyToSlotMap;
277 for (
size_t k = 0; k < nrUniqueKeys; k++) {
278 keyToSlotMap[hessianKeys[k]] = k;
283 dims, Matrix::Zero(NDD * nrUniqueKeys + 1, NDD * nrUniqueKeys + 1));
288 for (
size_t i = 0;
i < nrNonuniqueKeys;
i++) {
289 Key key_i = jacobianKeys.at(
i);
293 keyToSlotMap[key_i], nrUniqueKeys,
297 for (
size_t j =
i;
j < nrNonuniqueKeys;
j++) {
298 Key key_j = jacobianKeys.at(
j);
303 if (keyToSlotMap[key_i] != keyToSlotMap[key_j]) {
305 keyToSlotMap[key_i], keyToSlotMap[key_j],
319 nrUniqueKeys, augmentedHessian.
diagonalBlock(nrNonuniqueKeys));
321 return augmentedHessianUniqueKeys;
336 return SchurComplement<N, D>(Fs,
E,
P,
b);
345 bool diagonalDamping =
false) {
348 if (diagonalDamping) {
349 EtE.diagonal() +=
lambda * EtE.diagonal();
352 EtE +=
lambda * Eigen::MatrixXd::Identity(
n,
n);
360 bool diagonalDamping =
false) {
363 ComputePointCovariance<2>(
P2,
E,
lambda, diagonalDamping);
367 ComputePointCovariance<3>(
P3,
E,
lambda, diagonalDamping);
378 const double lambda = 0.0,
379 bool diagonalDamping =
false) {
382 ComputePointCovariance<2>(
P,
E,
lambda, diagonalDamping);
383 return SchurComplement<2>(Fblocks,
E,
P,
b);
386 ComputePointCovariance<3>(
P,
E,
lambda, diagonalDamping);
387 return SchurComplement<3>(Fblocks,
E,
P,
b);
401 assert(
keys.size() == Fs.size());
402 assert(
keys.size() <= allKeys.size());
405 for (
size_t slot = 0; slot < allKeys.size(); slot++)
406 KeySlotMap.emplace(allKeys[slot], slot);
413 size_t m = Fs.size();
414 size_t M = (augmentedHessian.
rows() - 1) /
D;
415 assert(allKeys.size() ==
M);
418 for (
size_t i = 0;
i <
m;
i++) {
421 const auto FiT = Fi.transpose();
423 E.template block<ZDim, N>(
ZDim *
i, 0) *
P;
450 Ei_P *
E.template block<ZDim, N>(
ZDim *
i, 0).transpose() * Fi)))
454 for (
size_t j =
i + 1;
j <
m;
j++) {
465 -FiT * (Ei_P *
E.template block<ZDim, N>(
ZDim *
j, 0).transpose() *
474 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
475 friend class boost::serialization::access;
477 template <
class ARCHIVE>
478 void serialize(ARCHIVE& ar,
const unsigned int ) {
487 template <
class CAMERA>
490 template <
class CAMERA>
493 template <
class CAMERA>
496 template <
class CAMERA>
const EIGEN_DEVICE_FUNC InverseReturnType inverse() const
static Matrix PointCov(const Matrix &E, const double lambda=0.0, bool diagonalDamping=false)
Computes Point Covariance P, with lambda parameter, dynamic version.
void setOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
Set an off-diagonal block. Only the upper triangular portion of xpr is evaluated.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static void UpdateSchurComplement(const FBlocks &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b, const KeyVector &allKeys, const KeyVector &keys, SymmetricBlockMatrix &augmentedHessian)
Concept check for values that can be used in unit tests.
static SymmetricBlockMatrix SchurComplement(const FBlocks &Fblocks, const Matrix &E, const Vector &b, const double lambda=0.0, bool diagonalDamping=false)
ZVector project2(const POINT &point, FBlocks *Fs=nullptr, Matrix *E=nullptr) const
Eigen::SelfAdjointView< constBlock, Eigen::Upper > selfadjointView(DenseIndex I, DenseIndex J) const
Return the square sub-matrix that contains blocks(i:j, i:j).
void setDiagonalBlock(DenseIndex I, const XprType &xpr)
Set a diagonal block. Only the upper triangular portion of xpr is evaluated.
static SymmetricBlockMatrix SchurComplementAndRearrangeBlocks(const std::vector< Eigen::Matrix< double, ZDim, ND >, Eigen::aligned_allocator< Eigen::Matrix< double, ZDim, ND >>> &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b, const KeyVector &jacobianKeys, const KeyVector &hessianKeys)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Vector reprojectionError(const POINT &point, const ZVector &measured, FBlocks *Fs=nullptr, Matrix *E=nullptr) const
Calculate vector [project2(point)-z] of re-projection errors.
Calibrated camera for which only pose is unknown.
A set of cameras, all with their own calibration.
virtual void print(const std::string &s="") const
GenericMeasurement< Point2, Point2 > Measurement
STL compatible allocator to use with types requiring a non standrad alignment.
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
Vector reprojectionError(const POINT &point, const ZVector &measured, OptArgs &... args) const
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
static SymmetricBlockMatrix SchurComplement(const std::vector< Eigen::Matrix< double, ZDim, ND >, Eigen::aligned_allocator< Eigen::Matrix< double, ZDim, ND >>> &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b)
Access to matrices via blocks of pre-defined sizes. Used in GaussianFactor and GaussianConditional.
std::enable_if<(sizeof...(OptArgs) !=0), ZVector >::type project2(const POINT &point, OptArgs &... args) const
bool equals(const CameraSet &p, double tol=1e-9) const
equals
CAMERA::MeasurementVector ZVector
static const int ZDim
Measurement dimension.
DenseIndex rows() const
Row size.
void updateDiagonalBlock(DenseIndex I, const XprType &xpr)
Increment the diagonal block by the values in xpr. Only reads the upper triangular part of xpr.
ptrdiff_t DenseIndex
The index type for Eigen objects.
void updateOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
static const int D
Camera dimension.
Eigen::SelfAdjointView< Block, Eigen::Upper > diagonalBlock(DenseIndex J)
Return the J'th diagonal block as a self adjoint view.
The matrix class, also used for vectors and row-vectors.
Give fixed size dimension of a type, fails at compile time if dynamic.
constBlock aboveDiagonalBlock(DenseIndex I, DenseIndex J) const
Get block above the diagonal (I, J).
static Vector ErrorVector(const ZVector &predicted, const ZVector &measured)
Make a vector of re-projection errors.
std::uint64_t Key
Integer nonlinear key type.
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
static void ComputePointCovariance(Eigen::Matrix< double, N, N > &P, const Matrix &E, double lambda, bool diagonalDamping=false)
Computes Point Covariance P, with lambda parameter.
A thin wrapper around std::map that uses boost's fast_pool_allocator.
virtual ~CameraSet()=default
Destructor.
Matrix< RealScalar, Dynamic, Dynamic > M
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:01:57