MCPcopy Create free account
hub / github.com/OctoMap/octomap_mapping / openFile

Method openFile

octomap_server/src/octomap_server.cpp:342–398  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342bool OctomapServer::openFile(const std::string & filename)
343{
344 if (filename.length() <= 3) {
345 return false;
346 }
347
348 std::string suffix = filename.substr(filename.length() - 3, 3);
349 if (suffix == ".bt") {
350 if (!octree_->readBinary(filename)) {
351 return false;
352 }
353 } else if (suffix == ".ot") {
354 std::unique_ptr<octomap::AbstractOcTree> tree{octomap::AbstractOcTree::read(filename)};
355 if (!tree) {
356 return false;
357 }
358 octree_ = std::unique_ptr<OcTreeT>(dynamic_cast<OcTreeT *>(tree.release()));
359 if (!octree_) {
360 RCLCPP_ERROR(
361 get_logger(),
362 "Could not read OcTree in file, currently there are no other types supported in .ot");
363 return false;
364 }
365
366 } else {
367 return false;
368 }
369
370 RCLCPP_INFO(
371 get_logger(), "Octomap file %s loaded (%zu nodes).", filename.c_str(),
372 octree_->size());
373
374 tree_depth_ = octree_->getTreeDepth();
375 max_tree_depth_ = tree_depth_;
376 res_ = octree_->getResolution();
377 gridmap_.info.resolution = res_;
378 double min_x{};
379 double min_y{};
380 double min_z{};
381 double max_x{};
382 double max_y{};
383 double max_z{};
384 octree_->getMetricMin(min_x, min_y, min_z);
385 octree_->getMetricMax(max_x, max_y, max_z);
386
387 update_bbox_min_[0] = octree_->coordToKey(min_x);
388 update_bbox_min_[1] = octree_->coordToKey(min_y);
389 update_bbox_min_[2] = octree_->coordToKey(min_z);
390
391 update_bbox_max_[0] = octree_->coordToKey(max_x);
392 update_bbox_max_[1] = octree_->coordToKey(max_y);
393 update_bbox_max_[2] = octree_->coordToKey(max_z);
394
395 publishAll(now());
396
397 return true;
398}
399

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected