transformable_object.cpp
Go to the documentation of this file.
00001 #include <jsk_interactive_marker/transformable_object.h>
00002 
00003 using namespace jsk_interactive_marker;
00004 
00005 TransformableObject::TransformableObject(){
00006   ROS_INFO("Init TransformableObject");
00007   pose_.orientation.x = 0;
00008   pose_.orientation.y = 0;
00009   pose_.orientation.z = 0;
00010   pose_.orientation.w = 1;
00011 }
00012 
00013 std::vector<visualization_msgs::InteractiveMarkerControl> TransformableObject::makeRotateTransFixControl(){
00014   visualization_msgs::InteractiveMarkerControl control;
00015 
00016   std::vector<visualization_msgs::InteractiveMarkerControl> controls;
00017   control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00018   control.orientation.w = 1;
00019   control.orientation.x = 1;
00020   control.orientation.y = 0;
00021   control.orientation.z = 0;
00022   control.name = "rotate_x";
00023   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00024   controls.push_back(control);
00025   control.name = "move_x";
00026   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00027   controls.push_back(control);
00028 
00029   control.orientation.w = 1;
00030   control.orientation.x = 0;
00031   control.orientation.y = 1;
00032   control.orientation.z = 0;
00033   control.name = "rotate_z";
00034   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00035   controls.push_back(control);
00036   control.name = "move_z";
00037   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00038   controls.push_back(control);
00039 
00040   control.orientation.w = 1;
00041   control.orientation.x = 0;
00042   control.orientation.y = 0;
00043   control.orientation.z = 1;
00044   control.name = "rotate_y";
00045   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00046   controls.push_back(control);
00047   control.name = "move_y";
00048   control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00049   controls.push_back(control);
00050 
00051   return controls;
00052 };
00053 
00054 void TransformableObject::addMarker(visualization_msgs::InteractiveMarker &int_marker, bool always_visible, unsigned int interaction_mode)
00055 {
00056   visualization_msgs::Marker marker = getVisualizationMsgMarker();
00057   visualization_msgs::InteractiveMarkerControl marker_control;
00058   marker_control.always_visible = always_visible;
00059   marker_control.markers.push_back(marker);
00060   marker_control.interaction_mode = interaction_mode;
00061   int_marker.controls.push_back(marker_control);
00062 };
00063 
00064 void TransformableObject::addControl(visualization_msgs::InteractiveMarker &int_marker, bool fixed)
00065 {
00066   if(fixed){
00067     std::vector<visualization_msgs::InteractiveMarkerControl> rotate_controls = makeRotateTransFixControl();
00068     int_marker.controls.insert(int_marker.controls.end(), rotate_controls.begin(), rotate_controls.end());
00069   }
00070 };
00071 
00072 visualization_msgs::InteractiveMarker TransformableObject::getInteractiveMarker(){
00073   visualization_msgs::InteractiveMarker int_marker;
00074 
00075   addMarker(int_marker);
00076   addControl(int_marker);
00077   int_marker.header.frame_id = frame_id_;
00078   int_marker.name = name_;
00079   int_marker.description = description_;
00080   int_marker.pose = pose_;
00081   int_marker.scale = getInteractiveMarkerScale();
00082   return int_marker;
00083 };
00084 
00085 void TransformableObject::addPose(geometry_msgs::Pose msg){
00086   pose_.position.x += msg.position.x;
00087   pose_.position.y += msg.position.y;
00088   pose_.position.z += msg.position.z;
00089   float tmp_x = pose_.orientation.x, tmp_y = pose_.orientation.y,
00090     tmp_z = pose_.orientation.z, tmp_w = pose_.orientation.w;
00091 
00092 
00093   // pose_.orientation.w =
00094   //   tmp_w * msg.orientation.w -
00095   //   tmp_x * msg.orientation.x -
00096   //   tmp_y * msg.orientation.y -
00097   //   tmp_z * msg.orientation.z;
00098   // pose_.orientation.x =
00099   //   tmp_y * msg.orientation.z -
00100   //   tmp_z * msg.orientation.y +
00101   //   tmp_y * msg.orientation.x +
00102   //   tmp_x * msg.orientation.w;
00103   // pose_.orientation.y =
00104   //   tmp_z * msg.orientation.x -
00105   //   tmp_x * msg.orientation.z +
00106   //   tmp_w * msg.orientation.y +
00107   //   tmp_y * msg.orientation.w ;
00108   // pose_.orientation.z =
00109   //   tmp_x * msg.orientation.y -
00110   //   tmp_y * msg.orientation.x +
00111   //   tmp_w * msg.orientation.z +
00112   //   tmp_z * msg.orientation.w;
00113 
00114   pose_.orientation.w =
00115     msg.orientation.w * tmp_w -
00116     msg.orientation.x * tmp_x -
00117     msg.orientation.y * tmp_y -
00118     msg.orientation.z * tmp_z;
00119   pose_.orientation.x =
00120     msg.orientation.y * tmp_z -
00121     msg.orientation.z * tmp_y +
00122     msg.orientation.y * tmp_x +
00123     msg.orientation.x * tmp_w;
00124   pose_.orientation.y =
00125     msg.orientation.z * tmp_x -
00126     msg.orientation.x * tmp_z +
00127     msg.orientation.w * tmp_y +
00128     msg.orientation.y * tmp_w ;
00129   pose_.orientation.z =
00130     msg.orientation.x * tmp_y -
00131     msg.orientation.y * tmp_x +
00132     msg.orientation.w * tmp_z +
00133     msg.orientation.z * tmp_w;
00134 }


jsk_interactive_marker
Author(s): furuta
autogenerated on Mon Oct 6 2014 01:19:15