NormalGenerator.h
Go to the documentation of this file.
00001 
00021 #ifndef NORMAL_GENERATOR_H_
00022 #define NORMAL_GENERATOR_H_
00023 
00024 #include <Eigen/Dense>
00025 #include <geometry_msgs/Point.h>
00026 
00027 namespace object_database {
00028 
00029     using namespace Eigen;
00030 
00031     class NormalGenerator {
00032 
00033     private:
00034         static Matrix3d getRotationMatrix(double angle_x, double angle_y, double angle_z) {
00035             Matrix3d m;
00036             m = AngleAxisd(angle_x, Vector3d::UnitX())
00037               * AngleAxisd(angle_y,  Vector3d::UnitY())
00038               * AngleAxisd(angle_z, Vector3d::UnitZ());
00039 
00040             return m;
00041         }
00042 
00043         static geometry_msgs::Point convertVectorFromEigen(Vector3d vec) {
00044             geometry_msgs::Point point;
00045             point.x = vec[0];
00046             point.y = vec[1];
00047             point.z = vec[2];
00048             return point;
00049         }
00050 
00051     public:
00052         static std::vector<geometry_msgs::Point> getNormalVectors(double angle_x, double angle_y, double angle_z, const std::string &savePath = std::string()) {
00053             //so far angle_z is not used
00054 
00055             std::vector<Vector3d> normals;
00056             Vector3d base_vec(0, 0, -1);
00057 
00058             normals.push_back(getRotationMatrix(0, 0, 0) * base_vec);
00059 
00060             normals.push_back(getRotationMatrix(angle_x, 0, 0) * base_vec);
00061             normals.push_back(getRotationMatrix(-angle_x, 0, 0) * base_vec);
00062             normals.push_back(getRotationMatrix(0, angle_y, 0) * base_vec);
00063             normals.push_back(getRotationMatrix(0, -angle_y, 0) * base_vec);
00064 
00065             normals.push_back(getRotationMatrix(angle_x, angle_y, 0) * base_vec);
00066             normals.push_back(getRotationMatrix(-angle_x, angle_y, 0) * base_vec);
00067             normals.push_back(getRotationMatrix(angle_x, -angle_y, 0) * base_vec);
00068             normals.push_back(getRotationMatrix(-angle_x, -angle_y, 0) * base_vec);
00069 
00070             std::vector<geometry_msgs::Point> geom_points;
00071             for (std::vector<Vector3d>::iterator iter = normals.begin(); iter != normals.end(); ++iter) {
00072                 geom_points.push_back(convertVectorFromEigen(*iter));
00073             }
00074 
00075              //save calculated normals
00076             if (!savePath.empty()) {
00077                 std::stringstream ss;
00078                 for (std::vector<geometry_msgs::Point>::iterator iter = geom_points.begin(); iter != geom_points.end(); ++iter) {
00079                     geometry_msgs::Point normal = *iter;
00080                     ss << boost::lexical_cast<std::string>(normal.x) << "," << boost::lexical_cast<std::string>(normal.y) << "," << boost::lexical_cast<std::string>(normal.z) << ";";
00081 
00082                 }
00083                 std::string contents = ss.str();
00084                 std::ofstream f(savePath.c_str());
00085                 if ( !f ) {
00086                     ROS_DEBUG("Can't open file to save normals");
00087                 }
00088                 if ( !contents.empty() ) f << contents;
00089             }
00090 
00091             return geom_points;
00092         }
00093     };
00094 
00095 }
00096 
00097 #endif /* NORMAL_GENERATOR_H_ */


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 Thu Jun 6 2019 21:11:02