UpdatePointcloudTest.cpp
Go to the documentation of this file.
1 
20 #define BOOST_TEST_STATIC_LINK
21 
22 #include <boost/test/included/unit_test.hpp>
24 #include "asr_next_best_view/GetAttributedPointCloud.h"
25 
26 using namespace asr_next_best_view;
27 using namespace boost::unit_test;
28 
30 public:
31  UpdatePointCloudTest(bool silent) : BaseTest (true, silent) { }
32 
33  virtual ~UpdatePointCloudTest() {}
34 
35  int test(SetAttributedPointCloud apc, std::vector<std::string> object_type_name_list) {
36  ROS_INFO("Setting initial pose");
37  geometry_msgs::Pose initialPose;
38  initialPose.position.x = -0.383223;
39  initialPose.position.y = 0.157997;
40  initialPose.position.z = 1.32;
41  initialPose.orientation.x = -0.17266;
42  initialPose.orientation.y = 0.2115588;
43  initialPose.orientation.z = 0.60825979;
44  initialPose.orientation.w = 0.74528563;
45  this->setInitialPose(initialPose);
46 
47  // Set point cloud
48  if (!mSetPointCloudClient.call(apc.request, apc.response)) {
49  ROS_ERROR("Could not set initial point cloud.");
50  }
51 
52  asr_next_best_view::GetAttributedPointCloud gpc;
53  if (!mGetPointCloudClient.call(gpc)) {
54  ROS_ERROR("Could not get initial point cloud.");
55  }
56 
57  asr_next_best_view::GetNextBestView nbv;
58  nbv.request.current_pose = initialPose;
59 
60  int i = 1;
61  int deactivatedNormals = 0;
62  while(ros::ok() && i <= 3) {
63  ROS_INFO_STREAM("Calculating NBV #" << i);
64  if (!mGetNextBestViewClient.call(nbv.request, nbv.response)) {
65  ROS_ERROR("Something went wrong in next best view");
66  break;
67  }
68 
69  asr_next_best_view::UpdatePointCloud upc_req;
70  upc_req.request.object_type_name_list = object_type_name_list;
71  upc_req.request.pose_for_update = nbv.response.viewport.pose;
72  if(!mUpdatePointCloudClient.call(upc_req)) {
73  ROS_ERROR("Update Point Cloud failed!");
74  break;
75  }
76  deactivatedNormals += upc_req.response.deactivated_object_normals;
77  this->waitForEnter();
78  i++;
79  }
80  return deactivatedNormals;
81  }
82 
83  void iterationTest() {
84  SetAttributedPointCloud apc;
85 
86  ROS_INFO("Generating point cloud");
87  // number of objects in point cloud
88  int nHp = 2;
89  next_best_view::SimpleVector3* location = new SimpleVector3[nHp];
90  location[0] = SimpleVector3(-0.43232, 0.6958, 0.7211);
91  location[1] = SimpleVector3(-0.283309, 0.710407, 0.718543);
92 
93  next_best_view::SimpleQuaternion* orientation = new SimpleQuaternion[nHp];
94  orientation[0] = euler2Quaternion(-90, 0.0, 0.0);
95  orientation[1] = euler2Quaternion(-90, 0.0, 0.0);
96 
97  std::string* types = new std::string[nHp];
98  types[0] = "Smacks";
99  types[1] = "PlateDeep";
100 
101  int elementsPerHp[2] = { 3, 1 };
102 
103  for (std::size_t idx = 0; idx < (std::size_t)nHp; idx++) {
104  for (std::size_t cnt = 0; cnt < (std::size_t)elementsPerHp[idx]; cnt++) {
105  next_best_view::SimpleVector3 curLocation = location[idx];
106 
107  asr_msgs::AsrAttributedPoint element;
108 
109  geometry_msgs::Pose pose;
110  pose.orientation.w = orientation[idx].w();
111  pose.orientation.x = orientation[idx].x();
112  pose.orientation.y = orientation[idx].y();
113  pose.orientation.z = orientation[idx].z();
114  pose.position.x = curLocation[0] - 0.1 * cnt; // put smacks in row next to each other
115  pose.position.y = curLocation[1];
116  pose.position.z = curLocation[2];
117 
118  element.type = types[idx];
119  element.identifier = std::to_string(idx);
120  element.pose = pose;
121  apc.request.point_cloud.elements.push_back(element);
122  }
123  }
124 
125  int deactivatedSmacksNormals = test(apc, {"Smacks"});
126  int deactivatedSmacksPlateDeepNormals = test(apc, {"Smacks", "PlateDeep"});
127  BOOST_CHECK_MESSAGE(deactivatedSmacksNormals < deactivatedSmacksPlateDeepNormals, "Update deactivated the same or more normals without PlateDeep");
128  ROS_INFO("deactivated normals [Smacks, PlateDeep]: %d", deactivatedSmacksPlateDeepNormals);
129  ROS_INFO("deactivated normals [Smacks]: %d", deactivatedSmacksNormals);
130  }
131 };
132 
133 test_suite* init_unit_test_suite( int argc, char* argv[] ) {
134  ros::init(argc, argv, "nbv_test");
135  ros::start();
136 
137  test_suite* evaluation = BOOST_TEST_SUITE("Evaluation NBV");
138 
139  bool silent = false;
140  if (argc >= 2) {
141  // caseinsensitive comparison
142  if (boost::iequals(argv[1], "silent") || boost::iequals(argv[1], "s")) {
143  silent = true;
144  }
145  }
147 
148  evaluation->add(BOOST_CLASS_TEST_CASE(&UpdatePointCloudTest::iterationTest, testPtr));
149 
150  framework::master_test_suite().add(evaluation);
151 
152  return 0;
153 }
154 
155 
156 
157 
ROSCPP_DECL void start()
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:53
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
test_suite * init_unit_test_suite(int argc, char *argv[])
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
int test(SetAttributedPointCloud apc, std::vector< std::string > object_type_name_list)
#define ROS_INFO_STREAM(args)
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:67
#define ROS_ERROR(...)


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18