Berkeley SfM
pose.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: David Fridovich-Keil ( dfk@eecs.berkeley.edu )
35  * Erik Nelson ( eanelson@eecs.berkeley.edu )
36  */
37 
38 #ifndef BSFM_POSE_POSE_H
39 #define BSFM_POSE_POSE_H
40 
41 #include <Eigen/Dense>
42 #include <glog/logging.h>
43 #include <string>
44 
45 #include "../util/types.h"
46 
47 namespace bsfm {
48 
49 using Eigen::Matrix3d;
50 using Eigen::Matrix4d;
51 using Eigen::Vector2d;
52 using Eigen::Vector3d;
53 using Eigen::Vector4d;
54 using Eigen::VectorXd;
55 
56 class Pose {
57  public:
58  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
59 
60  // Initialize to the identity.
61  Pose();
62 
63  // Construct a new Pose from a rotation matrix and translation vector.
64  Pose(const Matrix3d& R, const Vector3d& t);
65 
66  // Construct a new Pose from a de-homogenized 3x4 [R | t] matrix.
67  Pose(const Matrix34d& Rt);
68 
69  // Deep copy constructor.
70  Pose(const Pose& other);
71 
72  // Construct a new Pose from a 4x4 Rt matrix.
73  Pose(const Matrix4d& other);
74 
75  // Destroy this Pose.
76  ~Pose() { };
77 
78  // Individual element accessor.
79  double& operator()(int i, int j);
80  const double& operator()(int i, int j) const;
81 
82  // Access the homogeneous transformation matrix.
83  Matrix4d& Get();
84  const Matrix4d& Get() const;
85 
86  // Get the transformation's rotation components.
87  Matrix3d Rotation() const;
88 
89  // Get the transformation's rotation components.
90  Vector3d Translation() const;
91 
92  // Set the homogeneous transformation matrix.
93  void Set(const Matrix4d& transformation);
94 
95  // Set rotation and translation directly.
96  void SetRotation(const Matrix3d& rotation);
97  void SetTranslation(const Vector3d& translation);
98 
99  // Multiply two Poses.
100  Pose operator*(const Pose& other) const;
101 
102  // Multiply a homgenized point into a Pose.
103  Vector4d Project(const Vector4d&);
104 
105  // Project a 3D point into this Pose.
106  Vector2d ProjectTo2D(const Vector3d&);
107 
108  // Test if this pose (Rt_ only) is approximately equal to another Pose.
109  bool IsApprox(const Pose&) const;
110 
111  // Compose this Pose with the given pose so that both refer to the identity
112  // Pose as specified by the given Pose.
113  void Compose(const Pose& other);
114 
115  // Invert this pose.
116  Pose Inverse() const;
117 
118  // Extract just the extrinsics matrix as a 3x4 matrix.
120 
121  // Output axis-angle representation.
122  Vector3d AxisAngle();
123 
124  // Set based on axis-angle input, and return homogeneous matrix.
125  Matrix4d FromAxisAngle(const Vector3d& aa);
126 
127  // Set translation directly.
128  void SetX(double x);
129  void SetY(double y);
130  void SetZ(double z);
131 
132  // Get translation elements.
133  const double& X() const;
134  const double& Y() const;
135  const double& Z() const;
136  double& MutableX();
137  double& MutableY();
138  double& MutableZ();
139 
140  // Translate.
141  void TranslateX(double dx);
142  void TranslateY(double dy);
143  void TranslateZ(double dz);
144 
145  // Get the relative transformation from this Pose to another one.
146  Pose Delta(const Pose& rhs) const;
147 
148  // Print matrix entries.
149  void Print(const std::string& prefix = std::string()) const;
150 
151  private:
152  Matrix4d Rt_; // 4x4 homogeneous Pose matrix
153 }; //\class Pose
154 
155 }; // namespace bsfm
156 
157 #endif
void SetZ(double z)
Definition: pose.cpp:207
Matrix4d & Get()
Definition: pose.cpp:82
Vector3d Translation() const
Definition: pose.cpp:96
Pose operator*(const Pose &other) const
Definition: pose.cpp:115
void SetY(double y)
Definition: pose.cpp:203
void SetTranslation(const Vector3d &translation)
Definition: pose.cpp:110
void SetX(double x)
Definition: pose.cpp:199
Matrix3d Rotation() const
Definition: pose.cpp:91
void Set(const Matrix4d &transformation)
Definition: pose.cpp:101
double & MutableZ()
Definition: pose.cpp:231
Pose Inverse() const
Definition: pose.cpp:150
Vector2d ProjectTo2D(const Vector3d &)
Definition: pose.cpp:127
~Pose()
Definition: pose.h:76
Vector4d Project(const Vector4d &)
Definition: pose.cpp:121
bool IsApprox(const Pose &) const
Definition: pose.cpp:139
const double & X() const
Definition: pose.cpp:211
void TranslateY(double dy)
Definition: pose.cpp:239
const double & Z() const
Definition: pose.cpp:219
void Print(const std::string &prefix=std::string()) const
Definition: pose.cpp:248
double & MutableY()
Definition: pose.cpp:227
void TranslateZ(double dz)
Definition: pose.cpp:243
Definition: camera.cpp:50
void SetRotation(const Matrix3d &rotation)
Definition: pose.cpp:106
void Compose(const Pose &other)
Definition: pose.cpp:145
::Eigen::Matrix< double, 3, 4 > Matrix34d
Definition: types.h:87
Vector3d AxisAngle()
Definition: pose.cpp:162
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Pose()
Definition: pose.cpp:45
double & operator()(int i, int j)
Definition: pose.cpp:73
Matrix34d Dehomogenize()
Definition: pose.cpp:157
double & MutableX()
Definition: pose.cpp:223
Matrix4d FromAxisAngle(const Vector3d &aa)
Definition: pose.cpp:174
void TranslateX(double dx)
Definition: pose.cpp:235
Pose Delta(const Pose &rhs) const
Definition: pose.cpp:256
Matrix4d Rt_
Definition: pose.h:152
const double & Y() const
Definition: pose.cpp:215