sparse_value_grid.hpp
Go to the documentation of this file.
1 // Copyright 2024 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_SPARSE_VALUE_GRID_HPP
16 #define BELUGA_SENSOR_DATA_SPARSE_VALUE_GRID_HPP
17 
18 #include <Eigen/Core>
19 #include <optional>
20 #include <type_traits>
21 
29 namespace beluga {
30 
32 
45 template <typename MapType, int NDim>
46 class SparseValueGrid : public BaseRegularGrid<SparseValueGrid<MapType, NDim>, NDim> {
47  public:
49  SparseValueGrid() = default;
51  using map_type = MapType;
53  using mapped_type = typename map_type::mapped_type;
55  using key_type = typename map_type::key_type;
56 
57  static_assert(std::is_same_v<key_type, Eigen::Vector<int, NDim>>);
59 
64  assert(resolution_ > 0);
65  }
66 
68  [[nodiscard]] double resolution() const { return resolution_; }
69 
71  [[nodiscard]] std::size_t size() const { return data_.size(); }
72 
74  [[nodiscard]] const map_type& data() const { return data_; }
75 
77  [[nodiscard]] std::optional<mapped_type> data_at(const Eigen::Vector<int, NDim>& cell_index) const {
78  const auto itr = data_.find(cell_index);
79  if (itr == data_.end()) {
80  return std::nullopt;
81  }
82  return itr->second;
83  }
84 
86  [[nodiscard]] std::optional<mapped_type> data_near(const Eigen::Vector<double, NDim>& coordinates) const {
87  return data_at(this->self().cell_near(coordinates));
88  }
89 
90  private:
92  double resolution_ = 1.0;
93 };
94 
96 template <typename MapType>
98 
100 template <typename MapType>
102 } // namespace beluga
103 
104 #endif
beluga::SparseValueGrid::data_at
std::optional< mapped_type > data_at(const Eigen::Vector< int, NDim > &cell_index) const
Gets grid data at cell_index or std::nullopt if it's not present.
Definition: sparse_value_grid.hpp:77
eigen_compatibility.hpp
beluga::SparseValueGrid::size
std::size_t size() const
Gets grid size (ie. number of grid cells).
Definition: sparse_value_grid.hpp:71
beluga::SparseValueGrid::data
const map_type & data() const
Gets grid data.
Definition: sparse_value_grid.hpp:74
beluga::SparseValueGrid::key_type
typename map_type::key_type key_type
Key type for the key-value pairs.
Definition: sparse_value_grid.hpp:55
beluga::SparseValueGrid::map_type
MapType map_type
Underlying associative container.
Definition: sparse_value_grid.hpp:51
beluga::BaseRegularGrid< SparseValueGrid< MapType, NDim >, NDim >::cell_near
Eigen::Vector< int, NDim > cell_near(const Eigen::Vector< double, NDim > &p) const
Compute nearest grid cell coordinates given plane coordinates.
Definition: regular_grid.hpp:74
beluga::SparseValueGrid::data_near
std::optional< mapped_type > data_near(const Eigen::Vector< double, NDim > &coordinates) const
Gets grid data at real coordinates 'coordinates' or std::nullopt if it's not present.
Definition: sparse_value_grid.hpp:86
beluga::SparseValueGrid::resolution_
double resolution_
Definition: sparse_value_grid.hpp:92
beluga::BaseRegularGrid
Regularly spaced N dimensional grid base type.
Definition: regular_grid.hpp:65
beluga::SparseValueGrid::SparseValueGrid
SparseValueGrid()=default
Construct without data and with a 1 cell/meter resolution.
beluga::SparseValueGrid
Generic N dimensional sparse value regular grid.
Definition: sparse_value_grid.hpp:46
beluga::SparseValueGrid::SparseValueGrid
SparseValueGrid(map_type data, double resolution=1.)
Constructs the grid.
Definition: sparse_value_grid.hpp:63
beluga::SparseValueGrid::resolution
double resolution() const
Gets grid resolution.
Definition: sparse_value_grid.hpp:68
std
Definition: circular_array.hpp:529
Eigen::Vector
Eigen::Matrix< Scalar, Dims, 1 > Vector
Type alias for single-column matrices, available starting Eigen 3.4.
Definition: eigen_compatibility.hpp:24
regular_grid.hpp
Concepts and abstract implementations of regular grids.
beluga::SparseValueGrid::data_
map_type data_
Definition: sparse_value_grid.hpp:91
beluga::SparseValueGrid::mapped_type
typename map_type::mapped_type mapped_type
Value type of the key-value pairs stored in the data.
Definition: sparse_value_grid.hpp:53
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21


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