20 using signed_distance_field::Gridmap3dLookup;
26 : frameId_(gridMap.getFrameId()), timestamp_(gridMap.getTimestamp()) {
27 assert(maxHeight >= minHeight);
31 gridMap.
getPosition(Eigen::Vector2i(0, 0), mapOriginXY);
32 Position3 gridOrigin(mapOriginXY.x(), mapOriginXY.y(), minHeight);
35 const auto numZLayers =
static_cast<size_t>(std::max(std::ceil((maxHeight - minHeight) / gridMap.
getResolution()), 2.0));
36 const size_t numXrows = gridMap.
getSize().x();
37 const size_t numYrows = gridMap.
getSize().y();
47 const auto& elevationData = gridMap.
get(elevationLayer);
48 if (elevationData.hasNaN()) {
50 <<
"[grid_map_sdf::SignedDistanceField] elevation data contains NaN. The generated SDF will be invalid! Apply inpainting first" 63 return distance(nodeData) + jacobian.dot(position - nodePosition);
77 return {
distance(nodeData) + jacobian.dot(position - nodePosition), jacobian};
83 const auto minHeight = elevation.minCoeff();
84 const auto maxHeight = elevation.maxCoeff();
106 Matrix dxTranspose = Matrix::Zero(elevation.cols(), elevation.rows());
107 Matrix dxNextTranspose = Matrix::Zero(elevation.cols(), elevation.rows());
108 Matrix dy = Matrix::Zero(elevation.rows(), elevation.cols());
109 Matrix dz = Matrix::Zero(elevation.rows(), elevation.cols());
112 computeLayerSdfandDeltaX(elevation, currentLayer, dxTranspose, sdfTranspose, tmp, tmpTranspose, gridOriginZ, resolution, minHeight,
116 computeLayerSdfandDeltaX(elevation, nextLayer, dxNextTranspose, sdfTranspose, tmp, tmpTranspose, gridOriginZ + resolution, resolution,
117 minHeight, maxHeight);
128 previousLayer.swap(currentLayer);
129 currentLayer.swap(nextLayer);
130 dxTranspose.swap(dxNextTranspose);
134 gridOriginZ + (layerZ + 1) * resolution, resolution, minHeight, maxHeight);
145 previousLayer.swap(currentLayer);
146 currentLayer.swap(nextLayer);
147 dxTranspose.swap(dxNextTranspose);
157 Matrix& tmp,
Matrix& tmpTranspose,
float height,
float resolution,
float minHeight,
158 float maxHeight)
const {
162 currentLayer = sdfTranspose.transpose();
169 data_.emplace_back(
node_data_t{signedDistance(rowX, colY), dxTranspose(colY, rowX), dy(rowX, colY), dz(rowX, colY)});
const std::string & getFrameId() const noexcept
size_t size() const noexcept
const Matrix & get(const std::string &layer) const
const Size & getSize() const
static float distanceFloat(const node_data_t &nodeData) noexcept
void signedDistanceAtHeightTranspose(const Matrix &elevationMap, Matrix &sdfTranspose, Matrix &tmp, Matrix &tmpTranspose, float height, float resolution, float minHeight, float maxHeight)
signed_distance_field::Gridmap3dLookup gridmap3DLookup_
Object encoding the 3D grid.
size_t_3d gridsize_
3D size of the grid
Time timestamp_
Timestamp of the grid map (nanoseconds).
Eigen::Vector3d Derivative3
double value(const Position3 &position) const noexcept
double getResolution() const
Position3 nodePosition(const size_t_3d &index) const noexcept
size_t linearSize() const noexcept
std::pair< double, Derivative3 > valueAndDerivative(const Position3 &position) const noexcept
size_t linearIndex(const size_t_3d &index) const noexcept
std::string frameId_
Frame id of the grid map.
void computeSignedDistance(const Matrix &elevation)
static double distance(const node_data_t &nodeData) noexcept
double resolution_
Grid resolution.
void columnwiseCentralDifference(const Matrix &data, Matrix ¢ralDifference, float resolution)
Derivative3 derivative(const Position3 &position) const noexcept
void layerCentralDifference(const Matrix &data_km1, const Matrix &data_kp1, Matrix &result, float resolution)
void computeLayerSdfandDeltaX(const Matrix &elevation, Matrix ¤tLayer, Matrix &dxTranspose, Matrix &sdfTranspose, Matrix &tmp, Matrix &tmpTranspose, float height, float resolution, float minHeight, float maxHeight) const
Eigen::Vector3d Position3
std::array< float, 4 > node_data_t
Data structure to store together {signed distance value, derivative}.
void filterPoints(std::function< void(const Position3 &, float, const Derivative3 &)> func, size_t decimation=1) const
std::vector< node_data_t > data_
Object encoding the signed distance value and derivative in the grid.
void layerFiniteDifference(const Matrix &data_k, const Matrix &data_kp1, Matrix &result, float resolution)
SignedDistanceField(const GridMap &gridMap, const std::string &elevationLayer, double minHeight, double maxHeight)
bool getPosition(const Index &index, Position &position) const
void emplacebackLayerData(const Matrix &signedDistance, const Matrix &dxTranspose, const Matrix &dy, const Matrix &dz)
Time getTime() const noexcept
size_t_3d nearestNode(const Position3 &position) const noexcept
Position3 gridOrigin_
Origin position of the grid.