hri_tf.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 #include <algorithm>
30 
31 #include <boost/bind/bind.hpp>
32 
33 #include <OGRE/OgreSceneNode.h>
34 #include <OGRE/OgreSceneManager.h>
35 
36 #include <rviz/display_context.h>
37 #include <rviz/frame_manager.h>
39 #include <rviz/ogre_helpers/axes.h>
48 
49 #include "hri_tf.h"
50 
51 namespace rviz
52 {
53 class FrameSelectionHandler : public SelectionHandler
54 {
55 public:
56  FrameSelectionHandler(FrameInfo* frame, DisplayContext* context);
57  ~FrameSelectionHandler() override
58  {
59  }
60 
61  void createProperties(const Picked& obj, Property* parent_property) override;
62  void destroyProperties(const Picked& obj, Property* parent_property) override;
63 
64  bool getEnabled();
65  void setEnabled(bool enabled);
66  void setParentName(const std::string& parent_name);
67  void setPosition(const Ogre::Vector3& position);
68  void setOrientation(const Ogre::Quaternion& orientation);
69 
70 private:
71  FrameInfo* frame_;
72  Property* category_property_;
73  BoolProperty* enabled_property_;
74  StringProperty* parent_property_;
75  VectorProperty* position_property_;
76  QuaternionProperty* orientation_property_;
77 };
78 
79 FrameSelectionHandler::FrameSelectionHandler(FrameInfo* frame, DisplayContext* context)
80  : SelectionHandler(context)
81  , frame_(frame)
82  , category_property_(nullptr)
83  , enabled_property_(nullptr)
84  , parent_property_(nullptr)
85  , position_property_(nullptr)
86  , orientation_property_(nullptr)
87 {
88 }
89 
90 void FrameSelectionHandler::createProperties(const Picked& /*obj*/, Property* parent_property)
91 {
93  new Property("Frame " + QString::fromStdString(frame_->name_), QVariant(), "", parent_property);
94 
95  enabled_property_ = new BoolProperty("Enabled", true, "", category_property_,
96  SLOT(updateVisibilityFromSelection()), frame_);
97 
98  parent_property_ = new StringProperty("Parent", "", "", category_property_);
100 
101  position_property_ = new VectorProperty("Position", Ogre::Vector3::ZERO, "", category_property_);
103 
105  new QuaternionProperty("Orientation", Ogre::Quaternion::IDENTITY, "", category_property_);
107 }
108 
109 void FrameSelectionHandler::destroyProperties(const Picked& /*obj*/, Property* /*parent_property*/)
110 {
111  delete category_property_; // This deletes its children as well.
112  category_property_ = nullptr;
113  enabled_property_ = nullptr;
114  parent_property_ = nullptr;
115  position_property_ = nullptr;
116  orientation_property_ = nullptr;
117 }
118 
120 {
121  if (enabled_property_)
122  {
123  return enabled_property_->getBool();
124  }
125  return false; // should never happen, but don't want to crash if it does.
126 }
127 
128 void FrameSelectionHandler::setEnabled(bool enabled)
129 {
130  if (enabled_property_)
131  {
132  enabled_property_->setBool(enabled);
133  }
134 }
135 
136 void FrameSelectionHandler::setParentName(const std::string& parent_name)
137 {
138  if (parent_property_)
139  {
140  parent_property_->setStdString(parent_name);
141  }
142 }
143 
144 void FrameSelectionHandler::setPosition(const Ogre::Vector3& position)
145 {
146  if (position_property_)
147  {
148  position_property_->setVector(position);
149  }
150 }
151 
152 void FrameSelectionHandler::setOrientation(const Ogre::Quaternion& orientation)
153 {
155  {
156  orientation_property_->setQuaternion(orientation);
157  }
158 }
159 
160 typedef std::set<FrameInfo*> S_FrameInfo;
161 
162 HRITFDisplay::HRITFDisplay() : Display(), update_timer_(0.0f), changing_single_frame_enabled_state_(false),
163  showFaces_(true), showGazes_(true), showSkeletons_(true)
164 {
166  new BoolProperty("Show Names", true, "Whether or not names should be shown next to the frames.",
167  this, SLOT(updateShowNames()));
168 
170  new BoolProperty("Show Axes", true, "Whether or not the axes of each frame should be shown.", this,
171  SLOT(updateShowAxes()));
172 
173  show_arrows_property_ = new BoolProperty("Show Arrows", true,
174  "Whether or not arrows from child to parent should be shown.",
175  this, SLOT(updateShowArrows()));
176 
178  new FloatProperty("Marker Scale", 1, "Scaling factor for all names, axes and arrows.", this);
179 
180  alpha_property_ = new FloatProperty("Marker Alpha", 1, "Alpha channel value for all axes.", this);
183 
185  new BoolProperty("Show Faces", true, "Whether or not the face_ frames should be displayed.", this,
186  SLOT(updateShowFaces()));
188  new BoolProperty("Show Gazes", true, "Whether or not the gaze_ frames should be displayed.", this,
189  SLOT(updateShowGazes()));
190 
192  new BoolProperty("Show Skeletons", true, "'Whether or not human skeleton frames should be displayed.", this,
193  SLOT(updateshowSkeletons()));
194 
195  update_rate_property_ = new FloatProperty("Update Interval", 0,
196  "The interval, in seconds, at which to update the frame "
197  "transforms. 0 means to do so every update cycle.",
198  this);
200 
202  "Frame Timeout", 15,
203  "The length of time, in seconds, before a frame that has not been updated is considered \"dead\"."
204  " For 1/3 of this time the frame will appear correct, for the second 1/3rd it will fade to gray,"
205  " and then it will fade out completely.",
206  this);
208 
209  frames_category_ = new Property("Frames", QVariant(), "The list of all frames.", this);
210 
212  new BoolProperty("All Enabled", true, "Whether all the frames should be enabled or not.",
213  frames_category_, SLOT(allEnabledChanged()), this);
214 
215  tree_category_ = new Property(
216  "Tree", QVariant(), "A tree-view of the frames, showing the parent/child relationships.", this);
217 
218  skeleton_components_.push_back("body");
219  skeleton_components_.push_back("head");
220  skeleton_components_.push_back("torso");
221  skeleton_components_.push_back("waist");
222  skeleton_components_.push_back("p_head");
223  skeleton_components_.push_back("y_head");
224  skeleton_components_.push_back("l_ankle");
225  skeleton_components_.push_back("l_elbow");
226  skeleton_components_.push_back("l_hip");
227  skeleton_components_.push_back("l_knee");
228  skeleton_components_.push_back("l_p_hip");
229  skeleton_components_.push_back("l_p_shoulder");
230  skeleton_components_.push_back("l_shoulder");
231  skeleton_components_.push_back("l_wrist");
232  skeleton_components_.push_back("l_y_hip");
233  skeleton_components_.push_back("l_y_shoulder");
234  skeleton_components_.push_back("r_ankle");
235  skeleton_components_.push_back("r_elbow");
236  skeleton_components_.push_back("r_hip");
237  skeleton_components_.push_back("r_knee");
238  skeleton_components_.push_back("r_p_hip");
239  skeleton_components_.push_back("r_p_shoulder");
240  skeleton_components_.push_back("r_shoulder");
241  skeleton_components_.push_back("r_wrist");
242  skeleton_components_.push_back("r_y_hip");
243  skeleton_components_.push_back("r_y_shoulder");
244 }
245 
247 {
248  clear();
249  if (initialized())
250  {
251  root_node_->removeAndDestroyAllChildren();
252  scene_manager_->destroySceneNode(root_node_);
253  }
254 }
255 
257 {
259 
260  root_node_ = scene_node_->createChildSceneNode();
261 
262  names_node_ = root_node_->createChildSceneNode();
263  arrows_node_ = root_node_->createChildSceneNode();
264  axes_node_ = root_node_->createChildSceneNode();
265 }
266 
267 void HRITFDisplay::load(const Config& config)
268 {
270 
271  // Load the enabled state for all frames specified in the config, and store
272  // the values in a map so that the enabled state can be properly set once
273  // the frame is created
274  Config c = config.mapGetChild("Frames");
275  for (Config::MapIterator iter = c.mapIterator(); iter.isValid(); iter.advance())
276  {
277  QString key = iter.currentKey();
278  if (key != "All Enabled")
279  {
280  const Config& child = iter.currentChild();
281  bool enabled = child.mapGetChild("Value").getValue().toBool();
282 
283  frame_config_enabled_state_[key.toStdString()] = enabled;
284  }
285  }
286 }
287 
289 {
290  // Clear the tree.
292 
293  // Clear the frames category, except for the "All enabled" property, which is first.
295 
296  // Clear all frames
297  while (!frames_.empty())
298  deleteFrame(frames_.begin(), false);
299 
300  update_timer_ = 0.0f;
301 
302  clearStatuses();
303 }
304 
306 {
307  root_node_->setVisible(true);
308 
309  names_node_->setVisible(show_names_property_->getBool());
311  axes_node_->setVisible(show_axes_property_->getBool());
312 }
313 
315 {
316  root_node_->setVisible(false);
317  clear();
318 }
319 
321 {
322  names_node_->setVisible(show_names_property_->getBool());
323 
324  M_FrameInfo::iterator it = frames_.begin();
325  M_FrameInfo::iterator end = frames_.end();
326  for (; it != end; ++it)
327  {
328  FrameInfo* frame = it->second;
329 
330  frame->updateVisibilityFromFrame();
331  }
332 }
333 
335 {
336  axes_node_->setVisible(show_axes_property_->getBool());
337 
338  M_FrameInfo::iterator it = frames_.begin();
339  M_FrameInfo::iterator end = frames_.end();
340  for (; it != end; ++it)
341  {
342  FrameInfo* frame = it->second;
343 
344  frame->updateVisibilityFromFrame();
345  }
346 }
347 
350 }
351 
354 }
355 
358 }
359 
361 {
363 
364  M_FrameInfo::iterator it = frames_.begin();
365  M_FrameInfo::iterator end = frames_.end();
366  for (; it != end; ++it)
367  {
368  FrameInfo* frame = it->second;
369 
370  frame->updateVisibilityFromFrame();
371  }
372 }
373 
375 {
377  {
378  return;
379  }
380  bool enabled = all_enabled_property_->getBool();
381 
382  M_FrameInfo::iterator it = frames_.begin();
383  M_FrameInfo::iterator end = frames_.end();
384  for (; it != end; ++it)
385  {
386  FrameInfo* frame = it->second;
387 
388  frame->enabled_property_->setBool(enabled);
389  }
390 }
391 
392 void HRITFDisplay::update(float wall_dt, float /*ros_dt*/)
393 {
394  update_timer_ += wall_dt;
395  float update_rate = update_rate_property_->getFloat();
396  if (update_rate < 0.0001f || update_timer_ > update_rate)
397  {
398  updateFrames();
399 
400  update_timer_ = 0.0f;
401  }
402 }
403 
404 FrameInfo* HRITFDisplay::getFrameInfo(const std::string& frame)
405 {
406  M_FrameInfo::iterator it = frames_.find(frame);
407  if (it == frames_.end())
408  {
409  return nullptr;
410  }
411 
412  return it->second;
413 }
414 
416 {
417  typedef std::vector<std::string> V_string;
418  V_string frames;
419  context_->getTF2BufferPtr()->_getFrameStrings(frames);
420  std::sort(frames.begin(), frames.end());
421 
422  auto faces = hri_listener_.getFaces();
423  auto bodies = hri_listener_.getBodies();
424  std::string id;
425 
426  bool faceFound;
427  bool gazeFound;
428  bool skeletonFound; bool idFound;
429 
430  auto framesIt = frames.begin();
431  while(framesIt != frames.end()){
432  faceFound = ((*framesIt).rfind("face_", 0) == 0);
433 
434  if(showFaces_ && faceFound){
435  id = (*framesIt).substr((*framesIt).size()-5);
436  idFound = (faces.find(id) != faces.end()); // Checking if the face is among those currently tracked
437  if (idFound && showFaces_){
438  ++framesIt;
439  } else {
440  framesIt = frames.erase(framesIt);
441  }
442  continue;
443  }
444 
445  gazeFound = ((*framesIt).rfind("gaze_", 0) == 0);
446 
447  if(showGazes_ && gazeFound){
448  id = (*framesIt).substr((*framesIt).size()-5);
449  idFound = (faces.find(id) != faces.end()); // Checking if the face is among those currently tracked
450  if (idFound && showGazes_){
451  ++framesIt;
452  } else {
453  framesIt = frames.erase(framesIt);
454  }
455  continue;
456  }
457 
458  // At this point, if the frame name follows the ROS4HRI frame convention,
459  // it must be a skeleton frame.
460 
461  // First of all, it is to be confirmed that the frame follows the ROS4HRI
462  // naming convention. To do this, it is possible to check if the
463  // frame name belongs to one of the skeleton frames.
464 
465  std::string frameName = *framesIt;
466 
467  // Smaller possible body component name = body_<body_id>
468  // Considering that the body id is 5 chars, then the
469  // minimum size for a body component name is 10 chars
470  if (frameName.length() < 10){
471  framesIt = frames.erase(framesIt);
472  continue;
473  }
474 
475  std::string possibleSkeletonComponent = frameName.substr(0, frameName.length()-6);
476  skeletonFound = (std::find(skeleton_components_.begin(), skeleton_components_.end(), possibleSkeletonComponent) != skeleton_components_.end());
477  if(showSkeletons_ && skeletonFound){
478  id = (*framesIt).substr((*framesIt).size()-5);
479  idFound = (bodies.find(id) != bodies.end()); // Checking if the body is among those currently tracked
480  if (idFound){
481  ++framesIt;
482  } else {
483  framesIt = frames.erase(framesIt);
484  }
485  continue;
486  } else {
487  framesIt = frames.erase(framesIt);
488  continue;
489  }
490  }
491 
492  S_FrameInfo current_frames;
493 
494  {
495  for (const std::string& frame : frames)
496  {
497  if (frame.empty())
498  {
499  continue;
500  }
501 
502  FrameInfo* info = getFrameInfo(frame);
503  if (!info)
504  {
505  info = createFrame(frame);
506  }
507  else
508  {
509  updateFrame(info);
510  }
511 
512  current_frames.insert(info);
513  }
514  }
515 
516  {
517  M_FrameInfo::iterator frame_it = frames_.begin();
518  M_FrameInfo::iterator frame_end = frames_.end();
519  while (frame_it != frame_end)
520  {
521  if (current_frames.find(frame_it->second) == current_frames.end())
522  frame_it = deleteFrame(frame_it, true);
523  else
524  ++frame_it;
525  }
526  }
527 
529 }
530 
531 static const Ogre::ColourValue ARROW_HEAD_COLOR(1.0f, 0.1f, 0.6f, 1.0f);
532 static const Ogre::ColourValue ARROW_SHAFT_COLOR(0.8f, 0.8f, 0.3f, 1.0f);
533 
534 FrameInfo* HRITFDisplay::createFrame(const std::string& frame)
535 {
536  FrameInfo* info = new FrameInfo(this);
537  frames_.insert(std::make_pair(frame, info));
538 
539  info->name_ = frame;
540  info->last_update_ = ros::Time::now();
541  info->axes_ = new Axes(scene_manager_, axes_node_, 0.2, 0.02);
542  info->axes_->getSceneNode()->setVisible(show_axes_property_->getBool());
543  info->selection_handler_.reset(new FrameSelectionHandler(info, context_));
544  info->selection_handler_->addTrackedObjects(info->axes_->getSceneNode());
545 
546  info->name_text_ = new MovableText(frame, "Liberation Sans", 0.1);
548  info->name_node_ = names_node_->createChildSceneNode();
549  info->name_node_->attachObject(info->name_text_);
550  info->name_node_->setVisible(show_names_property_->getBool());
551 
552  info->parent_arrow_ = new Arrow(scene_manager_, arrows_node_, 1.0f, 0.01, 1.0f, 0.08);
553  info->parent_arrow_->getSceneNode()->setVisible(false);
556 
557  info->enabled_property_ = new BoolProperty(QString::fromStdString(info->name_), true,
558  "Enable or disable this individual frame.",
559  frames_category_, SLOT(updateVisibilityFromFrame()), info);
560 
561  info->parent_property_ =
562  new StringProperty("Parent", "", "Parent of this frame. (Not editable)", info->enabled_property_);
563  info->parent_property_->setReadOnly(true);
564 
565  info->position_property_ =
566  new VectorProperty("Position", Ogre::Vector3::ZERO,
567  "Position of this frame, in the current Fixed Frame. (Not editable)",
568  info->enabled_property_);
569  info->position_property_->setReadOnly(true);
570 
571  info->orientation_property_ =
572  new QuaternionProperty("Orientation", Ogre::Quaternion::IDENTITY,
573  "Orientation of this frame, in the current Fixed Frame. (Not editable)",
574  info->enabled_property_);
575  info->orientation_property_->setReadOnly(true);
576 
577  info->rel_position_property_ =
578  new VectorProperty("Relative Position", Ogre::Vector3::ZERO,
579  "Position of this frame, relative to it's parent frame. (Not editable)",
580  info->enabled_property_);
581  info->rel_position_property_->setReadOnly(true);
582 
584  new QuaternionProperty("Relative Orientation", Ogre::Quaternion::IDENTITY,
585  "Orientation of this frame, relative to it's parent frame. (Not editable)",
586  info->enabled_property_);
588 
589  // If the current frame was specified as disabled in the config file
590  // then its enabled state must be updated accordingly
591  if (frame_config_enabled_state_.count(frame) > 0 && !frame_config_enabled_state_[frame])
592  {
593  info->enabled_property_->setBool(false);
594  }
595 
596  updateFrame(info);
597 
598  return info;
599 }
600 
601 Ogre::ColourValue lerpColor(const Ogre::ColourValue& start, const Ogre::ColourValue& end, float t)
602 {
603  return start * t + end * (1 - t);
604 }
605 
607 {
608  auto tf = context_->getTF2BufferPtr();
609  tf2::CompactFrameID target_id = tf->_lookupFrameNumber(fixed_frame_.toStdString());
610  tf2::CompactFrameID source_id = tf->_lookupFrameNumber(frame->name_);
611 
612  // Check last received time so we can grey out/fade out frames that have stopped being published
613  ros::Time latest_time;
614  tf->_getLatestCommonTime(target_id, source_id, latest_time, nullptr);
615 
616  if ((latest_time != frame->last_time_to_fixed_) || (latest_time == ros::Time()))
617  {
618  frame->last_update_ = ros::Time::now();
619  frame->last_time_to_fixed_ = latest_time;
620  }
621 
622  // Fade from color -> grey, then grey -> fully transparent
623  ros::Duration age = ros::Time::now() - frame->last_update_;
624  float frame_timeout = frame_timeout_property_->getFloat();
625  float one_third_timeout = frame_timeout * 0.3333333f;
626  if (age > ros::Duration(frame_timeout))
627  {
628  frame->parent_arrow_->getSceneNode()->setVisible(false);
629  frame->axes_->getSceneNode()->setVisible(false);
630  frame->name_node_->setVisible(false);
631  return;
632  }
633  else if (age > ros::Duration(one_third_timeout))
634  {
635  Ogre::ColourValue grey(0.7, 0.7, 0.7, 1.0);
636 
637  if (age > ros::Duration(one_third_timeout * 2))
638  {
639  float a = std::max(0.0, (frame_timeout - age.toSec()) / one_third_timeout);
640  Ogre::ColourValue c = Ogre::ColourValue(grey.r, grey.g, grey.b, a);
641 
642  frame->axes_->setXColor(c);
643  frame->axes_->setYColor(c);
644  frame->axes_->setZColor(c);
645  frame->name_text_->setColor(c);
646  frame->parent_arrow_->setColor(c.r, c.g, c.b, c.a);
647  }
648  else
649  {
650  float t = std::max(0.0, (one_third_timeout * 2 - age.toSec()) / one_third_timeout);
651  frame->axes_->setXColor(lerpColor(frame->axes_->getDefaultXColor(), grey, t));
652  frame->axes_->setYColor(lerpColor(frame->axes_->getDefaultYColor(), grey, t));
653  frame->axes_->setZColor(lerpColor(frame->axes_->getDefaultZColor(), grey, t));
654  frame->name_text_->setColor(lerpColor(Ogre::ColourValue::White, grey, t));
657  }
658  }
659  else
660  {
661  frame->axes_->setToDefaultColors();
662  frame->name_text_->setColor(Ogre::ColourValue::White);
665  }
666 
667  setStatusStd(StatusProperty::Ok, frame->name_, "Transform OK");
668 
669  Ogre::Vector3 position;
670  Ogre::Quaternion orientation;
671  if (!context_->getFrameManager()->getTransform(frame->name_, ros::Time(), position, orientation))
672  {
673  std::stringstream ss;
674  ss << "No transform from [" << frame->name_ << "] to frame [" << fixed_frame_.toStdString() << "]";
675  setStatusStd(StatusProperty::Warn, frame->name_, ss.str());
676  ROS_DEBUG("Error transforming frame '%s' to frame '%s'", frame->name_.c_str(),
677  qPrintable(fixed_frame_));
678  frame->name_node_->setVisible(false);
679  frame->axes_->getSceneNode()->setVisible(false);
680  frame->parent_arrow_->getSceneNode()->setVisible(false);
681  return;
682  }
683 
684  frame->selection_handler_->setPosition(position);
685  frame->selection_handler_->setOrientation(orientation);
686 
687  bool frame_enabled = frame->enabled_property_->getBool();
688 
689  frame->axes_->setPosition(position);
690  frame->axes_->setOrientation(orientation);
691  frame->axes_->getSceneNode()->setVisible(show_axes_property_->getBool() && frame_enabled);
692  float scale = scale_property_->getFloat();
693  frame->axes_->setScale(Ogre::Vector3(scale, scale, scale));
694  float alpha = alpha_property_->getFloat();
695  frame->axes_->updateAlpha(alpha);
696 
697  frame->name_node_->setPosition(position);
698  frame->name_node_->setVisible(show_names_property_->getBool() && frame_enabled);
699  frame->name_node_->setScale(scale, scale, scale);
700 
701  frame->position_property_->setVector(position);
702  frame->orientation_property_->setQuaternion(orientation);
703 
704  std::string old_parent = frame->parent_;
705  frame->parent_.clear();
706  bool has_parent = tf->_getParent(frame->name_, ros::Time(), frame->parent_);
707  if (has_parent)
708  {
709  geometry_msgs::TransformStamped transform;
710  try
711  {
712  transform = tf->lookupTransform(frame->parent_, frame->name_, ros::Time());
713  }
714  catch (tf2::TransformException& e)
715  {
716  ROS_DEBUG("Error transforming frame '%s' (parent of '%s') to frame '%s'", frame->parent_.c_str(),
717  frame->name_.c_str(), qPrintable(fixed_frame_));
718  transform.transform.rotation.w = 1.0;
719  }
720 
721  // get the position/orientation relative to the parent frame
722  const auto& translation = transform.transform.translation;
723  const auto& quat = transform.transform.rotation;
724  Ogre::Vector3 relative_position(translation.x, translation.y, translation.z);
725  Ogre::Quaternion relative_orientation(quat.w, quat.x, quat.y, quat.z);
726  frame->rel_position_property_->setVector(relative_position);
727  frame->rel_orientation_property_->setQuaternion(relative_orientation);
728 
730  {
731  Ogre::Vector3 parent_position;
732  Ogre::Quaternion parent_orientation;
733  if (!context_->getFrameManager()->getTransform(frame->parent_, ros::Time(), parent_position,
734  parent_orientation))
735  {
736  ROS_DEBUG("Error transforming frame '%s' (parent of '%s') to frame '%s'", frame->parent_.c_str(),
737  frame->name_.c_str(), qPrintable(fixed_frame_));
738  }
739 
740  Ogre::Vector3 direction = parent_position - position;
741  float distance = direction.length();
742  direction.normalise();
743 
744  Ogre::Quaternion orient = Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo(direction);
745 
746  frame->distance_to_parent_ = distance;
747  float head_length = (distance < 0.1 * scale) ? (0.1 * scale * distance) : 0.1 * scale;
748  float shaft_length = distance - head_length;
749  // aleeper: This was changed from 0.02 and 0.08 to 0.01 and 0.04 to match proper radius handling in
750  // arrow.cpp
751  frame->parent_arrow_->set(shaft_length, 0.01 * scale, head_length, 0.04 * scale);
752 
753  if (distance > 0.001f)
754  {
755  frame->parent_arrow_->getSceneNode()->setVisible(show_arrows_property_->getBool() &&
756  frame_enabled);
757  }
758  else
759  {
760  frame->parent_arrow_->getSceneNode()->setVisible(false);
761  }
762 
763  frame->parent_arrow_->setPosition(position);
764  frame->parent_arrow_->setOrientation(orient);
765  }
766  else
767  {
768  frame->parent_arrow_->getSceneNode()->setVisible(false);
769  }
770  }
771  else
772  {
773  frame->parent_arrow_->getSceneNode()->setVisible(false);
774  }
775 
776  // If this frame has no tree property or the parent has changed,
777  if (!frame->tree_property_ || old_parent != frame->parent_)
778  {
779  // Look up the new parent.
780  FrameInfo* parent = has_parent ? getFrameInfo(frame->parent_) : nullptr;
781  // Retrieve tree property to add the new child at
782  rviz::Property* parent_tree_property = has_parent ? nullptr : tree_category_;
783  if (parent && parent->tree_property_)
784  parent_tree_property = parent->tree_property_;
785  else if (has_parent) // otherwise reset parent_ to retry if the parent property was created
786  frame->parent_ = old_parent;
787 
788  // If the parent has a tree property, make a new tree property for this frame.
789  if (!parent_tree_property)
790  ; // nothing more to do
791  else if (!frame->tree_property_) // create new property
792  {
793  frame->tree_property_ =
794  new Property(QString::fromStdString(frame->name_), QVariant(), "", parent_tree_property);
795  }
796  else // update property
797  {
798  // re-parent the tree property
800  parent_tree_property->addChild(frame->tree_property_);
801  }
802  }
803 
804  frame->parent_property_->setStdString(frame->parent_);
805  frame->selection_handler_->setParentName(frame->parent_);
806 }
807 
808 HRITFDisplay::M_FrameInfo::iterator HRITFDisplay::deleteFrame(M_FrameInfo::iterator it, bool delete_properties)
809 {
810  FrameInfo* frame = it->second;
811  it = frames_.erase(it);
812 
813  delete frame->axes_;
815  delete frame->parent_arrow_;
816  delete frame->name_text_;
817  scene_manager_->destroySceneNode(frame->name_node_);
818  if (delete_properties)
819  {
820  delete frame->enabled_property_;
821  delete frame->tree_property_;
822  }
823  delete frame;
824  return it;
825 }
826 
828 {
830 }
831 
833 {
834  Display::reset();
835  clear();
836 }
837 
839 // FrameInfo
840 
842  : display_(display)
843  , axes_(nullptr)
844  , axes_coll_(0)
845  , parent_arrow_(nullptr)
846  , name_text_(nullptr)
847  , distance_to_parent_(0.0f)
848  , arrow_orientation_(Ogre::Quaternion::IDENTITY)
849  , tree_property_(nullptr)
850 {
851 }
852 
854 {
855  bool enabled = enabled_property_->getBool();
856  selection_handler_->setEnabled(enabled);
857  setEnabled(enabled);
858 }
859 
861 {
862  bool enabled = selection_handler_->getEnabled();
863  enabled_property_->setBool(enabled);
864  setEnabled(enabled);
865 }
866 
867 void FrameInfo::setEnabled(bool enabled)
868 {
869  if (name_node_)
870  {
871  name_node_->setVisible(display_->show_names_property_->getBool() && enabled);
872  }
873 
874  if (axes_)
875  {
876  axes_->getSceneNode()->setVisible(display_->show_axes_property_->getBool() && enabled);
877  }
878 
879  if (parent_arrow_)
880  {
881  if (distance_to_parent_ > 0.001f)
882  {
883  parent_arrow_->getSceneNode()->setVisible(display_->show_arrows_property_->getBool() && enabled);
884  }
885  else
886  {
887  parent_arrow_->getSceneNode()->setVisible(false);
888  }
889  }
890 
891  if (display_->all_enabled_property_->getBool() && !enabled)
892  {
896  }
897 
898  // Update the configuration that stores the enabled state of all frames
899  display_->frame_config_enabled_state_[this->name_] = enabled;
900 
902 }
903 
904 } // namespace rviz
905 
rviz::MovableText::setTextAlignment
void setTextAlignment(const HorizontalAlignment &horizontalAlignment, const VerticalAlignment &verticalAlignment)
rviz::Arrow::set
void set(float shaft_length, float shaft_diameter, float head_length, float head_diameter)
rviz::HRITFDisplay::frames_
M_FrameInfo frames_
Definition: hri_tf.h:114
rviz::FrameInfo::axes_
Axes * axes_
Definition: hri_tf.h:173
rviz::HRITFDisplay::names_node_
Ogre::SceneNode * names_node_
Definition: hri_tf.h:110
rviz::FrameInfo::parent_arrow_
Arrow * parent_arrow_
Definition: hri_tf.h:176
rviz::BoolProperty::getBool
virtual bool getBool() const
rviz::Axes::getSceneNode
Ogre::SceneNode * getSceneNode()
forwards.h
rviz::Axes::getDefaultYColor
const Ogre::ColourValue & getDefaultYColor()
rviz::TFDisplay::show_arrows_property_
BoolProperty * show_arrows_property_
rviz::FrameInfo::tree_property_
Property * tree_property_
Definition: hri_tf.h:193
axes.h
rviz::HRITFDisplay::showSkeletons_
bool showSkeletons_
Definition: hri_tf.h:141
rviz::Axes::getDefaultZColor
const Ogre::ColourValue & getDefaultZColor()
rviz::HRITFDisplay::showGazes_
bool showGazes_
Definition: hri_tf.h:140
Ogre
rviz::DisplayContext::queueRender
virtual void queueRender()=0
rviz::HRITFDisplay::updateShowFaces
void updateShowFaces()
Definition: hri_tf.cpp:348
quaternion_property.h
rviz::HRITFDisplay::load
void load(const Config &config) override
Definition: hri_tf.cpp:267
rviz::HRITFDisplay::fixedFrameChanged
void fixedFrameChanged() override
Definition: hri_tf.cpp:827
rviz::Arrow::setHeadColor
void setHeadColor(const Ogre::ColourValue &color)
rviz::FrameSelectionHandler::~FrameSelectionHandler
~FrameSelectionHandler() override
rviz::HRITFDisplay::frame_timeout_property_
FloatProperty * frame_timeout_property_
Definition: hri_tf.h:125
rviz::FrameInfo::last_update_
ros::Time last_update_
Definition: hri_tf.h:183
rviz::Arrow
rviz::Display::initialized
bool initialized() const
rviz::FrameInfo::orientation_property_
QuaternionProperty * orientation_property_
Definition: hri_tf.h:189
rviz::Axes::setScale
void setScale(const Ogre::Vector3 &scale) override
rviz::FrameSelectionHandler::category_property_
Property * category_property_
Definition: hri_tf.cpp:72
rviz::Config::MapIterator::isValid
bool isValid()
rviz::FrameSelectionHandler::setParentName
void setParentName(const std::string &parent_name)
Definition: hri_tf.cpp:136
rviz::Arrow::setOrientation
void setOrientation(const Ogre::Quaternion &orientation) override
rviz::HRITFDisplay::onDisable
void onDisable() override
Definition: hri_tf.cpp:314
rviz::HRITFDisplay::root_node_
Ogre::SceneNode * root_node_
Definition: hri_tf.h:109
rviz::Display::clearStatuses
virtual void clearStatuses()
rviz::BoolProperty::setBool
bool setBool(bool value)
selection_manager.h
rviz::HRITFDisplay::updateShowAxes
void updateShowAxes()
Definition: hri_tf.cpp:334
rviz::FloatProperty::setMax
void setMax(float max)
rviz::TFDisplay::changing_single_frame_enabled_state_
bool changing_single_frame_enabled_state_
frame_manager.h
rviz::FrameSelectionHandler::parent_property_
StringProperty * parent_property_
Definition: hri_tf.cpp:74
rviz::Axes::setXColor
void setXColor(const Ogre::ColourValue &col)
rviz::Property::addChild
virtual void addChild(Property *child, int index=-1)
rviz::FrameInfo::name_
std::string name_
Definition: hri_tf.h:171
rviz::HRITFDisplay::clear
void clear()
Definition: hri_tf.cpp:288
rviz::HRITFDisplay
Displays a visual representation of the TF hierarchy.
Definition: hri_tf.h:68
rviz::BoolProperty::BoolProperty
BoolProperty(const QString &name, bool default_value, const QString &description, P *parent, Func &&changed_slot)
rviz::HRITFDisplay::onEnable
void onEnable() override
Definition: hri_tf.cpp:305
rviz::FrameSelectionHandler::setEnabled
void setEnabled(bool enabled)
Definition: hri_tf.cpp:128
rviz::HRITFDisplay::~HRITFDisplay
~HRITFDisplay() override
Definition: hri_tf.cpp:246
rviz::HRITFDisplay::tree_category_
Property * tree_category_
Definition: hri_tf.h:136
rviz::FrameInfo::rel_position_property_
VectorProperty * rel_position_property_
Definition: hri_tf.h:186
rviz::Display::fixed_frame_
QString fixed_frame_
rviz::HRITFDisplay::hri_listener_
hri::HRIListener hri_listener_
Definition: hri_tf.h:143
rviz::QuaternionProperty::setReadOnly
void setReadOnly(bool read_only) override
rviz::FrameSelectionHandler::FrameSelectionHandler
FrameSelectionHandler(FrameInfo *frame, DisplayContext *context)
Definition: hri_tf.cpp:79
rviz::HRITFDisplay::deleteFrame
M_FrameInfo::iterator deleteFrame(M_FrameInfo::iterator it, bool delete_properties)
Definition: hri_tf.cpp:808
rviz::MovableText
hri::HRIListener::getBodies
std::map< ID, BodyWeakConstPtr > getBodies() const
rviz::HRITFDisplay::scale_property_
FloatProperty * scale_property_
Definition: hri_tf.h:128
rviz::MovableText::V_BELOW
V_BELOW
rviz::FrameInfo::parent_property_
StringProperty * parent_property_
Definition: hri_tf.h:190
rviz::FloatProperty::setMin
void setMin(float min)
rviz::lerpColor
Ogre::ColourValue lerpColor(const Ogre::ColourValue &start, const Ogre::ColourValue &end, float t)
Definition: hri_tf.cpp:601
float_property.h
f
f
rviz::MovableText::H_CENTER
H_CENTER
rviz::Display
rviz::Arrow::setShaftColor
void setShaftColor(const Ogre::ColourValue &color)
rviz::HRITFDisplay::axes_node_
Ogre::SceneNode * axes_node_
Definition: hri_tf.h:112
rviz::HRITFDisplay::show_skeletons_property_
BoolProperty * show_skeletons_property_
Definition: hri_tf.h:133
rviz::QuaternionProperty
rviz::FloatProperty
tf2::CompactFrameID
uint32_t CompactFrameID
rviz::TFDisplay::show_names_property_
BoolProperty * show_names_property_
rviz::Property
rviz::FrameInfo::distance_to_parent_
float distance_to_parent_
Definition: hri_tf.h:180
rviz::HRITFDisplay::all_enabled_property_
BoolProperty * all_enabled_property_
Definition: hri_tf.h:126
rviz::HRITFDisplay::frame_config_enabled_state_
M_EnabledState frame_config_enabled_state_
Definition: hri_tf.h:117
rviz::HRITFDisplay::updateShowArrows
void updateShowArrows()
Definition: hri_tf.cpp:360
rviz::HRITFDisplay::updateShowNames
void updateShowNames()
Definition: hri_tf.cpp:320
rviz::TFDisplay::frame_config_enabled_state_
M_EnabledState frame_config_enabled_state_
rviz::V_string
std::vector< std::string > V_string
rviz::Config::mapGetChild
Config mapGetChild(const QString &key) const
rviz::HRITFDisplay::show_axes_property_
BoolProperty * show_axes_property_
Definition: hri_tf.h:123
bool_property.h
rviz::HRITFDisplay::updateFrames
void updateFrames()
Definition: hri_tf.cpp:415
rviz::FrameSelectionHandler::frame_
FrameInfo * frame_
Definition: hri_tf.cpp:71
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::FrameSelectionHandler::createProperties
void createProperties(const Picked &obj, Property *parent_property) override
Definition: hri_tf.cpp:90
rviz::FrameInfo::position_property_
VectorProperty * position_property_
Definition: hri_tf.h:188
rviz::FloatProperty::getFloat
virtual float getFloat() const
rviz::Axes::setZColor
void setZColor(const Ogre::ColourValue &col)
ROS_DEBUG
#define ROS_DEBUG(...)
rviz::S_FrameInfo
std::set< FrameInfo * > S_FrameInfo
rviz
rviz::HRITFDisplay::showFaces_
bool showFaces_
Definition: hri_tf.h:139
rviz::Property::Property
Property(const QString &name, const QVariant &default_value, const QString &description, P *parent, Func &&changed_slot)
rviz::FrameSelectionHandler::enabled_property_
BoolProperty * enabled_property_
Definition: hri_tf.cpp:73
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
rviz::FrameSelectionHandler::destroyProperties
void destroyProperties(const Picked &obj, Property *parent_property) override
Definition: hri_tf.cpp:109
rviz::VectorProperty::setVector
virtual bool setVector(const Ogre::Vector3 &vector)
rviz::Axes::updateAlpha
void updateAlpha(float alpha)
rviz::QuaternionProperty::setQuaternion
virtual bool setQuaternion(const Ogre::Quaternion &quaternion)
rviz::HRITFDisplay::changing_single_frame_enabled_state_
bool changing_single_frame_enabled_state_
Definition: hri_tf.h:138
rviz::StringProperty
rviz::StatusProperty::Ok
Ok
rviz::HRITFDisplay::alpha_property_
FloatProperty * alpha_property_
Definition: hri_tf.h:129
rviz::Axes::getDefaultXColor
const Ogre::ColourValue & getDefaultXColor()
rviz::StatusProperty::Warn
Warn
rviz::HRITFDisplay::reset
void reset() override
Definition: hri_tf.cpp:832
rviz::FrameInfo::axes_coll_
CollObjectHandle axes_coll_
Definition: hri_tf.h:174
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
rviz::FrameInfo::name_text_
MovableText * name_text_
Definition: hri_tf.h:177
rviz::Axes::setYColor
void setYColor(const Ogre::ColourValue &col)
rviz::FrameSelectionHandler::setOrientation
void setOrientation(const Ogre::Quaternion &orientation)
Definition: hri_tf.cpp:152
rviz::HRITFDisplay::createFrame
FrameInfo * createFrame(const std::string &frame)
Definition: hri_tf.cpp:534
rviz::Display::load
void load(const Config &config) override
rviz::FrameInfo::rel_orientation_property_
QuaternionProperty * rel_orientation_property_
Definition: hri_tf.h:187
rviz::FrameInfo::updateVisibilityFromFrame
void updateVisibilityFromFrame()
Definition: hri_tf.cpp:853
rviz::FrameInfo::name_node_
Ogre::SceneNode * name_node_
Definition: hri_tf.h:178
rviz::TFDisplay::all_enabled_property_
BoolProperty * all_enabled_property_
arrow.h
rviz::HRITFDisplay::arrows_node_
Ogre::SceneNode * arrows_node_
Definition: hri_tf.h:111
rviz::HRITFDisplay::updateshowSkeletons
void updateshowSkeletons()
Definition: hri_tf.cpp:356
hri_tf.h
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const=0
rviz::FrameInfo::selection_handler_
FrameSelectionHandlerPtr selection_handler_
Definition: hri_tf.h:175
rviz::ARROW_SHAFT_COLOR
static const Ogre::ColourValue ARROW_SHAFT_COLOR(0.8f, 0.8f, 0.3f, 1.0f)
rviz::Axes
rviz::Property::getParent
Property * getParent() const
rviz::SelectionManager::removeObject
void removeObject(CollObjectHandle obj)
rviz::FrameInfo::enabled_property_
BoolProperty * enabled_property_
Definition: hri_tf.h:191
rviz::HRITFDisplay::show_names_property_
BoolProperty * show_names_property_
Definition: hri_tf.h:121
rviz::FrameInfo::parent_
std::string parent_
Definition: hri_tf.h:172
rviz::ARROW_HEAD_COLOR
static const Ogre::ColourValue ARROW_HEAD_COLOR(1.0f, 0.1f, 0.6f, 1.0f)
start
ROSCPP_DECL void start()
rviz::TFDisplay::show_axes_property_
BoolProperty * show_axes_property_
rviz::HRITFDisplay::show_gazes_property_
BoolProperty * show_gazes_property_
Definition: hri_tf.h:132
hri::HRIListener::getFaces
std::map< ID, FaceWeakConstPtr > getFaces() const
rviz::HRITFDisplay::update
void update(float wall_dt, float ros_dt) override
Definition: hri_tf.cpp:392
rviz::FrameManager::getTransform
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
rviz::Display::setStatusStd
void setStatusStd(StatusProperty::Level level, const std::string &name, const std::string &text)
rviz::HRITFDisplay::show_faces_property_
BoolProperty * show_faces_property_
Definition: hri_tf.h:131
rviz::Display::context_
DisplayContext * context_
rviz::HRITFDisplay::update_timer_
float update_timer_
Definition: hri_tf.h:119
ros::Time
rviz::FrameInfo::setEnabled
void setEnabled(bool enabled)
Definition: hri_tf.cpp:867
rviz::Axes::setToDefaultColors
void setToDefaultColors()
rviz::Property::setReadOnly
virtual void setReadOnly(bool read_only)
rviz::FrameSelectionHandler::position_property_
VectorProperty * position_property_
Definition: hri_tf.cpp:75
rviz::FrameInfo::last_time_to_fixed_
ros::Time last_time_to_fixed_
Definition: hri_tf.h:184
rviz::FrameInfo::display_
TFDisplay * display_
rviz::VectorProperty::setReadOnly
void setReadOnly(bool read_only) override
rviz::FrameSelectionHandler::getEnabled
bool getEnabled()
Definition: hri_tf.cpp:119
rviz::HRITFDisplay::updateFrame
void updateFrame(FrameInfo *frame)
Definition: hri_tf.cpp:606
rviz::StringProperty::setStdString
bool setStdString(const std::string &std_str)
rviz::HRITFDisplay::onInitialize
void onInitialize() override
Definition: hri_tf.cpp:256
rviz::HRITFDisplay::show_arrows_property_
BoolProperty * show_arrows_property_
Definition: hri_tf.h:122
class_list_macros.hpp
rviz::HRITFDisplay::HRITFDisplay
HRITFDisplay()
Definition: hri_tf.cpp:162
movable_text.h
rviz::Display::reset
virtual void reset()
rviz::FrameSelectionHandler::setPosition
void setPosition(const Ogre::Vector3 &position)
Definition: hri_tf.cpp:144
tf
rviz::Axes::setPosition
void setPosition(const Ogre::Vector3 &position) override
rviz::DisplayContext::getSelectionManager
virtual SelectionManager * getSelectionManager() const=0
rviz::VectorProperty
rviz::FrameSelectionHandler
Definition: hri_tf.cpp:53
DurationBase< Duration >::toSec
double toSec() const
rviz::Config::MapIterator
rviz::Arrow::setPosition
void setPosition(const Ogre::Vector3 &position) override
rviz::HRITFDisplay::updateShowGazes
void updateShowGazes()
Definition: hri_tf.cpp:352
rviz::Axes::setOrientation
void setOrientation(const Ogre::Quaternion &orientation) override
vector_property.h
string_property.h
rviz::Arrow::getSceneNode
Ogre::SceneNode * getSceneNode()
tf2::TransformException
rviz::Property::removeChildren
virtual void removeChildren(int start_index=0, int count=-1)
rviz::FrameInfo::updateVisibilityFromSelection
void updateVisibilityFromSelection()
Definition: hri_tf.cpp:860
rviz::MovableText::setColor
void setColor(const Ogre::ColourValue &color)
rviz::HRITFDisplay::FrameInfo
friend class FrameInfo
Definition: hri_tf.h:147
rviz::Config::mapIterator
MapIterator mapIterator() const
config
config
ros::Duration
rviz::HRITFDisplay::frames_category_
Property * frames_category_
Definition: hri_tf.h:135
rviz::Property::takeChild
Property * takeChild(Property *child)
rviz::HRITFDisplay::allEnabledChanged
void allEnabledChanged()
Definition: hri_tf.cpp:374
rviz::DisplayContext::getTF2BufferPtr
std::shared_ptr< tf2_ros::Buffer > getTF2BufferPtr() const
rviz::Config
t
geometry_msgs::TransformStamped t
rviz::Arrow::setColor
void setColor(const Ogre::ColourValue &color)
rviz::HRITFDisplay::update_rate_property_
FloatProperty * update_rate_property_
Definition: hri_tf.h:124
rviz::FrameInfo
Internal class needed only by HRITFDisplay.
Definition: hri_tf.h:151
rviz::HRITFDisplay::skeleton_components_
std::vector< std::string > skeleton_components_
Definition: hri_tf.h:145
rviz::FrameInfo::FrameInfo
FrameInfo(TFDisplay *display)
rviz::Config::getValue
QVariant getValue() const
rviz::FrameSelectionHandler::orientation_property_
QuaternionProperty * orientation_property_
Definition: hri_tf.cpp:76
rviz::HRITFDisplay::getFrameInfo
FrameInfo * getFrameInfo(const std::string &frame)
Definition: hri_tf.cpp:404
ros::Time::now
static Time now()
display_context.h


hri_rviz
Author(s): Lorenzo Ferrini, Séverin Lemaignan
autogenerated on Fri Oct 20 2023 02:53:21