RotateFactor.h
Go to the documentation of this file.
1 /*
2  * @file RotateFactor.cpp
3  * @brief RotateFactor class
4  * @author Frank Dellaert
5  * @date December 17, 2013
6  */
7 
8 #pragma once
9 
11 #include <gtsam/geometry/Rot3.h>
12 
13 namespace gtsam {
14 
23 class RotateFactor: public NoiseModelFactor1<Rot3> {
24 
26 
28  typedef RotateFactor This;
29 
30 public:
31 
33  RotateFactor(Key key, const Rot3& P, const Rot3& Z,
34  const SharedNoiseModel& model) :
35  Base(model, key), p_(Rot3::Logmap(P)), z_(Rot3::Logmap(Z)) {
36  }
37 
40  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
42 
44  void print(const std::string& s = "",
45  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
46  Base::print(s);
47  std::cout << "RotateFactor:]\n";
48  std::cout << "p: " << p_.transpose() << std::endl;
49  std::cout << "z: " << z_.transpose() << std::endl;
50  }
51 
54  boost::optional<Matrix&> H = boost::none) const override {
55  // predict p_ as q = R*z_, derivative H will be filled if not none
56  Point3 q = R.rotate(z_,H);
57  // error is just difference, and note derivative of that wrpt q is I3
58  return (Vector(3) << q.x()-p_.x(), q.y()-p_.y(), q.z()-p_.z()).finished();
59  }
60 
61 };
62 
68 
69  Unit3 i_p_, c_z_;
70 
73 
74 public:
75 
77  RotateDirectionsFactor(Key key, const Unit3& i_p, const Unit3& c_z,
78  const SharedNoiseModel& model) :
79  Base(model, key), i_p_(i_p), c_z_(c_z) {
80  }
81 
83  static Rot3 Initialize(const Unit3& i_p, const Unit3& c_z) {
85  // setFromTwoVectors sets iRc to (a) quaternion which transform c_z into i_p
86  iRc.setFromTwoVectors(c_z.unitVector(), i_p.unitVector());
87  return Rot3(iRc);
88  }
89 
92  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
94 
96  void print(const std::string& s = "",
97  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
98  Base::print(s);
99  std::cout << "RotateDirectionsFactor:" << std::endl;
100  i_p_.print("p");
101  c_z_.print("z");
102  }
103 
105  Vector evaluateError(const Rot3& iRc, boost::optional<Matrix&> H = boost::none) const override {
106  Unit3 i_q = iRc * c_z_;
107  Vector error = i_p_.error(i_q, H);
108  if (H) {
109  Matrix DR;
110  iRc.rotate(c_z_, DR);
111  *H = (*H) * DR;
112  }
113  return error;
114  }
115 
117 };
118 } // namespace gtsam
119 
double error(const Values &c) const override
RotateDirectionsFactor This
Definition: RotateFactor.h:72
RotateDirectionsFactor(Key key, const Unit3 &i_p, const Unit3 &c_z, const SharedNoiseModel &model)
Constructor.
Definition: RotateFactor.h:77
noiseModel::Diagonal::shared_ptr model
Vector evaluateError(const Rot3 &R, boost::optional< Matrix & > H=boost::none) const override
vector of errors returns 2D vector
Definition: RotateFactor.h:53
static const Rot3 iRc(cameraX, cameraY, cameraZ)
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:43
Rot2 R(Rot2::fromAngle(0.1))
GTSAM_EXPORT Vector3 unitVector(OptionalJacobian< 3, 2 > H=boost::none) const
Return unit-norm Vector.
Definition: Unit3.cpp:143
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition: RotateFactor.h:96
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
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: RotateFactor.h:39
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: RotateFactor.h:91
Point3 rotate(const Point3 &p, OptionalJacobian< 3, 3 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
Definition: Rot3M.cpp:149
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
RotateFactor(Key key, const Rot3 &P, const Rot3 &Z, const SharedNoiseModel &model)
Constructor.
Definition: RotateFactor.h:33
EIGEN_DEVICE_FUNC Derived & setFromTwoVectors(const MatrixBase< Derived1 > &a, const MatrixBase< Derived2 > &b)
Represents a 3D point on a unit sphere.
Definition: Unit3.h:42
#define Z
Definition: icosphere.cpp:21
RotateFactor This
Definition: RotateFactor.h:28
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print
Definition: RotateFactor.h:44
Eigen::VectorXd Vector
Definition: Vector.h:38
Point3 z_
Predicted and measured directions, p = iRc * z.
Definition: RotateFactor.h:25
boost::shared_ptr< This > shared_ptr
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
RealScalar s
EIGEN_DEVICE_FUNC const Scalar & q
GTSAM_EXPORT Vector2 error(const Unit3 &q, OptionalJacobian< 2, 2 > H_q=boost::none) const
Definition: Unit3.cpp:191
Vector evaluateError(const Rot3 &iRc, boost::optional< Matrix & > H=boost::none) const override
vector of errors returns 2D vector
Definition: RotateFactor.h:105
GTSAM_EXPORT void print(const std::string &s=std::string()) const
The print fuction.
Definition: Unit3.cpp:156
traits
Definition: chartTesting.h:28
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Non-linear factor base classes.
The quaternion class used to represent 3D orientations and rotations.
NoiseModelFactor1< Rot3 > Base
Definition: RotateFactor.h:71
#define GTSAM_MAKE_ALIGNED_OPERATOR_NEW
Definition: types.h:269
Vector3 Point3
Definition: Point3.h:35
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
static Rot3 Initialize(const Unit3 &i_p, const Unit3 &c_z)
Initialize rotation iRc such that i_p = iRc * c_z.
Definition: RotateFactor.h:83
NoiseModelFactor1< Rot3 > Base
Definition: RotateFactor.h:27
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
3D rotation represented as a rotation matrix or quaternion


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:53