moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
test_voxel_grid.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2009, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Mrinal Kalakrishnan, Ken Anderson */
36
37#include <gtest/gtest.h>
38
40#include <rclcpp/rclcpp.hpp>
41
42using namespace distance_field;
43
44TEST(TestVoxelGrid, TestReadWrite)
45{
46 int i;
47 int def = -100;
48 VoxelGrid<int> vg(0.02, 0.02, 0.02, 0.01, 0, 0, 0, def);
49
50 int num_x = vg.getNumCells(DIM_X);
51 int num_y = vg.getNumCells(DIM_Y);
52 int num_z = vg.getNumCells(DIM_Z);
53
54 // Check dimensions
55 EXPECT_EQ(num_x, 2);
56 EXPECT_EQ(num_y, 2);
57 EXPECT_EQ(num_z, 2);
58
59 // check initial values
60 vg.reset(0);
61
62 i = 0;
63 for (int x = 0; x < num_x; ++x)
64 {
65 for (int y = 0; y < num_y; ++y)
66 {
67 for (int z = 0; z < num_z; ++z)
68 {
69 EXPECT_EQ(vg.getCell(x, y, z), 0);
70 i++;
71 }
72 }
73 }
74
75 // Check out-of-bounds query // FIXME-- this test fails!!
76 // EXPECT_EQ( vg.getCell(999,9999,999), def );
77 // EXPECT_EQ( vg.getCell(numX+1,0,0), def);
78 // EXPECT_EQ( vg.getCell(0,numY+1,0), def);
79 // EXPECT_EQ( vg.getCell(0,0,numZ+1), def);
80
81 // Set values
82 i = 0;
83 for (int x = 0; x < num_x; ++x)
84 {
85 for (int y = 0; y < num_y; ++y)
86 {
87 for (int z = 0; z < num_z; ++z)
88 {
89 vg.getCell(x, y, z) = i;
90 i++;
91 }
92 }
93 }
94
95 // check reset values
96 i = 0;
97 for (int x = 0; x < num_x; ++x)
98 {
99 for (int y = 0; y < num_y; ++y)
100 {
101 for (int z = 0; z < num_z; ++z)
102 {
103 EXPECT_EQ(i, vg.getCell(x, y, z));
104 i++;
105 }
106 }
107 }
108}
109
110int main(int argc, char** argv)
111{
112 testing::InitGoogleTest(&argc, argv);
113 return RUN_ALL_TESTS();
114}
VoxelGrid holds a dense 3D, axis-aligned set of data at a given resolution, where the data is supplie...
Definition voxel_grid.h:62
int getNumCells(Dimension dim) const
Gets the number of cells in the indicated dimension.
Definition voxel_grid.h:447
T & getCell(int x, int y, int z)
Gives the value of the given location (x,y,z) in the discretized voxel grid space.
Definition voxel_grid.h:470
void reset(const T &initial)
Sets every cell in the voxel grid to the supplied data.
Definition voxel_grid.h:532
Namespace for holding classes that generate distance fields.
int main(int argc, char **argv)
TEST(TestVoxelGrid, TestReadWrite)