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 #include <rviz/view_manager.h>
00036 #include <rviz/render_panel.h>
00037 #include <rviz/uniform_string_stream.h>
00038 #include <OGRE/OgreCamera.h>
00039 #include <OGRE/OgreMaterialManager.h>
00040 #include "target_visualizer_display.h"
00041 #include <OGRE/OgreManualObject.h>
00042 
00043 namespace jsk_rviz_plugins
00044 {
00045   const float arrow_animation_duration = 1.0;
00046   const double minimum_font_size = 0.2;
00047   
00048   TargetVisualizerDisplay::TargetVisualizerDisplay():
00049     message_recieved_(false)
00050   {
00051     target_name_property_ = new rviz::StringProperty(
00052       "target name", "target",
00053       "name of the target",
00054       this, SLOT(updateTargetName())
00055       );
00056     radius_property_ = new rviz::FloatProperty(
00057       "radius", 1.0,
00058       "radius of the target mark",
00059       this, SLOT(updateRadius()));
00060     radius_property_->setMin(0.0);
00061     alpha_property_ = new rviz::FloatProperty(
00062       "alpha", 0.8,
00063       "0 is fully transparent, 1.0 is fully opaque.",
00064       this, SLOT(updateAlpha()));
00065     alpha_property_->setMin(0.0);
00066     alpha_property_->setMax(1.0);
00067     color_property_ = new rviz::ColorProperty(
00068       "color", QColor(25, 255, 240),
00069       "color of the target",
00070       this, SLOT(updateColor()));
00071     shape_type_property_ = new rviz::EnumProperty(
00072       "type", "Simple Circle",
00073       "Shape to display the pose as",
00074       this, SLOT(updateShapeType()));
00075     shape_type_property_->addOption("Simple Circle", SimpleCircle);
00076     shape_type_property_->addOption("Decoreted Circle", GISCircle);
00077   }
00078 
00079   TargetVisualizerDisplay::~TargetVisualizerDisplay()
00080   {
00081     delete target_name_property_;
00082     delete alpha_property_;
00083     delete color_property_;
00084     delete radius_property_;
00085   }
00086 
00087   void TargetVisualizerDisplay::onEnable()
00088   {
00089     subscribe();
00090     visualizer_->setEnable(false); 
00091                                    
00092   }
00093   
00094   void TargetVisualizerDisplay::processMessage(
00095     const geometry_msgs::PoseStamped::ConstPtr& msg)
00096   {
00097     boost::mutex::scoped_lock lock(mutex_);
00098     message_recieved_ = true;
00099     visualizer_->setEnable(isEnabled());
00100     if (!isEnabled()) {
00101       return;
00102     }
00103     Ogre::Quaternion orientation;
00104     Ogre::Vector3 position;
00105     if(!context_->getFrameManager()->transform(msg->header,
00106                                                msg->pose,
00107                                                position, orientation))
00108     {
00109       std::ostringstream oss;
00110       oss << "Error transforming pose";
00111       oss << " from frame '" << msg->header.frame_id << "'";
00112       oss << " to frame '" << qPrintable(fixed_frame_) << "'";
00113       ROS_ERROR_STREAM(oss.str());
00114       setStatus(rviz::StatusProperty::Error, "Transform", QString::fromStdString(oss.str()));
00115       return;
00116     }
00117     visualizer_->setPosition(position);
00118   }
00119 
00120   
00121   void TargetVisualizerDisplay::update(float wall_dt, float ros_dt)
00122   {
00123     if (!message_recieved_) {
00124       return;
00125     }
00126     visualizer_->setOrientation(context_);
00127     visualizer_->update(wall_dt, ros_dt);
00128   }
00129 
00130   void TargetVisualizerDisplay::onInitialize()
00131   {
00132     visualizer_initialized_ = false;
00133     MFDClass::onInitialize();
00134     scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
00135     
00136     updateRadius();
00137     updateShapeType();
00138     
00139     
00140     
00141   }
00142 
00143   void TargetVisualizerDisplay::reset()
00144   {
00145     MFDClass::reset();
00146     message_recieved_ = false;
00147     if (visualizer_) {
00148       visualizer_->setEnable(false);
00149     }
00150   }
00151 
00152   void TargetVisualizerDisplay::updateTargetName()
00153   {
00154     boost::mutex::scoped_lock lock(mutex_);
00155     target_name_ = target_name_property_->getStdString();
00156     if (visualizer_) {
00157       visualizer_->setText(target_name_);
00158     }
00159   }
00160   
00161   void TargetVisualizerDisplay::updateRadius()
00162   {
00163     boost::mutex::scoped_lock lock(mutex_);
00164     radius_ = radius_property_->getFloat();
00165     if (visualizer_) {
00166       visualizer_->setSize(radius_);
00167     }
00168   }
00169 
00170   void TargetVisualizerDisplay::updateAlpha()
00171   {
00172     boost::mutex::scoped_lock lock(mutex_);
00173     alpha_ = alpha_property_->getFloat();
00174     if (visualizer_) {
00175       visualizer_->setAlpha(alpha_);
00176     }
00177   }
00178 
00179   void TargetVisualizerDisplay::updateColor()
00180   {
00181     boost::mutex::scoped_lock lock(mutex_);
00182     color_ = color_property_->getColor();
00183     if (visualizer_) {
00184       visualizer_->setColor(color_);
00185     }
00186   }
00187   
00188   void TargetVisualizerDisplay::updateShapeType()
00189   {
00190     if (!visualizer_initialized_ ||
00191         current_type_ != shape_type_property_->getOptionInt()) {
00192       {
00193         boost::mutex::scoped_lock lock(mutex_);
00194         if (shape_type_property_->getOptionInt() == SimpleCircle) {
00195           current_type_ = SimpleCircle;
00196           
00197           visualizer_.reset(new SimpleCircleFacingVisualizer(
00198                               scene_manager_,
00199                               scene_node_,
00200                               context_,
00201                               radius_));
00202         }
00203         else {
00204           current_type_ = GISCircle;
00205           
00206           GISCircleVisualizer* v = new GISCircleVisualizer(
00207             scene_manager_,
00208             scene_node_,
00209             radius_);
00210           v->setAnonymous(false);
00211           visualizer_.reset(v);
00212         }
00213         visualizer_initialized_ = true;
00214       }
00215       updateTargetName();
00216       updateColor();
00217       updateAlpha();
00218     }
00219   }
00220 }
00221 
00222 #include <pluginlib/class_list_macros.h>
00223 PLUGINLIB_EXPORT_CLASS( jsk_rviz_plugins::TargetVisualizerDisplay, rviz::Display )
00224