ndt_cell.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_NDT_CELL_HPP
16 #define BELUGA_SENSOR_DATA_NDT_CELL_HPP
17 
18 #include <ostream>
19 #include <type_traits>
20 
21 #include <Eigen/Core>
22 
23 #include <range/v3/view/zip.hpp>
24 
25 #include <sophus/common.hpp>
26 #include <sophus/se2.hpp>
27 #include <sophus/se3.hpp>
28 #include <sophus/so2.hpp>
29 
31 
32 namespace beluga {
33 
35 template <int NDim, typename Scalar = double>
36 struct NDTCell {
37  static_assert(std::is_floating_point_v<Scalar>, "Scalar template parameter should be a floating point.");
39  static constexpr int num_dim = NDim;
41  using scalar_type = Scalar;
45  Eigen::Matrix<Scalar, NDim, NDim> covariance;
46 
49  [[nodiscard]] double likelihood_at(const NDTCell& measurement, double d1 = 1.0, double d2 = 1.0) const {
50  const Eigen::Vector<Scalar, NDim> error = measurement.mean - mean;
51  const double rhs =
52  std::exp((-d2 / 2.0) * error.transpose() * (measurement.covariance + covariance).inverse() * error);
53  return d1 * rhs;
54  }
55 
57  friend std::ostream& operator<<(std::ostream& os, const NDTCell& cell) {
58  os << "Mean \n" << cell.mean.transpose() << " \n\nCovariance: \n" << cell.covariance;
59  return os;
60  }
61 
63  friend NDTCell operator*(const Sophus::SE2<scalar_type>& tf, const NDTCell& ndt_cell) {
64  static_assert(num_dim == 2, "Cannot transform a non 2D NDT Cell with a SE2 transform.");
65  const Eigen::Vector2d uij = tf * ndt_cell.mean;
66  const Eigen::Matrix2Xd cov = tf.so2().matrix() * ndt_cell.covariance * tf.so2().matrix().transpose();
67  return NDTCell{uij, cov};
68  }
69 
71  friend NDTCell operator*(const Sophus::SE3<scalar_type>& tf, const NDTCell& ndt_cell) {
72  static_assert(num_dim == 3, "Cannot transform a non 3D NDT Cell with a SE3 transform.");
73  const Eigen::Vector3d uij = tf * ndt_cell.mean;
74  const Eigen::Matrix3Xd cov = tf.so3().matrix() * ndt_cell.covariance * tf.so3().matrix().transpose();
75  return NDTCell{uij, cov};
76  }
77 };
78 
87 
88 } // namespace beluga
89 
90 #endif
eigen_compatibility.hpp
Sophus::SE3::so3
SOPHUS_FUNC SO3Member & so3()
beluga::NDTCell
Representation for a cell of a N dimensional NDT cell.
Definition: ndt_cell.hpp:36
Sophus::SE2::so2
SOPHUS_FUNC SO2Member & so2()
se2.hpp
common.hpp
Sophus::SE2
so2.hpp
beluga::NDTCell::mean
Eigen::Vector< Scalar, NDim > mean
Mean of the N dimensional normal distribution.
Definition: ndt_cell.hpp:43
Sophus::SE3
beluga::NDTCell::covariance
Eigen::Matrix< Scalar, NDim, NDim > covariance
Covariance of the N dimensional normal distribution.
Definition: ndt_cell.hpp:45
beluga::NDTCell::likelihood_at
double likelihood_at(const NDTCell &measurement, double d1=1.0, double d2=1.0) const
Definition: ndt_cell.hpp:49
beluga::NDTCell::operator*
friend NDTCell operator*(const Sophus::SE2< scalar_type > &tf, const NDTCell &ndt_cell)
Transform the normal distribution according to tf, both mean and covariance.
Definition: ndt_cell.hpp:63
Eigen::Vector
Eigen::Matrix< Scalar, Dims, 1 > Vector
Type alias for single-column matrices, available starting Eigen 3.4.
Definition: eigen_compatibility.hpp:24
beluga::NDTCell::num_dim
static constexpr int num_dim
Number of dimensions of the cell's translation.
Definition: ndt_cell.hpp:39
beluga::NDTCell::scalar_type
Scalar scalar_type
Floating point scalar type.
Definition: ndt_cell.hpp:41
beluga::NDTCell::operator<<
friend std::ostream & operator<<(std::ostream &os, const NDTCell &cell)
Ostream overload mostly for debugging purposes.
Definition: ndt_cell.hpp:57
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21
beluga::NDTCell::operator*
friend NDTCell operator*(const Sophus::SE3< scalar_type > &tf, const NDTCell &ndt_cell)
Transform the normal distribution according to tf, both mean and covariance.
Definition: ndt_cell.hpp:71
se3.hpp


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