10 #ifndef ba_internals_H 11 #define ba_internals_H 33 #define VERBOSE_COUT \ 38 template <
int FrameDof,
int Po
intDof,
int ObsDim>
67 template <
bool POSES_ARE_INVERSE>
77 if (POSES_ARE_INVERSE)
79 landmark_global.
x, landmark_global.
y, landmark_global.
z,
x,
y,
z);
82 landmark_global.
x, landmark_global.
y, landmark_global.
z,
x,
y,
z);
86 const double _z = 1.0 /
z;
87 const double fx_z = camera_params.
fx() * _z;
88 const double fy_z = camera_params.
fy() * _z;
89 const double _z2 =
square(_z);
90 const double fx_z2 = camera_params.
fx() * _z2;
91 const double fy_z2 = camera_params.
fy() * _z2;
93 if (POSES_ARE_INVERSE)
95 const double xy =
x *
y;
97 const double J_vals[] = {fx_z,
101 camera_params.
fx() * (1 +
square(
x * _z)),
106 -camera_params.
fy() * (1 +
square(
y * _z)),
115 const double jac_proj_vals[] = {fx_z, 0, -fx_z2 *
x,
116 0, fy_z, -fy_z2 *
y};
120 const double p_x = cam_pose.
x();
121 const double p_y = cam_pose.
y();
122 const double p_z = cam_pose.z();
123 const double tx = landmark_global.
x - p_x;
124 const double ty = landmark_global.
y - p_y;
125 const double tz = landmark_global.
z - p_z;
127 const double aux_vals[] = {
131 tz *
R(1, 0) -
ty *
R(2, 0) +
R(1, 0) * p_z -
R(2, 0) * p_y,
132 tx *
R(2, 0) -
tz *
R(0, 0) -
R(0, 0) * p_z +
R(2, 0) * p_x,
133 ty *
R(0, 0) - tx *
R(1, 0) +
R(0, 0) * p_y -
R(1, 0) * p_x,
137 tz *
R(1, 1) -
ty *
R(2, 1) +
R(1, 1) * p_z -
R(2, 1) * p_y,
138 tx *
R(2, 1) -
tz *
R(0, 1) -
R(0, 1) * p_z +
R(2, 1) * p_x,
139 ty *
R(0, 1) - tx *
R(1, 1) +
R(0, 1) * p_y -
R(1, 1) * p_x,
143 tz *
R(1, 2) -
ty *
R(2, 2) +
R(1, 2) * p_z -
R(2, 2) * p_y,
144 tx *
R(2, 2) -
tz *
R(0, 2) -
R(0, 2) * p_z +
R(2, 2) * p_x,
145 ty *
R(0, 2) - tx *
R(1, 2) +
R(0, 2) * p_y -
R(1, 2) * p_x};
147 out_J.multiply_AB(jac_proj, vals);
156 template <
bool POSES_ARE_INVERSE>
169 if (POSES_ARE_INVERSE)
171 landmark_global.
x, landmark_global.
y, landmark_global.
z, l.
x, l.
y,
175 landmark_global.
x, landmark_global.
y, landmark_global.
z, l.
x, l.
y,
180 const double _z = 1.0 / l.
z;
181 const double _z2 =
square(_z);
183 const double tmp_vals[] = {
184 camera_params.
fx() * _z, 0,
185 -camera_params.
fx() * l.
x * _z2, 0,
186 camera_params.
fy() * _z, -camera_params.
fy() * l.
y * _z2};
189 out_J.multiply_AB(tmp, dp_point);
197 template <
bool POSES_ARE_INVERSE>
203 const size_t num_fix_frames,
const size_t num_fix_points)
209 ASSERT_(!frame_poses.empty() && !landmark_points.empty())
211 const size_t N = jac_data_vec.size();
213 for (
size_t i = 0; i < N; i++)
223 if (i_f >= num_fix_frames)
225 frameJac<POSES_ARE_INVERSE>(
226 camera_params, frame_poses[i_f], landmark_points[i_p],
231 if (i_p >= num_fix_points)
233 pointJac<POSES_ARE_INVERSE>(
234 camera_params, frame_poses[i_f], landmark_points[i_p],
246 const TSequenceFeatureObservations& observations,
247 const std::vector<std::array<double, 2>>& residual_vec,
255 const size_t num_fix_frames,
const size_t num_fix_points,
256 const vector<double>* kernel_1st_deriv);
void pointJac(const mrpt::utils::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.
double x() const
Common members of all points & poses classes.
mrpt::math::CMatrixFixedNumeric< double, ObsDim, PointDof > J_point
#define MRPT_MAKE_ALIGNED_OPERATOR_NEW
Helper types for STL containers with Eigen memory allocators.
void frameJac(const mrpt::utils::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)
T square(const T x)
Inline function for the square of a number.
double fx() const
Get the value of the focal length x-value (in pixels).
mrpt::aligned_containers< mrpt::poses::CPose3D >::vector_t TFramePosesVec
A list of camera frames (6D poses), which assumes indexes are unique, consecutive IDs...
double fy() const
Get the value of the focal length y-value (in pixels).
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
double x
X,Y,Z coordinates.
void loadFromArray(const T *vals)
uint64_t TCameraPoseID
Unique IDs for camera frames (poses)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
uint64_t TLandmarkID
Unique IDs for landmarks.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void ba_build_gradient_Hessians(const TSequenceFeatureObservations &observations, const std::vector< std::array< double, 2 >> &residual_vec, const mrpt::aligned_containers< JacData< 6, 3, 2 >>::vector_t &jac_data_vec, mrpt::aligned_containers< mrpt::math::CMatrixFixedNumeric< double, 6, 6 >>::vector_t &U, mrpt::aligned_containers< CArrayDouble< 6 >>::vector_t &eps_frame, mrpt::aligned_containers< mrpt::math::CMatrixFixedNumeric< double, 3, 3 >>::vector_t &V, mrpt::aligned_containers< CArrayDouble< 3 >>::vector_t &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.
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...
T square(const T x)
Inline function for the square of a number.
std::vector< mrpt::math::TPoint3D > TLandmarkLocationsVec
A list of landmarks (3D points), which assumes indexes are unique, consecutive IDs.
A partial specialization of CArrayNumeric for double numbers.
mrpt::math::CMatrixFixedNumeric< double, ObsDim, FrameDof > J_frame
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
void ba_compute_Jacobians(const TFramePosesVec &frame_poses, const TLandmarkLocationsVec &landmark_points, const mrpt::utils::TCamera &camera_params, mrpt::aligned_containers< JacData< 6, 3, 2 >>::vector_t &jac_data_vec, const size_t num_fix_frames, const size_t num_fix_points)
Structure to hold the parameters of a pinhole camera model.
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 .