Allow easier access to CeresPose's data_ (#1149)
Introduce a FromPose function which transforms a Ridig3d pose into the CeresPose's Data format.master
parent
d2453bce50
commit
a0ec8046bd
|
@ -20,16 +20,19 @@ namespace cartographer {
|
||||||
namespace mapping {
|
namespace mapping {
|
||||||
namespace optimization {
|
namespace optimization {
|
||||||
|
|
||||||
|
CeresPose::Data FromPose(const transform::Rigid3d& pose) {
|
||||||
|
return CeresPose::Data{{{pose.translation().x(), pose.translation().y(),
|
||||||
|
pose.translation().z()}},
|
||||||
|
{{pose.rotation().w(), pose.rotation().x(),
|
||||||
|
pose.rotation().y(), pose.rotation().z()}}};
|
||||||
|
}
|
||||||
|
|
||||||
CeresPose::CeresPose(
|
CeresPose::CeresPose(
|
||||||
const transform::Rigid3d& rigid,
|
const transform::Rigid3d& pose,
|
||||||
std::unique_ptr<ceres::LocalParameterization> translation_parametrization,
|
std::unique_ptr<ceres::LocalParameterization> translation_parametrization,
|
||||||
std::unique_ptr<ceres::LocalParameterization> rotation_parametrization,
|
std::unique_ptr<ceres::LocalParameterization> rotation_parametrization,
|
||||||
ceres::Problem* problem)
|
ceres::Problem* problem)
|
||||||
: data_(std::make_shared<CeresPose::Data>(
|
: data_(std::make_shared<CeresPose::Data>(FromPose(pose))) {
|
||||||
CeresPose::Data{{{rigid.translation().x(), rigid.translation().y(),
|
|
||||||
rigid.translation().z()}},
|
|
||||||
{{rigid.rotation().w(), rigid.rotation().x(),
|
|
||||||
rigid.rotation().y(), rigid.rotation().z()}}})) {
|
|
||||||
problem->AddParameterBlock(data_->translation.data(), 3,
|
problem->AddParameterBlock(data_->translation.data(), 3,
|
||||||
translation_parametrization.release());
|
translation_parametrization.release());
|
||||||
problem->AddParameterBlock(data_->rotation.data(), 4,
|
problem->AddParameterBlock(data_->rotation.data(), 4,
|
||||||
|
|
|
@ -44,15 +44,20 @@ class CeresPose {
|
||||||
double* rotation() { return data_->rotation.data(); }
|
double* rotation() { return data_->rotation.data(); }
|
||||||
const double* rotation() const { return data_->rotation.data(); }
|
const double* rotation() const { return data_->rotation.data(); }
|
||||||
|
|
||||||
private:
|
|
||||||
struct Data {
|
struct Data {
|
||||||
std::array<double, 3> translation;
|
std::array<double, 3> translation;
|
||||||
// Rotation quaternion as (w, x, y, z).
|
// Rotation quaternion as (w, x, y, z).
|
||||||
std::array<double, 4> rotation;
|
std::array<double, 4> rotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Data& data() { return *data_; }
|
||||||
|
|
||||||
|
private:
|
||||||
std::shared_ptr<Data> data_;
|
std::shared_ptr<Data> data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CeresPose::Data FromPose(const transform::Rigid3d& pose);
|
||||||
|
|
||||||
} // namespace optimization
|
} // namespace optimization
|
||||||
} // namespace mapping
|
} // namespace mapping
|
||||||
} // namespace cartographer
|
} // namespace cartographer
|
||||||
|
|
Loading…
Reference in New Issue