75template <
class CAMERA>
80 typedef typename CAMERA::CalibrationType CALIBRATION;
81 typedef typename CAMERA::Measurement MEASUREMENT;
82 typedef typename CAMERA::MeasurementVector MEASUREMENTS;
84 static const int DimPose = 6;
85 static const int ZDim = 2;
99 typedef CAMERA Camera;
118 const std::shared_ptr<Cameras>&
cameraRig,
122 if (Base::params_.degeneracyMode != gtsam::ZERO_ON_DEGENERACY)
123 throw std::runtime_error(
124 "SmartProjectionRigFactor: "
125 "degeneracyMode must be set to ZERO_ON_DEGENERACY");
126 if (Base::params_.linearizationMode != gtsam::HESSIAN)
127 throw std::runtime_error(
128 "SmartProjectionRigFactor: "
129 "linearizationMode must be set to HESSIAN");
143 const size_t& cameraId = 0) {
146 this->nonUniqueKeys_.push_back(poseKey);
150 if (std::find(this->
keys_.begin(), this->keys_.end(), poseKey) ==
152 this->
keys_.push_back(poseKey);
170 if (poseKeys.size() != measurements.size() ||
172 throw std::runtime_error(
173 "SmartProjectionRigFactor: "
174 "trying to add inconsistent inputs");
177 throw std::runtime_error(
178 "SmartProjectionRigFactor: "
179 "camera rig includes multiple camera "
180 "but add did not input cameraIds");
182 for (
size_t i = 0; i < measurements.size(); i++) {
183 add(measurements[i], poseKeys[i],
204 const std::string& s =
"",
206 std::cout << s <<
"SmartProjectionRigFactor: \n ";
208 std::cout <<
"-- Measurement nr " << i << std::endl;
209 std::cout <<
"key: " << keyFormatter(
nonUniqueKeys_[i]) << std::endl;
210 std::cout <<
"cameraId: " <<
cameraIds_[i] << std::endl;
211 (*cameraRig_)[
cameraIds_[i]].print(
"camera in rig:\n");
218 const This* e =
dynamic_cast<const This*
>(&p);
236 const Pose3 world_P_sensor_i =
239 cameras.emplace_back(world_P_sensor_i,
240 std::make_shared<typename CAMERA::CalibrationType>(
241 camera_i.calibration()));
250 if (this->
active(values)) {
267 Matrix& E, Vector& b,
268 const Cameras&
cameras)
const {
270 throw(
"computeJacobiansWithTriangulatedPoint");
273 for (
size_t i = 0; i < Fs.size(); i++) {
275 const Pose3 world_P_body =
cameras[i].pose() * body_P_sensor.inverse();
276 Eigen::Matrix<double, DimPose, DimPose> H;
277 world_P_body.compose(body_P_sensor, H);
278 Fs.at(i) = Fs.at(i) * H;
285 const Values& values,
const double& lambda = 0.0,
286 bool diagonalDamping =
false)
const {
290 size_t nrUniqueKeys =
297 std::vector<size_t> js;
298 std::vector<Matrix> Gs(nrUniqueKeys * (nrUniqueKeys + 1) / 2);
299 std::vector<Vector> gs(nrUniqueKeys);
302 throw std::runtime_error(
303 "SmartProjectionRigFactor: "
304 "measured_.size() inconsistent with input");
310 if (this->params_.degeneracyMode == ZERO_ON_DEGENERACY) {
311 for (Matrix& m : Gs) m = Matrix::Zero(DimPose, DimPose);
312 for (Vector& v : gs) v = Vector::Zero(DimPose);
313 return std::make_shared<RegularHessianFactor<DimPose> >(this->
keys_, Gs,
316 throw std::runtime_error(
317 "SmartProjectionRigFactor: "
318 "only supported degeneracy mode is ZERO_ON_DEGENERACY");
323 typename Base::FBlocks Fs;
330 for (
size_t i = 0; i < Fs.size(); i++) {
340 Base::Cameras::template SchurComplementAndRearrangeBlocks<3, 6, 6>(
343 return std::make_shared<RegularHessianFactor<DimPose> >(
344 this->
keys_, augmentedHessianUniqueKeys);
355 const Values& values,
const double& lambda = 0.0)
const {
358 switch (this->params_.linearizationMode) {
362 throw std::runtime_error(
363 "SmartProjectionRigFactor: unknown linearization mode");
369 const Values& values)
const override {
374#if GTSAM_ENABLE_BOOST_SERIALIZATION
376 friend class boost::serialization::access;
377 template <
class ARCHIVE>
378 void serialize(ARCHIVE& ar,
const unsigned int ) {
379 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
389template <
class CAMERA>
391 :
public Testable<SmartProjectionRigFactor<CAMERA> > {};
Smart factor on cameras (pose + calibration).
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition Key.h:35
TriangulationResult triangulateSafe(const CameraSet< CAMERA > &cameras, const typename CAMERA::MeasurementVector &measured, const TriangulationParameters ¶ms)
triangulateSafe: extensive checking of the outcome
Definition triangulation.h:706
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
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
A set of cameras, all with their own calibration.
Definition CameraSet.h:37
A 3D pose (R,t) : (Rot3,Point3).
Definition Pose3.h:42
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:88
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
Definition Factor.cpp:29
Nonlinear factor base class.
Definition NonlinearFactor.h:70
virtual bool active(const Values &c) const
Checks whether a factor should be used based on a set of values.
Definition NonlinearFactor.h:143
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
const ValueType at(Key j) const
Retrieve a variable by key j.
Definition Values-inl.h:260
SharedIsotropic noiseModel_
As of Feb 22, 2015, the noise model is the same for all measurements and is isotropic.
Definition SmartFactorBase.h:73
ZVector measured_
Measurements for each of the m views.
Definition SmartFactorBase.h:80
const ZVector & measured() const
Return the 2D measurements (ZDim, in general).
Definition SmartFactorBase.h:162
static Matrix PointCov(const Matrix &E)
Computes Point Covariance P from the "point Jacobian" E.
Definition SmartFactorBase.h:307
CameraSet< CAMERA > Cameras
The CameraSet data structure is used to refer to a set of cameras.
Definition SmartFactorBase.h:93
Definition SmartFactorParams.h:42
SmartProjectionFactor()=default
Default constructor, only for serialization.
bool equals(const NonlinearFactor &factor, double tol=1e-9) const override
Compare with another camera-variable smart projection factor.
Definition SmartProjectionFactor.h:51
double totalReprojectionError(const Cameras &cameras, std::optional< Point3 > externalPoint={}) const
Calculate the error of the factor.
Definition SmartProjectionFactorBase.h:410
CAMERA Camera
Shorthand for a set of cameras.
Definition SmartProjectionFactorBase.h:61
TriangulationResult result_
result from triangulateSafe
Definition SmartProjectionFactorBase.h:51
If you are using the factor, please cite: L.
Definition SmartProjectionRigFactor.h:76
std::shared_ptr< typename Base::Cameras > cameraRig_
cameras in the rig (fixed poses wrt body and intrinsics, for each camera)
Definition SmartProjectionRigFactor.h:92
KeyVector nonUniqueKeys_
vector of keys (one for each observation) with potentially repeated keys
Definition SmartProjectionRigFactor.h:89
FastVector< size_t > cameraIds_
vector of camera Ids (one for each observation, in the same order), identifying which camera took the...
Definition SmartProjectionRigFactor.h:96
const FastVector< size_t > & cameraIds() const
return the calibration object
Definition SmartProjectionRigFactor.h:196
void add(const MEASUREMENT &measured, const Key &poseKey, const size_t &cameraId=0)
add a new measurement, corresponding to an observation from pose "poseKey" and taken from the camera ...
Definition SmartProjectionRigFactor.h:142
void computeJacobiansWithTriangulatedPoint(typename Base::FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras) const
Compute jacobian F, E and error vector at a given linearization point.
Definition SmartProjectionRigFactor.h:266
void add(const MEASUREMENTS &measurements, const KeyVector &poseKeys, const FastVector< size_t > &cameraIds=FastVector< size_t >())
Variant of the previous "add" function in which we include multiple measurements.
Definition SmartProjectionRigFactor.h:168
SmartProjectionRigFactor()
Default constructor, only for serialization.
Definition SmartProjectionRigFactor.h:106
const std::shared_ptr< Cameras > & cameraRig() const
return the calibration object
Definition SmartProjectionRigFactor.h:193
double error(const Values &values) const override
error calculates the error of the factor.
Definition SmartProjectionRigFactor.h:249
SmartProjectionRigFactor(const SharedNoiseModel &sharedNoiseModel, const std::shared_ptr< Cameras > &cameraRig, const SmartProjectionParams ¶ms=SmartProjectionParams())
Constructor.
Definition SmartProjectionRigFactor.h:116
Base::Cameras cameras(const Values &values) const override
Collect all cameras involved in this factor.
Definition SmartProjectionRigFactor.h:231
std::shared_ptr< GaussianFactor > linearize(const Values &values) const override
linearize
Definition SmartProjectionRigFactor.h:368
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition SmartProjectionRigFactor.h:203
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition SmartProjectionRigFactor.h:103
const KeyVector & nonUniqueKeys() const
return (for each observation) the (possibly non unique) keys involved in the measurements
Definition SmartProjectionRigFactor.h:190
std::shared_ptr< RegularHessianFactor< DimPose > > createHessianFactor(const Values &values, const double &lambda=0.0, bool diagonalDamping=false) const
linearize and return a Hessianfactor that is an approximation of error(p)
Definition SmartProjectionRigFactor.h:284
std::shared_ptr< GaussianFactor > linearizeDamped(const Values &values, const double &lambda=0.0) const
Linearize to Gaussian Factor (possibly adding a damping factor Lambda for LM).
Definition SmartProjectionRigFactor.h:354
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition SmartProjectionRigFactor.h:217