51 template <
class CAMERA>
96 const std::shared_ptr<Cameras>&
cameraRig,
98 : Base(sharedNoiseModel,
params), cameraRig_(cameraRig) {
101 throw std::runtime_error(
102 "SmartProjectionRigFactor: " 103 "degeneracyMode must be set to ZERO_ON_DEGENERACY");
105 throw std::runtime_error(
106 "SmartProjectionRigFactor: " 107 "linearizationMode must be set to HESSIAN");
121 const size_t& cameraId = 0) {
124 this->nonUniqueKeys_.push_back(poseKey);
130 this->
keys_.push_back(poseKey);
133 cameraIds_.push_back(cameraId);
148 if (poseKeys.size() != measurements.size() ||
150 throw std::runtime_error(
151 "SmartProjectionRigFactor: " 152 "trying to add inconsistent inputs");
154 if (
cameraIds.size() == 0 && cameraRig_->size() > 1) {
155 throw std::runtime_error(
156 "SmartProjectionRigFactor: " 157 "camera rig includes multiple camera " 158 "but add did not input cameraIds");
160 for (
size_t i = 0;
i < measurements.size();
i++) {
161 add(measurements[
i], poseKeys[i],
182 const std::string&
s =
"",
184 std::cout <<
s <<
"SmartProjectionRigFactor: \n ";
185 for (
size_t i = 0;
i < nonUniqueKeys_.size();
i++) {
186 std::cout <<
"-- Measurement nr " <<
i << std::endl;
187 std::cout <<
"key: " << keyFormatter(nonUniqueKeys_[
i]) << std::endl;
188 std::cout <<
"cameraId: " << cameraIds_[
i] << std::endl;
189 (*cameraRig_)[cameraIds_[
i]].print(
"camera in rig:\n");
196 const This*
e =
dynamic_cast<const This*
>(&
p);
197 return e &&
Base::equals(p,
tol) && nonUniqueKeys_ == e->nonUniqueKeys() &&
198 cameraRig_->
equals(*(e->cameraRig())) &&
199 std::equal(cameraIds_.begin(), cameraIds_.end(),
200 e->cameraIds().
begin());
211 cameras.reserve(nonUniqueKeys_.size());
212 for (
size_t i = 0;
i < nonUniqueKeys_.size();
i++) {
213 const typename Base::Camera& camera_i = (*cameraRig_)[cameraIds_[
i]];
214 const Pose3 world_P_sensor_i =
217 cameras.emplace_back(world_P_sensor_i,
218 make_shared<typename CAMERA::CalibrationType>(
219 camera_i.calibration()));
228 if (this->
active(values)) {
246 const Cameras&
cameras)
const {
248 throw(
"computeJacobiansWithTriangulatedPoint");
251 for (
size_t i = 0;
i < Fs.size();
i++) {
253 const Pose3 world_P_body = cameras[
i].pose() * body_P_sensor.
inverse();
255 world_P_body.
compose(body_P_sensor, H);
256 Fs.at(
i) = Fs.at(
i) *
H;
264 bool diagonalDamping =
false)
const {
268 size_t nrUniqueKeys =
275 std::vector<size_t> js;
276 std::vector<Matrix> Gs(nrUniqueKeys * (nrUniqueKeys + 1) / 2);
277 std::vector<Vector> gs(nrUniqueKeys);
279 if (this->
measured_.size() != cameras.size())
280 throw std::runtime_error(
281 "SmartProjectionRigFactor: " 282 "measured_.size() inconsistent with input");
289 for (
Matrix&
m : Gs)
m = Matrix::Zero(DimPose, DimPose);
290 for (
Vector&
v : gs)
v = Vector::Zero(DimPose);
291 return std::make_shared<RegularHessianFactor<DimPose> >(this->
keys_,
294 throw std::runtime_error(
295 "SmartProjectionRigFactor: " 296 "only supported degeneracy mode is ZERO_ON_DEGENERACY");
308 for (
size_t i = 0;
i < Fs.size();
i++) {
312 const Matrix3
P = Base::Cameras::PointCov(E,
lambda, diagonalDamping);
318 Base::Cameras::template SchurComplementAndRearrangeBlocks<3, 6, 6>(
321 return std::make_shared<RegularHessianFactor<DimPose> >(
322 this->
keys_, augmentedHessianUniqueKeys);
340 throw std::runtime_error(
341 "SmartProjectionRigFactor: unknown linearization mode");
352 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 353 friend class boost::serialization::access; 355 template <
class ARCHIVE>
356 void serialize(ARCHIVE& ar,
const unsigned int ) {
357 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
367 template <
class CAMERA>
369 :
public Testable<SmartProjectionRigFactor<CAMERA> > {};
Pose3 body_P_sensor() const
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
std::string serialize(const T &input)
serializes to a string
static const int ZDim
Measurement dimension.
const ValueType at(Key j) const
DegeneracyMode degeneracyMode
How to linearize the factor.
CameraSet< CAMERA > Cameras
const std::shared_ptr< Cameras > & cameraRig() const
return the calibration object
static const int DimPose
Pose3 dimension.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
TriangulationResult result_
result from triangulateSafe
Vector reprojectionError(const POINT &point, const ZVector &measured, FBlocks *Fs=nullptr, Matrix *E=nullptr) const
Calculate vector [project2(point)-z] of re-projection errors.
SmartProjectionFactor< CAMERA > Base
std::vector< MatrixZD, Eigen::aligned_allocator< MatrixZD > > FBlocks
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW
KeyVector keys_
The keys involved in this factor.
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)
const KeyVector & nonUniqueKeys() const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange [*:*] noreverse nowriteback set trange [*:*] noreverse nowriteback set urange [*:*] noreverse nowriteback set vrange [*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
SharedIsotropic noiseModel_
std::shared_ptr< typename Base::Cameras > cameraRig_
cameras in the rig (fixed poses wrt body and intrinsics, for each camera)
A set of cameras, all with their own calibration.
static const KeyFormatter DefaultKeyFormatter
void add(const MEASUREMENTS &measurements, const KeyVector &poseKeys, const FastVector< size_t > &cameraIds=FastVector< size_t >())
Pose3 inverse() const
inverse transformation with derivatives
static const SmartProjectionParams params
CAMERA::MeasurementVector MEASUREMENTS
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Smart factor on cameras (pose + calibration)
void add(const MEASUREMENT &measured, const Key &poseKey, const size_t &cameraId=0)
KeyVector nonUniqueKeys_
vector of keys (one for each observation) with potentially repeated keys
TriangulationResult triangulateSafe(const Cameras &cameras) const
Call gtsam::triangulateSafe iff we need to re-triangulate.
GenericMeasurement< Point2, Point2 > Measurement
SmartProjectionParams params_
Base::Cameras cameras(const Values &values) const override
Array< int, Dynamic, 1 > v
std::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Array< double, 1, 3 > e(1./3., 0.5, 2.)
LinearizationMode linearizationMode
How to linearize the factor.
SmartProjectionRigFactor()
Default constructor, only for serialization.
FastVector< size_t > cameraIds_
Class compose(const Class &g) const
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
double error(const Values &values) const override
SmartProjectionRigFactor(const SharedNoiseModel &sharedNoiseModel, const std::shared_ptr< Cameras > &cameraRig, const SmartProjectionParams ¶ms=SmartProjectionParams())
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
const ZVector & measured() const
Return the 2D measurements (ZDim, in general).
CAMERA::CalibrationType CALIBRATION
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
virtual bool active(const Values &) const
std::shared_ptr< GaussianFactor > linearizeDamped(const Values &values, const double &lambda=0.0) const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef CAMERA Camera
CAMERA::Measurement MEASUREMENT
CAMERA Camera
shorthand for a set of cameras
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
The matrix class, also used for vectors and row-vectors.
const_iterator begin() const
const FastVector< size_t > & cameraIds() const
return the calibration object
bool equal(const T &obj1, const T &obj2, double tol)
std::uint64_t Key
Integer nonlinear key type.
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
void computeJacobiansWithTriangulatedPoint(typename Base::FBlocks &Fs, Matrix &E, Vector &b, const Cameras &cameras) const
std::shared_ptr< GaussianFactor > linearize(const Values &values) const override
linearize
noiseModel::Base::shared_ptr SharedNoiseModel
CameraSet< CAMERA > Cameras
double totalReprojectionError(const Cameras &cameras, std::optional< Point3 > externalPoint={}) const
bool equals(const This &other, double tol=1e-9) const
check equality
SmartProjectionRigFactor< CAMERA > This