| 517 | } |
| 518 | |
| 519 | bool GridMap::addDataFrom(const GridMap& other, bool extendMap, bool overwriteData, bool copyAllLayers, std::vector<std::string> layers) { |
| 520 | // Set the layers to copy. |
| 521 | if (copyAllLayers) layers = other.getLayers(); |
| 522 | |
| 523 | // Resize map. |
| 524 | if (extendMap) extendToInclude(other); |
| 525 | |
| 526 | // Check if all layers to copy exist and add missing layers. |
| 527 | for (const auto& layer : layers) { |
| 528 | if (std::find(layers_.begin(), layers_.end(), layer) == layers_.end()) { |
| 529 | add(layer); |
| 530 | } |
| 531 | } |
| 532 | // Copy data. |
| 533 | for (GridMapIterator iterator(*this); !iterator.isPastEnd(); ++iterator) { |
| 534 | if (isValid(*iterator) && !overwriteData) continue; |
| 535 | Position position; |
| 536 | getPosition(*iterator, position); |
| 537 | Index index; |
| 538 | if (!other.isInside(position)) continue; |
| 539 | other.getIndex(position, index); |
| 540 | for (const auto& layer : layers) { |
| 541 | if (!other.isValid(index, layer)) continue; |
| 542 | at(layer, *iterator) = other.at(layer, index); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | return true; |
| 547 | } |
| 548 | |
| 549 | bool GridMap::extendToInclude(const GridMap& other) { |
| 550 | // Get dimension of maps. |