dense_grid.hpp
Go to the documentation of this file.
1 // Copyright 2023 Ekumen, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BELUGA_SENSOR_DATA_DENSE_GRID_HPP
16 #define BELUGA_SENSOR_DATA_DENSE_GRID_HPP
17 
18 #include <optional>
19 #include <vector>
20 
22 
23 #include <Eigen/Core>
25 
31 namespace beluga {
32 
73 
82 template <typename Derived>
83 class BaseDenseGrid2 : public BaseRegularGrid2<Derived> {
84  public:
86 
90  [[nodiscard]] bool contains(int xi, int yi) const {
91  const auto width = static_cast<int>(this->self().width());
92  const auto height = static_cast<int>(this->self().height());
93  return xi >= 0 && yi >= 0 && xi < width && yi < height;
94  }
95 
97 
100  [[nodiscard]] bool contains(const Eigen::Vector2i& pi) const { return this->self().contains(pi.x(), pi.y()); }
101 
103 
108  [[nodiscard]] auto data_at(int xi, int yi) const {
109  return this->self().contains(xi, yi) ? this->self().data_at(this->self().index_at(Eigen::Vector2i{xi, yi}))
110  : std::nullopt;
111  }
112 
114 
118  [[nodiscard]] auto data_at(const Eigen::Vector2i& pi) const { return this->self().data_at(pi.x(), pi.y()); }
119 
121 
126  [[nodiscard]] auto data_near(double x, double y) const {
127  return this->self().data_at(this->self().cell_near(Eigen::Vector2d{x, y}));
128  }
129 
131 
135  [[nodiscard]] auto data_near(const Eigen::Vector2d& p) const { return this->self().data_near(p.x(), p.y()); }
136 
138 
143  [[nodiscard]] auto neighborhood4(int xi, int yi) const {
144  auto result = std::vector<Eigen::Vector2i>{};
145  if (xi < static_cast<int>(this->self().width() - 1)) {
146  result.emplace_back(xi + 1, yi);
147  }
148  if (yi < static_cast<int>(this->self().height() - 1)) {
149  result.emplace_back(xi, yi + 1);
150  }
151  if (xi > 0) {
152  result.emplace_back(xi - 1, yi);
153  }
154  if (yi > 0) {
155  result.emplace_back(xi, yi - 1);
156  }
157  return result;
158  }
159 
161 
165  [[nodiscard]] auto neighborhood4(const Eigen::Vector2i& pi) const {
166  return this->self().neighborhood4(pi.x(), pi.y());
167  }
168 };
169 
170 } // namespace beluga
171 
172 #endif
result
result[0]
eigen_compatibility.hpp
beluga::BaseDenseGrid2::contains
bool contains(const Eigen::Vector2i &pi) const
Checks if a cell is included in the grid.
Definition: dense_grid.hpp:100
beluga::BaseDenseGrid2
Dense 2D grid base type.
Definition: dense_grid.hpp:83
beluga::BaseRegularGrid
Regularly spaced N dimensional grid base type.
Definition: regular_grid.hpp:65
beluga::BaseDenseGrid2::data_near
auto data_near(double x, double y) const
Gets nearest cell data, if included.
Definition: dense_grid.hpp:126
beluga::BaseDenseGrid2::data_near
auto data_near(const Eigen::Vector2d &p) const
Gets nearest cell data, if included.
Definition: dense_grid.hpp:135
beluga::BaseDenseGrid2::neighborhood4
auto neighborhood4(const Eigen::Vector2i &pi) const
Computes 4-connected neighborhood for cell.
Definition: dense_grid.hpp:165
regular_grid.hpp
Concepts and abstract implementations of regular grids.
beluga::BaseDenseGrid2::contains
bool contains(int xi, int yi) const
Checks if a cell is included in the grid.
Definition: dense_grid.hpp:90
beluga::BaseDenseGrid2::data_at
auto data_at(const Eigen::Vector2i &pi) const
Gets cell data, if included.
Definition: dense_grid.hpp:118
beluga::BaseDenseGrid2::data_at
auto data_at(int xi, int yi) const
Gets cell data, if included.
Definition: dense_grid.hpp:108
beluga::BaseDenseGrid2::neighborhood4
auto neighborhood4(int xi, int yi) const
Computes 4-connected neighborhood for cell.
Definition: dense_grid.hpp:143
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53