12 namespace signed_distance_field {
15 Eigen::Matrix<bool, -1, -1> occupancy = elevationMap.unaryExpr([=](
float val) {
return val > height; });
20 if (sdf0.cols() != sdf1.cols() || sdf0.rows() != sdf1.rows()) {
24 for (Eigen::Index col = 0; col < sdf0.cols(); ++col) {
25 for (Eigen::Index row = 0; row < sdf0.rows(); ++row) {
26 if (sdf0(row, col) == sdf1(row, col) || std::abs(sdf0(row, col) - sdf1(row, col)) < tol) {
38 Matrix signedDistance(elevationMap.rows(), elevationMap.cols());
41 for (Eigen::Index col = 0; col < elevationMap.cols(); ++col) {
42 for (Eigen::Index row = 0; row < elevationMap.rows(); ++row) {
43 if (elevationMap(row, col) >= height) {
44 signedDistance(row, col) = -
INF;
46 for (Eigen::Index j = 0; j < elevationMap.cols(); ++j) {
47 for (Eigen::Index i = 0; i < elevationMap.rows(); ++i) {
51 const float dz{std::max(elevationMap(i, j) - height, 0.0F)};
52 const float currentSignedDistance{-std::sqrt(dx * dx + dy * dy + dz * dz)};
53 signedDistance(row, col) = std::max(signedDistance(row, col), currentSignedDistance);
57 signedDistance(row, col) =
INF;
59 for (Eigen::Index j = 0; j < elevationMap.cols(); ++j) {
60 for (Eigen::Index i = 0; i < elevationMap.rows(); ++i) {
64 const float dz{std::max(height - elevationMap(i, j), 0.0F)};
65 const float currentSignedDistance{std::sqrt(dx * dx + dy * dy + dz * dz)};
66 signedDistance(row, col) = std::min(signedDistance(row, col), currentSignedDistance);
73 return signedDistance;
77 Matrix signedDistance(occupancyGrid.rows(), occupancyGrid.cols());
80 for (Eigen::Index col = 0; col < occupancyGrid.cols(); ++col) {
81 for (Eigen::Index row = 0; row < occupancyGrid.rows(); ++row) {
82 if (occupancyGrid(row, col)) {
83 signedDistance(row, col) = -
INF;
85 for (Eigen::Index j = 0; j < occupancyGrid.cols(); ++j) {
86 for (Eigen::Index i = 0; i < occupancyGrid.rows(); ++i) {
87 if (!occupancyGrid(i, j)) {
90 const float currentSignedDistance{-std::sqrt(dx * dx + dy * dy)};
91 signedDistance(row, col) = std::max(signedDistance(row, col), currentSignedDistance);
96 signedDistance(row, col) =
INF;
98 for (Eigen::Index j = 0; j < occupancyGrid.cols(); ++j) {
99 for (Eigen::Index i = 0; i < occupancyGrid.rows(); ++i) {
100 if (occupancyGrid(i, j)) {
103 const float currentSignedDistance{std::sqrt(dx * dx + dy * dy)};
104 signedDistance(row, col) = std::min(signedDistance(row, col), currentSignedDistance);
112 return signedDistance;
Matrix naiveSignedDistanceFromOccupancy(const Eigen::Matrix< bool, -1, -1 > &occupancyGrid, float resolution)
float pixelBorderDistance(float i, float j)
Eigen::Matrix< bool, -1, -1 > occupancyAtHeight(const Matrix &elevationMap, float height)
Matrix naiveSignedDistanceAtHeight(const Matrix &elevationMap, float height, float resolution)
constexpr float INF
Distance value that is considered infinite.
bool isEqualSdf(const Matrix &sdf0, const Matrix &sdf1, float tol)