Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "pictogram_array_display.h"
00037
00038 namespace jsk_rviz_plugins
00039 {
00040 PictogramArrayDisplay::PictogramArrayDisplay()
00041 {
00042 setupFont();
00043 }
00044
00045 PictogramArrayDisplay::~PictogramArrayDisplay()
00046 {
00047 }
00048
00049 void PictogramArrayDisplay::onInitialize()
00050 {
00051 MFDClass::onInitialize();
00052 scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
00053 }
00054
00055 void PictogramArrayDisplay::reset()
00056 {
00057 MFDClass::reset();
00058 for (size_t i = 0; i < pictograms_.size(); i++) {
00059 pictograms_[i]->setEnable(false);
00060 }
00061 }
00062
00063 void PictogramArrayDisplay::onEnable()
00064 {
00065 subscribe();
00066 for (size_t i = 0; i < pictograms_.size(); i++) {
00067 pictograms_[i]->setEnable(false);
00068 }
00069 }
00070
00071 void PictogramArrayDisplay::allocatePictograms(size_t num)
00072 {
00073 if (pictograms_.size() > num) {
00074 for (size_t i = num; i < pictograms_.size(); i++) {
00075 pictograms_[i]->setEnable(false);
00076 }
00077 pictograms_.resize(num);
00078 }
00079 else if (pictograms_.size() < num) {
00080 for (size_t i = pictograms_.size(); i < num; i++) {
00081
00082 PictogramObject::Ptr pictogram(new PictogramObject(scene_manager_,
00083 scene_node_,
00084 1.0));
00085 pictogram->setContext(context_);
00086 pictogram->setEnable(false);
00087 pictogram->start();
00088 pictogram->setColor(QColor(25, 255, 240));
00089 pictogram->setAlpha(1.0);
00090 pictograms_.push_back(pictogram);
00091 }
00092 }
00093 }
00094
00095 void PictogramArrayDisplay::processMessage(
00096 const jsk_rviz_plugins::PictogramArray::ConstPtr& msg)
00097 {
00098 boost::mutex::scoped_lock (mutex_);
00099 allocatePictograms(msg->pictograms.size());
00100 for (size_t i = 0; i < pictograms_.size(); i++) {
00101 pictograms_[i]->setEnable(isEnabled());
00102 }
00103 if (!isEnabled()) {
00104 return;
00105 }
00106 for (size_t i = 0; i < msg->pictograms.size(); i++) {
00107 PictogramObject::Ptr pictogram = pictograms_[i];
00108 pictogram->setAction(msg->pictograms[i].action);
00109 if (msg->pictograms[i].action == jsk_rviz_plugins::Pictogram::DELETE) {
00110 continue;
00111 }
00112
00113 if (msg->pictograms[i].size <= 0.0) {
00114 pictogram->setSize(0.5);
00115 }
00116 else {
00117 pictogram->setSize(msg->pictograms[i].size / 2.0);
00118 }
00119 pictogram->setColor(QColor(msg->pictograms[i].color.r * 255,
00120 msg->pictograms[i].color.g * 255,
00121 msg->pictograms[i].color.b * 255));
00122 pictogram->setAlpha(msg->pictograms[i].color.a);
00123 pictogram->setPose(msg->pictograms[i].pose,
00124 msg->pictograms[i].header.frame_id);
00125 pictogram->setText(msg->pictograms[i].character);
00126 pictogram->setMode(msg->pictograms[i].mode);
00127 pictogram->setTTL(msg->pictograms[i].ttl);
00128 pictogram->setSpeed(msg->pictograms[i].speed);
00129 }
00130 }
00131
00132 void PictogramArrayDisplay::update(float wall_dt, float ros_dt)
00133 {
00134 boost::mutex::scoped_lock (mutex_);
00135 for (size_t i = 0; i < pictograms_.size(); i++) {
00136 pictograms_[i]->update(wall_dt, ros_dt);
00137 }
00138 }
00139 }
00140
00141 #include <pluginlib/class_list_macros.h>
00142 PLUGINLIB_EXPORT_CLASS (jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display);