Gridmap3dLookup.hpp
Go to the documentation of this file.
1 /*
2  * Gridmap3dLookup.h
3  *
4  * Created on: Aug 13, 2020
5  * Author: Ruben Grandia
6  * Institute: ETH Zurich
7  */
8 
9 #pragma once
10 
12 
13 namespace grid_map {
14 namespace signed_distance_field {
15 
23  public:
24  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26  struct size_t_3d {
27  size_t x{0};
28  size_t y{0};
29  size_t z{0};
30 
31  size_t_3d() = default;
32  size_t_3d(size_t x, size_t y, size_t z) : x(x), y(y), z(z) {}
33  };
34 
36  size_t_3d gridsize_{0, 0, 0};
37 
39  Position3 gridOrigin_{0.0, 0.0, 0.0};
40 
43 
45  double resolution_{1.0};
46 
48  Gridmap3dLookup() = default;
49 
56  Gridmap3dLookup(const size_t_3d& gridsize, const Position3& gridOrigin, double resolution)
57  : gridsize_(gridsize),
58  gridOrigin_(gridOrigin),
59  gridMaxIndexAsDouble_(static_cast<double>(gridsize_.x - 1), static_cast<double>(gridsize_.y - 1),
60  static_cast<double>(gridsize_.z - 1)),
61  resolution_(resolution) {
62  assert(resolution_ > 0.0);
63  assert(gridsize_.x > 0);
64  assert(gridsize_.y > 0);
65  assert(gridsize_.z > 0);
66  };
67 
69  size_t_3d nearestNode(const Position3& position) const noexcept {
70  const double resInv{1.0 / resolution_};
71  Position3 subpixelVector{(gridOrigin_.x() - position.x()) * resInv, (gridOrigin_.y() - position.y()) * resInv,
72  (position.z() - gridOrigin_.z()) * resInv};
73  return {getNearestPositiveInteger(subpixelVector.x(), gridMaxIndexAsDouble_.x()),
74  getNearestPositiveInteger(subpixelVector.y(), gridMaxIndexAsDouble_.y()),
75  getNearestPositiveInteger(subpixelVector.z(), gridMaxIndexAsDouble_.z())};
76  }
77 
79  Position3 nodePosition(const size_t_3d& index) const noexcept {
80  assert(index.x < gridsize_.x);
81  assert(index.y < gridsize_.y);
82  assert(index.z < gridsize_.z);
83  return {gridOrigin_.x() - index.x * resolution_, gridOrigin_.y() - index.y * resolution_, gridOrigin_.z() + index.z * resolution_};
84  }
85 
87  size_t linearIndex(const size_t_3d& index) const noexcept {
88  assert(index.x < gridsize_.x);
89  assert(index.y < gridsize_.y);
90  assert(index.z < gridsize_.z);
91  return (index.z * gridsize_.y + index.y) * gridsize_.x + index.x;
92  }
93 
95  size_t linearSize() const noexcept { return gridsize_.x * gridsize_.y * gridsize_.z; }
96 
98  static size_t getNearestPositiveInteger(double val, double max) noexcept {
99  // Comparing bounds as double prevents underflow/overflow of size_t
100  return static_cast<size_t>(std::max(0.0, std::min(std::round(val), max)));
101  }
102 };
103 
104 } // namespace signed_distance_field
105 } // namespace grid_map
Position3 nodePosition(const size_t_3d &index) const noexcept
size_t linearIndex(const size_t_3d &index) const noexcept
static size_t getNearestPositiveInteger(double val, double max) noexcept
Eigen::Vector3d Position3
Gridmap3dLookup(const size_t_3d &gridsize, const Position3 &gridOrigin, double resolution)
Position3 gridMaxIndexAsDouble_
Maximum index per dimension stored as double.
size_t_3d nearestNode(const Position3 &position) const noexcept
Position3 gridOrigin_
Origin position of the grid.


grid_map_sdf
Author(s): Takahiro Miki , Péter Fankhauser
autogenerated on Wed Jul 5 2023 02:23:42