Skip to content

Commit

Permalink
Fill submaps slices (#1353)
Browse files Browse the repository at this point in the history
This implements a frequently used function (two times in cartographer_ros).
Also, it corrects a wrong repeated proto field access,
so we can fix cartographer_ros/issues/944.
  • Loading branch information
gaschler committed Jul 31, 2018
1 parent c041635 commit c1fbb6b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cartographer/io/submap_painter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ void CairoPaintSubmapSlices(
}
}

bool Has2DGrid(const mapping::proto::Submap& submap) {
return submap.has_submap_2d() && submap.submap_2d().has_grid();
}

bool Has3DGrids(const mapping::proto::Submap& submap) {
return submap.has_submap_3d() &&
submap.submap_3d().has_low_resolution_hybrid_grid() &&
submap.submap_3d().has_high_resolution_hybrid_grid();
}

} // namespace

PaintSubmapSlicesResult PaintSubmapSlices(
Expand Down Expand Up @@ -139,6 +149,31 @@ void FillSubmapSlice(
texture_proto.height(), &submap_slice->cairo_data);
}

void DeserializeAndFillSubmapSlices(
ProtoStreamDeserializer* deserializer,
std::map<mapping::SubmapId, SubmapSlice>* submap_slices,
mapping::ValueConversionTables* conversion_tables) {
std::map<mapping::SubmapId, transform::Rigid3d> submap_poses;
for (const auto& trajectory : deserializer->pose_graph().trajectory()) {
for (const auto& submap : trajectory.submap()) {
submap_poses[mapping::SubmapId(trajectory.trajectory_id(),
submap.submap_index())] =
transform::ToRigid3(submap.pose());
}
}
mapping::proto::SerializedData proto;
while (deserializer->ReadNextSerializedData(&proto)) {
if (proto.has_submap() &&
(Has2DGrid(proto.submap()) || Has3DGrids(proto.submap()))) {
const auto& submap = proto.submap();
const mapping::SubmapId id{submap.submap_id().trajectory_id(),
submap.submap_id().submap_index()};
FillSubmapSlice(submap_poses.at(id), submap, &(*submap_slices)[id],
conversion_tables);
}
}
}

SubmapTexture::Pixels UnpackTextureData(const std::string& compressed_cells,
const int width, const int height) {
SubmapTexture::Pixels pixels;
Expand Down
6 changes: 6 additions & 0 deletions cartographer/io/submap_painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Eigen/Geometry"
#include "cairo/cairo.h"
#include "cartographer/io/image.h"
#include "cartographer/io/proto_stream_deserializer.h"
#include "cartographer/mapping/id.h"
#include "cartographer/mapping/proto/serialization.pb.h"
#include "cartographer/mapping/value_conversion_tables.h"
Expand Down Expand Up @@ -84,6 +85,11 @@ void FillSubmapSlice(
SubmapSlice* const submap_slice,
mapping::ValueConversionTables* conversion_tables);

void DeserializeAndFillSubmapSlices(
ProtoStreamDeserializer* deserializer,
std::map<::cartographer::mapping::SubmapId, SubmapSlice>* submap_slices,
mapping::ValueConversionTables* conversion_tables);

// Unpacks cell data as provided by the backend into 'intensity' and 'alpha'.
SubmapTexture::Pixels UnpackTextureData(const std::string& compressed_cells,
int width, int height);
Expand Down

0 comments on commit c1fbb6b

Please sign in to comment.