gtsam  4.0.0
gtsam
SmartProjectionPoseFactor.h
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 #pragma once
21 
23 
24 namespace gtsam {
44 template<class CALIBRATION>
46  PinholePose<CALIBRATION> > {
47 
48 private:
52 
53 protected:
54 
55  boost::shared_ptr<CALIBRATION> K_;
56 
57 public:
58 
60  typedef boost::shared_ptr<This> shared_ptr;
61 
66 
75  const boost::shared_ptr<CALIBRATION> K,
76  const boost::optional<Pose3> body_P_sensor = boost::none,
77  const SmartProjectionParams& params = SmartProjectionParams()) :
78  Base(sharedNoiseModel, body_P_sensor, params), K_(K) {
79  }
80 
83  }
84 
90  void print(const std::string& s = "", const KeyFormatter& keyFormatter =
91  DefaultKeyFormatter) const {
92  std::cout << s << "SmartProjectionPoseFactor, z = \n ";
93  Base::print("", keyFormatter);
94  }
95 
97  virtual bool equals(const NonlinearFactor& p, double tol = 1e-9) const {
98  const This *e = dynamic_cast<const This*>(&p);
99  return e && Base::equals(p, tol);
100  }
101 
105  virtual double error(const Values& values) const {
106  if (this->active(values)) {
107  return this->totalReprojectionError(cameras(values));
108  } else { // else of active flag
109  return 0.0;
110  }
111  }
112 
114  inline const boost::shared_ptr<CALIBRATION> calibration() const {
115  return K_;
116  }
117 
124  typename Base::Cameras cameras(const Values& values) const {
125  typename Base::Cameras cameras;
126  for(const Key& k: this->keys_) {
127  Pose3 pose = values.at<Pose3>(k);
129  pose = pose.compose(*(Base::body_P_sensor_));
130 
131  Camera camera(pose, K_);
132  cameras.push_back(camera);
133  }
134  return cameras;
135  }
136 
137 private:
138 
141  template<class ARCHIVE>
142  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
143  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
144  ar & BOOST_SERIALIZATION_NVP(K_);
145  }
146 
147 };
148 // end of class declaration
149 
151 template<class CALIBRATION>
152 struct traits<SmartProjectionPoseFactor<CALIBRATION> > : public Testable<
153  SmartProjectionPoseFactor<CALIBRATION> > {
154 };
155 
156 } // \ namespace gtsam
This is the base class for all factor types.
Definition: Factor.h:54
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print
Definition: SmartProjectionFactor.h:101
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
ValueType at(Key j) const
Retrieve a variable by key j.
Definition: Values-inl.h:342
double totalReprojectionError(const Cameras &cameras, boost::optional< Point3 > externalPoint=boost::none) const
Calculate the error of the factor.
Definition: SmartProjectionFactor.h:390
SmartProjectionFactor: triangulates point and keeps an estimate of it around.
Definition: SmartProjectionFactor.h:45
SmartProjectionPoseFactor()
Default constructor, only for serialization.
Definition: SmartProjectionPoseFactor.h:65
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Definition: PinholePose.h:237
CameraSet< CAMERA > Cameras
shorthand for a set of cameras
Definition: SmartProjectionFactor.h:73
SmartProjectionPoseFactor(const SharedNoiseModel &sharedNoiseModel, const boost::shared_ptr< CALIBRATION > K, const boost::optional< Pose3 > body_P_sensor=boost::none, const SmartProjectionParams &params=SmartProjectionParams())
Constructor.
Definition: SmartProjectionPoseFactor.h:74
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
boost::shared_ptr< This > shared_ptr
shorthand for a smart pointer to a factor
Definition: SmartProjectionPoseFactor.h:60
const boost::shared_ptr< CALIBRATION > calibration() const
return calibration shared pointers
Definition: SmartProjectionPoseFactor.h:114
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
friend class boost::serialization::access
Serialization function.
Definition: SmartProjectionPoseFactor.h:140
Nonlinear factor base class.
Definition: NonlinearFactor.h:50
Definition: SmartProjectionPoseFactor.h:45
Definition: SmartFactorParams.h:42
virtual bool equals(const NonlinearFactor &p, double tol=1e-9) const
equals
Definition: SmartProjectionPoseFactor.h:97
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Base::Cameras cameras(const Values &values) const
Collect all cameras involved in this factor.
Definition: SmartProjectionPoseFactor.h:124
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print
Definition: SmartProjectionPoseFactor.h:90
virtual ~SmartProjectionPoseFactor()
Virtual destructor.
Definition: SmartProjectionPoseFactor.h:82
virtual bool active(const Values &) const
Checks whether a factor should be used based on a set of values.
Definition: NonlinearFactor.h:113
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:72
Smart factor on cameras (pose + calibration)
Definition: Pose3.h:37
virtual bool equals(const NonlinearFactor &p, double tol=1e-9) const
equals
Definition: SmartProjectionFactor.h:113
boost::shared_ptr< CALIBRATION > K_
calibration object (one for all cameras)
Definition: SmartProjectionPoseFactor.h:55
boost::optional< Pose3 > body_P_sensor_
Pose of the camera in the body frame.
Definition: SmartFactorBase.h:79
virtual double error(const Values &values) const
error calculates the error of the factor.
Definition: SmartProjectionPoseFactor.h:105