DebugDrawerHelper.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 #include <VirtualRobot/Robot.h>
27 #include <SimoxUtility/shapes/OrientedBox.h>
28 #include <SimoxUtility/shapes/XYConstrainedOrientedBox.h>
29 
30 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
32 
33 namespace armarx
34 {
35  class DebugDrawerHelper;
36  using DebugDrawerHelperPtr = std::shared_ptr<DebugDrawerHelper>;
37 }
38 
40 {
41  /**
42  * @brief This class provides the draw options for a given frame (static Matrix, or a robot node).
43  * It is used by the \ref DebugDrawerHelper.
44  *
45  * \note Do not use this class directly. Use it via \ref DebugDrawerHelper.
46  */
47  class FrameView
48  {
49  public:
51  FrameView(class DebugDrawerHelper& helper, const VirtualRobot::RobotNodePtr& rn);
52  //make global
53  public:
55  Eigen::Vector3f makeGlobalEigen(const Eigen::Vector3f& position) const;
56  Eigen::Vector3f makeGlobalDirectionEigen(const Eigen::Vector3f& direction) const;
57  PosePtr makeGlobal(const Eigen::Matrix4f& pose) const;
58  Vector3Ptr makeGlobal(const Eigen::Vector3f& position) const;
59  Vector3Ptr makeGlobalDirection(const Eigen::Vector3f& direction) const;
60 
61  //1st order draw functions (direct calls to proxy)
62  public:
63  void drawPose(const std::string& name, const Eigen::Matrix4f& pose);
64  void drawPose(const std::string& name, const Eigen::Matrix4f& pose, float scale);
65 
66  void drawBox(const std::string& name, const Eigen::Matrix4f& pose, const Eigen::Vector3f& size, const DrawColor& color);
67 
68  void drawLine(const std::string& name, const Eigen::Vector3f& p1, const Eigen::Vector3f& p2, float width, const DrawColor& color);
69 
70  void drawText(const std::string& name, const Eigen::Vector3f& p1, const std::string& text, const DrawColor& color, int size);
71 
72  void drawArrow(const std::string& name, const Eigen::Vector3f& pos, const Eigen::Vector3f& direction, const DrawColor& color, float length, float width);
73 
74  void drawSphere(const std::string& name, const Eigen::Vector3f& position, float size, const DrawColor& color);
75 
76  void drawPointCloud(const std::string& name, const std::vector<Eigen::Vector3f>& points, float pointSize, const DrawColor& color);
77 
78  void drawRobot(const std::string& name, const std::string& robotFile, const std::string& armarxProject, const Eigen::Matrix4f& pose, const DrawColor& color);
79  void setRobotConfig(const std::string& name, const std::map<std::string, float>& config);
80  void setRobotColor(const std::string& name, const DrawColor& color);
81  void setRobotPose(const std::string& name, const Eigen::Matrix4f& pose);
82 
83  //2nd order draw functions (call 1st order)
84  public:
85  void drawPoses(const std::string& prefix, const std::vector<Eigen::Matrix4f>& poses);
86  void drawPoses(const std::string& prefix, const std::vector<Eigen::Matrix4f>& poses, float scale);
87 
88  void drawBox(const std::string& name, const Eigen::Vector3f& position, float size, const DrawColor& color);
89  void drawBox(const std::string& name, const Eigen::Matrix4f& pose, float size, const DrawColor& color);
90  template<class FloatT>
91  void drawBox(const std::string& name, const simox::OrientedBox<FloatT>& box, const DrawColor& color)
92  {
93  drawBox(name, box.template transformation_centered<float>(), box.template dimensions<float>(), color);
94  }
95  template<class FloatT>
96  void drawBox(const std::string& name, const simox::XYConstrainedOrientedBox<FloatT>& box, const DrawColor& color)
97  {
98  drawBox(name, box.template transformation_centered<float>(), box.template dimensions<float>(), color);
99  }
100 
101 
102  void drawLine(const std::string& name, const Eigen::Vector3f& p1, const Eigen::Vector3f& p2);
103 
104  void drawLines(const std::string& prefix, const std::vector<Eigen::Vector3f>& ps, float width, const DrawColor& color);
105  void drawLines(const std::string& prefix, const std::vector<Eigen::Vector3f>& ps);
106  void drawLines(const std::string& prefix, const std::vector<Eigen::Matrix4f>& ps, float width, const DrawColor& color);
107  void drawLines(const std::string& prefix, const std::vector<Eigen::Matrix4f>& ps);
108  protected:
111  VirtualRobot::RobotNodePtr _rn;
112  };
113 }
114 
115 namespace armarx
116 {
117  /**
118  * @brief The DebugDrawerHelper class provides draw functions
119  * in a given frame (static matrix or robot node) and accepts eigen data types
120  *
121  *
122  * \note Implement new draw functions in \ref armarx::detail::DebugDrawerHelper::FrameView
123  */
125  {
128  public:
129  struct Defaults
130  {
131  float lineWidth = 2;
132  DrawColor lineColor = DrawColor {0, 1, 0, 1};
133  };
134  enum class DrawElementType
135  {
137  };
138  struct DrawElement
139  {
140  std::string name;
142  bool operator<(const DrawElement& rhs) const
143  {
144  int cmp = name.compare(rhs.name);
145  return cmp < 0 || (cmp == 0 && type < rhs.type);
146  }
147  };
148  class Colors
149  {
150  public:
151  static const DrawColor Red;
152  static const DrawColor Green;
153  static const DrawColor Blue;
154  static const DrawColor Yellow;
155  static const DrawColor Orange;
156  static DrawColor Lerp(const DrawColor& a, const DrawColor& b, float f);
157  };
158 
159  DebugDrawerHelper(const DebugDrawerInterfacePrx& debugDrawerPrx, const std::string& layerName, const VirtualRobot::RobotPtr& robot);
160  DebugDrawerHelper(const std::string& layerName);
161 
162  //utility
163  void clearLayer();
164  void cyclicCleanup();
165 
166  void setVisuEnabled(bool enableVisu);
167  void removeElement(const std::string& name, DrawElementType type);
168 
170 
171  const VirtualRobot::RobotPtr& getRobot() const;
173  void setDebugDrawer(const DebugDrawerInterfacePrx& drawer);
174  void setRobot(const VirtualRobot::RobotPtr& rob);
175 
178  FrameView inFrame(const std::string& nodeName);
179  FrameView inFrame(const VirtualRobot::RobotNodePtr& node);
180 
183  void setDefaultFrame(const std::string& nodeName);
184  void setDefaultFrame(const VirtualRobot::RobotNodePtr& node);
185 
186  private:
187  void addNewElement(const std::string& name, DrawElementType type);
188 
189  private:
190  std::set<DrawElement> newElements;
191  std::set<DrawElement> oldElements;
192  bool enableVisu = true;
193  DebugDrawerInterfacePrx debugDrawerPrx;
194  std::string layerName;
196  };
197 }
armarx::DebugDrawerHelper::Colors::Orange
static const DrawColor Orange
Definition: DebugDrawerHelper.h:155
armarx::DebugDrawerHelper::Defaults::lineColor
DrawColor lineColor
Definition: DebugDrawerHelper.h:132
armarx::DebugDrawerHelper::setDefaultFrameToGlobal
void setDefaultFrameToGlobal()
Definition: DebugDrawerHelper.cpp:402
armarx::detail::DebugDrawerHelper::FrameView::drawBox
void drawBox(const std::string &name, const Eigen::Matrix4f &pose, const Eigen::Vector3f &size, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:107
armarx::DebugDrawerHelper::DrawElementType::ColoredPointCloud
@ ColoredPointCloud
armarx::detail::DebugDrawerHelper::FrameView::setRobotPose
void setRobotPose(const std::string &name, const Eigen::Matrix4f &pose)
Definition: DebugDrawerHelper.cpp:179
armarx::detail::DebugDrawerHelper
Definition: DebugDrawerHelper.cpp:35
armarx::detail::DebugDrawerHelper::FrameView::makeGlobal
PosePtr makeGlobal(const Eigen::Matrix4f &pose) const
Definition: DebugDrawerHelper.cpp:73
armarx::detail::DebugDrawerHelper::FrameView::drawLines
void drawLines(const std::string &prefix, const std::vector< Eigen::Vector3f > &ps, float width, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:224
armarx::detail::DebugDrawerHelper::FrameView::setRobotColor
void setRobotColor(const std::string &name, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:174
armarx::detail::DebugDrawerHelper::FrameView::drawPoses
void drawPoses(const std::string &prefix, const std::vector< Eigen::Matrix4f > &poses)
Definition: DebugDrawerHelper.cpp:187
armarx::DebugDrawerHelper::setDebugDrawer
void setDebugDrawer(const DebugDrawerInterfacePrx &drawer)
Definition: DebugDrawerHelper.cpp:363
Pose.h
armarx::DebugDrawerHelper::DrawElement::type
DrawElementType type
Definition: DebugDrawerHelper.h:141
armarx::DebugDrawerHelper::clearLayer
void clearLayer()
Definition: DebugDrawerHelper.cpp:281
armarx::DebugDrawerHelper::setRobot
void setRobot(const VirtualRobot::RobotPtr &rob)
Definition: DebugDrawerHelper.cpp:369
armarx::DebugDrawerHelperPtr
std::shared_ptr< DebugDrawerHelper > DebugDrawerHelperPtr
Definition: DebugDrawerHelper.h:36
armarx::DebugDrawerHelper::setDefaultFrame
void setDefaultFrame(const Eigen::Matrix4f &frame=Eigen::Matrix4f::Identity())
Definition: DebugDrawerHelper.cpp:396
armarx::DebugDrawerHelper::removeElement
void removeElement(const std::string &name, DrawElementType type)
Definition: DebugDrawerHelper.cpp:324
armarx::DebugDrawerHelper::DrawElementType::Arrow
@ Arrow
armarx::detail::DebugDrawerHelper::FrameView::drawPose
void drawPose(const std::string &name, const Eigen::Matrix4f &pose)
Definition: DebugDrawerHelper.cpp:93
armarx::detail::DebugDrawerHelper::FrameView::drawSphere
void drawSphere(const std::string &name, const Eigen::Vector3f &position, float size, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:135
armarx::detail::DebugDrawerHelper::FrameView::makeGlobalDirection
Vector3Ptr makeGlobalDirection(const Eigen::Vector3f &direction) const
Definition: DebugDrawerHelper.cpp:83
armarx::detail::DebugDrawerHelper::FrameView::drawText
void drawText(const std::string &name, const Eigen::Vector3f &p1, const std::string &text, const DrawColor &color, int size)
Definition: DebugDrawerHelper.cpp:121
armarx::detail::DebugDrawerHelper::FrameView::drawPointCloud
void drawPointCloud(const std::string &name, const std::vector< Eigen::Vector3f > &points, float pointSize, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:141
IceInternal::Handle< Pose >
armarx::DebugDrawerHelper::DrawElementType::Box
@ Box
armarx::detail::DebugDrawerHelper::FrameView
This class provides the draw options for a given frame (static Matrix, or a robot node).
Definition: DebugDrawerHelper.h:47
armarx::detail::DebugDrawerHelper::FrameView::makeGlobalDirectionEigen
Eigen::Vector3f makeGlobalDirectionEigen(const Eigen::Vector3f &direction) const
Definition: DebugDrawerHelper.cpp:64
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::DebugDrawerHelper::Defaults::lineWidth
float lineWidth
Definition: DebugDrawerHelper.h:131
armarx::detail::DebugDrawerHelper::FrameView::FrameView
FrameView(class DebugDrawerHelper &helper, const Eigen::Matrix4f frame=Eigen::Matrix4f::Identity())
Definition: DebugDrawerHelper.cpp:37
armarx::detail::DebugDrawerHelper::FrameView::_helper
class DebugDrawerHelper * _helper
Definition: DebugDrawerHelper.h:109
armarx::DebugDrawerHelper::setVisuEnabled
void setVisuEnabled(bool enableVisu)
Definition: DebugDrawerHelper.cpp:319
armarx::DebugDrawerHelper::cyclicCleanup
void cyclicCleanup()
Definition: DebugDrawerHelper.cpp:289
armarx::detail::DebugDrawerHelper::FrameView::drawBox
void drawBox(const std::string &name, const simox::XYConstrainedOrientedBox< FloatT > &box, const DrawColor &color)
Definition: DebugDrawerHelper.h:96
armarx::detail::DebugDrawerHelper::FrameView::drawLine
void drawLine(const std::string &name, const Eigen::Vector3f &p1, const Eigen::Vector3f &p2, float width, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:114
armarx::DebugDrawerHelper::DrawElementType::Pose
@ Pose
armarx::DebugDrawerHelper::Colors::Blue
static const DrawColor Blue
Definition: DebugDrawerHelper.h:153
armarx::DebugDrawerHelper::DrawElementType::Line
@ Line
armarx::DebugDrawerHelper::DrawElement::name
std::string name
Definition: DebugDrawerHelper.h:140
armarx::detail::DebugDrawerHelper::FrameView::drawBox
void drawBox(const std::string &name, const simox::OrientedBox< FloatT > &box, const DrawColor &color)
Definition: DebugDrawerHelper.h:91
armarx::detail::DebugDrawerHelper::FrameView::setRobotConfig
void setRobotConfig(const std::string &name, const std::map< std::string, float > &config)
Definition: DebugDrawerHelper.cpp:169
armarx::DebugDrawerHelper::Colors::Red
static const DrawColor Red
Definition: DebugDrawerHelper.h:151
armarx::detail::DebugDrawerHelper::FrameView::_rn
VirtualRobot::RobotNodePtr _rn
Definition: DebugDrawerHelper.h:111
armarx::DebugDrawerHelper::DrawElement
Definition: DebugDrawerHelper.h:138
armarx::DebugDrawerHelper
The DebugDrawerHelper class provides draw functions in a given frame (static matrix or robot node) an...
Definition: DebugDrawerHelper.h:124
armarx::DebugDrawerHelper::DebugDrawerHelper
DebugDrawerHelper(const DebugDrawerInterfacePrx &debugDrawerPrx, const std::string &layerName, const VirtualRobot::RobotPtr &robot)
Definition: DebugDrawerHelper.cpp:265
armarx::DebugDrawerHelper::defaults
Defaults defaults
Definition: DebugDrawerHelper.h:169
armarx::DebugDrawerHelper::getDebugDrawer
const DebugDrawerInterfacePrx & getDebugDrawer() const
Definition: DebugDrawerHelper.cpp:358
armarx::detail::DebugDrawerHelper::FrameView::makeGlobalEigen
Eigen::Matrix4f makeGlobalEigen(const Eigen::Matrix4f &pose) const
Definition: DebugDrawerHelper.cpp:46
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::DebugDrawerHelper::inGlobalFrame
FrameView inGlobalFrame()
Definition: DebugDrawerHelper.cpp:378
armarx::DebugDrawerHelper::DrawElementType
DrawElementType
Definition: DebugDrawerHelper.h:134
armarx::DebugDrawerHelper::DrawElementType::Text
@ Text
simox::OrientedBox
Definition: ice_conversions.h:18
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::DebugDrawerHelper::Colors::Lerp
static DrawColor Lerp(const DrawColor &a, const DrawColor &b, float f)
Definition: DebugDrawerHelper.cpp:435
armarx::DebugDrawerHelper::getRobot
const VirtualRobot::RobotPtr & getRobot() const
Definition: DebugDrawerHelper.cpp:353
armarx::DebugDrawerHelper::Colors::Yellow
static const DrawColor Yellow
Definition: DebugDrawerHelper.h:154
armarx::DebugDrawerHelper::DrawElement::operator<
bool operator<(const DrawElement &rhs) const
Definition: DebugDrawerHelper.h:142
armarx::DebugDrawerHelper::Colors
Definition: DebugDrawerHelper.h:148
armarx::detail::DebugDrawerHelper::FrameView::drawRobot
void drawRobot(const std::string &name, const std::string &robotFile, const std::string &armarxProject, const Eigen::Matrix4f &pose, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:160
armarx::detail::DebugDrawerHelper::FrameView::drawArrow
void drawArrow(const std::string &name, const Eigen::Vector3f &pos, const Eigen::Vector3f &direction, const DrawColor &color, float length, float width)
Definition: DebugDrawerHelper.cpp:128
armarx::DebugDrawerHelper::Colors::Green
static const DrawColor Green
Definition: DebugDrawerHelper.h:152
armarx::DebugDrawerHelper::inFrame
FrameView inFrame(const Eigen::Matrix4f &frame=Eigen::Matrix4f::Identity())
Definition: DebugDrawerHelper.cpp:374
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::detail::DebugDrawerHelper::FrameView::_fallbackFrame
Eigen::Matrix4f _fallbackFrame
Definition: DebugDrawerHelper.h:110
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::DebugDrawerHelper::DrawElementType::Robot
@ Robot
armarx::DebugDrawerHelper::Defaults
Definition: DebugDrawerHelper.h:129