clickable_positions.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * Copyright (C) Brno University of Technology
00005  *
00006  * This file is part of software developed by Robo@FIT group.
00007  *
00008  * Author: Tomas Lokaj (xlokaj03@stud.fit.vutbr.cz)
00009  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00010  * Date: 12/09/2012
00011  *
00012  * This file is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License as published by
00014  * the Free Software Foundation, either version 3 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This file is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
00024  */
00025 
00026 #include "srs_interaction_primitives/clickable_positions/clickable_positions.h"
00027 
00028 namespace srs_interaction_primitives
00029 {
00030 
00031 ClickablePositionsMarker::ClickablePositionsMarker(InteractiveMarkerServerPtr imServer, std::string frame_id,
00032                                                    std::string topic_suffix, float radius, std_msgs::ColorRGBA color,
00033                                                    std::vector<geometry_msgs::Point> positions)
00034 {
00035   imServer_ = imServer;
00036   frame_id_ = frame_id;
00037   topic_suffix_ = topic_suffix;
00038   radius_ = radius;
00039   color_ = color;
00040   positions_ = positions;
00041 
00042   click_publisher_ = nh_.advertise<srs_interaction_primitives::PositionClicked>(BUT_PositionClicked_TOPIC(topic_suffix),
00043                                                                                 1);
00044 
00045   create();
00046 }
00047 
00048 ClickablePositionsMarker::~ClickablePositionsMarker()
00049 {
00050   click_publisher_.shutdown();
00051 }
00052 
00053 void ClickablePositionsMarker::create()
00054 {
00055 
00056   interactive_marker_.header.frame_id = frame_id_;
00057   interactive_marker_.name = "click_positions_marker_" + topic_suffix_;
00058 
00059   for (unsigned int i = 0; i < positions_.size(); i++)
00060   {
00061     std::stringstream cname;
00062     cname << interactive_marker_.name << "_" << i;
00063     visualization_msgs::InteractiveMarkerControl im_control;
00064     im_control.name = cname.str();
00065     im_control.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00066     im_control.always_visible = true;
00067     visualization_msgs::Marker marker;
00068     marker.pose.position = positions_.at(i);
00069     marker.type = visualization_msgs::Marker::SPHERE;
00070     marker.color = color_;
00071     marker.scale.x = radius_;
00072     marker.scale.y = radius_;
00073     marker.scale.z = radius_;
00074     im_control.markers.push_back(marker);
00075     interactive_marker_.controls.push_back(im_control);
00076     controls_.insert(std::make_pair(cname.str(), positions_.at(i)));
00077   }
00078 }
00079 
00080 void ClickablePositionsMarker::markerFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
00081 {
00082   if (feedback->event_type == visualization_msgs::InteractiveMarkerFeedback::MOUSE_UP)
00083   {
00084     ROS_INFO("Clicked");
00085     PositionClicked msg;
00086     msg.position = controls_[feedback->control_name];
00087     click_publisher_.publish(msg);
00088     imServer_->erase(interactive_marker_.name);
00089     imServer_->applyChanges();
00090   }
00091 }
00092 
00093 } /* namespace srs_interaction_primitives */


srs_interaction_primitives
Author(s): Tomas Lokaj, Michal Spanel (spanel@fit.vutbr.cz)
autogenerated on Mon Oct 6 2014 07:55:11