SmartStereoProjectionPoseFactor.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* ----------------------------------------------------------------------------
  2. * GTSAM Copyright 2010, Georgia Tech Research Corporation,
  3. * Atlanta, Georgia 30332-0415
  4. * All Rights Reserved
  5. * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
  6. * See LICENSE for the license information
  7. * -------------------------------------------------------------------------- */
  8. /**
  9. * @file SmartStereoProjectionPoseFactor.h
  10. * @brief Smart stereo factor on poses, assuming camera calibration is fixed
  11. * @author Luca Carlone
  12. * @author Antoni Rosinol
  13. * @author Chris Beall
  14. * @author Zsolt Kira
  15. * @author Frank Dellaert
  16. */
  17. #pragma once
  18. #include <gtsam_unstable/slam/SmartStereoProjectionFactor.h>
  19. namespace gtsam {
  20. /**
  21. *
  22. * @addtogroup SLAM
  23. *
  24. * If you are using the factor, please cite:
  25. * L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert,
  26. * Eliminating conditionally independent sets in factor graphs:
  27. * a unifying perspective based on smart factors,
  28. * Int. Conf. on Robotics and Automation (ICRA), 2014.
  29. *
  30. */
  31. /**
  32. * This factor assumes that camera calibration is fixed, but each camera
  33. * has its own calibration.
  34. * The factor only constrains poses (variable dimension is 6).
  35. * This factor requires that values contains the involved poses (Pose3).
  36. * @addtogroup SLAM
  37. */
  38. class SmartStereoProjectionPoseFactor : public SmartStereoProjectionFactor {
  39. protected:
  40. /// shared pointer to calibration object (one for each camera)
  41. std::vector<boost::shared_ptr<Cal3_S2Stereo>> K_all_;
  42. public:
  43. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  44. /// shorthand for base class type
  45. typedef SmartStereoProjectionFactor Base;
  46. /// shorthand for this class
  47. typedef SmartStereoProjectionPoseFactor This;
  48. /// shorthand for a smart pointer to a factor
  49. typedef boost::shared_ptr<This> shared_ptr;
  50. /**
  51. * Constructor
  52. * @param Isotropic measurement noise
  53. * @param params internal parameters of the smart factors
  54. */
  55. SmartStereoProjectionPoseFactor(
  56. const SharedNoiseModel& sharedNoiseModel,
  57. const SmartStereoProjectionParams& params = SmartStereoProjectionParams(),
  58. const boost::optional<Pose3>& body_P_sensor = boost::none);
  59. /** Virtual destructor */
  60. ~SmartStereoProjectionPoseFactor() override = default;
  61. /**
  62. * add a new measurement and pose key
  63. * @param measured is the 2m dimensional location of the projection of a
  64. * single landmark in the m view (the measurement)
  65. * @param poseKey is key corresponding to the camera observing the same
  66. * landmark
  67. * @param K is the (fixed) camera calibration
  68. */
  69. void add(const StereoPoint2& measured, const Key& poseKey,
  70. const boost::shared_ptr<Cal3_S2Stereo>& K);
  71. /**
  72. * Variant of the previous one in which we include a set of measurements
  73. * @param measurements vector of the 2m dimensional location of the projection
  74. * of a single landmark in the m view (the measurement)
  75. * @param poseKeys vector of keys corresponding to the camera observing
  76. * the same landmark
  77. * @param Ks vector of calibration objects
  78. */
  79. void add(const std::vector<StereoPoint2>& measurements,
  80. const KeyVector& poseKeys,
  81. const std::vector<boost::shared_ptr<Cal3_S2Stereo>>& Ks);
  82. /**
  83. * Variant of the previous one in which we include a set of measurements with
  84. * the same noise and calibration
  85. * @param measurements vector of the 2m dimensional location of the projection
  86. * of a single landmark in the m view (the measurement)
  87. * @param poseKeys vector of keys corresponding to the camera observing the
  88. * same landmark
  89. * @param K the (known) camera calibration (same for all measurements)
  90. */
  91. void add(const std::vector<StereoPoint2>& measurements,
  92. const KeyVector& poseKeys,
  93. const boost::shared_ptr<Cal3_S2Stereo>& K);
  94. /**
  95. * print
  96. * @param s optional string naming the factor
  97. * @param keyFormatter optional formatter useful for printing Symbols
  98. */
  99. void print(const std::string& s = "", const KeyFormatter& keyFormatter =
  100. DefaultKeyFormatter) const override;
  101. /// equals
  102. bool equals(const NonlinearFactor& p, double tol = 1e-9) const override;
  103. /**
  104. * error calculates the error of the factor.
  105. */
  106. double error(const Values& values) const override;
  107. /** return the calibration object */
  108. inline std::vector<boost::shared_ptr<Cal3_S2Stereo>> calibration() const {
  109. return K_all_;
  110. }
  111. /**
  112. * Collect all cameras involved in this factor
  113. * @param values Values structure which must contain camera poses
  114. * corresponding
  115. * to keys involved in this factor
  116. * @return vector of Values
  117. */
  118. Base::Cameras cameras(const Values& values) const override;
  119. private:
  120. /// Serialization function
  121. friend class boost::serialization::access;
  122. template <class ARCHIVE>
  123. void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
  124. ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
  125. ar& BOOST_SERIALIZATION_NVP(K_all_);
  126. }
  127. }; // end of class declaration
  128. /// traits
  129. template <>
  130. struct traits<SmartStereoProjectionPoseFactor>
  131. : public Testable<SmartStereoProjectionPoseFactor> {};
  132. } // namespace gtsam