23 #ifndef ba_internals_H 24 #define ba_internals_H 44 #define VERBOSE_COUT \ 49 template <
int FrameDof,
int Po
intDof,
int ObsDim>
78 template <
bool POSES_ARE_INVERSE>
88 if (POSES_ARE_INVERSE)
90 landmark_global.
x, landmark_global.
y, landmark_global.
z,
x,
y,
z);
93 landmark_global.
x, landmark_global.
y, landmark_global.
z,
x,
y,
z);
96 const double _z = 1.0 /
z;
97 const double fx_z = camera_params.
fx() * _z;
98 const double fy_z = camera_params.
fy() * _z;
99 const double _z2 =
square(_z);
100 const double fx_z2 = camera_params.
fx() * _z2;
101 const double fy_z2 = camera_params.
fy() * _z2;
103 if (POSES_ARE_INVERSE)
105 const double xy =
x *
y;
107 const double J_vals[] = {fx_z,
111 camera_params.
fx() * (1 +
square(
x * _z)),
116 -camera_params.
fy() * (1 +
square(
y * _z)),
125 const double jac_proj_vals[] = {fx_z, 0, -fx_z2 *
x,
126 0, fy_z, -fy_z2 *
y};
130 const double p_x = cam_pose.
x();
131 const double p_y = cam_pose.
y();
132 const double p_z = cam_pose.z();
133 const double tx = landmark_global.
x - p_x;
134 const double ty = landmark_global.
y - p_y;
135 const double tz = landmark_global.
z - p_z;
137 const double aux_vals[] = {
141 tz *
R(1, 0) -
ty *
R(2, 0) +
R(1, 0) * p_z -
R(2, 0) * p_y,
142 tx *
R(2, 0) -
tz *
R(0, 0) -
R(0, 0) * p_z +
R(2, 0) * p_x,
143 ty *
R(0, 0) - tx *
R(1, 0) +
R(0, 0) * p_y -
R(1, 0) * p_x,
147 tz *
R(1, 1) -
ty *
R(2, 1) +
R(1, 1) * p_z -
R(2, 1) * p_y,
148 tx *
R(2, 1) -
tz *
R(0, 1) -
R(0, 1) * p_z +
R(2, 1) * p_x,
149 ty *
R(0, 1) - tx *
R(1, 1) +
R(0, 1) * p_y -
R(1, 1) * p_x,
153 tz *
R(1, 2) -
ty *
R(2, 2) +
R(1, 2) * p_z -
R(2, 2) * p_y,
154 tx *
R(2, 2) -
tz *
R(0, 2) -
R(0, 2) * p_z +
R(2, 2) * p_x,
155 ty *
R(0, 2) - tx *
R(1, 2) +
R(0, 2) * p_y -
R(1, 2) * p_x};
157 out_J.multiply_AB(jac_proj, vals);
166 template <
bool POSES_ARE_INVERSE>
179 if (POSES_ARE_INVERSE)
181 landmark_global.
x, landmark_global.
y, landmark_global.
z, l.
x, l.
y,
185 landmark_global.
x, landmark_global.
y, landmark_global.
z, l.
x, l.
y,
189 const double _z = 1.0 / l.
z;
190 const double _z2 =
square(_z);
192 const double tmp_vals[] = {
193 camera_params.
fx() * _z, 0,
194 -camera_params.
fx() * l.
x * _z2, 0,
195 camera_params.
fy() * _z, -camera_params.
fy() * l.
y * _z2};
198 out_J.multiply_AB(tmp, dp_point);
206 template <
bool POSES_ARE_INVERSE>
212 const size_t num_fix_frames,
const size_t num_fix_points)
218 ASSERT_(!frame_poses.empty() && !landmark_points.empty());
219 const size_t N = jac_data_vec.size();
221 for (
size_t i = 0; i < N; i++)
231 if (i_f >= num_fix_frames)
233 frameJac<POSES_ARE_INVERSE>(
234 camera_params, frame_poses[i_f], landmark_points[i_p],
239 if (i_p >= num_fix_points)
241 pointJac<POSES_ARE_INVERSE>(
242 camera_params, frame_poses[i_f], landmark_points[i_p],
255 const std::vector<std::array<double, 2>>& residual_vec,
261 const size_t num_fix_frames,
const size_t num_fix_points,
262 const vector<double>* kernel_1st_deriv);
double x() const
Common members of all points & poses classes.
mrpt::math::CMatrixFixedNumeric< double, ObsDim, PointDof > J_point
uint64_t TCameraPoseID
Unique IDs for camera frames (poses)
uint64_t TLandmarkID
Unique IDs for landmarks.
double fx() const
Get the value of the focal length x-value (in pixels).
double fy() const
Get the value of the focal length y-value (in pixels).
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
void pointJac(const mrpt::img::TCamera &camera_params, const mrpt::poses::CPose3D &cam_pose, const mrpt::math::TPoint3D &landmark_global, mrpt::math::CMatrixFixedNumeric< double, 2, 3 > &out_J)
Jacobians wrt the point.
#define MRPT_MAKE_ALIGNED_OPERATOR_NEW
Put this macro inside any class with members that require {16,32,64}-byte memory alignment (e...
std::vector< T, mrpt::aligned_allocator_cpp11< T > > aligned_std_vector
A complete sequence of observations of features from different camera frames (poses).
T square(const T x)
Inline function for the square of a number.
#define ASSERT_(f)
Defines an assertion mechanism.
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
CArrayNumeric< double, N > CArrayDouble
A partial specialization of CArrayNumeric for double numbers.
Classes for computer vision, detectors, features, etc.
Structure to hold the parameters of a pinhole camera model.
double x
X,Y,Z coordinates.
void loadFromArray(const T *vals)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void ba_compute_Jacobians(const TFramePosesVec &frame_poses, const TLandmarkLocationsVec &landmark_points, const mrpt::img::TCamera &camera_params, mrpt::aligned_std_vector< JacData< 6, 3, 2 >> &jac_data_vec, const size_t num_fix_frames, const size_t num_fix_points)
void ba_build_gradient_Hessians(const TSequenceFeatureObservations &observations, const std::vector< std::array< double, 2 >> &residual_vec, const mrpt::aligned_std_vector< JacData< 6, 3, 2 >> &jac_data_vec, mrpt::aligned_std_vector< mrpt::math::CMatrixFixedNumeric< double, 6, 6 >> &U, mrpt::aligned_std_vector< CArrayDouble< 6 >> &eps_frame, mrpt::aligned_std_vector< mrpt::math::CMatrixFixedNumeric< double, 3, 3 >> &V, mrpt::aligned_std_vector< CArrayDouble< 3 >> &eps_point, const size_t num_fix_frames, const size_t num_fix_points, const vector< double > *kernel_1st_deriv)
Construct the BA linear system.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
mrpt::aligned_std_vector< mrpt::poses::CPose3D > TFramePosesVec
A list of camera frames (6D poses), which assumes indexes are unique, consecutive IDs...
mrpt::math::CMatrixFixedNumeric< double, ObsDim, FrameDof > J_frame
void frameJac(const mrpt::img::TCamera &camera_params, const mrpt::poses::CPose3D &cam_pose, const mrpt::math::TPoint3D &landmark_global, mrpt::math::CMatrixFixedNumeric< double, 2, 6 > &out_J)
The projective camera 2x6 Jacobian (wrt the 6D camera pose)
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
std::vector< mrpt::math::TPoint3D > TLandmarkLocationsVec
A list of landmarks (3D points), which assumes indexes are unique, consecutive IDs.
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr) const
Computes the 3D point L such as .