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();
54 if (measured.size() !=
m)
55 throw std::runtime_error(
"CameraSet::errors: size mismatch");
65 b.segment<ZDim>(
row) = bi;
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();
119 if (
E)
E->resize(ZDim * m, N);
120 if (Fs) Fs->resize(m);
123 for (
size_t i = 0;
i <
m;
i++) {
126 z.emplace_back(this->at(
i).
project2(point, Fs ? &Fi : 0,
E ? &Ei : 0));
127 if (Fs) (*Fs)[
i] = Fi;
128 if (
E)
E->block<
ZDim, N>(ZDim *
i, 0) = Ei;
138 template <
class POINT,
class... OptArgs>
145 template <
class POINT>
156 template <
class POINT,
class... OptArgs,
typename =
std::enable_if_t<
sizeof...(OptArgs)!=0>>
158 OptArgs&...
args)
const {
177 size_t m = Fs.size();
181 size_t M1 = ND * m + 1;
182 std::vector<DenseIndex> dims(m + 1);
183 std::fill(dims.begin(), dims.end() - 1, ND);
188 for (
size_t i = 0;
i <
m;
i++) {
191 const auto FiT = Fi.transpose();
193 E.block(ZDim *
i, 0, ZDim, N) *
P;
198 FiT * b.segment<ZDim>(ZDim * i)
208 FiT * (Fi - Ei_P * E.block(ZDim * i, 0, ZDim, N).transpose() * Fi));
211 for (
size_t j = i + 1;
j <
m;
j++) {
217 -FiT * (Ei_P * E.block(ZDim *
j, 0, ZDim, N).transpose() * Fj));
222 return augmentedHessian;
238 template <
int N,
int ND,
int NDD>
245 size_t nrNonuniqueKeys = jacobianKeys.size();
246 size_t nrUniqueKeys = hessianKeys.size();
252 std::vector<DenseIndex> dims(nrUniqueKeys + 1);
253 std::fill(dims.begin(), dims.end() - 1, NDD);
258 if (nrUniqueKeys == nrNonuniqueKeys) {
265 std::vector<DenseIndex> nonuniqueDims(nrNonuniqueKeys + 1);
266 std::fill(nonuniqueDims.begin(), nonuniqueDims.end() - 1, NDD);
267 nonuniqueDims.back() = 1;
273 std::map<Key, size_t> keyToSlotMap;
274 for (
size_t k = 0; k < nrUniqueKeys; k++) {
275 keyToSlotMap[hessianKeys[k]] = k;
280 dims, Matrix::Zero(NDD * nrUniqueKeys + 1, NDD * nrUniqueKeys + 1));
285 for (
size_t i = 0;
i < nrNonuniqueKeys;
i++) {
286 Key key_i = jacobianKeys.at(
i);
290 keyToSlotMap[key_i], nrUniqueKeys,
294 for (
size_t j =
i;
j < nrNonuniqueKeys;
j++) {
295 Key key_j = jacobianKeys.at(
j);
300 if (keyToSlotMap[key_i] != keyToSlotMap[key_j]) {
302 keyToSlotMap[key_i], keyToSlotMap[key_j],
316 nrUniqueKeys, augmentedHessian.
diagonalBlock(nrNonuniqueKeys));
318 return augmentedHessianUniqueKeys;
331 return SchurComplement<N, D>(Fs,
E,
P,
b);
338 bool diagonalDamping =
false) {
339 Matrix EtE = E.transpose() *
E;
341 if (diagonalDamping) {
342 EtE.diagonal() += lambda * EtE.diagonal();
345 EtE += lambda * Eigen::MatrixXd::Identity(n, n);
353 bool diagonalDamping =
false) {
356 ComputePointCovariance<2>(
P2,
E,
lambda, diagonalDamping);
360 ComputePointCovariance<3>(
P3,
E,
lambda, diagonalDamping);
371 const double lambda = 0.0,
372 bool diagonalDamping =
false) {
375 ComputePointCovariance<2>(
P,
E,
lambda, diagonalDamping);
376 return SchurComplement<2>(Fblocks,
E,
P,
b);
379 ComputePointCovariance<3>(
P,
E,
lambda, diagonalDamping);
380 return SchurComplement<3>(Fblocks,
E,
P,
b);
394 assert(keys.size() == Fs.size());
395 assert(keys.size() <= allKeys.size());
398 for (
size_t slot = 0; slot < allKeys.size(); slot++)
399 KeySlotMap.emplace(allKeys[slot], slot);
406 size_t m = Fs.size();
407 size_t M = (augmentedHessian.
rows() - 1) / D;
408 assert(allKeys.size() ==
M);
411 for (
size_t i = 0;
i <
m;
i++) {
414 const auto FiT = Fi.transpose();
416 E.template block<ZDim, N>(ZDim *
i, 0) * P;
429 FiT * b.segment<ZDim>(ZDim * i)
444 Ei_P * E.template block<ZDim, N>(ZDim * i, 0).transpose() * Fi)))
448 for (
size_t j = i + 1;
j <
m;
j++) {
459 -FiT * (Ei_P * E.template block<ZDim, N>(ZDim * j, 0).transpose() *
468 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 469 friend class boost::serialization::access; 471 template <
class ARCHIVE>
472 void serialize(ARCHIVE& ar,
const unsigned int ) {
481 template <
class CAMERA>
484 template <
class CAMERA>
487 template <
class CAMERA>
490 template <
class CAMERA>
static Matrix PointCov(const Matrix &E, const double lambda=0.0, bool diagonalDamping=false)
Computes Point Covariance P, with lambda parameter, dynamic version.
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
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)
Matrix< RealScalar, Dynamic, Dynamic > M
bool equals(const CameraSet &p, double tol=1e-9) const
equals
Concept check for values that can be used in unit tests.
Access to matrices via blocks of pre-defined sizes. Used in GaussianFactor and GaussianConditional.
void setOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
Set an off-diagonal block. Only the upper triangular portion of xpr is evaluated. ...
std::string serialize(const T &input)
serializes to a string
Vector reprojectionError(const POINT &point, const ZVector &measured, OptArgs &... args) const
Give fixed size dimension of a type, fails at compile time if dynamic.
Vector reprojectionError(const POINT &point, const ZVector &measured, FBlocks *Fs=nullptr, Matrix *E=nullptr) const
Calculate vector [project2(point)-z] of re-projection errors.
virtual ~CameraSet()=default
Destructor.
static Vector ErrorVector(const ZVector &predicted, const ZVector &measured)
Make a vector of re-projection errors.
A set of cameras, all with their own calibration.
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)
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
ptrdiff_t DenseIndex
The index type for Eigen objects.
static const int D
Camera dimension.
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).
DenseIndex rows() const
Row size.
void setDiagonalBlock(DenseIndex I, const XprType &xpr)
Set a diagonal block. Only the upper triangular portion of xpr is evaluated.
virtual void print(const std::string &s="") const
STL compatible allocator to use with types requiring a non standrad alignment.
static SymmetricBlockMatrix SchurComplement(const FBlocks &Fblocks, const Matrix &E, const Vector &b, const double lambda=0.0, bool diagonalDamping=false)
GenericMeasurement< Point2, Point2 > Measurement
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void updateDiagonalBlock(DenseIndex I, const XprType &xpr)
Increment the diagonal block by the values in xpr. Only reads the upper triangular part of xpr...
static const int ZDim
Measurement dimension.
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Calibrated camera for which only pose is unknown.
static const Point3 P2(3.5,-8.2, 4.2)
CAMERA::MeasurementVector ZVector
A thin wrapper around std::map that uses boost's fast_pool_allocator.
static void ComputePointCovariance(Eigen::Matrix< double, N, N > &P, const Matrix &E, double lambda, bool diagonalDamping=false)
Computes Point Covariance P, with lambda parameter.
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
void updateOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Eigen::SelfAdjointView< Block, Eigen::Upper > diagonalBlock(DenseIndex J)
Return the J'th diagonal block as a self adjoint view.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
The matrix class, also used for vectors and row-vectors.
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)
std::uint64_t Key
Integer nonlinear key type.
constBlock aboveDiagonalBlock(DenseIndex I, DenseIndex J) const
Get block above the diagonal (I, J).
ZVector project2(const POINT &point, OptArgs &... args) const
static SymmetricBlockMatrix SchurComplement(const FBlocks &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b)