32 #include "ceres/ceres.h" 33 #include "glog/logging.h" 37 namespace scan_matching {
41 proto::CeresScanMatcherOptions3D options;
42 for (
int i = 0;; ++i) {
43 const std::string lua_identifier =
44 "occupied_space_weight_" + std::to_string(i);
45 if (!parameter_dictionary->
HasKey(lua_identifier)) {
48 options.add_occupied_space_weight(
49 parameter_dictionary->
GetDouble(lua_identifier));
51 options.set_translation_weight(
52 parameter_dictionary->
GetDouble(
"translation_weight"));
53 options.set_rotation_weight(
54 parameter_dictionary->
GetDouble(
"rotation_weight"));
55 options.set_only_optimize_yaw(
56 parameter_dictionary->
GetBool(
"only_optimize_yaw"));
57 *options.mutable_ceres_solver_options() =
59 parameter_dictionary->
GetDictionary(
"ceres_solver_options").get());
64 const proto::CeresScanMatcherOptions3D& options)
66 ceres_solver_options_(
72 const Eigen::Vector3d& target_translation,
74 const std::vector<PointCloudAndHybridGridPointers>&
75 point_clouds_and_hybrid_grids,
77 ceres::Solver::Summary*
const summary) {
78 ceres::Problem problem;
80 initial_pose_estimate,
nullptr ,
82 ? std::unique_ptr<ceres::LocalParameterization>(
85 : std::unique_ptr<ceres::LocalParameterization>(
86 common::make_unique<ceres::QuaternionParameterization>()),
89 CHECK_EQ(
options_.occupied_space_weight_size(),
90 point_clouds_and_hybrid_grids.size());
91 for (
size_t i = 0; i != point_clouds_and_hybrid_grids.size(); ++i) {
92 CHECK_GT(
options_.occupied_space_weight(i), 0.);
94 *point_clouds_and_hybrid_grids[i].first;
95 const HybridGrid& hybrid_grid = *point_clouds_and_hybrid_grids[i].second;
96 problem.AddResidualBlock(
99 std::sqrt(static_cast<double>(point_cloud.size())),
100 point_cloud, hybrid_grid),
101 nullptr , ceres_pose.translation(),
102 ceres_pose.rotation());
104 CHECK_GT(
options_.translation_weight(), 0.);
105 problem.AddResidualBlock(
107 options_.translation_weight(), target_translation),
108 nullptr , ceres_pose.translation());
109 CHECK_GT(
options_.rotation_weight(), 0.);
110 problem.AddResidualBlock(
113 nullptr , ceres_pose.rotation());
117 *pose_estimate = ceres_pose.ToRigid();
_Unique_if< T >::_Single_object make_unique(Args &&... args)
proto::CeresScanMatcherOptions3D CreateCeresScanMatcherOptions3D(common::LuaParameterDictionary *const parameter_dictionary)
ceres::Solver::Options ceres_solver_options_
double GetDouble(const std::string &key)
static ceres::CostFunction * CreateAutoDiffCostFunction(const double scaling_factor, const Eigen::Vector3d &target_translation)
static ceres::CostFunction * CreateAutoDiffCostFunction(const double scaling_factor, const sensor::PointCloud &point_cloud, const mapping::HybridGrid &hybrid_grid)
proto::ProbabilityGridRangeDataInserterOptions2D options_
CeresScanMatcher3D(const proto::CeresScanMatcherOptions3D &options)
void Match(const Eigen::Vector3d &target_translation, const transform::Rigid3d &initial_pose_estimate, const std::vector< PointCloudAndHybridGridPointers > &point_clouds_and_hybrid_grids, transform::Rigid3d *pose_estimate, ceres::Solver::Summary *summary)
ceres::Solver::Options CreateCeresSolverOptions(const proto::CeresSolverOptions &proto)
std::vector< Eigen::Vector3f > PointCloud
static ceres::CostFunction * CreateAutoDiffCostFunction(const double scaling_factor, const Eigen::Quaterniond &target_rotation)
std::unique_ptr< LuaParameterDictionary > GetDictionary(const std::string &key)
proto::CeresSolverOptions CreateCeresSolverOptionsProto(common::LuaParameterDictionary *parameter_dictionary)
const proto::CeresScanMatcherOptions3D options_
bool GetBool(const std::string &key)
bool HasKey(const std::string &key) const