22 #include "glog/logging.h" 27 proto::SparsePoseGraph::Constraint::Tag
ToProto(
30 case SparsePoseGraph::Constraint::Tag::INTRA_SUBMAP:
31 return proto::SparsePoseGraph::Constraint::INTRA_SUBMAP;
32 case SparsePoseGraph::Constraint::Tag::INTER_SUBMAP:
33 return proto::SparsePoseGraph::Constraint::INTER_SUBMAP;
35 LOG(FATAL) <<
"Unsupported tag.";
40 proto::SparsePoseGraphOptions options;
41 options.set_optimize_every_n_scans(
42 parameter_dictionary->
GetInt(
"optimize_every_n_scans"));
43 *options.mutable_constraint_builder_options() =
45 parameter_dictionary->
GetDictionary(
"constraint_builder").get());
46 options.set_matcher_translation_weight(
47 parameter_dictionary->
GetDouble(
"matcher_translation_weight"));
48 options.set_matcher_rotation_weight(
49 parameter_dictionary->
GetDouble(
"matcher_rotation_weight"));
50 *options.mutable_optimization_problem_options() =
52 parameter_dictionary->
GetDictionary(
"optimization_problem").get());
53 options.set_max_num_final_iterations(
55 CHECK_GT(options.max_num_final_iterations(), 0);
56 options.set_global_sampling_ratio(
57 parameter_dictionary->
GetDouble(
"global_sampling_ratio"));
62 proto::SparsePoseGraph proto;
64 std::map<NodeId, NodeId> node_id_remapping;
67 for (
size_t trajectory_id = 0; trajectory_id != all_trajectory_nodes.size();
69 const auto& single_trajectory_nodes = all_trajectory_nodes[trajectory_id];
70 auto* trajectory_proto = proto.add_trajectory();
72 for (
size_t old_node_index = 0;
73 old_node_index != single_trajectory_nodes.size(); ++old_node_index) {
74 const auto& node = single_trajectory_nodes[old_node_index];
75 if (!node.trimmed()) {
76 node_id_remapping[
NodeId{
static_cast<int>(trajectory_id),
77 static_cast<int>(old_node_index)}] =
78 NodeId{
static_cast<int>(trajectory_id),
79 static_cast<int>(trajectory_proto->node_size())};
80 auto* node_proto = trajectory_proto->add_node();
81 node_proto->set_timestamp(
84 node.pose * node.constant_data->tracking_to_pose);
88 if (!single_trajectory_nodes.empty()) {
89 const int num_submaps_in_trajectory =
num_submaps(trajectory_id);
90 for (
int submap_index = 0; submap_index != num_submaps_in_trajectory;
92 const SubmapId submap_id{
static_cast<int>(trajectory_id), submap_index};
93 *trajectory_proto->add_submap()->mutable_pose() =
100 auto*
const constraint_proto = proto.add_constraint();
101 *constraint_proto->mutable_relative_pose() =
103 constraint_proto->set_translation_weight(
104 constraint.pose.translation_weight);
105 constraint_proto->set_rotation_weight(constraint.pose.rotation_weight);
106 constraint_proto->mutable_submap_id()->set_trajectory_id(
107 constraint.submap_id.trajectory_id);
108 constraint_proto->mutable_submap_id()->set_submap_index(
109 constraint.submap_id.submap_index);
111 const NodeId node_id = node_id_remapping.at(constraint.node_id);
112 constraint_proto->mutable_scan_id()->set_trajectory_id(
114 constraint_proto->mutable_scan_id()->set_scan_index(node_id.
node_index);
virtual transform::Rigid3d GetSubmapTransform(const SubmapId &submap_id)=0
int GetNonNegativeInt(const string &key)
int GetInt(const string &key)
virtual std::vector< std::vector< TrajectoryNode > > GetTrajectoryNodes()=0
double GetDouble(const string &key)
proto::SparsePoseGraph ToProto()
int64 ToUniversal(const Time time)
proto::OptimizationProblemOptions CreateOptimizationProblemOptions(common::LuaParameterDictionary *const parameter_dictionary)
virtual std::vector< Constraint > constraints()=0
virtual int num_submaps(int trajectory_id)=0
proto::SparsePoseGraph::Constraint::Tag ToProto(const SparsePoseGraph::Constraint::Tag &tag)
std::unique_ptr< LuaParameterDictionary > GetDictionary(const string &key)
proto::SparsePoseGraphOptions CreateSparsePoseGraphOptions(common::LuaParameterDictionary *const parameter_dictionary)
proto::ConstraintBuilderOptions CreateConstraintBuilderOptions(common::LuaParameterDictionary *const parameter_dictionary)