36 #include <jsk_recognition_msgs/Int32Stamped.h> 37 #include <jsk_interactive_marker/IndexRequest.h> 38 #include <jsk_recognition_msgs/PolygonArray.h> 40 #include <boost/algorithm/string.hpp> 44 std::shared_ptr<interactive_markers::InteractiveMarkerServer>
server;
53 jsk_recognition_msgs::PolygonArray array_msg;
55 array_msg.polygons.push_back(
polygon_msg->polygons[msg.data]);
56 polygon_arr_pub.
publish(array_msg);
60 const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
63 if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_DOWN) {
64 std::string control_name = feedback->control_name;
65 ROS_INFO(
"control_name: %s", control_name.c_str());
66 std::list<std::string> splitted_string;
67 boost::split(splitted_string, control_name, boost::is_space());
68 jsk_recognition_msgs::Int32Stamped
index;
69 index.header.stamp.sec = boost::lexical_cast<
int>(splitted_string.front());
70 splitted_string.pop_front();
71 index.header.stamp.nsec = boost::lexical_cast<
int>(splitted_string.front());
72 splitted_string.pop_front();
73 index.data = boost::lexical_cast<
int>(splitted_string.front());
89 for (
size_t i = 0; i < msg->polygons.size(); i++) {
90 geometry_msgs::PolygonStamped polygon = msg->polygons[i];
91 visualization_msgs::InteractiveMarker int_marker;
92 int_marker.header.frame_id = polygon.header.frame_id;
93 int_marker.pose.orientation.w = 1;
96 ss <<
"polygon" <<
"_" << i;
97 int_marker.name = ss.str();
99 visualization_msgs::InteractiveMarkerControl control;
100 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
103 std::stringstream ss;
105 ss << polygon.header.stamp.sec <<
" " << polygon.header.stamp.nsec <<
" " << i;
106 control.name = ss.str();
108 visualization_msgs::Marker
marker;
109 marker.type = visualization_msgs::Marker::TRIANGLE_LIST;
110 marker.scale.x = 1.0;
111 marker.scale.y = 1.0;
112 marker.scale.z = 1.0;
113 marker.color.r = 1.0;
114 marker.color.g = 1.0;
115 marker.color.b = 1.0;
116 marker.color.a = 0.0;
119 std::vector<jsk_recognition_utils::Polygon::Ptr> decomposed_triangles
120 = polygon_obj->decomposeToTriangles();
121 for (
size_t j = 0; j < decomposed_triangles.size(); j++) {
123 = decomposed_triangles[j]->getVertices();
124 for (
size_t k = 0; k < vs.size(); k++) {
125 geometry_msgs::Point
p;
129 marker.points.push_back(p);
132 control.markers.push_back(marker);
133 control.always_visible =
true;
134 int_marker.controls.push_back(control);
135 server->insert(int_marker);
141 int main(
int argc,
char** argv)
143 ros::init(argc, argv,
"polygon_interactive_marker");
146 pub = pnh.
advertise<jsk_recognition_msgs::Int32Stamped>(
"selected_index", 1);
147 polygon_pub = pnh.
advertise<geometry_msgs::PolygonStamped>(
"selected_polygon", 1);
148 polygon_arr_pub = pnh.
advertise<jsk_recognition_msgs::PolygonArray>(
"selected_polygon_array", 1);
void publishClickedPolygon(jsk_recognition_msgs::Int32Stamped &msg)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::Publisher polygon_pub
void polygonCallback(const jsk_recognition_msgs::PolygonArray::ConstPtr &msg)
ROSCPP_DECL void spin(Spinner &spinner)
static Polygon::Ptr fromROSMsgPtr(const geometry_msgs::Polygon &polygon)
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
ros::Publisher polygon_arr_pub
std::shared_ptr< interactive_markers::InteractiveMarkerServer > server
jsk_recognition_msgs::PolygonArray::ConstPtr polygon_msg
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > Vertices
int main(int argc, char **argv)