10 #include <ceres/ceres.h>
11 #include <ceres/rotation.h>
17 #include "ceres/ceres.h"
20 #if CERES_VERSION_MAJOR >= 3 || \
21 (CERES_VERSION_MAJOR == 2 && CERES_VERSION_MINOR >= 1)
22 problem->SetManifold(quat_xyzw,
new ceres::EigenQuaternionManifold);
24 problem->SetParameterization(quat_xyzw,
25 new ceres::EigenQuaternionParameterization);
30 const std::vector<int>& constant_params,
31 ceres::Problem* problem,
33 #if CERES_VERSION_MAJOR >= 3 || \
34 (CERES_VERSION_MAJOR == 2 && CERES_VERSION_MINOR >= 1)
35 problem->SetManifold(params,
36 new ceres::SubsetManifold(
size, constant_params));
38 problem->SetParameterization(
39 params,
new ceres::SubsetParameterization(
size, constant_params));
45 #if CERES_VERSION_MAJOR >= 3 || \
46 (CERES_VERSION_MAJOR == 2 && CERES_VERSION_MINOR >= 1)
47 problem->SetManifold(params,
new ceres::SphereManifold<size>);
49 problem->SetParameterization(
50 params,
new ceres::HomogeneousVectorParameterization(
size));
56 #if CERES_VERSION_MAJOR >= 3 || \
57 (CERES_VERSION_MAJOR == 2 && CERES_VERSION_MINOR >= 1)
58 template <
int AmbientSpaceDimension>
59 class PositiveExponentialManifold :
public ceres::Manifold {
61 static_assert(ceres::DYNAMIC == Eigen::Dynamic,
62 "ceres::DYNAMIC needs to be the same as Eigen::Dynamic.");
64 PositiveExponentialManifold() :
size_{AmbientSpaceDimension} {}
65 explicit PositiveExponentialManifold(
int size) :
size_{
size} {
66 if (AmbientSpaceDimension != Eigen::Dynamic) {
67 CHECK_EQ(AmbientSpaceDimension,
size)
68 <<
"Specified size by template parameter differs from the "
72 CHECK_GT(
size_, 0) <<
"The size of the manifold needs to be a "
77 bool Plus(
const double*
x,
79 double* x_plus_delta)
const override {
80 for (
int i = 0; i <
size_; ++i) {
81 x_plus_delta[i] =
x[i] * std::exp(delta[i]);
86 bool PlusJacobian(
const double*
x,
double* jacobian)
const override {
87 for (
int i = 0; i <
size_; ++i) {
88 jacobian[
size_ * i + i] =
x[i];
93 virtual bool Minus(
const double*
y,
95 double* y_minus_x)
const override {
96 for (
int i = 0; i <
size_; ++i) {
97 y_minus_x[i] = std::log(
y[i] /
x[i]);
102 virtual bool MinusJacobian(
const double*
x,
103 double* jacobian)
const override {
104 for (
int i = 0; i <
size_; ++i) {
105 jacobian[
size_ * i + i] = 1.0 /
x[i];
110 int AmbientSize()
const override {
111 return AmbientSpaceDimension == ceres::DYNAMIC ?
size_
112 : AmbientSpaceDimension;
114 int TangentSize()
const override {
return AmbientSize(); }
121 :
public ceres::LocalParameterization {
125 <<
"The size of the manifold needs to be a positive integer.";
131 double* x_plus_delta)
const override {
132 for (
int i = 0; i < size_; ++i) {
133 x_plus_delta[i] =
x[i] * std::exp(delta[i]);
139 for (
int i = 0; i < size_; ++i) {
140 jacobian[
size_ * i + i] =
x[i];
157 #if CERES_VERSION_MAJOR >= 3 || \
158 (CERES_VERSION_MAJOR == 2 && CERES_VERSION_MINOR >= 1)
159 problem->SetManifold(params,
new PositiveExponentialManifold<size>);
161 problem->SetParameterization(params,
167 const double* param) {
168 #if CERES_VERSION_MAJOR >= 3 || \
169 (CERES_VERSION_MAJOR == 2 && CERES_VERSION_MINOR >= 1)
170 return problem->ParameterBlockTangentSize(param);
172 return problem->ParameterBlockLocalSize(param);
~PositiveExponentialParameterization()
bool ComputeJacobian(const double *x, double *jacobian) const override
PositiveExponentialParameterization(int size)
bool Plus(const double *x, const double *delta, double *x_plus_delta) const override
int GlobalSize() const override
int LocalSize() const override
int ParameterBlockTangentSize(ceres::Problem *problem, const double *param)
void SetQuaternionManifold(ceres::Problem *problem, double *quat_xyzw)
void SetPositiveExponentialManifold(ceres::Problem *problem, double *params)
void SetSubsetManifold(int size, const std::vector< int > &constant_params, ceres::Problem *problem, double *params)
void SetSphereManifold(ceres::Problem *problem, double *params)