MCPcopy Create free account
hub / github.com/ANYbotics/grid_map / getTransformedMap

Method getTransformedMap

grid_map_core/src/GridMap.cpp:337–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335}
336
337GridMap GridMap::getTransformedMap(const Eigen::Isometry3d& transform, const std::string& heightLayerName, const std::string& newFrameId,
338 const double sampleRatio) const {
339 // Check if height layer is valid.
340 if (!exists(heightLayerName)) {
341 throw std::out_of_range("GridMap::getTransformedMap(...) : No map layer '" + heightLayerName + "' available.");
342 }
343
344 // Initialization.
345 std::vector<Position3> positionSamples;
346 Position3 center;
347 Index newIndex;
348
349 const double sampleLength = resolution_ * sampleRatio;
350
351 // Find edges in new coordinate frame.
352 const double halfLengthX = length_.x() * 0.5;
353 const double halfLengthY = length_.y() * 0.5;
354 const Position3 topLeftCorner(position_.x() + halfLengthX, position_.y() + halfLengthY, 0.0);
355 const Position3 topRightCorner(position_.x() + halfLengthX, position_.y() - halfLengthY, 0.0);
356 const Position3 bottomLeftCorner(position_.x() - halfLengthX, position_.y() + halfLengthY, 0.0);
357 const Position3 bottomRightCorner(position_.x() - halfLengthX, position_.y() - halfLengthY, 0.0);
358
359 std::vector<Position3> newEdges;
360 newEdges.reserve(4);
361 newEdges.push_back(transform * topLeftCorner);
362 newEdges.push_back(transform * topRightCorner);
363 newEdges.push_back(transform * bottomLeftCorner);
364 newEdges.push_back(transform * bottomRightCorner);
365
366 // Find new grid center.
367 Position3 newCenter = Position3::Zero();
368 for (const auto& newEdge : newEdges) {
369 newCenter += newEdge;
370 }
371 newCenter *= 0.25;
372
373 // Find new grid length.
374 Length maxLengthFromCenter = Length(0.0, 0.0);
375 for (const auto& newEdge : newEdges) {
376 Position3 positionCenterToEdge = newEdge - newCenter;
377 maxLengthFromCenter.x() = std::fmax(std::fabs(positionCenterToEdge.x()), maxLengthFromCenter.x());
378 maxLengthFromCenter.y() = std::fmax(std::fabs(positionCenterToEdge.y()), maxLengthFromCenter.y());
379 }
380 Length newLength = 2.0 * maxLengthFromCenter;
381
382 // Create new grid map.
383 GridMap newMap(layers_);
384 newMap.setBasicLayers(basicLayers_);
385 newMap.setTimestamp(timestamp_);
386 newMap.setFrameId(newFrameId);
387 newMap.setGeometry(newLength, resolution_, Position(newCenter.x(), newCenter.y()));
388 newMap.startIndex_.setZero();
389
390 for (GridMapIterator iterator(*this); !iterator.isPastEnd(); ++iterator) {
391 // Get position at current index.
392 if (!getPosition3(heightLayerName, *iterator, center)) {
393 continue;
394 }

Callers 1

TESTFunction · 0.45

Calls 8

setBasicLayersMethod · 0.80
setGeometryMethod · 0.80
clearMethod · 0.80
getIndexMethod · 0.80
atMethod · 0.80
setTimestampMethod · 0.45
setFrameIdMethod · 0.45
isPastEndMethod · 0.45

Tested by 1

TESTFunction · 0.36