test3dLookup.cpp
Go to the documentation of this file.
1 /*
2  * test3dLookup.cpp
3  *
4  * Created on: Aug 18, 2020
5  * Author: Ruben Grandia
6  * Institute: ETH Zurich
7  */
8 
9 #include <gtest/gtest.h>
10 
12 
13 using namespace grid_map;
14 using namespace signed_distance_field;
16 
17 TEST(testGridmap3dLookup, nearestNode) {
18  const size_t_3d gridsize{8, 9, 10};
19  const Position3 gridOrigin{-0.1, -0.2, -0.4};
20  const double resolution = 0.1;
21 
22  Gridmap3dLookup gridmap3DLookup(gridsize, gridOrigin, resolution);
23 
24  // Retrieve origin
25  const size_t_3d originNode = gridmap3DLookup.nearestNode(gridOrigin);
26  ASSERT_EQ(originNode.x, 0);
27  ASSERT_EQ(originNode.y, 0);
28  ASSERT_EQ(originNode.z, 0);
29 
30  // test underflow
31  const size_t_3d originNodeProjected = gridmap3DLookup.nearestNode(gridOrigin + Position3{1e20, 1e20, -1e20});
32  ASSERT_EQ(originNodeProjected.x, 0);
33  ASSERT_EQ(originNodeProjected.y, 0);
34  ASSERT_EQ(originNodeProjected.z, 0);
35 
36  // test overflow
37  const size_t_3d maxNodeProjected = gridmap3DLookup.nearestNode(gridOrigin + Position3{-1e20, -1e20, +1e20});
38  ASSERT_EQ(maxNodeProjected.x, gridsize.x - 1);
39  ASSERT_EQ(maxNodeProjected.y, gridsize.y - 1);
40  ASSERT_EQ(maxNodeProjected.z, gridsize.z - 1);
41 
42  // Nearest neighbour
43  const size_t_3d nodeIndex{3, 4, 5};
44  const Position3 nodePosition = gridmap3DLookup.nodePosition(nodeIndex);
45  const size_t_3d closestNodeIndex = gridmap3DLookup.nearestNode(nodePosition + 0.49 * Position3::Constant(resolution));
46  ASSERT_EQ(closestNodeIndex.x, nodeIndex.x);
47  ASSERT_EQ(closestNodeIndex.y, nodeIndex.y);
48  ASSERT_EQ(closestNodeIndex.z, nodeIndex.z);
49 }
50 
51 TEST(testGridmap3dLookup, linearIndex) {
52  const size_t_3d gridsize{8, 9, 10};
53  const Position3 gridOrigin{-0.1, -0.2, -0.4};
54  const double resolution = 0.1;
55 
56  Gridmap3dLookup gridmap3DLookup(gridsize, gridOrigin, resolution);
57  ASSERT_EQ(gridmap3DLookup.linearIndex({0, 0, 0}), 0);
58  ASSERT_EQ(gridmap3DLookup.linearIndex({gridsize.x - 1, gridsize.y - 1, gridsize.z - 1}), gridmap3DLookup.linearSize() - 1);
59 }
Position3 nodePosition(const size_t_3d &index) const noexcept
Gridmap3dLookup::size_t_3d size_t_3d
size_t linearIndex(const size_t_3d &index) const noexcept
Eigen::Vector3d Position3
TEST(GridMap, CopyConstructor)
size_t_3d nearestNode(const Position3 &position) const noexcept


grid_map_sdf
Author(s): Takahiro Miki , Péter Fankhauser
autogenerated on Wed Jul 5 2023 02:23:42