32 void DrawTrajectoriesIntoImage(
33 const mapping::ProbabilityGrid& probability_grid,
34 const Eigen::Array2i& offset,
35 const std::vector<mapping::proto::Trajectory>& trajectories,
36 cairo_surface_t* cairo_surface) {
37 for (
size_t i = 0; i < trajectories.size(); ++i) {
41 return probability_grid.limits().GetCellIndex(
42 pose.cast<
float>().translation().head<2>()) -
49 uint8 ProbabilityToColor(
float probability_from_grid) {
50 const float probability = 1.f - probability_from_grid;
59 const double resolution,
60 const mapping::proto::ProbabilityGridRangeDataInserterOptions2D&
61 probability_grid_range_data_inserter_options,
63 std::unique_ptr<FileWriter> file_writer,
64 const std::vector<mapping::proto::Trajectory>& trajectories,
66 : draw_trajectories_(draw_trajectories),
67 trajectories_(trajectories),
68 file_writer_(std::move(file_writer)),
73 std::unique_ptr<ProbabilityGridPointsProcessor>
75 const std::vector<mapping::proto::Trajectory>& trajectories,
79 const auto draw_trajectories = (!dictionary->
HasKey(
"draw_trajectories") ||
80 dictionary->
GetBool(
"draw_trajectories"))
83 return common::make_unique<ProbabilityGridPointsProcessor>(
88 file_writer_factory(dictionary->
GetString(
"filename") +
".png"),
93 std::unique_ptr<PointsBatch> batch) {
100 Eigen::Array2i offset;
101 std::unique_ptr<Image> image =
103 if (image !=
nullptr) {
107 image->GetCairoSurface().get());
115 LOG(FATAL) <<
"ProbabilityGrid generation must be configured to occur " 116 "after any stages that require multiple passes.";
132 LOG(WARNING) <<
"Not writing output: empty probability grid";
135 auto image = common::make_unique<Image>(cell_limits.
num_x_cells,
137 for (
const Eigen::Array2i& xy_index :
139 const Eigen::Array2i index = xy_index + *offset;
140 constexpr
uint8 kUnknownValue = 128;
142 probability_grid.
IsKnown(index)
145 image->SetPixel(xy_index.x(), xy_index.y(), {{value, value, value}});
151 constexpr
int kInitialProbabilityGridSize = 100;
152 Eigen::Vector2d max =
153 0.5 * kInitialProbabilityGridSize * resolution * Eigen::Vector2d::Ones();
157 kInitialProbabilityGridSize)));
virtual void Process(std::unique_ptr< PointsBatch > points_batch)=0
mapping::ProbabilityGrid probability_grid_
std::function< std::unique_ptr< FileWriter >(const std::string &filename)> FileWriterFactory
const std::vector< mapping::proto::Trajectory > trajectories_
std::string GetString(const std::string &key)
void Process(std::unique_ptr< PointsBatch > batch) override
ProbabilityGrid probability_grid_
proto::ProbabilityGridRangeDataInserterOptions2D CreateProbabilityGridRangeDataInserterOptions2D(common::LuaParameterDictionary *parameter_dictionary)
int RoundToInt(const float x)
std::unique_ptr< Image > DrawProbabilityGrid(const mapping::ProbabilityGrid &probability_grid, Eigen::Array2i *offset)
constexpr float kMinProbability
const DrawTrajectories draw_trajectories_
std::unique_ptr< FileWriter > file_writer_
double GetDouble(const std::string &key)
static std::unique_ptr< ProbabilityGridPointsProcessor > FromDictionary(const std::vector< mapping::proto::Trajectory > &trajectories, const FileWriterFactory &file_writer_factory, common::LuaParameterDictionary *dictionary, PointsProcessor *next)
constexpr float kMaxProbability
mapping::ProbabilityGrid CreateProbabilityGrid(const double resolution)
FloatColor GetColor(int id)
std::unique_ptr< ProbabilityGridRangeDataInserter2D > range_data_inserter_
float GetProbability(const Eigen::Array2i &cell_index) const
void ComputeCroppedLimits(Eigen::Array2i *const offset, CellLimits *const limits) const
virtual FlushResult Flush()=0
mapping::ProbabilityGridRangeDataInserter2D range_data_inserter_
FlushResult Flush() override
PointsProcessor *const next_
bool IsKnown(const Eigen::Array2i &cell_index) const
std::unique_ptr< LuaParameterDictionary > GetDictionary(const std::string &key)
virtual void Insert(const sensor::RangeData &range_data, GridInterface *grid) const override
ProbabilityGridPointsProcessor(double resolution, const mapping::proto::ProbabilityGridRangeDataInserterOptions2D &probability_grid_range_data_inserter_options, const DrawTrajectories &draw_trajectories, std::unique_ptr< FileWriter > file_writer, const std::vector< mapping::proto::Trajectory > &trajectorios, PointsProcessor *next)
bool GetBool(const std::string &key)
void DrawTrajectory(const mapping::proto::Trajectory &trajectory, const FloatColor &color, const PoseToPixelFunction &pose_to_pixel, cairo_surface_t *surface)
bool HasKey(const std::string &key) const