test_shape_extraction.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014, Unbounded Robotics Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Unbounded Robotics, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 // Author: Michael Ferguson
31 
32 #include <gtest/gtest.h>
34 
35 TEST(test_shape_extraction, simple_cube)
36 {
37  // simple cube 4 corners of cube, plus one extra point
38  pcl::PointCloud<pcl::PointXYZRGB> cloud;
39  pcl::PointXYZRGB p;
40  p.x = 0.2;
41  p.y = 0.1;
42  p.z = 0.1;
43  cloud.push_back(p);
44  p.x = 0.25;
45  p.y = 0.1;
46  cloud.push_back(p);
47  p.x = 0.25;
48  p.y = 0.15;
49  cloud.push_back(p);
50  p.x = 0.2;
51  p.y = 0.15;
52  cloud.push_back(p);
53  p.x = 0.225;
54  p.y = 0.14;
55  cloud.push_back(p);
56 
57  pcl::PointCloud<pcl::PointXYZRGB> output;
58 
59  // create a plane at z = 0.05
60  pcl::ModelCoefficients::Ptr plane(new pcl::ModelCoefficients);
61  plane->values.resize(4);
62  plane->values[0] = 0.0;
63  plane->values[1] = 0.0;
64  plane->values[2] = 1.0;
65  plane->values[3] = -0.05;
66 
67  shape_msgs::SolidPrimitive shape;
68  geometry_msgs::Pose pose;
69 
70  bool ret = simple_grasping::extractShape(cloud, plane, output, shape, pose);
71  EXPECT_TRUE(ret);
72 
73  EXPECT_EQ(shape.BOX, shape.type);
74  ASSERT_EQ(3, shape.dimensions.size());
75  EXPECT_FLOAT_EQ(0.05, shape.dimensions[0]);
76  EXPECT_FLOAT_EQ(0.05, shape.dimensions[1]);
77  EXPECT_FLOAT_EQ(0.05, shape.dimensions[2]);
78 
79  EXPECT_FLOAT_EQ(0.225, pose.position.x);
80  EXPECT_FLOAT_EQ(0.125, pose.position.y);
81  EXPECT_FLOAT_EQ(0.075, pose.position.z);
82 
83  EXPECT_FLOAT_EQ(0.0, pose.orientation.x);
84  EXPECT_FLOAT_EQ(0.0, pose.orientation.y);
85  EXPECT_FLOAT_EQ(0.0, pose.orientation.z);
86  EXPECT_FLOAT_EQ(1.0, pose.orientation.w);
87 }
88 
89 // Run all the tests that were declared with TEST()
90 int main(int argc, char **argv)
91 {
92  testing::InitGoogleTest(&argc, argv);
93  return RUN_ALL_TESTS();
94 }
TEST(test_shape_extraction, simple_cube)
bool extractShape(const pcl::PointCloud< pcl::PointXYZRGB > &input, pcl::PointCloud< pcl::PointXYZRGB > &output, shape_msgs::SolidPrimitive &shape, geometry_msgs::Pose &pose)
Find the smallest shape primitive we can fit around this object.
int main(int argc, char **argv)


simple_grasping
Author(s): Michael Ferguson
autogenerated on Wed Jun 5 2019 20:04:47