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 <SimoxUtility/shapes/OrientedBox.h>
27 #include <SimoxUtility/shapes/XYConstrainedOrientedBox.h>
28 #include <VirtualRobot/VirtualRobot.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 } // namespace armarx
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:
50  FrameView(class DebugDrawerHelper& helper,
52  FrameView(class DebugDrawerHelper& helper, const VirtualRobot::RobotNodePtr& rn);
53  //make global
54  public:
56  Eigen::Vector3f makeGlobalEigen(const Eigen::Vector3f& position) const;
57  Eigen::Vector3f makeGlobalDirectionEigen(const Eigen::Vector3f& direction) const;
58  PosePtr makeGlobal(const Eigen::Matrix4f& pose) const;
59  Vector3Ptr makeGlobal(const Eigen::Vector3f& position) const;
60  Vector3Ptr makeGlobalDirection(const Eigen::Vector3f& direction) const;
61 
62  //1st order draw functions (direct calls to proxy)
63  public:
64  void drawPose(const std::string& name, const Eigen::Matrix4f& pose);
65  void drawPose(const std::string& name, const Eigen::Matrix4f& pose, float scale);
66 
67  void drawBox(const std::string& name,
68  const Eigen::Matrix4f& pose,
69  const Eigen::Vector3f& size,
70  const DrawColor& color);
71 
72  void drawLine(const std::string& name,
73  const Eigen::Vector3f& p1,
74  const Eigen::Vector3f& p2,
75  float width,
76  const DrawColor& color);
77 
78  void drawText(const std::string& name,
79  const Eigen::Vector3f& p1,
80  const std::string& text,
81  const DrawColor& color,
82  int size);
83 
84  void drawArrow(const std::string& name,
85  const Eigen::Vector3f& pos,
86  const Eigen::Vector3f& direction,
87  const DrawColor& color,
88  float length,
89  float width);
90 
91  void drawSphere(const std::string& name,
92  const Eigen::Vector3f& position,
93  float size,
94  const DrawColor& color);
95 
96  void drawPointCloud(const std::string& name,
97  const std::vector<Eigen::Vector3f>& points,
98  float pointSize,
99  const DrawColor& color);
100 
101  void drawRobot(const std::string& name,
102  const std::string& robotFile,
103  const std::string& armarxProject,
104  const Eigen::Matrix4f& pose,
105  const DrawColor& color);
106  void setRobotConfig(const std::string& name, const std::map<std::string, float>& config);
107  void setRobotColor(const std::string& name, const DrawColor& color);
108  void setRobotPose(const std::string& name, const Eigen::Matrix4f& pose);
109 
110  //2nd order draw functions (call 1st order)
111  public:
112  void drawPoses(const std::string& prefix, const std::vector<Eigen::Matrix4f>& poses);
113  void drawPoses(const std::string& prefix,
114  const std::vector<Eigen::Matrix4f>& poses,
115  float scale);
116 
117  void drawBox(const std::string& name,
118  const Eigen::Vector3f& position,
119  float size,
120  const DrawColor& color);
121  void drawBox(const std::string& name,
122  const Eigen::Matrix4f& pose,
123  float size,
124  const DrawColor& color);
125 
126  template <class FloatT>
127  void
128  drawBox(const std::string& name,
129  const simox::OrientedBox<FloatT>& box,
130  const DrawColor& color)
131  {
132  drawBox(name,
133  box.template transformation_centered<float>(),
134  box.template dimensions<float>(),
135  color);
136  }
137 
138  template <class FloatT>
139  void
140  drawBox(const std::string& name,
141  const simox::XYConstrainedOrientedBox<FloatT>& box,
142  const DrawColor& color)
143  {
144  drawBox(name,
145  box.template transformation_centered<float>(),
146  box.template dimensions<float>(),
147  color);
148  }
149 
150  void
151  drawLine(const std::string& name, const Eigen::Vector3f& p1, const Eigen::Vector3f& p2);
152 
153  void drawLines(const std::string& prefix,
154  const std::vector<Eigen::Vector3f>& ps,
155  float width,
156  const DrawColor& color);
157  void drawLines(const std::string& prefix, const std::vector<Eigen::Vector3f>& ps);
158  void drawLines(const std::string& prefix,
159  const std::vector<Eigen::Matrix4f>& ps,
160  float width,
161  const DrawColor& color);
162  void drawLines(const std::string& prefix, const std::vector<Eigen::Matrix4f>& ps);
163 
164  protected:
167  VirtualRobot::RobotNodePtr _rn;
168  };
169 } // namespace armarx::detail::DebugDrawerHelper
170 
171 namespace armarx
172 {
173  /**
174  * @brief The DebugDrawerHelper class provides draw functions
175  * in a given frame (static matrix or robot node) and accepts eigen data types
176  *
177  *
178  * \note Implement new draw functions in \ref armarx::detail::DebugDrawerHelper::FrameView
179  */
181  {
184 
185  public:
186  struct Defaults
187  {
188  float lineWidth = 2;
189  DrawColor lineColor = DrawColor{0, 1, 0, 1};
190  };
191  enum class DrawElementType
192  {
193  Pose,
194  Box,
195  Line,
196  Text,
197  Arrow,
199  Robot
200  };
201 
202  struct DrawElement
203  {
204  std::string name;
206 
207  bool
208  operator<(const DrawElement& rhs) const
209  {
210  int cmp = name.compare(rhs.name);
211  return cmp < 0 || (cmp == 0 && type < rhs.type);
212  }
213  };
214 
215  class Colors
216  {
217  public:
218  static const DrawColor Red;
219  static const DrawColor Green;
220  static const DrawColor Blue;
221  static const DrawColor Yellow;
222  static const DrawColor Orange;
223  static DrawColor Lerp(const DrawColor& a, const DrawColor& b, float f);
224  };
225 
226  DebugDrawerHelper(const DebugDrawerInterfacePrx& debugDrawerPrx,
227  const std::string& layerName,
228  const VirtualRobot::RobotPtr& robot);
229  DebugDrawerHelper(const std::string& layerName);
230 
231  //utility
232  void clearLayer();
233  void cyclicCleanup();
234 
235  void setVisuEnabled(bool enableVisu);
236  void removeElement(const std::string& name, DrawElementType type);
237 
239 
240  const VirtualRobot::RobotPtr& getRobot() const;
242  void setDebugDrawer(const DebugDrawerInterfacePrx& drawer);
243  void setRobot(const VirtualRobot::RobotPtr& rob);
244 
247  FrameView inFrame(const std::string& nodeName);
248  FrameView inFrame(const VirtualRobot::RobotNodePtr& node);
249 
252  void setDefaultFrame(const std::string& nodeName);
253  void setDefaultFrame(const VirtualRobot::RobotNodePtr& node);
254 
255  private:
256  void addNewElement(const std::string& name, DrawElementType type);
257 
258  private:
259  std::set<DrawElement> newElements;
260  std::set<DrawElement> oldElements;
261  bool enableVisu = true;
262  DebugDrawerInterfacePrx debugDrawerPrx;
263  std::string layerName;
265  };
266 } // namespace armarx
armarx::DebugDrawerHelper::Colors::Orange
static const DrawColor Orange
Definition: DebugDrawerHelper.h:222
armarx::DebugDrawerHelper::Defaults::lineColor
DrawColor lineColor
Definition: DebugDrawerHelper.h:189
armarx::DebugDrawerHelper::setDefaultFrameToGlobal
void setDefaultFrameToGlobal()
Definition: DebugDrawerHelper.cpp:529
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:131
armarx::DebugDrawerHelper::DrawElementType::ColoredPointCloud
@ ColoredPointCloud
armarx::detail::DebugDrawerHelper::FrameView::setRobotPose
void setRobotPose(const std::string &name, const Eigen::Matrix4f &pose)
Definition: DebugDrawerHelper.cpp:252
armarx::detail::DebugDrawerHelper
Definition: DebugDrawerHelper.cpp:37
armarx::detail::DebugDrawerHelper::FrameView::makeGlobal
PosePtr makeGlobal(const Eigen::Matrix4f &pose) const
Definition: DebugDrawerHelper.cpp:84
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:318
armarx::detail::DebugDrawerHelper::FrameView::setRobotColor
void setRobotColor(const std::string &name, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:245
armarx::detail::DebugDrawerHelper::FrameView::drawPoses
void drawPoses(const std::string &prefix, const std::vector< Eigen::Matrix4f > &poses)
Definition: DebugDrawerHelper.cpp:262
armarx::DebugDrawerHelper::setDebugDrawer
void setDebugDrawer(const DebugDrawerInterfacePrx &drawer)
Definition: DebugDrawerHelper.cpp:479
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
Pose.h
armarx::DebugDrawerHelper::DrawElement::type
DrawElementType type
Definition: DebugDrawerHelper.h:205
armarx::DebugDrawerHelper::clearLayer
void clearLayer()
Definition: DebugDrawerHelper.cpp:390
armarx::DebugDrawerHelper::setRobot
void setRobot(const VirtualRobot::RobotPtr &rob)
Definition: DebugDrawerHelper.cpp:486
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:521
armarx::DebugDrawerHelper::removeElement
void removeElement(const std::string &name, DrawElementType type)
Definition: DebugDrawerHelper.cpp:436
armarx::DebugDrawerHelper::DrawElementType::Arrow
@ Arrow
armarx::detail::DebugDrawerHelper::FrameView::drawPose
void drawPose(const std::string &name, const Eigen::Matrix4f &pose)
Definition: DebugDrawerHelper.cpp:114
armarx::detail::DebugDrawerHelper::FrameView::drawSphere
void drawSphere(const std::string &name, const Eigen::Vector3f &position, float size, const DrawColor &color)
Definition: DebugDrawerHelper.cpp:188
armarx::detail::DebugDrawerHelper::FrameView::makeGlobalDirection
Vector3Ptr makeGlobalDirection(const Eigen::Vector3f &direction) const
Definition: DebugDrawerHelper.cpp:98
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:156
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:199
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:73
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::DebugDrawerHelper::Defaults::lineWidth
float lineWidth
Definition: DebugDrawerHelper.h:188
armarx::detail::DebugDrawerHelper::FrameView::FrameView
FrameView(class DebugDrawerHelper &helper, const Eigen::Matrix4f frame=Eigen::Matrix4f::Identity())
Definition: DebugDrawerHelper.cpp:39
armarx::detail::DebugDrawerHelper::FrameView::_helper
class DebugDrawerHelper * _helper
Definition: DebugDrawerHelper.h:165
armarx::DebugDrawerHelper::setVisuEnabled
void setVisuEnabled(bool enableVisu)
Definition: DebugDrawerHelper.cpp:430
armarx::DebugDrawerHelper::cyclicCleanup
void cyclicCleanup()
Definition: DebugDrawerHelper.cpp:399
armarx::detail::DebugDrawerHelper::FrameView::drawBox
void drawBox(const std::string &name, const simox::XYConstrainedOrientedBox< FloatT > &box, const DrawColor &color)
Definition: DebugDrawerHelper.h:140
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:143
armarx::DebugDrawerHelper::DrawElementType::Pose
@ Pose
armarx::DebugDrawerHelper::Colors::Blue
static const DrawColor Blue
Definition: DebugDrawerHelper.h:220
armarx::DebugDrawerHelper::DrawElementType::Line
@ Line
armarx::DebugDrawerHelper::DrawElement::name
std::string name
Definition: DebugDrawerHelper.h:204
armarx::detail::DebugDrawerHelper::FrameView::drawBox
void drawBox(const std::string &name, const simox::OrientedBox< FloatT > &box, const DrawColor &color)
Definition: DebugDrawerHelper.h:128
armarx::detail::DebugDrawerHelper::FrameView::setRobotConfig
void setRobotConfig(const std::string &name, const std::map< std::string, float > &config)
Definition: DebugDrawerHelper.cpp:238
armarx::DebugDrawerHelper::Colors::Red
static const DrawColor Red
Definition: DebugDrawerHelper.h:218
armarx::detail::DebugDrawerHelper::FrameView::_rn
VirtualRobot::RobotNodePtr _rn
Definition: DebugDrawerHelper.h:167
armarx::DebugDrawerHelper::DrawElement
Definition: DebugDrawerHelper.h:202
armarx::DebugDrawerHelper
The DebugDrawerHelper class provides draw functions in a given frame (static matrix or robot node) an...
Definition: DebugDrawerHelper.h:180
armarx::DebugDrawerHelper::DebugDrawerHelper
DebugDrawerHelper(const DebugDrawerInterfacePrx &debugDrawerPrx, const std::string &layerName, const VirtualRobot::RobotPtr &robot)
Definition: DebugDrawerHelper.cpp:372
armarx::DebugDrawerHelper::defaults
Defaults defaults
Definition: DebugDrawerHelper.h:238
armarx::DebugDrawerHelper::getDebugDrawer
const DebugDrawerInterfacePrx & getDebugDrawer() const
Definition: DebugDrawerHelper.cpp:473
armarx::detail::DebugDrawerHelper::FrameView::makeGlobalEigen
Eigen::Matrix4f makeGlobalEigen(const Eigen::Matrix4f &pose) const
Definition: DebugDrawerHelper.cpp:51
armarx::DebugDrawerHelper::inGlobalFrame
FrameView inGlobalFrame()
Definition: DebugDrawerHelper.cpp:498
armarx::DebugDrawerHelper::DrawElementType
DrawElementType
Definition: DebugDrawerHelper.h:191
armarx::DebugDrawerHelper::DrawElementType::Text
@ Text
simox::OrientedBox
Definition: ice_conversions.h:17
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::DebugDrawerHelper::Colors::Lerp
static DrawColor Lerp(const DrawColor &a, const DrawColor &b, float f)
Definition: DebugDrawerHelper.cpp:569
armarx::DebugDrawerHelper::getRobot
const VirtualRobot::RobotPtr & getRobot() const
Definition: DebugDrawerHelper.cpp:467
armarx::DebugDrawerHelper::Colors::Yellow
static const DrawColor Yellow
Definition: DebugDrawerHelper.h:221
armarx::DebugDrawerHelper::DrawElement::operator<
bool operator<(const DrawElement &rhs) const
Definition: DebugDrawerHelper.h:208
armarx::DebugDrawerHelper::Colors
Definition: DebugDrawerHelper.h:215
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:223
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:169
armarx::DebugDrawerHelper::Colors::Green
static const DrawColor Green
Definition: DebugDrawerHelper.h:219
armarx::DebugDrawerHelper::inFrame
FrameView inFrame(const Eigen::Matrix4f &frame=Eigen::Matrix4f::Identity())
Definition: DebugDrawerHelper.cpp:492
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::detail::DebugDrawerHelper::FrameView::_fallbackFrame
Eigen::Matrix4f _fallbackFrame
Definition: DebugDrawerHelper.h:166
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::DebugDrawerHelper::DrawElementType::Robot
@ Robot
armarx::DebugDrawerHelper::Defaults
Definition: DebugDrawerHelper.h:186