38 #include <boost/algorithm/string.hpp> 58 TexturedMarkerPlugin::TexturedMarkerPlugin() :
59 config_widget_(new QWidget()),
60 is_marker_array_(false)
66 p.setColor(QPalette::Background, Qt::white);
70 QPalette p3(
ui_.status->palette());
71 p3.setColor(QPalette::Text, Qt::red);
72 ui_.status->setPalette(p3);
74 QObject::connect(
ui_.selecttopic, SIGNAL(clicked()),
this, SLOT(
SelectTopic()));
75 QObject::connect(
ui_.topic, SIGNAL(editingFinished()),
this, SLOT(
TopicEdited()));
79 qRegisterMetaType<marti_visualization_msgs::TexturedMarkerConstPtr>(
"TexturedMarkerConstPtr");
80 qRegisterMetaType<marti_visualization_msgs::TexturedMarkerArrayConstPtr>(
"TexturedMarkerArrayConstPtr");
82 QObject::connect(
this,
83 SIGNAL(
MarkerReceived(
const marti_visualization_msgs::TexturedMarkerConstPtr)),
85 SLOT(
ProcessMarker(
const marti_visualization_msgs::TexturedMarkerConstPtr)));
86 QObject::connect(
this,
87 SIGNAL(
MarkersReceived(
const marti_visualization_msgs::TexturedMarkerArrayConstPtr)),
89 SLOT(
ProcessMarkers(
const marti_visualization_msgs::TexturedMarkerArrayConstPtr)));
104 "marti_visualization_msgs/TexturedMarker",
105 "marti_visualization_msgs/TexturedMarkerArray");
107 if (!topic.
name.empty())
109 ui_.topic->setText(QString::fromStdString(topic.
name));
111 if (topic.
datatype ==
"marti_visualization_msgs/TexturedMarkerArray")
122 std::string topic =
ui_.topic->text().trimmed().toStdString();
167 if (marker.action == marti_visualization_msgs::TexturedMarker::ADD)
170 markerData.
stamp = marker.header.stamp;
173 markerData.
alpha_ = marker.alpha;
197 marker.pose.orientation.x,
198 marker.pose.orientation.y,
199 marker.pose.orientation.z,
200 marker.pose.orientation.w),
202 marker.pose.position.x,
203 marker.pose.position.y,
204 marker.pose.position.z));
206 double right = marker.image.width * marker.resolution / 2.0;
207 double left = -right;
208 double top = marker.image.height * marker.resolution / 2.0;
209 double bottom = -top;
216 top_left = offset * top_left;
217 top_right = offset * top_right;
218 bottom_left = offset * bottom_left;
219 bottom_right = offset * bottom_right;
221 markerData.
quad_.clear();
222 markerData.
quad_.push_back(top_left);
223 markerData.
quad_.push_back(top_right);
224 markerData.
quad_.push_back(bottom_right);
226 markerData.
quad_.push_back(top_left);
227 markerData.
quad_.push_back(bottom_right);
228 markerData.
quad_.push_back(bottom_left);
231 for (
size_t i = 0; i < markerData.
quad_.size(); i++)
236 int32_t max_dimension = std::max(marker.image.height, marker.image.width);
237 int32_t new_size = 1;
238 while (new_size < max_dimension)
239 new_size = new_size << 1;
245 markerData.
encoding_ = marker.image.encoding;
252 ids[0] =
static_cast<GLuint
>(markerData.
texture_id_);
253 glDeleteTextures(1, &ids[0]);
257 glGenTextures(1, &ids[0]);
261 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(markerData.
texture_id_));
263 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
282 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
283 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
285 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
286 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
288 glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
290 glBindTexture(GL_TEXTURE_2D, 0);
293 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(markerData.
texture_id_));
297 for (
size_t row = 0; row < marker.image.height; row++)
299 for (
size_t col = 0; col < marker.image.width; col++)
301 size_t src_index = (row * marker.image.width + col) * 4;
302 size_t dst_index = (row * markerData.
texture_size_ + col) * 4;
304 markerData.
texture_[dst_index + 0] = marker.image.data[src_index + 0];
305 markerData.
texture_[dst_index + 1] = marker.image.data[src_index + 1];
306 markerData.
texture_[dst_index + 2] = marker.image.data[src_index + 2];
307 markerData.
texture_[dst_index + 3] = marker.image.data[src_index + 3];
324 for (
size_t row = 0; row < marker.image.height; row++)
326 for (
size_t col = 0; col < marker.image.width; col++)
328 size_t src_index = (row * marker.image.width + col) * 3;
329 size_t dst_index = (row * markerData.
texture_size_ + col) * 3;
331 markerData.
texture_[dst_index + 0] = marker.image.data[src_index + 0];
332 markerData.
texture_[dst_index + 1] = marker.image.data[src_index + 1];
333 markerData.
texture_[dst_index + 2] = marker.image.data[src_index + 2];
350 for (
size_t row = 0; row < marker.image.height; row++)
352 for (
size_t col = 0; col < marker.image.width; col++)
354 size_t src_index = row * marker.image.width + col;
357 markerData.
texture_[dst_index] = marker.image.data[src_index];
373 glBindTexture(GL_TEXTURE_2D, 0);
376 markerData.
texture_y_ =
static_cast<float>(marker.image.height) / static_cast<float>(markerData.
texture_size_);
380 markers_[marker.ns].erase(marker.id);
386 for (
unsigned int i = 0; i < markers->markers.size(); i++)
436 std::map<std::string, std::map<int, MarkerData> >::iterator nsIter;
439 std::map<int, MarkerData>::iterator markerIter;
440 for (markerIter = nsIter->second.begin(); markerIter != nsIter->second.end(); ++markerIter)
448 glEnable(GL_TEXTURE_2D);
450 glBindTexture(GL_TEXTURE_2D, static_cast<GLuint>(marker.
texture_id_));
452 glBegin(GL_TRIANGLES);
454 glColor4f(1.0
f, 1.0
f, 1.0
f, marker.
alpha_);
469 glBindTexture(GL_TEXTURE_2D, 0);
471 glDisable(GL_TEXTURE_2D);
482 std::map<std::string, std::map<int, MarkerData> >::iterator nsIter;
485 std::map<int, MarkerData>::iterator markerIter;
486 for (markerIter = nsIter->second.begin(); markerIter != nsIter->second.end(); ++markerIter)
489 if (
GetTransform(markerIter->second.source_frame_, markerIter->second.stamp, transform))
491 markerIter->second.transformed_quad_.clear();
492 for (
size_t i = 0; i < markerIter->second.quad_.size(); i++)
494 markerIter->second.transformed_quad_.push_back(transform * markerIter->second.quad_[i]);
506 node[
"topic"] >> topic;
507 ui_.topic->setText(boost::trim_copy(topic).c_str());
510 if (node[
"is_marker_array"])
520 emitter << YAML::Key <<
"topic" << YAML::Value << boost::trim_copy(
ui_.topic->text().toStdString());
521 emitter << YAML::Key <<
"is_marker_array" << YAML::Value <<
is_marker_array_;
bool GetTransform(const ros::Time &stamp, swri_transform_util::Transform &transform, bool use_latest_transforms=true)
std::vector< tf::Vector3 > transformed_quad_
static ros::master::TopicInfo selectTopic(const std::string &datatype, QWidget *parent=0)
void MarkersReceived(const marti_visualization_msgs::TexturedMarkerArrayConstPtr markers)
void PrintInfo(const std::string &message)
void MarkerArrayCallback(const marti_visualization_msgs::TexturedMarkerArrayConstPtr markers)
void ProcessMarkers(const marti_visualization_msgs::TexturedMarkerArrayConstPtr markers)
void transform(Route &route, const swri_transform_util::Transform &transform, const std::string &target_frame)
void LoadConfig(const YAML::Node &node, const std::string &path)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
static void PrintWarningHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
static void PrintErrorHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
bool Initialize(QGLWidget *canvas)
std::string target_frame_
static void PrintInfoHelper(QLabel *status_label, const std::string &message, double throttle=0.0)
void PrintError(const std::string &message)
std::map< std::string, std::map< int, MarkerData > > markers_
void MarkerCallback(const marti_visualization_msgs::TexturedMarkerConstPtr marker)
std::vector< tf::Vector3 > quad_
void PrintWarning(const std::string &message)
void MarkerReceived(const marti_visualization_msgs::TexturedMarkerConstPtr marker)
QWidget * GetConfigWidget(QWidget *parent)
ROSTIME_DECL const Time TIME_MAX
virtual ~TexturedMarkerPlugin()
ros::Subscriber marker_sub_
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
std::vector< uint8_t > texture_
std::string source_frame_
void ProcessMarker(const marti_visualization_msgs::TexturedMarkerConstPtr marker)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void Draw(double x, double y, double scale)