22 #include "glog/logging.h" 27 proto::PoseGraph::Constraint::Tag
ToProto(
30 case PoseGraph::Constraint::Tag::INTRA_SUBMAP:
31 return proto::PoseGraph::Constraint::INTRA_SUBMAP;
32 case PoseGraph::Constraint::Tag::INTER_SUBMAP:
33 return proto::PoseGraph::Constraint::INTER_SUBMAP;
35 LOG(FATAL) <<
"Unsupported tag.";
39 const proto::PoseGraph::Constraint::Tag& proto) {
41 case proto::PoseGraph::Constraint::INTRA_SUBMAP:
42 return PoseGraph::Constraint::Tag::INTRA_SUBMAP;
43 case proto::PoseGraph::Constraint::INTER_SUBMAP:
44 return PoseGraph::Constraint::Tag::INTER_SUBMAP;
45 case ::google::protobuf::kint32max:
46 case ::google::protobuf::kint32min: {
49 LOG(FATAL) <<
"Unsupported tag.";
53 const ::google::protobuf::RepeatedPtrField<proto::PoseGraph::Constraint>&
55 std::vector<PoseGraph::Constraint> constraints;
56 for (
const auto& constraint_proto : constraint_protos) {
59 constraint_proto.submap_id().submap_index()};
61 constraint_proto.node_id().node_index()};
62 const PoseGraph::Constraint::Pose
pose{
64 constraint_proto.translation_weight(),
65 constraint_proto.rotation_weight()};
74 proto::PoseGraphOptions options;
75 options.set_optimize_every_n_nodes(
76 parameter_dictionary->
GetInt(
"optimize_every_n_nodes"));
77 *options.mutable_constraint_builder_options() =
79 parameter_dictionary->
GetDictionary(
"constraint_builder").get());
80 options.set_matcher_translation_weight(
81 parameter_dictionary->
GetDouble(
"matcher_translation_weight"));
82 options.set_matcher_rotation_weight(
83 parameter_dictionary->
GetDouble(
"matcher_rotation_weight"));
84 *options.mutable_optimization_problem_options() =
86 parameter_dictionary->
GetDictionary(
"optimization_problem").get());
87 options.set_max_num_final_iterations(
89 CHECK_GT(options.max_num_final_iterations(), 0);
90 options.set_global_sampling_ratio(
91 parameter_dictionary->
GetDouble(
"global_sampling_ratio"));
92 options.set_log_residual_histograms(
93 parameter_dictionary->
GetBool(
"log_residual_histograms"));
94 options.set_global_constraint_search_after_n_seconds(
96 "global_constraint_search_after_n_seconds"));
101 proto::PoseGraph::Constraint constraint_proto;
102 *constraint_proto.mutable_relative_pose() =
106 constraint_proto.mutable_submap_id()->set_trajectory_id(
108 constraint_proto.mutable_submap_id()->set_submap_index(
110 constraint_proto.mutable_node_id()->set_trajectory_id(
112 constraint_proto.mutable_node_id()->set_node_index(
115 return constraint_proto;
119 proto::PoseGraph proto;
121 std::map<int, proto::Trajectory* const> trajectory_protos;
122 const auto trajectory = [&proto, &trajectory_protos](
123 const int trajectory_id) -> proto::Trajectory* {
124 if (trajectory_protos.count(trajectory_id) == 0) {
125 auto*
const trajectory_proto = proto.add_trajectory();
126 trajectory_proto->set_trajectory_id(trajectory_id);
127 CHECK(trajectory_protos.emplace(trajectory_id, trajectory_proto).second);
129 return trajectory_protos.at(trajectory_id);
133 CHECK(node_id_data.data.constant_data !=
nullptr);
134 auto*
const node_proto =
135 trajectory(node_id_data.id.trajectory_id)->add_node();
136 node_proto->set_node_index(node_id_data.id.node_index);
137 node_proto->set_timestamp(
139 *node_proto->mutable_pose() =
144 CHECK(submap_id_data.data.submap !=
nullptr);
145 auto*
const submap_proto =
146 trajectory(submap_id_data.id.trajectory_id)->add_submap();
147 submap_proto->set_submap_index(submap_id_data.id.submap_index);
148 *submap_proto->mutable_pose() =
153 proto.mutable_constraint()->Reserve(constraints_copy.size());
154 for (
const auto& constraint : constraints_copy) {
159 proto.mutable_landmark_poses()->Reserve(landmarks_copy.size());
160 for (
const auto& id_pose : landmarks_copy) {
161 auto* landmark_proto = proto.add_landmark_poses();
162 landmark_proto->set_landmark_id(id_pose.first);
PoseGraph::Constraint::Tag FromProto(const proto::PoseGraph::Constraint::Tag &proto)
proto::PoseGraph ToProto() const override
enum cartographer::mapping::PoseGraphInterface::Constraint::Tag tag
virtual std::map< std::string, transform::Rigid3d > GetLandmarkPoses() const =0
int GetNonNegativeInt(const std::string &key)
transform::Rigid3d zbar_ij
double GetDouble(const std::string &key)
proto::OptimizationProblemOptions CreateOptimizationProblemOptions(common::LuaParameterDictionary *const parameter_dictionary)
proto::PoseGraphOptions CreatePoseGraphOptions(common::LuaParameterDictionary *const parameter_dictionary)
proto::ConstraintBuilderOptions CreateConstraintBuilderOptions(common::LuaParameterDictionary *const parameter_dictionary)
int64 ToUniversal(const Time time)
double translation_weight
virtual std::vector< Constraint > constraints() const =0
std::unique_ptr< LuaParameterDictionary > GetDictionary(const std::string &key)
virtual MapById< SubmapId, SubmapData > GetAllSubmapData() const =0
proto::MapLimits ToProto(const MapLimits &map_limits)
virtual MapById< NodeId, TrajectoryNode > GetTrajectoryNodes() const =0
bool GetBool(const std::string &key)
int GetInt(const std::string &key)