test_ndt_cell.cpp
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 #include <gtest/gtest.h>
16 
17 #include <sstream>
18 
19 #include <Eigen/Core>
20 #include <sophus/common.hpp>
21 #include <sophus/se2.hpp>
22 
24 
25 namespace beluga {
26 
27 namespace {
28 
29 Eigen::Matrix2Xd get_diagonal_covariance(double x_var = 0.5, double y_var = 0.8) {
30  return Eigen::Vector2d{x_var, y_var}.asDiagonal();
31 }
32 
33 } // namespace
34 
35 TEST(NDTCellTests, Product) {
36  {
37  const NDTCell2d cell{Eigen::Vector2d{1, 2}, get_diagonal_covariance()};
38  const Sophus::SE2d tf{};
39  const auto transformed = tf * cell;
40  ASSERT_TRUE(cell.mean.isApprox(transformed.mean));
41  ASSERT_TRUE(cell.covariance.isApprox(transformed.covariance));
42  }
43  {
44  const NDTCell2d cell{Eigen::Vector2d{1, 2}, get_diagonal_covariance()};
45  const Sophus::SE2d tf{Sophus::SO2d{}, Eigen::Vector2d{1, 2}};
46  const auto transformed = tf * cell;
47  ASSERT_TRUE(cell.mean.isApprox(transformed.mean - Eigen::Vector2d{1, 2}));
48  ASSERT_TRUE(cell.covariance.isApprox(transformed.covariance));
49  }
50  {
51  const NDTCell2d cell{Eigen::Vector2d{1, 2}, get_diagonal_covariance()};
52  const Sophus::SE2d tf{Sophus::SO2d{Sophus::Constants<double>::pi() / 2}, Eigen::Vector2d::Zero()};
53 
54  Eigen::Matrix<double, 2, 2> expected_transformed_cov;
55  // clang-format off
56  expected_transformed_cov << 0.8, 0.0,
57  0.0, 0.5;
58  // clang-format on
59  const auto transformed = tf * cell;
60  EXPECT_TRUE(transformed.covariance.isApprox(expected_transformed_cov));
61  EXPECT_TRUE(transformed.mean.isApprox(Eigen::Vector2d{-2, 1})) << transformed;
62  }
63 }
64 
65 TEST(NDTCellTests, Ostream) {
66  const NDTCell2d cell{Eigen::Vector2d{1, 2}, get_diagonal_covariance()};
67  std::stringstream ss;
68  ss << cell;
69  ASSERT_GT(ss.str().size(), 0);
70 }
71 
72 } // namespace beluga
Sophus::SO2
beluga::NDTCell
Representation for a cell of a N dimensional NDT cell.
Definition: ndt_cell.hpp:36
se2.hpp
common.hpp
Sophus::SE2
Sophus::Constants::pi
static SOPHUS_FUNC Scalar pi()
ndt_cell.hpp
beluga
The main Beluga namespace.
Definition: 3d_embedding.hpp:21
beluga::TEST
TEST(Bresenham, MultiPassGuarantee)
Definition: test_bresenham.cpp:27


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