Ocean
MotionModel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_TRACKING_MOTION_MODEL_H
9 #define META_OCEAN_TRACKING_MOTION_MODEL_H
10 
11 #include "ocean/tracking/Tracker.h"
12 
15 #include "ocean/math/Pose.h"
16 #include "ocean/math/Quaternion.h"
17 #include "ocean/math/Vector3.h"
18 
19 namespace Ocean
20 {
21 
22 namespace Tracking
23 {
24 
25 /**
26  * This class implements a 6DOF pose with internal motion model.
27  * @ingroup tracking
28  */
29 class OCEAN_TRACKING_EXPORT MotionModel
30 {
31  public:
32 
33  /**
34  * Creates a new but invalid motion model.
35  */
37 
38  /**
39  * Creates a new pose with a given homogeneous matrix.
40  * The given transformation must be scale and shear free.
41  * @param transformation Matrix defining the pose
42  */
43  explicit MotionModel(const HomogenousMatrix4& transformation);
44 
45  /**
46  * Creates a new pose by a given translation and orientation.
47  * @param translation Translation of the pose
48  * @param orientation Orientation of the pose
49  */
50  MotionModel(const Vector3& translation, const Quaternion& orientation);
51 
52  /**
53  * Creates a new pose by a given translation and orientation.
54  * @param translation Translation of the pose
55  * @param orientation Orientation of the pose
56  */
57  MotionModel(const Vector3& translation, const Rotation& orientation);
58 
59  /**
60  * Updates the model with a new precise pose.
61  * @param pose New pose to updating the model and creating a new prediction
62  */
63  void update(const HomogenousMatrix4& pose);
64 
65  /**
66  * Returns the current pose of this motion model as transformation matrix.
67  * @return Current pose
68  */
69  inline const HomogenousMatrix4& pose() const;
70 
71  /**
72  * Returns the predicted pose of this motion model as transformation matrix.
73  * @return Predicted pose
74  */
75  inline const HomogenousMatrix4& predictedPose() const;
76 
77  /**
78  * Returns the current velocity of this motion model.
79  * @return Current velocity
80  */
81  inline const Pose& velocity() const;
82 
83  /**
84  * Returns the current velocity of this motion model.
85  * @return Current velocity
86  */
87  inline const Pose& predictedVelocity() const;
88 
89  /**
90  * Resets the motion model.
91  * All gathered information will be lost.
92  */
93  void reset();
94 
95  /**
96  * Returns whether no pose has been registered.
97  * @return True, if so
98  */
99  inline bool isNull() const;
100 
101  /**
102  * Returns whether at least one pose has been registered.
103  * @return True, if so
104  */
105  explicit inline operator bool() const;
106 
107  /**
108  * Applies a liner (and spherical linear) interpolation between two camera poses by application of an interpolation factor.
109  * @param pose0 The first camera pose that will be returned if an interpolation factor of 0.0 is applied
110  * @param pose1 The second camera pose that will be returned if an interpolation factor of 1.0 is applied
111  * @param factor The interpolation factor with range [0.0, 1.0]
112  * @return The resulting interpolated camera pose
113  */
114  static inline HomogenousMatrix4 interpolate(const HomogenousMatrix4& pose0, const HomogenousMatrix4& pose1, const Scalar factor);
115 
116  /**
117  * Predicts (extrapolates) the camera pose for a current camera frame, if poses for the previous frames are known.
118  * This function predicts a pose for each two pairs of concurrent poses of the given set of previous poses.<br>
119  * The prediction of the most recent pose pairs is interpolated with the precision of the next pose pairs and so on.<br>
120  * Thus, the influence of the previous poses can be adjusted with the interpolation factor.<br>
121  * A given factor of of 0.4 means that the youngest poses have an influence of 60% while each older pose has an influence of 40% (recursively).<br>
122  * @param previousPoses A concurrent set of valid poses for the previous frames, at least two poses must be provided.
123  * @param factor The interpolation factor that defines the influence of the most recent poses, with range [0.0, 1.0]
124  */
125  static HomogenousMatrix4 predictPose(const HomogenousMatrices4& previousPoses, const Scalar factor = Scalar(0.4));
126 
127  private:
128 
129  /// Current pose.
131 
132  /// Predicted pose.
134 
135  /// Current velocity.
137 
138  /// Predicted velocity.
140 
141  /// State determining whether at least one pose has been registered
143 };
144 
146 {
147  return modelPose;
148 }
149 
151 {
152  return modelPredictedPose;
153 }
154 
155 inline const Pose& MotionModel::velocity() const
156 {
157  return modelVelocity;
158 }
159 
161 {
162  return modelPredictedVelocity;
163 }
164 
165 inline bool MotionModel::isNull() const
166 {
167  return !modelHasPose;
168 }
169 
170 inline MotionModel::operator bool() const
171 {
172  return modelHasPose;
173 }
174 
176 {
177  return HomogenousMatrix4(Interpolation::linear(std::make_pair(pose0.translation(), pose0.rotation()), std::make_pair(pose1.translation(), pose1.rotation()), factor));
178 }
179 
180 }
181 
182 }
183 
184 #endif // META_OCEAN_TRACKING_MOTION_MODEL_H
VectorT3< T > translation() const
Returns the translation of the transformation.
Definition: HomogenousMatrix4.h:1381
QuaternionT< T > rotation() const
Returns the rotation of the transformation as quaternion.
Definition: HomogenousMatrix4.h:1388
static T linear(const T &v0, const T &v1, const TFactor &t)
Performs a linear interpolation between two values.
Definition: Interpolation.h:508
This class implements a axis-angle rotation using floating point values.
Definition: Rotation.h:79
This class implements a 6DOF pose with internal motion model.
Definition: MotionModel.h:30
const Pose & velocity() const
Returns the current velocity of this motion model.
Definition: MotionModel.h:155
MotionModel(const Vector3 &translation, const Quaternion &orientation)
Creates a new pose by a given translation and orientation.
MotionModel(const Vector3 &translation, const Rotation &orientation)
Creates a new pose by a given translation and orientation.
Pose modelVelocity
Current velocity.
Definition: MotionModel.h:136
void reset()
Resets the motion model.
HomogenousMatrix4 modelPose
Current pose.
Definition: MotionModel.h:130
const HomogenousMatrix4 & pose() const
Returns the current pose of this motion model as transformation matrix.
Definition: MotionModel.h:145
const Pose & predictedVelocity() const
Returns the current velocity of this motion model.
Definition: MotionModel.h:160
bool modelHasPose
State determining whether at least one pose has been registered.
Definition: MotionModel.h:142
Pose modelPredictedVelocity
Predicted velocity.
Definition: MotionModel.h:139
const HomogenousMatrix4 & predictedPose() const
Returns the predicted pose of this motion model as transformation matrix.
Definition: MotionModel.h:150
MotionModel(const HomogenousMatrix4 &transformation)
Creates a new pose with a given homogeneous matrix.
bool isNull() const
Returns whether no pose has been registered.
Definition: MotionModel.h:165
MotionModel()
Creates a new but invalid motion model.
HomogenousMatrix4 modelPredictedPose
Predicted pose.
Definition: MotionModel.h:133
static HomogenousMatrix4 interpolate(const HomogenousMatrix4 &pose0, const HomogenousMatrix4 &pose1, const Scalar factor)
Applies a liner (and spherical linear) interpolation between two camera poses by application of an in...
Definition: MotionModel.h:175
void update(const HomogenousMatrix4 &pose)
Updates the model with a new precise pose.
static HomogenousMatrix4 predictPose(const HomogenousMatrices4 &previousPoses, const Scalar factor=Scalar(0.4))
Predicts (extrapolates) the camera pose for a current camera frame, if poses for the previous frames ...
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition: HomogenousMatrix4.h:73
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition: HomogenousMatrix4.h:37
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15