24 #include "gmock/gmock.h" 27 namespace mapping_3d {
28 namespace scan_matching {
31 TEST(PrecomputedGridGeneratorTest, TestAgainstNaiveAlgorithm) {
32 HybridGrid hybrid_grid(2.f);
34 std::mt19937 rng(23847);
35 std::uniform_int_distribution<int> coordinate_distribution(-50, 49);
36 std::uniform_real_distribution<float> value_distribution(
38 for (
int i = 0; i < 1000; ++i) {
39 const auto x = coordinate_distribution(rng);
40 const auto y = coordinate_distribution(rng);
41 const auto z = coordinate_distribution(rng);
42 const Eigen::Array3i cell_index(x, y, z);
43 hybrid_grid.SetProbability(cell_index, value_distribution(rng));
46 std::vector<PrecomputationGrid> precomputed_grids;
47 for (
int depth = 0; depth <= 3; ++depth) {
51 precomputed_grids.push_back(
53 (1 << (depth - 1)) * Eigen::Array3i::Ones()));
55 const int width = 1 << depth;
56 for (
int i = 0; i < 100; ++i) {
57 const auto x = coordinate_distribution(rng);
58 const auto y = coordinate_distribution(rng);
59 const auto z = coordinate_distribution(rng);
61 for (
int dx = 0; dx < width; ++dx) {
62 for (
int dy = 0; dy < width; ++dy) {
63 for (
int dz = 0; dz < width; ++dz) {
64 max_probability = std::max(
65 max_probability, hybrid_grid.GetProbability(
66 Eigen::Array3i(x + dx, y + dy, z + dz)));
71 EXPECT_NEAR(max_probability,
73 precomputed_grids.back().value(Eigen::Array3i(x, y, z))),
static float ToProbability(float value)
constexpr float kMinProbability
constexpr float kMaxProbability
PrecomputationGrid PrecomputeGrid(const PrecomputationGrid &grid, const bool half_resolution, const Eigen::Array3i &shift)
PrecomputationGrid ConvertToPrecomputationGrid(const HybridGrid &hybrid_grid)