29namespace localization {
31namespace pyramid_map {
36 map_matrix_handler_(NULL),
37 compression_strategy_(NULL) {
48 map_matrix_handler_(NULL),
49 compression_strategy_(strategy) {
86 std::vector<std::string> paths;
88 paths.push_back(path);
90 snprintf(buf,
sizeof(buf),
"/map");
94 snprintf(buf,
sizeof(buf),
"/%03u",
101 path = path + paths.back();
103 snprintf(buf,
sizeof(buf),
"/%02d",
105 paths.push_back(buf);
109 paths.push_back(buf);
119 FILE* file = fopen(path.c_str(),
"wb");
126 AERROR <<
"Can't write to file: " << path <<
".";
134 std::vector<std::string> paths;
135 paths.push_back(path);
136 snprintf(buf,
sizeof(buf),
"/map");
137 paths.push_back(buf);
139 snprintf(buf,
sizeof(buf),
"/%03u",
141 paths.push_back(buf);
145 path = path + paths.back();
146 snprintf(buf,
sizeof(buf),
"/%02d",
148 paths.push_back(buf);
151 paths.push_back(buf);
158 return Load(path.c_str());
164 FILE* file = fopen(filename,
"rb");
172 AERROR <<
"Can't find the file: " << filename;
180 std::vector<unsigned char> buf(header_size);
181 size_t read_size = fread(&buf[0], 1, header_size, file);
182 if (read_size != header_size) {
186 if (processed_size != header_size) {
204 std::vector<unsigned char> buffer;
205 buffer.resize(buf_size);
207 size_t binary_size = 0;
208 std::vector<unsigned char> body_buffer;
216 if (processed_size == 0) {
222 std::vector<unsigned char> header_buf(header_size);
225 if (header_size != processed_size) {
229 size_t buffer_bias = processed_size;
230 buf_size -= processed_size;
231 binary_size += processed_size;
233 memcpy(&buffer[buffer_bias], &body_buffer[0], body_buffer.size());
235 binary_size +=
static_cast<unsigned int>(body_buffer.size());
236 fwrite(&buffer[0], 1, binary_size, file);
247 std::shared_ptr<BaseMapNodeConfig> node_config_tem =
264 size_t buf_size)
const {
277 std::vector<unsigned char> buf_uncompressed;
280 AERROR <<
"compression Decode error: " << ret;
284 AINFO <<
"map node compress ratio: "
285 <<
static_cast<float>(buf->size()) /
294 buf->resize(body_size);
299 std::vector<unsigned char> buf_uncompressed;
302 buf_uncompressed.resize(body_size);
305 if (binary_size == 0) {
320 unsigned int* x,
unsigned int* y)
const {
322 unsigned int off_x =
static_cast<unsigned int>(
324 unsigned int off_y =
static_cast<unsigned int>(
336 unsigned int* x,
unsigned int* y)
const {
337 Eigen::Vector2d coord2d(coordinate[0], coordinate[1]);
342 unsigned int y)
const {
344 Eigen::Vector2d coord(
358 Eigen::Vector2d coord;
362 static_cast<float>(index.
n_);
366 static_cast<float>(index.
m_);
368 throw "[BaseMapNode::ComputeLeftTopCorner] coord[0]"
369 " >= config.map_range_.GetMaxX()";
372 throw "[BaseMapNode::compute_left_top_corner] coord[1]"
373 " >= config.map_range_.GetMaxY()";
380 Eigen::Vector2d coord;
384 static_cast<float>(index.
n_);
388 static_cast<float>(index.
m_);
402 const std::vector<std::string>& paths)
const {
403 std::string path =
"";
405 for (
unsigned int i = 0; i < paths.size(); ++i) {
406 path = path + paths[i];
415 const std::vector<std::string>& paths)
const {
416 std::string path =
"";
418 for (
unsigned int i = 0; i < paths.size(); ++i) {
419 path = path + paths[i];
432 std::vector<std::string> paths;
434 paths.push_back(path);
436 snprintf(buf,
sizeof(buf),
"/image");
437 paths.push_back(buf);
440 snprintf(buf,
sizeof(buf),
"/%03u",
442 paths.push_back(buf);
447 path = path + paths.back();
449 snprintf(buf,
sizeof(buf),
"/%02d",
451 paths.push_back(buf);
455 paths.push_back(buf);
472 bool success = cv::imwrite(path, image);
480 std::vector<std::string> paths;
482 paths.push_back(path);
484 snprintf(buf,
sizeof(buf),
"/image_alt");
485 paths.push_back(buf);
488 snprintf(buf,
sizeof(buf),
"/%03u",
490 paths.push_back(buf);
495 path = path + paths.back();
497 snprintf(buf,
sizeof(buf),
"/%02d",
499 paths.push_back(buf);
503 paths.push_back(buf);
524 bool success = cv::imwrite(path, image);
static void ComputeBinaryMd5(const unsigned char *binary, size_t size, unsigned char res[kUcharMd5Length])
Compute file md5 given a binary chunk.
T GetMaxY() const
Get the max y of the rectangle.
T GetMaxX() const
Get the max x of the rectangle.
T GetMinX() const
Get the min x of the rectangle.
T GetMinY() const
Get the min y of the rectangle.
The options of the reflectance map.
std::string map_folder_path_
The map folder path.
unsigned int map_node_size_y_
The map node size in pixels.
std::vector< float > map_resolutions_
The pixel resolutions in the map in meters.
Rect2D< double > map_range_
The minimum and maximum UTM range in the map.
unsigned int map_node_size_x_
The map node size in pixels.
The data structure of the map cells in a map node.
virtual void Finalize()
call before deconstruction or reset.
std::shared_ptr< CompressionStrategy > compression_strategy_
@bried The compression strategy.
virtual bool LoadBinary(FILE *file)
Load the map cell from a binary chunk.
bool SaveIntensityImage() const
Save intensity image of node.
virtual bool GetCoordinate(const Eigen::Vector2d &coordinate, unsigned int *x, unsigned int *y) const
Given the global coordinate, get the local 2D coordinate of the map cell matrix.
const BaseMapConfig * map_config_
The map settings.
bool SaveAltitudeImage() const
Save altitude image of node.
bool is_changed_
Has the map node been changed.
virtual void ResetMapNode()
Reset map cells data.
bool is_reserved_
If the node is reserved in map.
bool Load()
Load the map node from the disk.
bool CreateMapDirectory(const std::string &path) const
Try to create the map directory.
virtual ~BaseMapNode()
Destruct a map node.
virtual size_t LoadBodyBinary(std::vector< unsigned char > *buf)
Load the map node body from a binary chunk.
const Eigen::Vector2d & GetLeftTopCorner() const
size_t uncompressed_file_body_size_
virtual size_t GetBodyBinarySize() const
Get the size of the body in bytes.
virtual bool CreateBinary(FILE *file) const
Create the binary.
virtual size_t GetBinarySize() const
Get the binary size of the object.
static Eigen::Vector2d ComputeLeftTopCorner(const BaseMapConfig &config, const MapNodeIndex &index)
std::shared_ptr< BaseMapMatrixHandler > map_matrix_handler_
The class to load and create map matrix binary.
std::shared_ptr< BaseMapMatrix > map_matrix_
The data structure of the map datas, which is a matrix.
Eigen::Vector2d left_top_corner_
The left top corner of the map node in the global coordinate system.
bool CheckMapDirectoryRecursively(const std::vector< std::string > &paths) const
Try to check the map directory recursively.
bool Save()
Save the map node to the disk.
BaseMapNode()
Construct a map node.
size_t file_body_binary_size_
The body binary size in file.
std::shared_ptr< BaseMapNodeConfig > map_node_config_
The map node config.
float GetMapResolution() const
Get the resolution of this map nodex.
virtual size_t GetHeaderBinarySize() const
Get the size of the header in bytes.
virtual size_t LoadHeaderBinary(const unsigned char *buf)
Load the map node header from a binary chunk.
virtual size_t CreateHeaderBinary(unsigned char *buf, size_t buf_size) const
Create the binary header.
void SetMapNodeIndex(const MapNodeIndex &index)
Set the map node index.
virtual void InitMapMatrix(const BaseMapConfig *map_config)
Initialize the map matrix.
virtual size_t CreateBodyBinary(std::vector< unsigned char > *buf) const
Create the binary body.
bool CreateMapDirectoryRecursively(const std::vector< std::string > &paths) const
Try to create the map directory recursively.
unsigned int m_
The map node ID at the northing direction.
unsigned int resolution_id_
The ID of the resolution.
unsigned int n_
The map node ID at the easting direction.
bool DirectoryExists(const std::string &directory_path)
Check if the directory specified by directory_path exists and is indeed a directory.
bool EnsureDirectory(const std::string &directory_path)
Check if a specified directory specified by directory_path exists.