| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef CERES_PUBLIC_LINE_MANIFOLD_H_ |
| #define CERES_PUBLIC_LINE_MANIFOLD_H_ |
|
|
| #include <Eigen/Core> |
| #include <algorithm> |
| #include <array> |
| #include <memory> |
| #include <vector> |
|
|
| #include "ceres/internal/disable_warnings.h" |
| #include "ceres/internal/export.h" |
| #include "ceres/internal/householder_vector.h" |
| #include "ceres/internal/sphere_manifold_functions.h" |
| #include "ceres/manifold.h" |
| #include "ceres/types.h" |
| #include "glog/logging.h" |
|
|
| namespace ceres { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| template <int AmbientSpaceDimension> |
| class LineManifold final : public Manifold { |
| public: |
| static_assert(AmbientSpaceDimension == DYNAMIC || AmbientSpaceDimension >= 2, |
| "The ambient space must be at least 2."); |
| static_assert(ceres::DYNAMIC == Eigen::Dynamic, |
| "ceres::DYNAMIC needs to be the same as Eigen::Dynamic."); |
|
|
| LineManifold(); |
| explicit LineManifold(int size); |
|
|
| int AmbientSize() const override { return 2 * size_; } |
| int TangentSize() const override { return 2 * (size_ - 1); } |
| bool Plus(const double* x, |
| const double* delta, |
| double* x_plus_delta) const override; |
| bool PlusJacobian(const double* x, double* jacobian) const override; |
| bool Minus(const double* y, |
| const double* x, |
| double* y_minus_x) const override; |
| bool MinusJacobian(const double* x, double* jacobian) const override; |
|
|
| private: |
| static constexpr bool IsDynamic = (AmbientSpaceDimension == ceres::DYNAMIC); |
| static constexpr int TangentSpaceDimension = |
| IsDynamic ? ceres::DYNAMIC : AmbientSpaceDimension - 1; |
|
|
| static constexpr int DAmbientSpaceDimension = |
| IsDynamic ? ceres::DYNAMIC : 2 * AmbientSpaceDimension; |
| static constexpr int DTangentSpaceDimension = |
| IsDynamic ? ceres::DYNAMIC : 2 * TangentSpaceDimension; |
|
|
| using AmbientVector = Eigen::Matrix<double, AmbientSpaceDimension, 1>; |
| using TangentVector = Eigen::Matrix<double, TangentSpaceDimension, 1>; |
| using MatrixPlusJacobian = Eigen::Matrix<double, |
| DAmbientSpaceDimension, |
| DTangentSpaceDimension, |
| Eigen::RowMajor>; |
| using MatrixMinusJacobian = Eigen::Matrix<double, |
| DTangentSpaceDimension, |
| DAmbientSpaceDimension, |
| Eigen::RowMajor>; |
|
|
| const int size_{AmbientSpaceDimension}; |
| }; |
|
|
| template <int AmbientSpaceDimension> |
| LineManifold<AmbientSpaceDimension>::LineManifold() |
| : size_{AmbientSpaceDimension} { |
| static_assert( |
| AmbientSpaceDimension != Eigen::Dynamic, |
| "The size is set to dynamic. Please call the constructor with a size."); |
| } |
|
|
| template <int AmbientSpaceDimension> |
| LineManifold<AmbientSpaceDimension>::LineManifold(int size) : size_{size} { |
| if (AmbientSpaceDimension != Eigen::Dynamic) { |
| CHECK_EQ(AmbientSpaceDimension, size) |
| << "Specified size by template parameter differs from the supplied " |
| "one."; |
| } else { |
| CHECK_GT(size_, 1) |
| << "The size of the manifold needs to be greater than 1."; |
| } |
| } |
|
|
| template <int AmbientSpaceDimension> |
| bool LineManifold<AmbientSpaceDimension>::Plus(const double* x_ptr, |
| const double* delta_ptr, |
| double* x_plus_delta_ptr) const { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Eigen::Map<const AmbientVector> o(x_ptr, size_); |
| Eigen::Map<const AmbientVector> d(x_ptr + size_, size_); |
|
|
| Eigen::Map<const TangentVector> delta_o(delta_ptr, size_ - 1); |
| Eigen::Map<const TangentVector> delta_d(delta_ptr + size_ - 1, size_ - 1); |
| Eigen::Map<AmbientVector> o_plus_delta(x_plus_delta_ptr, size_); |
| Eigen::Map<AmbientVector> d_plus_delta(x_plus_delta_ptr + size_, size_); |
|
|
| const double norm_delta_d = delta_d.norm(); |
|
|
| o_plus_delta = o; |
|
|
| |
| if (norm_delta_d == 0.0) { |
| d_plus_delta = d; |
|
|
| if (delta_o.isZero(0.0)) { |
| return true; |
| } |
| } |
|
|
| |
| AmbientVector v(size_); |
| double beta; |
|
|
| |
| |
| |
| internal::ComputeHouseholderVector<Eigen::Map<const AmbientVector>, |
| double, |
| AmbientSpaceDimension>(d, &v, &beta); |
|
|
| if (norm_delta_d != 0.0) { |
| internal::ComputeSphereManifoldPlus( |
| v, beta, d, delta_d, norm_delta_d, &d_plus_delta); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| AmbientVector y(size_); |
| y << 0.5 * delta_o, 0; |
| o_plus_delta += internal::ApplyHouseholderVector(y, v, beta); |
|
|
| return true; |
| } |
|
|
| template <int AmbientSpaceDimension> |
| bool LineManifold<AmbientSpaceDimension>::PlusJacobian( |
| const double* x_ptr, double* jacobian_ptr) const { |
| Eigen::Map<const AmbientVector> d(x_ptr + size_, size_); |
| Eigen::Map<MatrixPlusJacobian> jacobian( |
| jacobian_ptr, 2 * size_, 2 * (size_ - 1)); |
|
|
| |
| jacobian.setZero(); |
|
|
| auto jacobian_d = |
| jacobian |
| .template topLeftCorner<AmbientSpaceDimension, TangentSpaceDimension>( |
| size_, size_ - 1); |
| auto jacobian_o = jacobian.template bottomRightCorner<AmbientSpaceDimension, |
| TangentSpaceDimension>( |
| size_, size_ - 1); |
| internal::ComputeSphereManifoldPlusJacobian(d, &jacobian_d); |
| jacobian_o = jacobian_d; |
| return true; |
| } |
|
|
| template <int AmbientSpaceDimension> |
| bool LineManifold<AmbientSpaceDimension>::Minus(const double* y_ptr, |
| const double* x_ptr, |
| double* y_minus_x) const { |
| Eigen::Map<const AmbientVector> y_o(y_ptr, size_); |
| Eigen::Map<const AmbientVector> y_d(y_ptr + size_, size_); |
| Eigen::Map<const AmbientVector> x_o(x_ptr, size_); |
| Eigen::Map<const AmbientVector> x_d(x_ptr + size_, size_); |
|
|
| Eigen::Map<TangentVector> y_minus_x_o(y_minus_x, size_ - 1); |
| Eigen::Map<TangentVector> y_minus_x_d(y_minus_x + size_ - 1, size_ - 1); |
|
|
| AmbientVector v(size_); |
| double beta; |
|
|
| |
| |
| |
| internal::ComputeHouseholderVector<Eigen::Map<const AmbientVector>, |
| double, |
| AmbientSpaceDimension>(x_d, &v, &beta); |
|
|
| internal::ComputeSphereManifoldMinus(v, beta, x_d, y_d, &y_minus_x_d); |
|
|
| AmbientVector delta_o = y_o - x_o; |
| const AmbientVector h_delta_o = |
| 2.0 * internal::ApplyHouseholderVector(delta_o, v, beta); |
| y_minus_x_o = h_delta_o.template head<TangentSpaceDimension>(size_ - 1); |
|
|
| return true; |
| } |
|
|
| template <int AmbientSpaceDimension> |
| bool LineManifold<AmbientSpaceDimension>::MinusJacobian( |
| const double* x_ptr, double* jacobian_ptr) const { |
| Eigen::Map<const AmbientVector> d(x_ptr + size_, size_); |
| Eigen::Map<MatrixMinusJacobian> jacobian( |
| jacobian_ptr, 2 * (size_ - 1), 2 * size_); |
|
|
| |
| jacobian.setZero(); |
|
|
| auto jacobian_d = |
| jacobian |
| .template topLeftCorner<TangentSpaceDimension, AmbientSpaceDimension>( |
| size_ - 1, size_); |
| auto jacobian_o = jacobian.template bottomRightCorner<TangentSpaceDimension, |
| AmbientSpaceDimension>( |
| size_ - 1, size_); |
| internal::ComputeSphereManifoldMinusJacobian(d, &jacobian_d); |
| jacobian_o = jacobian_d; |
|
|
| return true; |
| } |
|
|
| } |
|
|
| |
| #include "ceres/internal/reenable_warnings.h" |
| |
|
|
| #endif |
|
|