pictogram_array_display.cpp
Go to the documentation of this file.
00001 // -*- mode: c++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2014, JSK Lab
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/o2r other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
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         //pictograms_[i]->setEnable(false);
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);


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Wed May 1 2019 02:40:22