36 #include <boost/algorithm/string.hpp> 44 #define IS_INSTANCE(msg, type) \ 45 (msg->getDataType() == ros::message_traits::datatype<type>()) 47 MarkerPlugin::MarkerPlugin() :
48 config_widget_(new QWidget()),
55 p.setColor(QPalette::Background, Qt::white);
59 QPalette p3(
ui_.status->palette());
60 p3.setColor(QPalette::Text, Qt::red);
61 ui_.status->setPalette(p3);
63 QObject::connect(
ui_.selecttopic, SIGNAL(clicked()),
this, SLOT(
SelectTopic()));
64 QObject::connect(
ui_.topic, SIGNAL(editingFinished()),
this, SLOT(
TopicEdited()));
65 QObject::connect(
ui_.clear, SIGNAL(clicked()),
this, SLOT(
ClearHistory()));
76 ROS_DEBUG(
"MarkerPlugin::ClearHistory()");
85 "visualization_msgs/Marker",
86 "visualization_msgs/MarkerArray");
88 if (topic.
name.empty())
93 ui_.topic->setText(QString::fromStdString(topic.
name));
99 std::string topic =
ui_.topic->text().trimmed().toStdString();
118 ROS_INFO(
"Subscribing to %s", topic_.c_str());
128 handleMarker(*(msg->instantiate<visualization_msgs::Marker>()));
130 else if (
IS_INSTANCE(msg, visualization_msgs::MarkerArray))
136 PrintError(
"Unknown message type: " + msg->getDataType());
142 if (marker.type == visualization_msgs::Marker::ARROW &&
143 marker.points.size() == 1)
160 if (marker.action == visualization_msgs::Marker::ADD)
163 markerData.
points.clear();
164 markerData.
text.clear();
165 markerData.
stamp = marker.header.stamp;
167 markerData.
color = {marker.color.
r, marker.color.g, marker.color.b, marker.color.a};
168 markerData.
scale_x =
static_cast<float>(marker.scale.x);
169 markerData.
scale_y =
static_cast<float>(marker.scale.y);
170 markerData.
scale_z =
static_cast<float>(marker.scale.z);
176 QString name_string(marker.ns.c_str());
177 auto* item =
new QListWidgetItem(name_string,
ui_.nsList);
178 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
179 item->setCheckState(Qt::Unchecked);
180 item->setCheckState(Qt::Checked);
189 if (marker.pose.orientation.x ||
190 marker.pose.orientation.y ||
191 marker.pose.orientation.z ||
192 marker.pose.orientation.w)
195 marker.pose.orientation.y,
196 marker.pose.orientation.z,
197 marker.pose.orientation.w);
204 marker.pose.position.y,
205 marker.pose.position.z)));
207 markerData.
points.clear();
208 markerData.
text = std::string();
229 if (markerData.
display_type == visualization_msgs::Marker::ARROW)
235 if (marker.points.empty())
250 markerData.
points.push_back(point);
252 if (!marker.points.empty())
262 else if (markerData.
display_type == visualization_msgs::Marker::CYLINDER ||
263 markerData.
display_type == visualization_msgs::Marker::SPHERE ||
264 markerData.
display_type == visualization_msgs::Marker::TEXT_VIEW_FACING)
270 markerData.
points.push_back(point);
271 markerData.
text = marker.text;
273 else if (markerData.
display_type == visualization_msgs::Marker::CUBE)
278 point.
point =
tf::Point(marker.scale.x / 2, marker.scale.y / 2, 0.0);
280 markerData.
points.push_back(point);
282 point.
point =
tf::Point(-marker.scale.x / 2, marker.scale.y / 2, 0.0);
284 markerData.
points.push_back(point);
286 point.
point =
tf::Point(-marker.scale.x / 2, -marker.scale.y / 2, 0.0);
288 markerData.
points.push_back(point);
290 point.
point =
tf::Point(marker.scale.x / 2, -marker.scale.y / 2, 0.0);
292 markerData.
points.push_back(point);
294 else if (markerData.
display_type == visualization_msgs::Marker::LINE_STRIP ||
295 markerData.
display_type == visualization_msgs::Marker::LINE_LIST ||
296 markerData.
display_type == visualization_msgs::Marker::CUBE_LIST ||
297 markerData.
display_type == visualization_msgs::Marker::SPHERE_LIST ||
298 markerData.
display_type == visualization_msgs::Marker::POINTS ||
299 markerData.
display_type == visualization_msgs::Marker::TRIANGLE_LIST)
301 markerData.
points.reserve(marker.points.size());
303 for (
unsigned int i = 0; i < marker.points.size(); i++)
305 point.
point =
tf::Point(marker.points[i].x, marker.points[i].y, marker.points[i].z);
308 if (i < marker.colors.size())
310 point.
color = {marker.colors[i].
r, marker.colors[i].g, marker.colors[i].b, marker.colors[i].a};
317 markerData.
points.push_back(point);
325 else if (marker.action == visualization_msgs::Marker::DELETE)
327 markers_.erase(std::make_pair(marker.ns, marker.id));
329 else if (marker.action == 3)
349 if (markerData.
points.size() == 1)
374 double angle = std::atan2(pointDiff.
getY(), pointDiff.
getX());
385 for (
unsigned int i = 0; i < markers.markers.size(); i++)
422 for (
size_t i = 0; i <
ui_.nsList->count(); i++)
424 if (
ui_.nsList->item(i)->checkState() == Qt::Checked)
437 while (markerIter !=
markers_.end())
443 markerIter =
markers_.erase(markerIter);
460 if (marker.
display_type == visualization_msgs::Marker::ARROW) {
461 if (marker.
points.size() == 1) {
472 for (
const auto &point : marker.
points) {
473 glColor4f(point.color.r, point.color.g, point.color.b, point.color.a);
476 point.transformed_point.getX(),
477 point.transformed_point.getY());
479 point.transformed_arrow_point.getX(),
480 point.transformed_arrow_point.getY());
482 point.transformed_arrow_point.getX(),
483 point.transformed_arrow_point.getY());
485 point.transformed_arrow_left.getX(),
486 point.transformed_arrow_left.getY());
488 point.transformed_arrow_point.getX(),
489 point.transformed_arrow_point.getY());
491 point.transformed_arrow_right.getX(),
492 point.transformed_arrow_right.getY());
497 else if (marker.
display_type == visualization_msgs::Marker::LINE_STRIP) {
498 glLineWidth(std::max(1.0
f, marker.
scale_x));
499 glBegin(GL_LINE_STRIP);
501 for (
const auto &point : marker.
points) {
502 glColor4f(point.color.r, point.color.g, point.color.b, point.color.a);
505 point.transformed_point.getX(),
506 point.transformed_point.getY());
511 else if (marker.
display_type == visualization_msgs::Marker::LINE_LIST) {
512 glLineWidth(std::max(1.0
f, marker.
scale_x));
515 for (
const auto &point : marker.
points) {
516 glColor4f(point.color.r, point.color.g, point.color.b, point.color.a);
519 point.transformed_point.getX(),
520 point.transformed_point.getY());
525 else if (marker.
display_type == visualization_msgs::Marker::POINTS) {
526 glPointSize(std::max(1.0
f, marker.
scale_x));
529 for (
const auto &point : marker.
points) {
530 glColor4f(point.color.r, point.color.g, point.color.b, point.color.a);
533 point.transformed_point.getX(),
534 point.transformed_point.getY());
539 else if (marker.
display_type == visualization_msgs::Marker::TRIANGLE_LIST) {
540 glBegin(GL_TRIANGLES);
542 for (
const auto &point : marker.
points) {
543 glColor4f(point.color.r, point.color.g, point.color.b, point.color.a);
546 point.transformed_point.getX(),
547 point.transformed_point.getY());
552 else if (marker.
display_type == visualization_msgs::Marker::CYLINDER ||
553 marker.
display_type == visualization_msgs::Marker::SPHERE ||
554 marker.
display_type == visualization_msgs::Marker::SPHERE_LIST) {
555 for (
const auto &point : marker.
points) {
556 glColor4f(point.color.r, point.color.g, point.color.b, point.color.a);
558 glBegin(GL_TRIANGLE_FAN);
561 double marker_x = point.transformed_point.getX();
562 double marker_y = point.transformed_point.getY();
564 glVertex2d(marker_x, marker_y);
566 for (int32_t i = 0; i <= 360; i += 10) {
573 marker_x + std::sin(radians) * marker.
scale_x,
574 marker_y + std::cos(radians) * marker.
scale_y);
580 else if (marker.
display_type == visualization_msgs::Marker::CUBE ||
581 marker.
display_type == visualization_msgs::Marker::CUBE_LIST) {
582 glBegin(GL_TRIANGLE_FAN);
583 for (
const auto &point : marker.
points) {
584 glColor4f(point.color.r, point.color.g, point.color.b, point.color.a);
586 glVertex2d(point.transformed_point.getX(), point.transformed_point.getY());
598 for (
size_t i = 0; i <
ui_.nsList->count(); i++)
600 if (
ui_.nsList->item(i)->checkState() == Qt::Checked)
619 QTransform
tf = painter->worldTransform();
620 QFont font(
"Helvetica", 10);
621 painter->setFont(font);
623 painter->resetTransform();
625 for (
auto markerIter =
markers_.begin(); markerIter !=
markers_.end(); ++markerIter)
629 if (marker.
display_type != visualization_msgs::Marker::TEXT_VIEW_FACING ||
641 QPen pen(QBrush(QColor::fromRgbF(marker.
color.
r, marker.
color.
g,
643 painter->setPen(pen);
649 auto text = QString::fromStdString(marker.
text);
651 QRectF rect(point, QSizeF(10,10));
652 rect = painter->boundingRect(rect, Qt::AlignLeft | Qt::AlignHCenter, text);
653 painter->drawText(rect, text);
663 for (
auto markerIter =
markers_.begin(); markerIter !=
markers_.end(); ++markerIter)
672 if (marker.
display_type == visualization_msgs::Marker::ARROW)
680 for (
auto &point : marker.
points)
682 point.transformed_point = transform * (marker.
local_transform * point.point);
698 node[
"topic"] >> topic;
699 ui_.topic->setText(boost::trim_copy(topic).c_str());
707 emitter << YAML::Key <<
"topic" << YAML::Value << boost::trim_copy(
ui_.topic->text().toStdString());
bool GetTransform(const ros::Time &stamp, swri_transform_util::Transform &transform, bool use_latest_transforms=true)
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
static tf::Quaternion createQuaternionFromRPY(double roll, double pitch, double yaw)
static const long double _deg_2_rad
void transform(Route &route, const swri_transform_util::Transform &transform, const std::string &target_frame)
tf::Point transformed_arrow_right
std::unordered_map< std::string, bool, MarkerNsHash > marker_visible_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void handleMessage(const topic_tools::ShapeShifter::ConstPtr &msg)
void handleMarker(const visualization_msgs::Marker &marker)
tf::Quaternion orientation
void Draw(double x, double y, double scale)
static void PrintWarningHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
tf::Point transformed_point
ros::Subscriber marker_sub_
static void PrintErrorHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
TFSIMD_FORCE_INLINE const tfScalar & getY() const
std::string target_frame_
void PrintError(const std::string &message)
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
QWidget * GetConfigWidget(QWidget *parent)
void transformArrow(MarkerData &markerData, const swri_transform_util::Transform &transform)
void LoadConfig(const YAML::Node &node, const std::string &path)
#define IS_INSTANCE(msg, type)
TFSIMD_FORCE_INLINE const tfScalar & x() const
tf::Point transformed_arrow_point
void PrintWarning(const std::string &message)
tf::Point transformed_arrow_left
#define ROS_WARN_ONCE(...)
uint32_t getNumPublishers() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
ROSTIME_DECL const Time TIME_MAX
void timerEvent(QTimerEvent *)
void Paint(QPainter *painter, double x, double y, double scale)
swri_transform_util::Transform local_transform
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
TFSIMD_FORCE_INLINE const tfScalar & getX() const
void handleMarkerArray(const visualization_msgs::MarkerArray &markers)
std::unordered_map< MarkerId, MarkerData, MarkerIdHash > markers_
void PrintInfo(const std::string &message)
std::vector< StampedPoint > points
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
bool Initialize(QGLWidget *canvas)