NormalGenerator.h
Go to the documentation of this file.
1 
21 #ifndef NORMAL_GENERATOR_H_
22 #define NORMAL_GENERATOR_H_
23 
24 #include <Eigen/Dense>
25 #include <geometry_msgs/Point.h>
26 
27 namespace object_database {
28 
29  using namespace Eigen;
30 
32 
33  private:
34  static Matrix3d getRotationMatrix(double angle_x, double angle_y, double angle_z) {
35  Matrix3d m;
36  m = AngleAxisd(angle_x, Vector3d::UnitX())
37  * AngleAxisd(angle_y, Vector3d::UnitY())
38  * AngleAxisd(angle_z, Vector3d::UnitZ());
39 
40  return m;
41  }
42 
43  static geometry_msgs::Point convertVectorFromEigen(Vector3d vec) {
44  geometry_msgs::Point point;
45  point.x = vec[0];
46  point.y = vec[1];
47  point.z = vec[2];
48  return point;
49  }
50 
51  public:
52  static std::vector<geometry_msgs::Point> getNormalVectors(double angle_x, double angle_y, double angle_z, const std::string &savePath = std::string()) {
53  //so far angle_z is not used
54 
55  std::vector<Vector3d> normals;
56  Vector3d base_vec(0, 0, -1);
57 
58  normals.push_back(getRotationMatrix(0, 0, 0) * base_vec);
59 
60  normals.push_back(getRotationMatrix(angle_x, 0, 0) * base_vec);
61  normals.push_back(getRotationMatrix(-angle_x, 0, 0) * base_vec);
62  normals.push_back(getRotationMatrix(0, angle_y, 0) * base_vec);
63  normals.push_back(getRotationMatrix(0, -angle_y, 0) * base_vec);
64 
65  normals.push_back(getRotationMatrix(angle_x, angle_y, 0) * base_vec);
66  normals.push_back(getRotationMatrix(-angle_x, angle_y, 0) * base_vec);
67  normals.push_back(getRotationMatrix(angle_x, -angle_y, 0) * base_vec);
68  normals.push_back(getRotationMatrix(-angle_x, -angle_y, 0) * base_vec);
69 
70  std::vector<geometry_msgs::Point> geom_points;
71  for (std::vector<Vector3d>::iterator iter = normals.begin(); iter != normals.end(); ++iter) {
72  geom_points.push_back(convertVectorFromEigen(*iter));
73  }
74 
75  //save calculated normals
76  if (!savePath.empty()) {
77  std::stringstream ss;
78  for (std::vector<geometry_msgs::Point>::iterator iter = geom_points.begin(); iter != geom_points.end(); ++iter) {
79  geometry_msgs::Point normal = *iter;
80  ss << boost::lexical_cast<std::string>(normal.x) << "," << boost::lexical_cast<std::string>(normal.y) << "," << boost::lexical_cast<std::string>(normal.z) << ";";
81 
82  }
83  std::string contents = ss.str();
84  std::ofstream f(savePath.c_str());
85  if ( !f ) {
86  ROS_DEBUG("Can't open file to save normals");
87  }
88  if ( !contents.empty() ) f << contents;
89  }
90 
91  return geom_points;
92  }
93  };
94 
95 }
96 
97 #endif /* NORMAL_GENERATOR_H_ */
static geometry_msgs::Point convertVectorFromEigen(Vector3d vec)
static std::vector< geometry_msgs::Point > getNormalVectors(double angle_x, double angle_y, double angle_z, const std::string &savePath=std::string())
::xsd::cxx::tree::string< char, simple_type > string
static Matrix3d getRotationMatrix(double angle_x, double angle_y, double angle_z)
#define ROS_DEBUG(...)


asr_object_database
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Braun Kai, Heizmann Heinrich, Heller Florian, Kasper Alexander, Marek Felix, Mehlhaus Jonas, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Walter Milena
autogenerated on Mon Feb 28 2022 21:49:21