axes_marker.cpp
Go to the documentation of this file.
00001 #include "surface_perception/axes_marker.h"
00002 
00003 #include "Eigen/Eigen"
00004 #include "geometry_msgs/Point.h"
00005 #include "geometry_msgs/Pose.h"
00006 #include "ros/ros.h"
00007 #include "std_msgs/ColorRGBA.h"
00008 #include "visualization_msgs/Marker.h"
00009 #include "visualization_msgs/MarkerArray.h"
00010 
00011 namespace surface_perception {
00012 visualization_msgs::MarkerArray GetAxesMarkerArray(
00013     const std::string& name_space, const std::string& frame_id,
00014     const geometry_msgs::Pose& pose, double scale) {
00015   visualization_msgs::MarkerArray res;
00016   Eigen::Matrix3f rotation_matrix =
00017       Eigen::Quaternionf(pose.orientation.w, pose.orientation.x,
00018                          pose.orientation.y, pose.orientation.z)
00019           .toRotationMatrix();
00020 
00021   // X axis setup
00022   visualization_msgs::Marker x_axis;
00023   x_axis.ns = name_space;
00024   x_axis.header.frame_id = frame_id;
00025   x_axis.id = 0;
00026   x_axis.type = visualization_msgs::Marker::CYLINDER;
00027   x_axis.scale.x = x_axis.scale.y = std::max(scale * 0.1, 0.01);
00028   x_axis.scale.z = scale;
00029 
00030   // X axis orientation
00031   Eigen::Matrix3f x_matrix;
00032   x_matrix.col(0) = rotation_matrix.col(2) * -1.0;
00033   x_matrix.col(2) = rotation_matrix.col(0);
00034   x_matrix.col(1) = rotation_matrix.col(1);
00035   Eigen::Quaternionf x_quaternion(x_matrix);
00036   x_axis.pose.orientation.x = x_quaternion.x();
00037   x_axis.pose.orientation.y = x_quaternion.y();
00038   x_axis.pose.orientation.z = x_quaternion.z();
00039   x_axis.pose.orientation.w = x_quaternion.w();
00040 
00041   // Shift x axis position a bit to relocate the cylinder
00042   Eigen::Vector3f x_position =
00043       Eigen::Vector3f(pose.position.x, pose.position.y, pose.position.z) +
00044       x_matrix.col(2) * scale / 2.0;
00045   x_axis.pose.position.x = x_position(0);
00046   x_axis.pose.position.y = x_position(1);
00047   x_axis.pose.position.z = x_position(2);
00048 
00049   // X axis color
00050   x_axis.color.r = 1.0;
00051   x_axis.color.g = 0.0;
00052   x_axis.color.b = 0.0;
00053   x_axis.color.a = 1.0;
00054 
00055   // Y axis setup
00056   visualization_msgs::Marker y_axis;
00057   y_axis.ns = name_space;
00058   y_axis.header.frame_id = frame_id;
00059   y_axis.id = 1;
00060   y_axis.type = visualization_msgs::Marker::CYLINDER;
00061   y_axis.scale.x = y_axis.scale.y = std::max(scale * 0.1, 0.01);
00062   y_axis.scale.z = scale;
00063 
00064   // Y axis orientation
00065   Eigen::Matrix3f y_matrix;
00066   y_matrix.col(0) = rotation_matrix.col(0);
00067   y_matrix.col(2) = rotation_matrix.col(1);
00068   y_matrix.col(1) = rotation_matrix.col(2) * -1.0;
00069   Eigen::Quaternionf y_quaternion(y_matrix);
00070   y_axis.pose.orientation.x = y_quaternion.x();
00071   y_axis.pose.orientation.y = y_quaternion.y();
00072   y_axis.pose.orientation.z = y_quaternion.z();
00073   y_axis.pose.orientation.w = y_quaternion.w();
00074 
00075   // Y axis position shifting
00076   Eigen::Vector3f y_position =
00077       Eigen::Vector3f(pose.position.x, pose.position.y, pose.position.z) +
00078       y_matrix.col(2) * scale / 2.0;
00079   y_axis.pose.position.x = y_position(0);
00080   y_axis.pose.position.y = y_position(1);
00081   y_axis.pose.position.z = y_position(2);
00082 
00083   // Y axis color
00084   y_axis.color.r = 0.0;
00085   y_axis.color.g = 1.0;
00086   y_axis.color.b = 0.0;
00087   y_axis.color.a = 1.0;
00088 
00089   // Z axis setup
00090   visualization_msgs::Marker z_axis;
00091   z_axis.ns = name_space;
00092   z_axis.header.frame_id = frame_id;
00093   z_axis.id = 2;
00094   z_axis.type = visualization_msgs::Marker::CYLINDER;
00095   z_axis.scale.x = z_axis.scale.y = std::max(scale * 0.1, 0.01);
00096   z_axis.scale.z = scale;
00097 
00098   // Z axis orientation, which has the same orientation as the given pose.
00099   z_axis.pose.orientation = pose.orientation;
00100 
00101   // Z axis position shifting
00102   z_axis.pose.position = pose.position;
00103   Eigen::Vector3f z_position =
00104       Eigen::Vector3f(pose.position.x, pose.position.y, pose.position.z) +
00105       rotation_matrix.col(2) * scale / 2.0;
00106   z_axis.pose.position.x = z_position(0);
00107   z_axis.pose.position.y = z_position(1);
00108   z_axis.pose.position.z = z_position(2);
00109 
00110   // Z axis color
00111   z_axis.color.r = 0.0;
00112   z_axis.color.g = 0.0;
00113   z_axis.color.b = 1.0;
00114   z_axis.color.a = 1.0;
00115 
00116   res.markers.push_back(x_axis);
00117   res.markers.push_back(y_axis);
00118   res.markers.push_back(z_axis);
00119 
00120   return res;
00121 }
00122 }  // namespace surface_perception


surface_perception
Author(s): Yu-Tang Peng
autogenerated on Thu Jun 6 2019 17:36:21