target_visualizer_display.cpp
Go to the documentation of this file.
1 // -*- mode: c++; -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2014, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 #include <rviz/view_manager.h>
36 #include <rviz/render_panel.h>
38 #include <OGRE/OgreCamera.h>
39 #include <OGRE/OgreMaterialManager.h>
41 #include <OGRE/OgreManualObject.h>
42 
43 namespace jsk_rviz_plugins
44 {
45  const float arrow_animation_duration = 1.0;
46  const double minimum_font_size = 0.2;
47 
49  message_recieved_(false)
50  {
52  "target name", "target",
53  "name of the target",
54  this, SLOT(updateTargetName())
55  );
57  "radius", 1.0,
58  "radius of the target mark",
59  this, SLOT(updateRadius()));
62  "alpha", 0.8,
63  "0 is fully transparent, 1.0 is fully opaque.",
64  this, SLOT(updateAlpha()));
65  alpha_property_->setMin(0.0);
66  alpha_property_->setMax(1.0);
68  "color", QColor(25, 255, 240),
69  "color of the target",
70  this, SLOT(updateColor()));
72  "type", "Simple Circle",
73  "Shape to display the pose as",
74  this, SLOT(updateShapeType()));
75  shape_type_property_->addOption("Simple Circle", SimpleCircle);
76  shape_type_property_->addOption("Decoreted Circle", GISCircle);
77  }
78 
80  {
81  delete target_name_property_;
82  delete alpha_property_;
83  delete color_property_;
84  delete radius_property_;
85  }
86 
88  {
89  subscribe();
90  visualizer_->setEnable(false); // keep false, it will be true
91  // in side of processMessae callback.
92  }
93 
95  const geometry_msgs::PoseStamped::ConstPtr& msg)
96  {
97  boost::mutex::scoped_lock lock(mutex_);
98  message_recieved_ = true;
99  visualizer_->setEnable(isEnabled());
100  if (!isEnabled()) {
101  return;
102  }
103  Ogre::Quaternion orientation;
104  Ogre::Vector3 position;
105  if(!context_->getFrameManager()->transform(msg->header,
106  msg->pose,
107  position, orientation))
108  {
109  std::ostringstream oss;
110  oss << "Error transforming pose";
111  oss << " from frame '" << msg->header.frame_id << "'";
112  oss << " to frame '" << qPrintable(fixed_frame_) << "'";
113  ROS_ERROR_STREAM(oss.str());
114  setStatus(rviz::StatusProperty::Error, "Transform", QString::fromStdString(oss.str()));
115  return;
116  }
117  visualizer_->setPosition(position);
118  }
119 
120 
121  void TargetVisualizerDisplay::update(float wall_dt, float ros_dt)
122  {
123  if (!message_recieved_) {
124  return;
125  }
126  visualizer_->setOrientation(context_);
127  visualizer_->update(wall_dt, ros_dt);
128  }
129 
131  {
132  visualizer_initialized_ = false;
134  scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
135 
136  updateRadius();
137  updateShapeType();
138  // updateTargetName();
139  // updateColor();
140  // updateAlpha();
141  }
142 
144  {
145  MFDClass::reset();
146  message_recieved_ = false;
147  if (visualizer_) {
148  visualizer_->setEnable(false);
149  }
150  }
151 
153  {
154  boost::mutex::scoped_lock lock(mutex_);
156  if (visualizer_) {
157  visualizer_->setText(target_name_);
158  }
159  }
160 
162  {
163  boost::mutex::scoped_lock lock(mutex_);
165  if (visualizer_) {
166  visualizer_->setSize(radius_);
167  }
168  }
169 
171  {
172  boost::mutex::scoped_lock lock(mutex_);
174  if (visualizer_) {
175  visualizer_->setAlpha(alpha_);
176  }
177  }
178 
180  {
181  boost::mutex::scoped_lock lock(mutex_);
183  if (visualizer_) {
184  visualizer_->setColor(color_);
185  }
186  }
187 
189  {
192  {
193  boost::mutex::scoped_lock lock(mutex_);
196  // simple circle
199  scene_node_,
200  context_,
201  radius_));
202  }
203  else {
205  // GIS
208  scene_node_,
209  radius_);
210  v->setAnonymous(false);
211  visualizer_.reset(v);
212  }
214  }
216  updateColor();
217  updateAlpha();
218  }
219  }
220 }
221 
224 
virtual QColor getColor() const
void setMin(float min)
void setMax(float max)
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
DisplayContext * context_
virtual float getFloat() const
const double minimum_font_size
Ogre::SceneNode * scene_node_
std::string getStdString()
bool isEnabled() const
QString fixed_frame_
virtual void addOption(const QString &option, int value=0)
virtual void setAnonymous(bool anonymous)
const float arrow_animation_duration
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
virtual FrameManager * getFrameManager() const =0
Ogre::SceneManager * scene_manager_
void processMessage(const geometry_msgs::PoseStamped::ConstPtr &msg)
#define ROS_ERROR_STREAM(args)
virtual int getOptionInt()
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18