10 #ifndef ba_internals_H 11 #define ba_internals_H 31 #define VERBOSE_COUT if (verbose) cout 34 template <
int FrameDof,
int Po
intDof,
int ObsDim>
59 template <
bool POSES_ARE_INVERSE>
69 if (POSES_ARE_INVERSE)
71 landmark_global.
x,landmark_global.
y,landmark_global.
z,
75 landmark_global.
x,landmark_global.
y,landmark_global.
z,
80 const double _z = 1.0/
z;
81 const double fx_z = camera_params.
fx() *_z;
82 const double fy_z = camera_params.
fy() *_z;
83 const double _z2 =
square(_z);
84 const double fx_z2 = camera_params.
fx()*_z2;
85 const double fy_z2 = camera_params.
fy()*_z2;
87 if (POSES_ARE_INVERSE)
89 const double xy =
x*
y;
91 const double J_vals[] = {
92 fx_z, 0, -fx_z2*
x, -fx_z2*xy, camera_params.
fx()*(1+
square(
x*_z)), -fx_z*
y,
93 0, fy_z, -fy_z2*
y, -camera_params.
fy()*(1+
square(
y*_z)), fy_z2*xy, fy_z*
x };
100 const double jac_proj_vals[] = {
105 const double p_x = cam_pose.
x();
106 const double p_y = cam_pose.
y();
107 const double p_z = cam_pose.z();
108 const double tx = landmark_global.
x - p_x;
109 const double ty = landmark_global.
y - p_y;
110 const double tz = landmark_global.
z - p_z;
112 const double aux_vals[] = {
113 -
R(0,0), -
R(1,0), -
R(2,0),
tz *
R(1,0) -
ty *
R(2,0) +
R(1,0) * p_z -
R(2,0) * p_y, tx *
R(2,0) -
tz *
R(0,0) -
R(0,0) * p_z +
R(2,0) * p_x,
ty *
R(0,0) - tx *
R(1,0) +
R(0,0) * p_y -
R(1,0) * p_x,
114 -
R(0,1), -
R(1,1), -
R(2,1),
tz *
R(1,1) -
ty *
R(2,1) +
R(1,1) * p_z -
R(2,1) * p_y, tx *
R(2,1) -
tz *
R(0,1) -
R(0,1) * p_z +
R(2,1) * p_x,
ty *
R(0,1) - tx *
R(1,1) +
R(0,1) * p_y -
R(1,1) * p_x,
115 -
R(0,2), -
R(1,2), -
R(2,2),
tz *
R(1,2) -
ty *
R(2,2) +
R(1,2) * p_z -
R(2,2) * p_y, tx *
R(2,2) -
tz *
R(0,2) -
R(0,2) * p_z +
R(2,2) * p_x,
ty *
R(0,2) - tx *
R(1,2) +
R(0,2) * p_y -
R(1,2) * p_x
118 out_J.multiply_AB(jac_proj, vals);
125 template <
bool POSES_ARE_INVERSE>
138 if (POSES_ARE_INVERSE)
140 landmark_global.
x,landmark_global.
y,landmark_global.
z,
145 landmark_global.
x,landmark_global.
y,landmark_global.
z,
151 const double _z = 1.0/l.
z;
152 const double _z2 =
square(_z);
154 const double tmp_vals[] = {
155 camera_params.
fx()*_z, 0, -camera_params.
fx()*l.
x*_z2,
156 0 , camera_params.
fy()*_z, -camera_params.
fy()*l.
y*_z2 };
159 out_J.multiply_AB(tmp, dp_point);
166 template <
bool POSES_ARE_INVERSE>
172 const size_t num_fix_frames,
173 const size_t num_fix_points)
178 ASSERT_(!frame_poses.empty() && !landmark_points.empty())
180 const size_t N = jac_data_vec.size();
182 for (
size_t i=0;i<N;i++)
192 if (i_f>=num_fix_frames)
194 frameJac<POSES_ARE_INVERSE>(camera_params, frame_poses[i_f], landmark_points[i_p], D.
J_frame);
198 if (i_p>=num_fix_points)
200 pointJac<POSES_ARE_INVERSE>(camera_params, frame_poses[i_f], landmark_points[i_p], D.
J_point);
211 const TSequenceFeatureObservations & observations,
218 const size_t num_fix_frames,
219 const size_t num_fix_points,
220 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.
#define MRPT_MAKE_ALIGNED_OPERATOR_NEW
double z
X,Y,Z coordinates.
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).
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)
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).
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL, 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...
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
A STL container (as wrapper) for arrays of constant size defined at compile time. ...
void ba_build_gradient_Hessians(const TSequenceFeatureObservations &observations, const std::vector< mrpt::utils::CArray< 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 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.
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=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=NULL) const
Computes the 3D point L such as .
#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).
mrpt::math::CMatrixFixedNumeric< double, ObsDim, FrameDof > J_frame
mrpt::math::CMatrixFixedNumeric< double, ObsDim, PointDof > J_point
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.
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Structure to hold the parameters of a pinhole camera model.