29 #include <boost/optional.hpp> 30 #include <boost/make_shared.hpp> 44 template<
class CAMERA>
88 : Base(sharedNoiseModel),
103 std::cout <<
s <<
"SmartProjectionFactor\n";
106 std::cout <<
"triangulationParameters:\n" << params_.
triangulation 108 std::cout <<
"result:\n" << result_ << std::endl;
114 const This *
e =
dynamic_cast<const This*
>(&
p);
125 size_t m = cameras.size();
127 bool retriangulate =
false;
130 if (cameraPosesTriangulation_.empty()
131 || cameras.size() != cameraPosesTriangulation_.size())
132 retriangulate =
true;
134 if (!retriangulate) {
135 for (
size_t i = 0;
i < cameras.size();
i++) {
136 if (!cameras[
i].
pose().equals(cameraPosesTriangulation_[
i],
138 retriangulate =
true;
145 cameraPosesTriangulation_.clear();
146 cameraPosesTriangulation_.reserve(m);
147 for (
size_t i = 0;
i <
m;
i++)
149 cameraPosesTriangulation_.push_back(cameras[
i].pose());
152 return retriangulate;
158 size_t m = cameras.size();
172 return bool(result_);
177 const Cameras&
cameras,
const double lambda = 0.0,
bool diagonalDamping =
180 size_t numKeys = this->
keys_.size();
183 std::vector<Matrix> Gs(numKeys * (numKeys + 1) / 2);
184 std::vector<Vector> gs(numKeys);
186 if (this->
measured_.size() != cameras.size())
187 throw std::runtime_error(
"SmartProjectionHessianFactor: this->measured_" 188 ".size() inconsistent with input");
198 return boost::make_shared<RegularHessianFactor<Base::Dim> >(this->
keys_,
203 std::vector<typename Base::MatrixZD, Eigen::aligned_allocator<typename Base::MatrixZD> > Fblocks;
215 return boost::make_shared<RegularHessianFactor<Base::Dim> >(this->
keys_,
226 return boost::shared_ptr<RegularImplicitSchurFactor<CAMERA> >();
236 return boost::make_shared<JacobianFactorQ<Base::Dim, 2> >(this->
keys_);
252 return boost::make_shared<JacobianFactorSVD<Base::Dim, 2> >(this->
keys_);
279 const double lambda = 0.0)
const {
291 throw std::runtime_error(
"SmartFactorlinearize: unknown mode");
301 const double lambda = 0.0)
const {
320 cameras.
project2(*result_, boost::none, E);
321 return nonDegenerate;
338 const Cameras&
cameras)
const {
343 Unit3 backProjected = cameras[0].backprojectPointAtInfinity(
360 return nonDegenerate;
371 return nonDegenerate;
381 return Vector::Zero(cameras.size() * 2);
391 boost::optional<Point3> externalPoint = boost::none)
const {
403 Unit3 backprojected = cameras.front().backprojectPointAtInfinity(
413 if (this->
active(values)) {
449 friend class boost::serialization::access;
450 template<
class ARCHIVE>
452 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
453 ar & BOOST_SERIALIZATION_NVP(params_);
454 ar & BOOST_SERIALIZATION_NVP(result_);
455 ar & BOOST_SERIALIZATION_NVP(cameraPosesTriangulation_);
461 template<
class CAMERA>
463 SmartProjectionFactor<CAMERA> > {
ZVector project2(const POINT &point, boost::optional< FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
boost::shared_ptr< JacobianFactor > createJacobianSVDFactor(const Cameras &cameras, double lambda) const
different (faster) way to compute Jacobian factor
double totalReprojectionError(const Cameras &cameras, boost::optional< Point3 > externalPoint=boost::none) const
boost::shared_ptr< JacobianFactorQ< Base::Dim, 2 > > createJacobianQFactor(const Cameras &cameras, double lambda) const
create factor
virtual boost::shared_ptr< RegularHessianFactor< Base::Dim > > linearizeToHessian(const Values &values, double lambda=0.0) const
linearize to a Hessianfactor
bool behindCamera() const
boost::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
bool decideIfTriangulate(const Cameras &cameras) const
Check if the new linearization point is the same as the one used for previous triangulation.
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
DegeneracyMode degeneracyMode
How to linearize the factor.
virtual Cameras cameras(const Values &values) const
Collect all cameras: important that in key order.
boost::shared_ptr< RegularHessianFactor< Base::Dim > > createHessianFactor(const Cameras &cameras, const double lambda=0.0, bool diagonalDamping=false) const
linearize returns a Hessianfactor that is an approximation of error(p)
TriangulationResult result_
result from triangulateSafe
boost::shared_ptr< JacobianFactorQ< Dim, ZDim > > createJacobianQFactor(const Cameras &cameras, const Point3 &point, double lambda=0.0, bool diagonalDamping=false) const
bool triangulateAndComputeE(Matrix &E, const Values &values) const
TriangulationParameters triangulation
boost::shared_ptr< RegularImplicitSchurFactor< CAMERA > > createRegularImplicitSchurFactor(const Cameras &cameras, double lambda) const
KeyVector keys_
The keys involved in this factor.
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
bool triangulateAndComputeJacobiansSVD(std::vector< typename Base::MatrixZD, Eigen::aligned_allocator< typename Base::MatrixZD > > &Fblocks, Matrix &Enull, Vector &b, const Values &values) const
takes values
boost::shared_ptr< GaussianFactor > linearizeDamped(const Cameras &cameras, const double lambda=0.0) const
A set of cameras, all with their own calibration.
static const KeyFormatter DefaultKeyFormatter
bool isPointBehindCamera() const
virtual bool active(const Values &) const
SmartFactorBase< CAMERA > Base
Base class to create smart factors on poses or cameras.
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, noise model and an optional sensor pose. This class mainly computes the derivatives and returns them as a variety of factors. The methods take a Cameras argument, which should behave like PinholeCamera, and the value of a point, which is kept in the base class.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
bool triangulateAndComputeJacobians(std::vector< typename Base::MatrixZD, Eigen::aligned_allocator< typename Base::MatrixZD > > &Fblocks, Matrix &E, Vector &b, const Values &values) const
Version that takes values, and creates the point.
STL compatible allocator to use with types requiring a non standrad alignment.
static const Pose3 pose(Rot3(Vector3(1,-1,-1).asDiagonal()), Point3(0, 0, 0.5))
SmartProjectionParams params_
Functions for triangulation.
Vector reprojectionErrorAfterTriangulation(const Values &values) const
Calculate vector of re-projection errors, before applying noise model.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
TriangulationResult triangulateSafe(const Cameras &cameras) const
triangulateSafe
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.
static SmartStereoProjectionParams params
TriangulationResult triangulateSafe(const CameraSet< CAMERA > &cameras, const typename CAMERA::MeasurementVector &measured, const TriangulationParameters ¶ms)
triangulateSafe: extensive checking of the outcome
bool isDegenerate() const
boost::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
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
bool triangulateForLinearize(const Cameras &cameras) const
triangulate
boost::shared_ptr< JacobianFactorQ< Base::Dim, 2 > > createJacobianQFactor(const Values &values, double lambda) const
Create a factor, takes values.
boost::shared_ptr< GaussianFactor > linearizeDamped(const Values &values, const double lambda=0.0) const
virtual boost::shared_ptr< JacobianFactorQ< Base::Dim, 2 > > linearizeToJacobian(const Values &values, double lambda=0.0) const
linearize to a JacobianfactorQ
SmartProjectionFactor< CAMERA > This
TriangulationResult point(const Values &values) const
void computeJacobians(FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras, const POINT &point) const
virtual boost::shared_ptr< RegularImplicitSchurFactor< CAMERA > > linearizeToImplicit(const Values &values, double lambda=0.0) const
linearize to an Implicit Schur factor
static const int Dim
Camera dimension.
double totalReprojectionError(const Cameras &cameras, const POINT &point) const
void whitenJacobians(FBlocks &F, Matrix &E, Vector &b) const
Whiten the Jacobians computed by computeJacobians using noiseModel_.
static TriangulationResult Degenerate()
SmartProjectionFactor(const SharedNoiseModel &sharedNoiseModel, const SmartProjectionParams ¶ms=SmartProjectionParams())
boost::shared_ptr< GaussianFactor > linearize(const Values &values) const override
linearize
Eigen::Matrix< double, ZDim, Dim > MatrixZD
Vector unwhitenedError(const Cameras &cameras, const POINT &point, boost::optional< typename Cameras::FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
bool triangulateAndComputeE(Matrix &E, const Cameras &cameras) const
boost::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.
std::vector< Pose3, Eigen::aligned_allocator< Pose3 > > cameraPosesTriangulation_
~SmartProjectionFactor() override
void serialize(ARCHIVE &ar, const unsigned int version)
utility functions for loading datasets
void computeJacobiansWithTriangulatedPoint(std::vector< typename Base::MatrixZD, Eigen::aligned_allocator< typename Base::MatrixZD > > &Fblocks, Matrix &E, Vector &b, const Cameras &cameras) const
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
TriangulationResult point() const
bool isValid() const
Is result valid?
noiseModel::Base::shared_ptr SharedNoiseModel
CameraSet< CAMERA > Cameras
shorthand for a set of cameras
void computeJacobiansSVD(FBlocks &Fs, Matrix &Enull, Vector &b, const Cameras &cameras, const POINT &point) const
SVD version.
static SymmetricBlockMatrix SchurComplement(const FBlocks &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b)
double retriangulationThreshold