rapid
A ROS robotics library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
vector3.hpp
Go to the documentation of this file.
1 #include <exception>
2 
3 #include "Eigen/Dense"
4 #include "geometry_msgs/Point.h"
5 #include "geometry_msgs/Vector3.h"
6 #include "pcl/point_types.h"
7 
8 namespace rapid {
9 template <typename T>
10 void get_xyz(const T& value, double* x, double* y, double* z) {
11  throw std::invalid_argument("Unsupported type");
12 }
13 
14 template <>
15 void get_xyz(const Eigen::Vector3f& value, double* x, double* y, double* z) {
16  *x = value.x();
17  *y = value.y();
18  *z = value.z();
19 }
20 
21 template <>
22 void get_xyz(const Eigen::Vector3d& value, double* x, double* y, double* z) {
23  *x = value.x();
24  *y = value.y();
25  *z = value.z();
26 }
27 
28 template <>
29 void get_xyz(const geometry_msgs::Point& value, double* x, double* y,
30  double* z) {
31  *x = value.x;
32  *y = value.y;
33  *z = value.z;
34 }
35 
36 template <>
37 void get_xyz(const geometry_msgs::Vector3& value, double* x, double* y,
38  double* z) {
39  *x = value.x;
40  *y = value.y;
41  *z = value.z;
42 }
43 
44 template <>
45 void get_xyz(const pcl::PointXYZ& value, double* x, double* y, double* z) {
46  *x = value.x;
47  *y = value.y;
48  *z = value.z;
49 }
50 
51 template <>
52 void get_xyz(const pcl::PointXYZRGB& value, double* x, double* y, double* z) {
53  *x = value.x;
54  *y = value.y;
55  *z = value.z;
56 }
57 
58 template <>
59 void get_xyz(const pcl::Normal& value, double* x, double* y, double* z) {
60  *x = value.normal_x;
61  *y = value.normal_y;
62  *z = value.normal_z;
63 }
64 
78 template <typename T>
79 Eigen::Vector3d AsVector3d(const T& value) {
80  double x, y, z;
81  get_xyz<T>(value, &x, &y, &z);
82  Eigen::Vector3d result;
83  result << x, y, z;
84  return result;
85 }
86 } // namespace rapid
void get_xyz(const T &value, double *x, double *y, double *z)
Definition: vector3.hpp:10
Eigen::Vector3d AsVector3d(const T &value)
Function to get the XYZ value from common ROS types.
Definition: vector3.hpp:79