43 template<
class CAMERA>
63 mutable std::vector<Pose3, Eigen::aligned_allocator<Pose3> >
89 : Base(sharedNoiseModel),
104 std::cout <<
s <<
"SmartProjectionFactor\n";
107 std::cout <<
"triangulationParameters:\n" << params_.
triangulation 109 std::cout <<
"result:\n" << result_ << std::endl;
115 const This *
e =
dynamic_cast<const This*
>(&
p);
134 size_t m = cameras.size();
136 bool retriangulate =
false;
142 retriangulate =
true;
145 if (!retriangulate) {
146 for (
size_t i = 0;
i < cameras.size();
i++) {
149 retriangulate =
true;
159 for (
size_t i = 0;
i <
m;
i++)
164 return retriangulate;
175 size_t m = cameras.size();
194 return bool(result_);
200 bool diagonalDamping =
false)
const {
201 size_t numKeys = this->
keys_.size();
204 std::vector<Matrix> Gs(numKeys * (numKeys + 1) / 2);
205 std::vector<Vector> gs(numKeys);
207 if (this->
measured_.size() != cameras.size())
208 throw std::runtime_error(
209 "SmartProjectionHessianFactor: this->measured_" 210 ".size() inconsistent with input");
218 return std::make_shared<RegularHessianFactor<Base::Dim> >(this->
keys_,
235 return std::make_shared<RegularHessianFactor<Base::Dim> >(
236 this->
keys_, augmentedHessian);
246 return std::shared_ptr<RegularImplicitSchurFactor<CAMERA> >();
256 return std::make_shared<JacobianFactorQ<Base::Dim, 2> >(this->
keys_);
272 return std::make_shared<JacobianFactorSVD<Base::Dim, 2> >(this->
keys_);
299 const double lambda = 0.0)
const {
311 throw std::runtime_error(
"SmartFactorlinearize: unknown mode");
321 const double lambda = 0.0)
const {
340 cameras.
project2(*result_,
nullptr, &E);
342 return nonDegenerate;
359 const Cameras&
cameras)
const {
364 Unit3 backProjected = cameras[0].backprojectPointAtInfinity(
381 return nonDegenerate;
392 return nonDegenerate;
402 return Vector::Zero(cameras.size() * 2);
412 std::optional<Point3> externalPoint = {})
const {
424 Unit3 backprojected = cameras.front().backprojectPointAtInfinity(
434 if (this->
active(values)) {
448 Cameras cameras = this->
cameras(values);
469 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 470 friend class boost::serialization::access; 472 template<
class ARCHIVE>
474 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
475 ar & BOOST_SERIALIZATION_NVP(params_);
476 ar & BOOST_SERIALIZATION_NVP(result_);
484 template<
class CAMERA>
486 SmartProjectionFactor<CAMERA> > {
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
virtual Cameras cameras(const Values &values) const
Collect all cameras: important that in key order.
void computeJacobians(FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras, const POINT &point) const
bool triangulateAndComputeE(Matrix &E, const Cameras &cameras) const
bool triangulateForLinearize(const Cameras &cameras) const
Possibly re-triangulate before calculating Jacobians.
bool isPointBehindCamera() const
double totalReprojectionError(const Cameras &cameras, const POINT &point) const
std::shared_ptr< GaussianFactor > linearize(const Values &values) const override
linearize
std::shared_ptr< JacobianFactorQ< Base::Dim, 2 > > createJacobianQFactor(const Cameras &cameras, double lambda) const
Create JacobianFactorQ factor.
std::string serialize(const T &input)
serializes to a string
void computeJacobiansWithTriangulatedPoint(typename Base::FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras) const
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
DegeneracyMode degeneracyMode
How to linearize the factor.
std::shared_ptr< JacobianFactorQ< Base::Dim, 2 > > createJacobianQFactor(const Values &values, double lambda) const
Create JacobianFactorQ factor, takes values.
virtual std::shared_ptr< JacobianFactorQ< Base::Dim, 2 > > linearizeToJacobian(const Values &values, double lambda=0.0) const
Linearize to a JacobianfactorQ.
TriangulationResult result_
result from triangulateSafe
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
TriangulationParameters triangulation
KeyVector keys_
The keys involved in this factor.
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
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)
virtual std::shared_ptr< RegularHessianFactor< Base::Dim > > linearizeToHessian(const Values &values, double lambda=0.0) const
Linearize to a Hessianfactor.
static const KeyFormatter DefaultKeyFormatter
Vector reprojectionErrorAfterTriangulation(const Values &values) const
Calculate vector of re-projection errors, before applying noise model.
static const SmartProjectionParams params
std::shared_ptr< GaussianFactor > linearizeDamped(const Cameras &cameras, const double lambda=0.0) const
SmartFactorBase< CAMERA > Base
Base class to create smart factors on poses or cameras.
bool decideIfTriangulate(const Cameras &cameras) const
Check if the new linearization point is the same as the one used for previous triangulation.
ZVector project2(const POINT &point, FBlocks *Fs=nullptr, Matrix *E=nullptr) const
Represents a 3D point on a unit sphere.
Base class for smart factors. This base class has no internal point, but it has a measurement...
std::shared_ptr< RegularImplicitSchurFactor< CAMERA > > createRegularImplicitSchurFactor(const Cameras &cameras, const Point3 &point, double lambda=0.0, bool diagonalDamping=false) const
Return Jacobians as RegularImplicitSchurFactor with raw access.
bool triangulateAndComputeJacobians(typename Base::FBlocks &Fs, Matrix &E, Vector &b, const Values &values) const
Version that takes values, and creates the point.
void computeJacobiansSVD(FBlocks &Fs, Matrix &Enull, Vector &b, const Cameras &cameras, const POINT &point) const
TriangulationResult triangulateSafe(const Cameras &cameras) const
Call gtsam::triangulateSafe iff we need to re-triangulate.
virtual std::shared_ptr< RegularImplicitSchurFactor< CAMERA > > linearizeToImplicit(const Values &values, double lambda=0.0) const
Linearize to an Implicit Schur factor.
SmartProjectionParams params_
Functions for triangulation.
Array< int, Dynamic, 1 > v
SmartProjectionFactor< CAMERA > SmartProjectionCameraFactor
Array< double, 1, 3 > e(1./3., 0.5, 2.)
double error(const Values &values) const override
Calculate total reprojection error.
LinearizationMode linearizationMode
How to linearize the factor.
TriangulationResult triangulateSafe(const CameraSet< CAMERA > &cameras, const typename CAMERA::MeasurementVector &measured, const TriangulationParameters ¶ms)
triangulateSafe: extensive checking of the outcome
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
std::shared_ptr< JacobianFactor > createJacobianSVDFactor(const Cameras &cameras, double lambda) const
Different (faster) way to compute a JacobianFactorSVD factor.
std::shared_ptr< JacobianFactor > createJacobianSVDFactor(const Cameras &cameras, const Point3 &point, double lambda=0.0) const
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
TriangulationResult point(const Values &values) const
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
static const Pose3 pose(Rot3(Vector3(1, -1, -1).asDiagonal()), Point3(0, 0, 0.5))
SmartProjectionFactor< CAMERA > This
TriangulationResult point() const
virtual bool active(const Values &) const
std::shared_ptr< JacobianFactorQ< Dim, ZDim > > createJacobianQFactor(const Cameras &cameras, const Point3 &point, double lambda=0.0, bool diagonalDamping=false) const
Return Jacobians as JacobianFactorQ.
static const int Dim
Camera dimension.
static TriangulationResult Degenerate()
bool isValid() const
Is result valid?
bool triangulateAndComputeE(Matrix &E, const Values &values) const
std::shared_ptr< GaussianFactor > linearizeDamped(const Values &values, const double lambda=0.0) const
CAMERA Camera
shorthand for a set of cameras
SmartProjectionFactor(const SharedNoiseModel &sharedNoiseModel, const SmartProjectionParams ¶ms=SmartProjectionParams())
std::shared_ptr< RegularImplicitSchurFactor< CAMERA > > createRegularImplicitSchurFactor(const Cameras &cameras, double lambda) const
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
void whitenJacobians(FBlocks &F, Matrix &E, Vector &b) const
Whiten the Jacobians computed by computeJacobians using noiseModel_.
bool triangulateAndComputeJacobiansSVD(typename Base::FBlocks &Fs, Matrix &Enull, Vector &b, const Values &values) const
takes values
std::vector< Pose3, Eigen::aligned_allocator< Pose3 > > cameraPosesTriangulation_
current triangulation poses
~SmartProjectionFactor() override
utility functions for loading datasets
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
bool isDegenerate() const
std::shared_ptr< RegularHessianFactor< Base::Dim > > createHessianFactor(const Cameras &cameras, const double lambda=0.0, bool diagonalDamping=false) const
Create a Hessianfactor that is an approximation of error(p).
Collect common parameters for SmartProjection and SmartStereoProjection factors.
noiseModel::Base::shared_ptr SharedNoiseModel
CameraSet< CAMERA > Cameras
double totalReprojectionError(const Cameras &cameras, std::optional< Point3 > externalPoint={}) const
Vector unwhitenedError(const Cameras &cameras, const POINT &point, typename Cameras::FBlocks *Fs=nullptr, Matrix *E=nullptr) const
bool behindCamera() const
double retriangulationThreshold
threshold to decide whether to re-triangulate