SmartStereoProjectionFactorPP.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 
21 #include <cassert>
22 
23 namespace gtsam {
24 
26  const SharedNoiseModel& sharedNoiseModel,
28  : Base(sharedNoiseModel, params) {} // note: no extrinsic specified!
29 
31  const StereoPoint2& measured,
32  const Key& w_P_body_key, const Key& body_P_cam_key,
33  const std::shared_ptr<Cal3_S2Stereo>& K) {
34  // we index by cameras..
35  Base::add(measured, w_P_body_key);
36  // but we also store the extrinsic calibration keys in the same order
37  world_P_body_keys_.push_back(w_P_body_key);
38  body_P_cam_keys_.push_back(body_P_cam_key);
39 
40  // pose keys are assumed to be unique (1 observation per time stamp), but calibration can be shared
41  if(std::find(keys_.begin(), keys_.end(), body_P_cam_key) == keys_.end())
42  keys_.push_back(body_P_cam_key); // add only unique keys
43 
44  K_all_.push_back(K);
45 }
46 
48  const std::vector<StereoPoint2>& measurements,
49  const KeyVector& world_P_body_keys, const KeyVector& body_P_cam_keys,
50  const std::vector<std::shared_ptr<Cal3_S2Stereo>>& Ks) {
51  assert(world_P_body_keys.size() == measurements.size());
52  assert(world_P_body_keys.size() == body_P_cam_keys.size());
53  assert(world_P_body_keys.size() == Ks.size());
54  for (size_t i = 0; i < measurements.size(); i++) {
55  Base::add(measurements[i], world_P_body_keys[i]);
56  // pose keys are assumed to be unique (1 observation per time stamp), but calibration can be shared
57  if(std::find(keys_.begin(), keys_.end(), body_P_cam_keys[i]) == keys_.end())
58  keys_.push_back(body_P_cam_keys[i]); // add only unique keys
59 
60  world_P_body_keys_.push_back(world_P_body_keys[i]);
61  body_P_cam_keys_.push_back(body_P_cam_keys[i]);
62 
63  K_all_.push_back(Ks[i]);
64  }
65 }
66 
68  const std::vector<StereoPoint2>& measurements,
69  const KeyVector& world_P_body_keys, const KeyVector& body_P_cam_keys,
70  const std::shared_ptr<Cal3_S2Stereo>& K) {
71  assert(world_P_body_keys.size() == measurements.size());
72  assert(world_P_body_keys.size() == body_P_cam_keys.size());
73  for (size_t i = 0; i < measurements.size(); i++) {
74  Base::add(measurements[i], world_P_body_keys[i]);
75  // pose keys are assumed to be unique (1 observation per time stamp), but calibration can be shared
76  if(std::find(keys_.begin(), keys_.end(), body_P_cam_keys[i]) == keys_.end())
77  keys_.push_back(body_P_cam_keys[i]); // add only unique keys
78 
79  world_P_body_keys_.push_back(world_P_body_keys[i]);
80  body_P_cam_keys_.push_back(body_P_cam_keys[i]);
81 
82  K_all_.push_back(K);
83  }
84 }
85 
87  const std::string& s, const KeyFormatter& keyFormatter) const {
88  std::cout << s << "SmartStereoProjectionFactorPP: \n ";
89  for (size_t i = 0; i < K_all_.size(); i++) {
90  K_all_[i]->print("calibration = ");
91  std::cout << " extrinsic pose key: " << keyFormatter(body_P_cam_keys_[i]) << std::endl;
92  }
93  Base::print("", keyFormatter);
94 }
95 
97  double tol) const {
99  dynamic_cast<const SmartStereoProjectionFactorPP*>(&p);
100 
101  return e && Base::equals(p, tol) &&
102  body_P_cam_keys_ == e->getExtrinsicPoseKeys();
103 }
104 
106  if (this->active(values)) {
107  return this->totalReprojectionError(cameras(values));
108  } else { // else of active flag
109  return 0.0;
110  }
111 }
112 
115  assert(world_P_body_keys_.size() == K_all_.size());
116  assert(world_P_body_keys_.size() == body_P_cam_keys_.size());
118  for (size_t i = 0; i < world_P_body_keys_.size(); i++) {
119  Pose3 w_P_body = values.at<Pose3>(world_P_body_keys_[i]);
120  Pose3 body_P_cam = values.at<Pose3>(body_P_cam_keys_[i]);
121  Pose3 w_P_cam = w_P_body.compose(body_P_cam);
122  cameras.push_back(StereoCamera(w_P_cam, K_all_[i]));
123  }
124  return cameras;
125 }
126 
127 } // \ namespace gtsam
gtsam::SmartStereoProjectionFactorPP::body_P_cam_keys_
KeyVector body_P_cam_keys_
The keys corresponding to the extrinsic pose calibration for each view (pose that transform from came...
Definition: SmartStereoProjectionFactorPP.h:53
gtsam::SmartStereoProjectionFactorPP::cameras
Base::Cameras cameras(const Values &values) const override
Definition: SmartStereoProjectionFactorPP.cpp:114
SmartStereoProjectionFactorPP.h
Smart stereo factor on poses and extrinsic calibration.
gtsam::SmartStereoProjectionFactor::totalReprojectionError
double totalReprojectionError(const Cameras &cameras, std::optional< Point3 > externalPoint={}) const
Definition: SmartStereoProjectionFactor.h:420
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::SmartProjectionParams
Definition: SmartFactorParams.h:42
gtsam::LieGroup::compose
Class compose(const Class &g) const
Definition: Lie.h:48
gtsam::SmartFactorBase< StereoCamera >::measured
const ZVector & measured() const
Return the 2D measurements (ZDim, in general).
Definition: SmartFactorBase.h:164
measured
Point2 measured(-17, 30)
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::Factor
Definition: Factor.h:70
gtsam::SmartStereoProjectionFactorPP::add
void add(const StereoPoint2 &measured, const Key &world_P_body_key, const Key &body_P_cam_key, const std::shared_ptr< Cal3_S2Stereo > &K)
Definition: SmartStereoProjectionFactorPP.cpp:30
vanilla::params
static const SmartProjectionParams params
Definition: smartFactorScenarios.h:69
gtsam::SmartStereoProjectionFactorPP::K_all_
std::vector< std::shared_ptr< Cal3_S2Stereo > > K_all_
shared pointer to calibration object (one for each camera)
Definition: SmartStereoProjectionFactorPP.h:47
gtsam::NonlinearFactor::active
virtual bool active(const Values &) const
Definition: NonlinearFactor.h:142
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::KeyFormatter
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
gtsam::Pose3
Definition: Pose3.h:37
add
graph add(PriorFactor< Pose2 >(1, priorMean, priorNoise))
gtsam::SmartStereoProjectionFactorPP::error
double error(const Values &values) const override
Definition: SmartStereoProjectionFactorPP.cpp:105
vanillaPose::Cameras
CameraSet< Camera > Cameras
Definition: smartFactorScenarios.h:76
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::SmartStereoProjectionFactorPP::world_P_body_keys_
KeyVector world_P_body_keys_
The keys corresponding to the pose of the body (with respect to an external world frame) for each vie...
Definition: SmartStereoProjectionFactorPP.h:50
gtsam
traits
Definition: SFMdata.h:40
gtsam::Factor::keys_
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:88
K
#define K
Definition: igam.h:8
estimation_fixture::measurements
std::vector< double > measurements
Definition: testHybridEstimation.cpp:51
gtsam::Values
Definition: Values.h:65
gtsam::StereoPoint2
Definition: StereoPoint2.h:34
gtsam::Factor::equals
bool equals(const This &other, double tol=1e-9) const
check equality
Definition: Factor.cpp:42
gtsam::NonlinearFactor
Definition: NonlinearFactor.h:69
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::StereoCamera
Definition: StereoCamera.h:47
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::Factor::print
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
Definition: Factor.cpp:29
gtsam::SmartStereoProjectionFactorPP::SmartStereoProjectionFactorPP
SmartStereoProjectionFactorPP(const SharedNoiseModel &sharedNoiseModel, const SmartStereoProjectionParams &params=SmartStereoProjectionParams())
Definition: SmartStereoProjectionFactorPP.cpp:25
gtsam::SmartStereoProjectionFactorPP::equals
bool equals(const NonlinearFactor &p, double tol=1e-9) const override
equals
Definition: SmartStereoProjectionFactorPP.cpp:96
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::SmartStereoProjectionFactorPP::print
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: SmartStereoProjectionFactorPP.cpp:86
gtsam::SmartStereoProjectionFactorPP
Definition: SmartStereoProjectionFactorPP.h:43
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:13:28