tf_display.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <boost/bind.hpp>
31 
32 #include <OgreSceneNode.h>
33 #include <OgreSceneManager.h>
34 
35 #include <tf/transform_listener.h>
36 
37 #include "rviz/display_context.h"
38 #include "rviz/frame_manager.h"
40 #include "rviz/ogre_helpers/axes.h"
49 
51 
52 namespace rviz
53 {
55 {
56 public:
57  FrameSelectionHandler(FrameInfo* frame, TFDisplay* display, DisplayContext* context);
59  {
60  }
61 
62  void createProperties(const Picked& obj, Property* parent_property) override;
63  void destroyProperties(const Picked& obj, Property* parent_property) override;
64 
65  bool getEnabled();
66  void setEnabled(bool enabled);
67  void setParentName(std::string parent_name);
68  void setPosition(const Ogre::Vector3& position);
69  void setOrientation(const Ogre::Quaternion& orientation);
70 
71 private:
79 };
80 
82  TFDisplay* display,
83  DisplayContext* context)
84  : SelectionHandler(context)
85  , frame_(frame)
86  , display_(display)
87  , category_property_(nullptr)
88  , enabled_property_(nullptr)
89  , parent_property_(nullptr)
90  , position_property_(nullptr)
91  , orientation_property_(nullptr)
92 {
93 }
94 
95 void FrameSelectionHandler::createProperties(const Picked& /*obj*/, Property* parent_property)
96 {
98  new Property("Frame " + QString::fromStdString(frame_->name_), QVariant(), "", parent_property);
99 
100  enabled_property_ = new BoolProperty("Enabled", true, "", category_property_,
101  SLOT(updateVisibilityFromSelection()), frame_);
102 
103  parent_property_ = new StringProperty("Parent", "", "", category_property_);
105 
106  position_property_ = new VectorProperty("Position", Ogre::Vector3::ZERO, "", category_property_);
108 
110  new QuaternionProperty("Orientation", Ogre::Quaternion::IDENTITY, "", category_property_);
112 }
113 
114 void FrameSelectionHandler::destroyProperties(const Picked& /*obj*/, Property* /*parent_property*/)
115 {
116  delete category_property_; // This deletes its children as well.
117  category_property_ = nullptr;
118  enabled_property_ = nullptr;
119  parent_property_ = nullptr;
120  position_property_ = nullptr;
121  orientation_property_ = nullptr;
122 }
123 
125 {
126  if (enabled_property_)
127  {
128  return enabled_property_->getBool();
129  }
130  return false; // should never happen, but don't want to crash if it does.
131 }
132 
134 {
135  if (enabled_property_)
136  {
137  enabled_property_->setBool(enabled);
138  }
139 }
140 
141 void FrameSelectionHandler::setParentName(std::string parent_name)
142 {
143  if (parent_property_)
144  {
145  parent_property_->setStdString(parent_name);
146  }
147 }
148 
149 void FrameSelectionHandler::setPosition(const Ogre::Vector3& position)
150 {
151  if (position_property_)
152  {
153  position_property_->setVector(position);
154  }
155 }
156 
157 void FrameSelectionHandler::setOrientation(const Ogre::Quaternion& orientation)
158 {
160  {
161  orientation_property_->setQuaternion(orientation);
162  }
163 }
164 
165 typedef std::set<FrameInfo*> S_FrameInfo;
166 
167 TFDisplay::TFDisplay() : Display(), update_timer_(0.0f), changing_single_frame_enabled_state_(false)
168 {
170  new BoolProperty("Show Names", true, "Whether or not names should be shown next to the frames.",
171  this, SLOT(updateShowNames()));
172 
174  new BoolProperty("Show Axes", true, "Whether or not the axes of each frame should be shown.", this,
175  SLOT(updateShowAxes()));
176 
177  show_arrows_property_ = new BoolProperty("Show Arrows", true,
178  "Whether or not arrows from child to parent should be shown.",
179  this, SLOT(updateShowArrows()));
180 
182  new FloatProperty("Marker Scale", 1, "Scaling factor for all names, axes and arrows.", this);
183 
184  update_rate_property_ = new FloatProperty("Update Interval", 0,
185  "The interval, in seconds, at which to update the frame "
186  "transforms. 0 means to do so every update cycle.",
187  this);
189 
191  "Frame Timeout", 15,
192  "The length of time, in seconds, before a frame that has not been updated is considered \"dead\"."
193  " For 1/3 of this time the frame will appear correct, for the second 1/3rd it will fade to gray,"
194  " and then it will fade out completely.",
195  this);
197 
198  frames_category_ = new Property("Frames", QVariant(), "The list of all frames.", this);
199 
201  new BoolProperty("All Enabled", true, "Whether all the frames should be enabled or not.",
202  frames_category_, SLOT(allEnabledChanged()), this);
203 
204  tree_category_ = new Property(
205  "Tree", QVariant(), "A tree-view of the frames, showing the parent/child relationships.", this);
206 }
207 
209 {
210  clear();
211  if (initialized())
212  {
213  root_node_->removeAndDestroyAllChildren();
214  scene_manager_->destroySceneNode(root_node_);
215  }
216 }
217 
219 {
221 
222  root_node_ = scene_node_->createChildSceneNode();
223 
224  names_node_ = root_node_->createChildSceneNode();
225  arrows_node_ = root_node_->createChildSceneNode();
226  axes_node_ = root_node_->createChildSceneNode();
227 }
228 
229 void TFDisplay::load(const Config& config)
230 {
231  Display::load(config);
232 
233  // Load the enabled state for all frames specified in the config, and store
234  // the values in a map so that the enabled state can be properly set once
235  // the frame is created
236  Config c = config.mapGetChild("Frames");
237  for (Config::MapIterator iter = c.mapIterator(); iter.isValid(); iter.advance())
238  {
239  QString key = iter.currentKey();
240  if (key != "All Enabled")
241  {
242  const Config& child = iter.currentChild();
243  bool enabled = child.mapGetChild("Value").getValue().toBool();
244 
245  frame_config_enabled_state_[key.toStdString()] = enabled;
246  }
247  }
248 }
249 
251 {
252  // Clear the tree.
254 
255  // Clear the frames category, except for the "All enabled" property, which is first.
257 
258  // Clear all frames
259  while (!frames_.empty())
260  deleteFrame(frames_.begin(), false);
261 
262  update_timer_ = 0.0f;
263 
264  clearStatuses();
265 }
266 
268 {
269  root_node_->setVisible(true);
270 
271  names_node_->setVisible(show_names_property_->getBool());
273  axes_node_->setVisible(show_axes_property_->getBool());
274 }
275 
277 {
278  root_node_->setVisible(false);
279  clear();
280 }
281 
283 {
284  names_node_->setVisible(show_names_property_->getBool());
285 
286  M_FrameInfo::iterator it = frames_.begin();
287  M_FrameInfo::iterator end = frames_.end();
288  for (; it != end; ++it)
289  {
290  FrameInfo* frame = it->second;
291 
292  frame->updateVisibilityFromFrame();
293  }
294 }
295 
297 {
298  axes_node_->setVisible(show_axes_property_->getBool());
299 
300  M_FrameInfo::iterator it = frames_.begin();
301  M_FrameInfo::iterator end = frames_.end();
302  for (; it != end; ++it)
303  {
304  FrameInfo* frame = it->second;
305 
306  frame->updateVisibilityFromFrame();
307  }
308 }
309 
311 {
313 
314  M_FrameInfo::iterator it = frames_.begin();
315  M_FrameInfo::iterator end = frames_.end();
316  for (; it != end; ++it)
317  {
318  FrameInfo* frame = it->second;
319 
320  frame->updateVisibilityFromFrame();
321  }
322 }
323 
325 {
327  {
328  return;
329  }
330  bool enabled = all_enabled_property_->getBool();
331 
332  M_FrameInfo::iterator it = frames_.begin();
333  M_FrameInfo::iterator end = frames_.end();
334  for (; it != end; ++it)
335  {
336  FrameInfo* frame = it->second;
337 
338  frame->enabled_property_->setBool(enabled);
339  }
340 }
341 
342 void TFDisplay::update(float wall_dt, float /*ros_dt*/)
343 {
344  update_timer_ += wall_dt;
345  float update_rate = update_rate_property_->getFloat();
346  if (update_rate < 0.0001f || update_timer_ > update_rate)
347  {
348  updateFrames();
349 
350  update_timer_ = 0.0f;
351  }
352 }
353 
354 FrameInfo* TFDisplay::getFrameInfo(const std::string& frame)
355 {
356  M_FrameInfo::iterator it = frames_.find(frame);
357  if (it == frames_.end())
358  {
359  return nullptr;
360  }
361 
362  return it->second;
363 }
364 
366 {
367  typedef std::vector<std::string> V_string;
368  V_string frames;
369 // TODO(wjwwood): remove this and use tf2 interface instead
370 #ifndef _WIN32
371 #pragma GCC diagnostic push
372 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
373 #endif
374 
376 
377 #ifndef _WIN32
378 #pragma GCC diagnostic pop
379 #endif
380  std::sort(frames.begin(), frames.end());
381 
382  S_FrameInfo current_frames;
383 
384  {
385  for (const std::string& frame : frames)
386  {
387  if (frame.empty())
388  {
389  continue;
390  }
391 
392  FrameInfo* info = getFrameInfo(frame);
393  if (!info)
394  {
395  info = createFrame(frame);
396  }
397  else
398  {
399  updateFrame(info);
400  }
401 
402  current_frames.insert(info);
403  }
404  }
405 
406  {
407  M_FrameInfo::iterator frame_it = frames_.begin();
408  M_FrameInfo::iterator frame_end = frames_.end();
409  while (frame_it != frame_end)
410  {
411  if (current_frames.find(frame_it->second) == current_frames.end())
412  frame_it = deleteFrame(frame_it, true);
413  else
414  ++frame_it;
415  }
416  }
417 
419 }
420 
421 static const Ogre::ColourValue ARROW_HEAD_COLOR(1.0f, 0.1f, 0.6f, 1.0f);
422 static const Ogre::ColourValue ARROW_SHAFT_COLOR(0.8f, 0.8f, 0.3f, 1.0f);
423 
424 FrameInfo* TFDisplay::createFrame(const std::string& frame)
425 {
426  FrameInfo* info = new FrameInfo(this);
427  frames_.insert(std::make_pair(frame, info));
428 
429  info->name_ = frame;
430  info->last_update_ = ros::Time::now();
431  info->axes_ = new Axes(scene_manager_, axes_node_, 0.2, 0.02);
432  info->axes_->getSceneNode()->setVisible(show_axes_property_->getBool());
433  info->selection_handler_.reset(new FrameSelectionHandler(info, this, context_));
434  info->selection_handler_->addTrackedObjects(info->axes_->getSceneNode());
435 
436  info->name_text_ = new MovableText(frame, "Liberation Sans", 0.1);
438  info->name_node_ = names_node_->createChildSceneNode();
439  info->name_node_->attachObject(info->name_text_);
440  info->name_node_->setVisible(show_names_property_->getBool());
441 
442  info->parent_arrow_ = new Arrow(scene_manager_, arrows_node_, 1.0f, 0.01, 1.0f, 0.08);
443  info->parent_arrow_->getSceneNode()->setVisible(false);
444  info->parent_arrow_->setHeadColor(ARROW_HEAD_COLOR);
445  info->parent_arrow_->setShaftColor(ARROW_SHAFT_COLOR);
446 
447  info->enabled_property_ = new BoolProperty(QString::fromStdString(info->name_), true,
448  "Enable or disable this individual frame.",
449  frames_category_, SLOT(updateVisibilityFromFrame()), info);
450 
451  info->parent_property_ =
452  new StringProperty("Parent", "", "Parent of this frame. (Not editable)", info->enabled_property_);
453  info->parent_property_->setReadOnly(true);
454 
455  info->position_property_ =
456  new VectorProperty("Position", Ogre::Vector3::ZERO,
457  "Position of this frame, in the current Fixed Frame. (Not editable)",
458  info->enabled_property_);
459  info->position_property_->setReadOnly(true);
460 
461  info->orientation_property_ =
462  new QuaternionProperty("Orientation", Ogre::Quaternion::IDENTITY,
463  "Orientation of this frame, in the current Fixed Frame. (Not editable)",
464  info->enabled_property_);
465  info->orientation_property_->setReadOnly(true);
466 
467  info->rel_position_property_ =
468  new VectorProperty("Relative Position", Ogre::Vector3::ZERO,
469  "Position of this frame, relative to it's parent frame. (Not editable)",
470  info->enabled_property_);
471  info->rel_position_property_->setReadOnly(true);
472 
474  new QuaternionProperty("Relative Orientation", Ogre::Quaternion::IDENTITY,
475  "Orientation of this frame, relative to it's parent frame. (Not editable)",
476  info->enabled_property_);
478 
479  // If the current frame was specified as disabled in the config file
480  // then its enabled state must be updated accordingly
481  if (frame_config_enabled_state_.count(frame) > 0 && !frame_config_enabled_state_[frame])
482  {
483  info->enabled_property_->setBool(false);
484  }
485 
486  updateFrame(info);
487 
488  return info;
489 }
490 
491 Ogre::ColourValue lerpColor(const Ogre::ColourValue& start, const Ogre::ColourValue& end, float t)
492 {
493  return start * t + end * (1 - t);
494 }
495 
497 {
498 // TODO(wjwwood): remove this and use tf2 interface instead
499 #ifndef _WIN32
500 #pragma GCC diagnostic push
501 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
502 #endif
503 
505 
506 #ifndef _WIN32
507 #pragma GCC diagnostic pop
508 #endif
509 
510  // Check last received time so we can grey out/fade out frames that have stopped being published
511  ros::Time latest_time;
512  tf->getLatestCommonTime(fixed_frame_.toStdString(), frame->name_, latest_time, nullptr);
513 
514  if ((latest_time != frame->last_time_to_fixed_) || (latest_time == ros::Time()))
515  {
516  frame->last_update_ = ros::Time::now();
517  frame->last_time_to_fixed_ = latest_time;
518  }
519 
520  // Fade from color -> grey, then grey -> fully transparent
521  ros::Duration age = ros::Time::now() - frame->last_update_;
522  float frame_timeout = frame_timeout_property_->getFloat();
523  float one_third_timeout = frame_timeout * 0.3333333f;
524  if (age > ros::Duration(frame_timeout))
525  {
526  frame->parent_arrow_->getSceneNode()->setVisible(false);
527  frame->axes_->getSceneNode()->setVisible(false);
528  frame->name_node_->setVisible(false);
529  return;
530  }
531  else if (age > ros::Duration(one_third_timeout))
532  {
533  Ogre::ColourValue grey(0.7, 0.7, 0.7, 1.0);
534 
535  if (age > ros::Duration(one_third_timeout * 2))
536  {
537  float a = std::max(0.0, (frame_timeout - age.toSec()) / one_third_timeout);
538  Ogre::ColourValue c = Ogre::ColourValue(grey.r, grey.g, grey.b, a);
539 
540  frame->axes_->setXColor(c);
541  frame->axes_->setYColor(c);
542  frame->axes_->setZColor(c);
543  frame->name_text_->setColor(c);
544  frame->parent_arrow_->setColor(c.r, c.g, c.b, c.a);
545  }
546  else
547  {
548  float t = std::max(0.0, (one_third_timeout * 2 - age.toSec()) / one_third_timeout);
549  frame->axes_->setXColor(lerpColor(frame->axes_->getDefaultXColor(), grey, t));
550  frame->axes_->setYColor(lerpColor(frame->axes_->getDefaultYColor(), grey, t));
551  frame->axes_->setZColor(lerpColor(frame->axes_->getDefaultZColor(), grey, t));
552  frame->name_text_->setColor(lerpColor(Ogre::ColourValue::White, grey, t));
553  frame->parent_arrow_->setShaftColor(lerpColor(ARROW_SHAFT_COLOR, grey, t));
554  frame->parent_arrow_->setHeadColor(lerpColor(ARROW_HEAD_COLOR, grey, t));
555  }
556  }
557  else
558  {
559  frame->axes_->setToDefaultColors();
560  frame->name_text_->setColor(Ogre::ColourValue::White);
561  frame->parent_arrow_->setHeadColor(ARROW_HEAD_COLOR);
562  frame->parent_arrow_->setShaftColor(ARROW_SHAFT_COLOR);
563  }
564 
565  setStatusStd(StatusProperty::Ok, frame->name_, "Transform OK");
566 
567  Ogre::Vector3 position;
568  Ogre::Quaternion orientation;
569  if (!context_->getFrameManager()->getTransform(frame->name_, ros::Time(), position, orientation))
570  {
571  std::stringstream ss;
572  ss << "No transform from [" << frame->name_ << "] to frame [" << fixed_frame_.toStdString() << "]";
573  setStatusStd(StatusProperty::Warn, frame->name_, ss.str());
574  ROS_DEBUG("Error transforming frame '%s' to frame '%s'", frame->name_.c_str(),
575  qPrintable(fixed_frame_));
576  frame->name_node_->setVisible(false);
577  frame->axes_->getSceneNode()->setVisible(false);
578  frame->parent_arrow_->getSceneNode()->setVisible(false);
579  return;
580  }
581 
582  frame->selection_handler_->setPosition(position);
583  frame->selection_handler_->setOrientation(orientation);
584 
585  bool frame_enabled = frame->enabled_property_->getBool();
586 
587  frame->axes_->setPosition(position);
588  frame->axes_->setOrientation(orientation);
589  frame->axes_->getSceneNode()->setVisible(show_axes_property_->getBool() && frame_enabled);
590  float scale = scale_property_->getFloat();
591  frame->axes_->setScale(Ogre::Vector3(scale, scale, scale));
592 
593  frame->name_node_->setPosition(position);
594  frame->name_node_->setVisible(show_names_property_->getBool() && frame_enabled);
595  frame->name_node_->setScale(scale, scale, scale);
596 
597  frame->position_property_->setVector(position);
598  frame->orientation_property_->setQuaternion(orientation);
599 
600  std::string old_parent = frame->parent_;
601  frame->parent_.clear();
602  bool has_parent = tf->getParent(frame->name_, ros::Time(), frame->parent_);
603  if (has_parent)
604  {
605  tf::StampedTransform transform;
606  try
607  {
608 // TODO(wjwwood): remove this and use tf2 interface instead
609 #ifndef _WIN32
610 #pragma GCC diagnostic push
611 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
612 #endif
613 
614  auto tf_client = context_->getFrameManager()->getTFClientPtr();
615 
616 #ifndef _WIN32
617 #pragma GCC diagnostic pop
618 #endif
619  tf_client->lookupTransform(frame->parent_, frame->name_, ros::Time(0), transform);
620  }
621  catch (tf::TransformException& e)
622  {
623  ROS_DEBUG("Error transforming frame '%s' (parent of '%s') to frame '%s'", frame->parent_.c_str(),
624  frame->name_.c_str(), qPrintable(fixed_frame_));
625  }
626 
627  // get the position/orientation relative to the parent frame
628  Ogre::Vector3 relative_position(transform.getOrigin().x(), transform.getOrigin().y(),
629  transform.getOrigin().z());
630  Ogre::Quaternion relative_orientation(transform.getRotation().w(), transform.getRotation().x(),
631  transform.getRotation().y(), transform.getRotation().z());
632  frame->rel_position_property_->setVector(relative_position);
633  frame->rel_orientation_property_->setQuaternion(relative_orientation);
634 
636  {
637  Ogre::Vector3 parent_position;
638  Ogre::Quaternion parent_orientation;
639  if (!context_->getFrameManager()->getTransform(frame->parent_, ros::Time(), parent_position,
640  parent_orientation))
641  {
642  ROS_DEBUG("Error transforming frame '%s' (parent of '%s') to frame '%s'", frame->parent_.c_str(),
643  frame->name_.c_str(), qPrintable(fixed_frame_));
644  }
645 
646  Ogre::Vector3 direction = parent_position - position;
647  float distance = direction.length();
648  direction.normalise();
649 
650  Ogre::Quaternion orient = Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo(direction);
651 
652  frame->distance_to_parent_ = distance;
653  float head_length = (distance < 0.1 * scale) ? (0.1 * scale * distance) : 0.1 * scale;
654  float shaft_length = distance - head_length;
655  // aleeper: This was changed from 0.02 and 0.08 to 0.01 and 0.04 to match proper radius handling in
656  // arrow.cpp
657  frame->parent_arrow_->set(shaft_length, 0.01 * scale, head_length, 0.04 * scale);
658 
659  if (distance > 0.001f)
660  {
661  frame->parent_arrow_->getSceneNode()->setVisible(show_arrows_property_->getBool() &&
662  frame_enabled);
663  }
664  else
665  {
666  frame->parent_arrow_->getSceneNode()->setVisible(false);
667  }
668 
669  frame->parent_arrow_->setPosition(position);
670  frame->parent_arrow_->setOrientation(orient);
671  }
672  else
673  {
674  frame->parent_arrow_->getSceneNode()->setVisible(false);
675  }
676  }
677  else
678  {
679  frame->parent_arrow_->getSceneNode()->setVisible(false);
680  }
681 
682  // If this frame has no tree property or the parent has changed,
683  if (!frame->tree_property_ || old_parent != frame->parent_)
684  {
685  // Look up the new parent.
686  FrameInfo* parent = has_parent ? getFrameInfo(frame->parent_) : nullptr;
687  // Retrieve tree property to add the new child at
688  rviz::Property* parent_tree_property = has_parent ? nullptr : tree_category_;
689  if (parent && parent->tree_property_)
690  parent_tree_property = parent->tree_property_;
691  else if (has_parent) // otherwise reset parent_ to retry if the parent property was created
692  frame->parent_ = old_parent;
693 
694  // If the parent has a tree property, make a new tree property for this frame.
695  if (!parent_tree_property)
696  ; // nothing more to do
697  else if (!frame->tree_property_) // create new property
698  {
699  frame->tree_property_ =
700  new Property(QString::fromStdString(frame->name_), QVariant(), "", parent_tree_property);
701  }
702  else // update property
703  {
704  // re-parent the tree property
706  parent_tree_property->addChild(frame->tree_property_);
707  }
708  }
709 
710  frame->parent_property_->setStdString(frame->parent_);
711  frame->selection_handler_->setParentName(frame->parent_);
712 }
713 
714 TFDisplay::M_FrameInfo::iterator TFDisplay::deleteFrame(M_FrameInfo::iterator it, bool delete_properties)
715 {
716  FrameInfo* frame = it->second;
717  it = frames_.erase(it);
718 
719  delete frame->axes_;
721  delete frame->parent_arrow_;
722  delete frame->name_text_;
723  scene_manager_->destroySceneNode(frame->name_node_->getName());
724  if (delete_properties)
725  {
726  delete frame->enabled_property_;
727  delete frame->tree_property_;
728  }
729  delete frame;
730  return it;
731 }
732 
734 {
736 }
737 
739 {
740  Display::reset();
741  clear();
742 }
743 
745 // FrameInfo
746 
748  : display_(display)
749  , axes_(nullptr)
750  , axes_coll_(0)
751  , parent_arrow_(nullptr)
752  , name_text_(nullptr)
753  , distance_to_parent_(0.0f)
754  , arrow_orientation_(Ogre::Quaternion::IDENTITY)
755  , tree_property_(nullptr)
756 {
757 }
758 
760 {
761  bool enabled = enabled_property_->getBool();
762  selection_handler_->setEnabled(enabled);
763  setEnabled(enabled);
764 }
765 
767 {
768  bool enabled = selection_handler_->getEnabled();
769  enabled_property_->setBool(enabled);
770  setEnabled(enabled);
771 }
772 
773 void FrameInfo::setEnabled(bool enabled)
774 {
775  if (name_node_)
776  {
777  name_node_->setVisible(display_->show_names_property_->getBool() && enabled);
778  }
779 
780  if (axes_)
781  {
782  axes_->getSceneNode()->setVisible(display_->show_axes_property_->getBool() && enabled);
783  }
784 
785  if (parent_arrow_)
786  {
787  if (distance_to_parent_ > 0.001f)
788  {
789  parent_arrow_->getSceneNode()->setVisible(display_->show_arrows_property_->getBool() && enabled);
790  }
791  else
792  {
793  parent_arrow_->getSceneNode()->setVisible(false);
794  }
795  }
796 
797  if (display_->all_enabled_property_->getBool() && !enabled)
798  {
802  }
803 
804  // Update the configuration that stores the enabled state of all frames
805  display_->frame_config_enabled_state_[this->name_] = enabled;
806 
808 }
809 
810 } // namespace rviz
811 
bool getParent(const std::string &frame_id, ros::Time time, std::string &parent) const
Ogre::ColourValue lerpColor(const Ogre::ColourValue &start, const Ogre::ColourValue &end, float t)
Definition: tf_display.cpp:491
Property * frames_category_
Definition: tf_display.h:123
void setStatusStd(StatusProperty::Level level, const std::string &name, const std::string &text)
Show status level and text, using a std::string. Convenience function which converts std::string to Q...
Definition: display.h:163
FrameInfo(TFDisplay *display)
Definition: tf_display.cpp:747
void setMin(float min)
FloatProperty * scale_property_
Definition: tf_display.h:121
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: axes.cpp:88
bool changing_single_frame_enabled_state_
Definition: tf_display.h:126
void updateVisibilityFromSelection()
Update whether the frame is visible or not, based on the enabled_property_ in the selection handler...
Definition: tf_display.cpp:766
void reset() override
Called to tell the display to clear its state.
Definition: tf_display.cpp:738
std::string name_
Definition: tf_display.h:151
BoolProperty * show_arrows_property_
Definition: tf_display.h:115
virtual bool setVector(const Ogre::Vector3 &vector)
Quaternion getRotation() const
Ogre::SceneNode * root_node_
Definition: tf_display.h:102
f
virtual tf::TransformListener * getTFClient() const =0
Convenience function: returns getFrameManager()->getTFClient().
std::set< FrameInfo * > S_FrameInfo
Definition: tf_display.cpp:165
QVariant getValue() const
If this config object is valid and is a Value type, this returns its value. Otherwise it returns an i...
Definition: config.cpp:324
StringProperty * parent_property_
Definition: tf_display.cpp:76
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:287
Property * getParent() const
Return the parent Property.
Definition: property.cpp:231
M_FrameInfo::iterator deleteFrame(M_FrameInfo::iterator it, bool delete_properties)
Definition: tf_display.cpp:714
void updateShowNames()
Definition: tf_display.cpp:282
Ogre::SceneNode * names_node_
Definition: tf_display.h:103
StringProperty * parent_property_
Definition: tf_display.h:170
void setPosition(const Ogre::Vector3 &position) override
Set the position of the base of the arrow.
Definition: arrow.cpp:114
Property * tree_category_
Definition: tf_display.h:124
void setEnabled(bool enabled)
Definition: tf_display.cpp:133
Ogre::SceneNode * arrows_node_
Definition: tf_display.h:104
Displays a visual representation of the TF hierarchy.
Definition: tf_display.h:64
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
float distance_to_parent_
Definition: tf_display.h:160
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.
M_EnabledState frame_config_enabled_state_
Definition: tf_display.h:110
static const Ogre::ColourValue & getDefaultYColor()
Definition: axes.cpp:151
void removeObject(CollObjectHandle obj)
ros::Time last_update_
Definition: tf_display.h:163
void load(const Config &config) override
Load the settings for this display from the given Config node, which must be a map.
Definition: display.cpp:228
void updateShowAxes()
Definition: tf_display.cpp:296
void allEnabledChanged()
Definition: tf_display.cpp:324
Internal class needed only by TFDisplay.
Definition: tf_display.h:131
void updateShowArrows()
Definition: tf_display.cpp:310
FrameSelectionHandler(FrameInfo *frame, TFDisplay *display, DisplayContext *context)
Definition: tf_display.cpp:81
bool isValid()
Return true if the iterator currently points to a valid entry, false if not.
Definition: config.cpp:397
Config mapGetChild(const QString &key) const
If the referenced Node is a Map and it has a child with the given key, return a reference to the chil...
Definition: config.cpp:212
void setZColor(const Ogre::ColourValue &col)
Definition: axes.cpp:130
static const Ogre::ColourValue & getDefaultXColor()
Definition: axes.cpp:146
Property specialized to enforce floating point max/min.
void set(float shaft_length, float shaft_diameter, float head_length, float head_diameter)
Set the parameters for this arrow.
Definition: arrow.cpp:74
BoolProperty * show_names_property_
Definition: tf_display.h:114
VectorProperty * rel_position_property_
Definition: tf_display.h:166
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.
geometry_msgs::TransformStamped t
void setYColor(const Ogre::ColourValue &col)
Definition: axes.cpp:125
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this arrow.
Definition: arrow.h:149
static const Ogre::ColourValue ARROW_SHAFT_COLOR(0.8f, 0.8f, 0.3f, 1.0f)
void createProperties(const Picked &obj, Property *parent_property) override
Override to create properties of the given picked object(s).
Definition: tf_display.cpp:95
Property * takeChild(Property *child)
Remove a given child object and return a pointer to it.
Definition: property.cpp:321
Configuration data storage class.
Definition: config.h:124
VectorProperty * position_property_
Definition: tf_display.h:168
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
void updateFrame(FrameInfo *frame)
Definition: tf_display.cpp:496
FrameInfo * getFrameInfo(const std::string &frame)
Definition: tf_display.cpp:354
QuaternionProperty * rel_orientation_property_
Definition: tf_display.h:167
void destroyProperties(const Picked &obj, Property *parent_property) override
Destroy all properties for the given picked object(s).
Definition: tf_display.cpp:114
void setXColor(const Ogre::ColourValue &col)
Definition: axes.cpp:120
static const Ogre::ColourValue ARROW_HEAD_COLOR(1.0f, 0.1f, 0.6f, 1.0f)
virtual void removeChildren(int start_index=0, int count=-1)
Remove and delete some or all child Properties. Does not change the value of this Property...
Definition: property.cpp:104
Pure-virtual base class for objects which give Display subclasses context in which to work...
virtual void clearStatuses()
Delete all status children. This is thread-safe.
Definition: display.cpp:210
CollObjectHandle axes_coll_
Definition: tf_display.h:154
std::string parent_
Definition: tf_display.h:152
virtual void reset()
Called to tell the display to clear its state.
Definition: display.cpp:287
const boost::shared_ptr< tf::TransformListener > & getTFClientPtr()
Return a boost shared pointer to the tf::TransformListener used to receive transform data...
void setToDefaultColors()
Definition: axes.cpp:135
void onDisable() override
Derived classes override this to do the actual work of disabling themselves.
Definition: tf_display.cpp:276
void updateVisibilityFromFrame()
Update whether the frame is visible or not, based on the enabled_property_ in this FrameInfo...
Definition: tf_display.cpp:759
BoolProperty * all_enabled_property_
Definition: tf_display.h:119
BoolProperty * enabled_property_
Definition: tf_display.cpp:75
Ogre::SceneNode * axes_node_
Definition: tf_display.h:105
Iterator class for looping over all entries in a Map type Config Node.
Definition: config.h:288
virtual bool setQuaternion(const Ogre::Quaternion &quaternion)
void setEnabled(bool enabled)
Set this frame to be visible or invisible.
Definition: tf_display.cpp:773
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
virtual SelectionManager * getSelectionManager() const =0
Return a pointer to the SelectionManager.
BoolProperty * enabled_property_
Definition: tf_display.h:171
TFDisplay * display_
Definition: tf_display.h:150
Property(const QString &name=QString(), const QVariant default_value=QVariant(), const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
Constructor.
Definition: property.cpp:58
void setOrientation(const Ogre::Quaternion &orientation)
Definition: tf_display.cpp:157
float update_timer_
Definition: tf_display.h:112
void setParentName(std::string parent_name)
Definition: tf_display.cpp:141
~TFDisplay() override
Definition: tf_display.cpp:208
void setTextAlignment(const HorizontalAlignment &horizontalAlignment, const VerticalAlignment &verticalAlignment)
void setShaftColor(float r, float g, float b, float a=1.0f)
Set the color of the arrow&#39;s shaft. Values are in the range [0, 1].
Definition: arrow.cpp:104
Ogre::SceneNode * name_node_
Definition: tf_display.h:158
An object that displays a set of X/Y/Z axes, with X=Red, Y=Green, Z=Blue.
Definition: axes.h:59
std::vector< std::string > V_string
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
FrameSelectionHandlerPtr selection_handler_
Definition: tf_display.h:155
void getFrameStrings(std::vector< std::string > &ids) const
FrameInfo * createFrame(const std::string &frame)
Definition: tf_display.cpp:424
VectorProperty * position_property_
Definition: tf_display.cpp:77
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: axes.cpp:83
BoolProperty(const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
FloatProperty * update_rate_property_
Definition: tf_display.h:117
int getLatestCommonTime(const std::string &source_frame, const std::string &target_frame, ros::Time &time, std::string *error_string) const
Property specialized for string values.
MovableText * name_text_
Definition: tf_display.h:157
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
BoolProperty * show_axes_property_
Definition: tf_display.h:116
void setColor(const Ogre::ColourValue &color)
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
void onInitialize() override
Override this function to do subclass-specific initialization.
Definition: tf_display.cpp:218
virtual float getFloat() const
void setPosition(const Ogre::Vector3 &position)
Definition: tf_display.cpp:149
virtual void addChild(Property *child, int index=-1)
Add a child property.
Definition: property.cpp:355
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Return the pose for a header, relative to the fixed frame, in Ogre classes.
friend class FrameInfo
Definition: tf_display.h:127
An arrow consisting of a cylinder and a cone.
Definition: arrow.h:59
static Time now()
void fixedFrameChanged() override
Called by setFixedFrame(). Override to respond to changes to fixed_frame_.
Definition: tf_display.cpp:733
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation.
Definition: arrow.cpp:119
void onEnable() override
Derived classes override this to do the actual work of enabling themselves.
Definition: tf_display.cpp:267
void setColor(float r, float g, float b, float a) override
Set the color of this arrow. Sets both the head and shaft color to the same value. Values are in the range [0, 1].
Definition: arrow.cpp:89
MapIterator mapIterator() const
Return a new iterator for looping over key/value pairs.
Definition: config.cpp:356
void load(const Config &config) override
Load the value of this property and/or its children from the given Config reference.
Definition: tf_display.cpp:229
bool initialized() const
Returns true if the display has been initialized.
Definition: display.h:275
Arrow * parent_arrow_
Definition: tf_display.h:156
M_FrameInfo frames_
Definition: tf_display.h:107
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this object.
Definition: axes.h:95
Property * tree_property_
Definition: tf_display.h:173
virtual bool getBool() const
ros::Time last_time_to_fixed_
Definition: tf_display.h:164
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:433
void setHeadColor(float r, float g, float b, float a=1.0f)
Set the color of the arrow&#39;s head. Values are in the range [0, 1].
Definition: arrow.cpp:109
bool setStdString(const std::string &std_str)
FloatProperty * frame_timeout_property_
Definition: tf_display.h:118
bool setBool(bool value)
Definition: bool_property.h:62
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
static const Ogre::ColourValue & getDefaultZColor()
Definition: axes.cpp:156
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: axes.cpp:93
void update(float wall_dt, float ros_dt) override
Called periodically by the visualization manager.
Definition: tf_display.cpp:342
QuaternionProperty * orientation_property_
Definition: tf_display.cpp:78
QuaternionProperty * orientation_property_
Definition: tf_display.h:169
#define ROS_DEBUG(...)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Fri Feb 3 2023 03:06:42