109 const std::vector<armem::MemoryID>& snapshotIDs)
113 const std::vector<armem::MemoryID> relevantCostmaps =
115 ranges::views::filter(
118 std::string name =
id.providerSegmentName +
"/" +
id.entityName;
119 return std::find(properties.costmapsToMerge.cbegin(),
120 properties.costmapsToMerge.cend(),
121 name) != properties.costmapsToMerge.cend();
125 if (relevantCostmaps.empty())
130 ARMARX_INFO <<
"Relevant costmaps changed: " << relevantCostmaps;
139 std::lock_guard g{mergeCostmapMtx};
145 std::vector<Costmap> costmaps;
147 for (
const auto& costmap : properties.costmapsToMerge)
150 const std::vector<std::string> splits = simox::alg::split(costmap,
"/");
154 .providerName = splits.front(), .name = splits.back(), .timestamp =
timestamp};
155 auto result = costmapReaderPlugin->get().query(query);
160 <<
"` which doesn't exist (yet) (" << result.errorMessage <<
")";
165 costmaps.emplace_back(std::move(*result.costmap));
169 if (costmaps.empty())
178 auto mergedCostmap = [&]()
182 Eigen::AlignedBox2f aabb;
183 float minCellSize = std::numeric_limits<float>::max();
184 for (
const auto&
c : costmaps)
187 Eigen::Vector2f globalCornerA =
c.origin() *
c.getLocalSceneBounds().min;
188 Eigen::Vector2f globalCornerB =
c.origin() *
c.getLocalSceneBounds().max;
190 aabb.extend(globalCornerA);
191 aabb.extend(globalCornerB);
193 minCellSize = std::min(minCellSize,
c.params().cellSize);
196 ARMARX_VERBOSE <<
"Scene bounds intersections is " << aabb.min() <<
" and "
197 << aabb.max() <<
" with minCellSize as " << minCellSize;
203 Eigen::Vector2f boundingSizes = aabb.sizes();
204 const auto cX =
static_cast<std::size_t
>((boundingSizes.x() / minCellSize) + 1);
205 const auto cY =
static_cast<std::size_t
>((boundingSizes.y() / minCellSize) + 1);
207 Eigen::MatrixXf grid(cX, cY);
216 costmap.getMutableMask()->setOnes();
224 const auto& checkInOrder = [&](
int x,
int y,
const Eigen::Vector2f& position)
226 for (
const auto& other : costmaps)
228 Eigen::AlignedBox2f bounds(other.getLocalSceneBounds().min,
229 other.getLocalSceneBounds().max);
230 const auto otherVertex = other.toVertex(position);
232 if (bounds.contains(position) && other.isValid(otherVertex.index))
234 mergedCostmap.getMutableGrid()(
x, y) = *other.value(otherVertex.index);
241 for (
int x = 0;
x < mergedCostmap.getGrid().rows();
x++)
243 for (
int y = 0; y < mergedCostmap.getGrid().cols(); y++)
247 mergedCostmap.getMutableMask().value()(
x, y) = checkInOrder(
x, y, position);
251 costmapWriterPlugin->get().store(