19 #ifndef GRAPH_FACTORS_POSE_ROTATION_FACTOR_H_ 
   20 #define GRAPH_FACTORS_POSE_ROTATION_FACTOR_H_ 
   22 #include <gtsam/geometry/Pose3.h> 
   23 #include <gtsam/geometry/Rot3.h> 
   24 #include <gtsam/nonlinear/NonlinearFactor.h> 
   30   typedef NoiseModelFactor2<Pose3, Pose3> Base;
 
   37       : Base(model, pose_key_1, pose_key_2), rotation_(
rotation) {}
 
   39   gtsam::NonlinearFactor::shared_ptr 
clone()
 const override {
 
   40     return boost::static_pointer_cast<gtsam::NonlinearFactor>(gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
 
   43   void print(
const std::string& s = 
"", 
const KeyFormatter& keyFormatter = DefaultKeyFormatter)
 const override {
 
   44     std::cout << s << 
"PoseRotationFactor, z = ";
 
   46     Base::print(
"", keyFormatter);
 
   49   bool equals(
const NonlinearFactor& p, 
double tol = 1e-9)
 const override {
 
   50     const This* e = 
dynamic_cast<const This*
>(&p);
 
   51     return e && Base::equals(p, tol) && traits<Rot3>::Equals(this->rotation_, e->
rotation(), tol);
 
   54   Vector 
evaluateError(
const Pose3& pose1, 
const Pose3& pose2, boost::optional<Matrix&> H1 = boost::none,
 
   55                        boost::optional<Matrix&> H2 = boost::none)
 const override {
 
   56     const auto& rot1 = pose1.rotation(H1);
 
   57     const auto& rot2 = pose2.rotation(H2);
 
   61     boost::optional<Matrix&> H1_rot = H1_rot_matrix;
 
   62     boost::optional<Matrix&> H2_rot = H2_rot_matrix;
 
   63     if (!H1) H1_rot = boost::none;
 
   64     if (!H2) H2_rot = boost::none;
 
   66     const auto relative_rotation = traits<Rot3>::Between(rot1, rot2, H1_rot, H2_rot);
 
   68     traits<Rot3>::ChartJacobian::Jacobian Hlocal;
 
   69     Vector 
error = traits<Rot3>::Local(rotation_, relative_rotation, boost::none, (H1_rot || H2_rot) ? &Hlocal : 0);
 
   71       *H1_rot = Hlocal * (*H1_rot);
 
   72       H1->block<3, 3>(0, 0) = H1_rot_matrix;
 
   75       *H2_rot = Hlocal * (*H2_rot);
 
   76       H2->block<3, 3>(0, 0) = H2_rot_matrix;
 
   81   const Rot3& 
rotation()
 const { 
return rotation_; }
 
   85   template <
class ARCHIVE>
 
   86   void serialize(ARCHIVE& ar, 
const unsigned int ) {
 
   87     ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
 
   88     ar& BOOST_SERIALIZATION_NVP(rotation_);
 
   94   GTSAM_MAKE_ALIGNED_OPERATOR_NEW
 
   98 #endif  // GRAPH_FACTORS_POSE_ROTATION_FACTOR_H_