29#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_MAP_UTILS_H_
30#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_MAP_UTILS_H_
53 idx = std::round(pt.x() / resolution);
54 idy = std::round(pt.y() / resolution);
60 int const submap_size,
int const map_size,
62 int pos_idx = 0, pos_idy = 0;
64 index.
left = pos_idx - submap_size / 2;
65 index.
right = pos_idx + submap_size / 2;
66 index.
bottom = pos_idy - submap_size / 2;
67 index.
top = pos_idy + submap_size / 2;
77 if (index.
right > map_size) {
80 if (index.
top > map_size) {
81 offset.
top = map_size - index.
top;
88template <
typename T = MapType>
90 int const map_size, T
const &map,
int const submap_size,
93 ComputeOffsets(resolution, pos, submap_size, map_size, index, offset);
99template <
typename T = MapType>
101 int const map_size, T
const &map,
int const submap_size) {
103 ComputeOffsets(resolution, pos, submap_size, map_size, index, offset);
110 std::ofstream file_obj(file_name);
112 std::cerr <<
"[Error] Could not open " << file_name <<
" for writing."
123 std::ofstream file_obj(file_name);
125 std::cerr <<
"[Error] Could not open " << file_name <<
" for writing."
129 for (
int i = 0; i < map.rows(); ++i) {
130 for (
int j = 0; j < map.cols(); ++j) {
131 if (map(i, j) >= 0) {
132 file_obj << i <<
" " << j <<
" " << map(i, j) << std::endl;
141 int const sensor_size,
int const boundary) {
142 if (pos.x() <= -sensor_size * resolution / 2.) {
145 if (pos.y() <= -sensor_size * resolution / 2.) {
148 if (pos.x() >= boundary * resolution + sensor_size * resolution / 2.) {
151 if (pos.y() >= boundary * resolution + sensor_size * resolution / 2.) {
Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MapType
int IsPointOutsideBoundary(double const resolution, Point2 const &pos, int const sensor_size, int const boundary)
void GetSubMap(double const resolution, Point2 const &pos, int const map_size, T const &map, int const submap_size, T &submap)
void ComputeOffsets(double const resolution, Point2 const &pos, int const submap_size, int const map_size, MapBounds &index, MapBounds &offset)
int WriteMap(MapType const &map, std::string const &file_name)
Write the world map to a file.
void GetClosestGridCoordinate(double const resolution, Point2 const &pt, int &idx, int &idy)
Gets the closest point on the grid.
int WriteMapSparse(MapType const &map, std::string const &file_name)
Write the world map to a file.
Namespace for the CoverageControl library.
Contains typedefs for the library.