36 #include <boost/algorithm/string.hpp> 44 #define IS_INSTANCE(msg, type) \ 45 (msg->getDataType() == ros::message_traits::datatype<type>()) 47 ObjectPlugin::ObjectPlugin() :
48 config_widget_(new QWidget()),
53 ui_.color->setColor(Qt::red);
57 p.setColor(QPalette::Background, Qt::white);
61 QPalette p3(
ui_.status->palette());
62 p3.setColor(QPalette::Text, Qt::red);
63 ui_.status->setPalette(p3);
65 QObject::connect(
ui_.selecttopic, SIGNAL(clicked()),
this, SLOT(
SelectTopic()));
66 QObject::connect(
ui_.topic, SIGNAL(editingFinished()),
this, SLOT(
TopicEdited()));
67 QObject::connect(
ui_.color, SIGNAL(colorEdited(
const QColor&)),
this,
90 "marti_nav_msgs/TrackedObjectArray",
91 "marti_nav_msgs/ObstacleArray");
93 if (topic.
name.empty())
98 ui_.topic->setText(QString::fromStdString(topic.
name));
104 std::string topic =
ui_.topic->text().trimmed().toStdString();
121 ROS_INFO(
"Subscribing to %s", topic_.c_str());
129 if (
IS_INSTANCE(msg, marti_nav_msgs::TrackedObjectArray))
133 auto objs = msg->instantiate<marti_nav_msgs::TrackedObjectArray>();
134 objects_.reserve(objs->objects.size());
135 for (
const auto& obj: objs->objects)
140 else if (
IS_INSTANCE(msg, marti_nav_msgs::ObstacleArray))
144 auto objs = msg->instantiate<marti_nav_msgs::ObstacleArray>();
145 objects_.reserve(objs->obstacles.size());
146 for (
const auto& obj: objs->obstacles)
153 PrintError(
"Unknown message type: " + msg->getDataType());
169 if (obj.pose.orientation.x ||
170 obj.pose.orientation.y ||
171 obj.pose.orientation.z ||
172 obj.pose.orientation.w)
175 obj.pose.orientation.y,
176 obj.pose.orientation.z,
177 obj.pose.orientation.w);
186 obj.pose.position.z)));
189 data.
stamp = header.stamp;
198 data.
polygon.reserve(obj.polygon.size()+1);
199 for (
auto& point: obj.polygon)
204 data.
polygon.push_back({pt, transformed});
225 if (obj.pose.pose.orientation.x ||
226 obj.pose.pose.orientation.y ||
227 obj.pose.pose.orientation.z ||
228 obj.pose.pose.orientation.w)
231 obj.pose.pose.orientation.y,
232 obj.pose.pose.orientation.z,
233 obj.pose.pose.orientation.w);
241 obj.pose.pose.position.y,
242 obj.pose.pose.position.z)));
243 data.
stamp = obj.header.stamp;
245 data.
id = std::to_string(obj.id);
254 data.
polygon.reserve(obj.polygon.size()+1);
255 for (
auto& point: obj.polygon)
260 data.
polygon.push_back({pt, transformed});
303 if (!obj.transformed)
311 glBegin(GL_LINE_STRIP);
313 for (
const auto &point : obj.polygon) {
315 point.transformed_point.getX(),
316 point.transformed_point.getY());
327 if (!
ui_.show_ids->isChecked())
341 QTransform
tf = painter->worldTransform();
342 QFont font(
"Helvetica", 10);
343 painter->setFont(font);
345 painter->resetTransform();
349 if (!obj.transformed)
354 QPen pen(QBrush(QColor::fromRgbF(0, 0, 0, 1)), 1);
355 painter->setPen(pen);
361 auto text = QString::fromStdString(obj.id);
363 QRectF rect(point, QSizeF(10,10));
364 rect = painter->boundingRect(rect, Qt::AlignLeft | Qt::AlignHCenter, text);
365 painter->drawText(rect, text);
378 if (
GetTransform(obj.source_frame, obj.stamp, transform))
380 obj.transformed =
true;
382 for (
auto &point : obj.polygon)
384 point.transformed_point = transform * point.point;
389 obj.transformed =
false;
399 node[
"topic"] >> topic;
400 ui_.topic->setText(boost::trim_copy(topic).c_str());
408 node[
"color"] >> color;
409 QColor qcolor(color.c_str());
411 ui_.color->setColor(qcolor);
414 if (node[
"show_ids"])
417 node[
"show_ids"] >> checked;
418 ui_.show_ids->setChecked( checked );
424 emitter << YAML::Key <<
"topic" << YAML::Value << boost::trim_copy(
ui_.topic->text().toStdString());
426 emitter << YAML::Key <<
"color" << YAML::Value
427 <<
ui_.color->color().name().toStdString();
429 emitter << YAML::Key <<
"show_ids" << YAML::Value <<
ui_.show_ids->isChecked();
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)
void timerEvent(QTimerEvent *)
void transform(Route &route, const swri_transform_util::Transform &transform, const std::string &target_frame)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::vector< ObjectData > objects_
void Draw(double x, double y, double scale)
void handleMessage(const topic_tools::ShapeShifter::ConstPtr &msg)
bool Initialize(QGLWidget *canvas)
static void PrintWarningHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void Paint(QPainter *painter, double x, double y, double scale)
static void PrintErrorHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
void PrintWarning(const std::string &message)
tf::Point transformed_point
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
QWidget * GetConfigWidget(QWidget *parent)
void SetColor(const QColor &color)
std::vector< StampedPoint > polygon
TFSIMD_FORCE_INLINE const tfScalar & x() const
void LoadConfig(const YAML::Node &node, const std::string &path)
uint32_t getNumPublishers() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
void handleObstacle(const marti_nav_msgs::Obstacle &obj, const std_msgs::Header &header)
void handleTrack(const marti_nav_msgs::TrackedObject &obj)
ros::Subscriber object_sub_
void PrintInfo(const std::string &message)
swri_transform_util::Transform local_transform
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void PrintError(const std::string &message)
#define IS_INSTANCE(msg, type)