Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <interactive_markers/interactive_marker_server.h>
00036 #include <jsk_pcl_ros/Int32Stamped.h>
00037 #include <jsk_pcl_ros/BoundingBoxArray.h>
00038 #include <ros/ros.h>
00039 #include <boost/algorithm/string.hpp>
00040
00041
00042 boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server;
00043 boost::mutex mutex;
00044 ros::Publisher pub, box_pub, box_arr_pub;
00045 jsk_pcl_ros::BoundingBoxArray::ConstPtr box_msg;
00046
00047 void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
00048 {
00049 boost::mutex::scoped_lock(mutex);
00050
00051 if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_DOWN) {
00052 std::string control_name = feedback->control_name;
00053 ROS_INFO_STREAM("control_name: " << control_name);
00054 std::list<std::string> splitted_string;
00055 boost::split(splitted_string, control_name, boost::is_space());
00056 jsk_pcl_ros::Int32Stamped index;
00057 index.header.stamp.sec = boost::lexical_cast<int>(splitted_string.front());
00058 splitted_string.pop_front();
00059 index.header.stamp.nsec = boost::lexical_cast<int>(splitted_string.front());
00060 splitted_string.pop_front();
00061 index.data = boost::lexical_cast<int>(splitted_string.front());
00062 pub.publish(index);
00063 box_pub.publish(box_msg->boxes[index.data]);
00064 jsk_pcl_ros::BoundingBoxArray array_msg;
00065 array_msg.header = box_msg->header;
00066 array_msg.boxes.push_back(box_msg->boxes[index.data]);
00067 box_arr_pub.publish(array_msg);
00068 }
00069 }
00070
00071 void boxCallback(const jsk_pcl_ros::BoundingBoxArray::ConstPtr& msg)
00072 {
00073 boost::mutex::scoped_lock(mutex);
00074 box_msg = msg;
00075 server->clear();
00076
00077 for (size_t i = 0; i < msg->boxes.size(); i++) {
00078 jsk_pcl_ros::BoundingBox box = msg->boxes[i];
00079 visualization_msgs::InteractiveMarker int_marker;
00080 int_marker.header.frame_id = box.header.frame_id;
00081 int_marker.pose = box.pose;
00082 {
00083 std::stringstream ss;
00084 ss << "box" << "_" << i;
00085 int_marker.name = ss.str();
00086 }
00087 visualization_msgs::InteractiveMarkerControl control;
00088 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00089
00090 {
00091 std::stringstream ss;
00092
00093 ss << box.header.stamp.sec << " " << box.header.stamp.nsec << " " << i;
00094 control.name = ss.str();
00095 }
00096 visualization_msgs::Marker marker;
00097 marker.type = visualization_msgs::Marker::CUBE;
00098 marker.scale.x = box.dimensions.x + 0.01;
00099 marker.scale.y = box.dimensions.y + 0.01;
00100 marker.scale.z = box.dimensions.z + 0.01;
00101 marker.color.r = 1.0;
00102 marker.color.g = 1.0;
00103 marker.color.b = 1.0;
00104 marker.color.a = 0.0;
00105 control.markers.push_back(marker);
00106 control.always_visible = true;
00107 int_marker.controls.push_back(control);
00108 server->insert(int_marker);
00109 server->setCallback(int_marker.name, &processFeedback);
00110 }
00111 server->applyChanges();
00112 }
00113
00114 int main(int argc, char** argv)
00115 {
00116 ros::init(argc, argv, "bounding_box_interactive_marker");
00117 ros::NodeHandle n, pnh("~");
00118 server.reset(new interactive_markers::InteractiveMarkerServer("bounding_box_interactive_marker", "", false));
00119 pub = pnh.advertise<jsk_pcl_ros::Int32Stamped>("selected_index", 1);
00120 box_pub = pnh.advertise<jsk_pcl_ros::BoundingBox>("selected_box", 1);
00121 box_arr_pub = pnh.advertise<jsk_pcl_ros::BoundingBoxArray>("selected_box_array", 1);
00122 ros::Subscriber sub = pnh.subscribe("bounding_box_array", 1, boxCallback);
00123 ros::spin();
00124 server.reset();
00125 return 0;
00126 }