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
33namespace armarx
34{
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 */
48 {
49 public:
50 FrameView(class DebugDrawerHelper& helper,
51 const Eigen::Matrix4f frame = Eigen::Matrix4f::Identity());
52 FrameView(class DebugDrawerHelper& helper, const VirtualRobot::RobotNodePtr& rn);
53 //make global
54 public:
55 Eigen::Matrix4f makeGlobalEigen(const Eigen::Matrix4f& pose) const;
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,
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:
166 Eigen::Matrix4f _fallbackFrame = Eigen::Matrix4f::Identity();
167 VirtualRobot::RobotNodePtr _rn;
168 };
169} // namespace armarx::detail::DebugDrawerHelper
170
171namespace 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 };
201
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
245 FrameView inFrame(const Eigen::Matrix4f& frame = Eigen::Matrix4f::Identity());
246 FrameView inGlobalFrame();
247 FrameView inFrame(const std::string& nodeName);
248 FrameView inFrame(const VirtualRobot::RobotNodePtr& node);
249
250 void setDefaultFrame(const Eigen::Matrix4f& frame = Eigen::Matrix4f::Identity());
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
static DrawColor Lerp(const DrawColor &a, const DrawColor &b, float f)
The DebugDrawerHelper class provides draw functions in a given frame (static matrix or robot node) an...
DebugDrawerHelper(const DebugDrawerInterfacePrx &debugDrawerPrx, const std::string &layerName, const VirtualRobot::RobotPtr &robot)
void removeElement(const std::string &name, DrawElementType type)
const DebugDrawerInterfacePrx & getDebugDrawer() const
void setVisuEnabled(bool enableVisu)
FrameView inFrame(const Eigen::Matrix4f &frame=Eigen::Matrix4f::Identity())
void setDebugDrawer(const DebugDrawerInterfacePrx &drawer)
void setRobot(const VirtualRobot::RobotPtr &rob)
const VirtualRobot::RobotPtr & getRobot() const
void setDefaultFrame(const Eigen::Matrix4f &frame=Eigen::Matrix4f::Identity())
This class provides the draw options for a given frame (static Matrix, or a robot node).
void drawBox(const std::string &name, const simox::XYConstrainedOrientedBox< FloatT > &box, const DrawColor &color)
void drawLine(const std::string &name, const Eigen::Vector3f &p1, const Eigen::Vector3f &p2, float width, const DrawColor &color)
FrameView(class DebugDrawerHelper &helper, const Eigen::Matrix4f frame=Eigen::Matrix4f::Identity())
void setRobotConfig(const std::string &name, const std::map< std::string, float > &config)
void drawText(const std::string &name, const Eigen::Vector3f &p1, const std::string &text, const DrawColor &color, int size)
void drawLines(const std::string &prefix, const std::vector< Eigen::Vector3f > &ps, float width, const DrawColor &color)
void drawBox(const std::string &name, const Eigen::Matrix4f &pose, const Eigen::Vector3f &size, const DrawColor &color)
void drawArrow(const std::string &name, const Eigen::Vector3f &pos, const Eigen::Vector3f &direction, const DrawColor &color, float length, float width)
void drawBox(const std::string &name, const simox::OrientedBox< FloatT > &box, const DrawColor &color)
Eigen::Matrix4f makeGlobalEigen(const Eigen::Matrix4f &pose) const
void setRobotPose(const std::string &name, const Eigen::Matrix4f &pose)
void drawRobot(const std::string &name, const std::string &robotFile, const std::string &armarxProject, const Eigen::Matrix4f &pose, const DrawColor &color)
void drawPointCloud(const std::string &name, const std::vector< Eigen::Vector3f > &points, float pointSize, const DrawColor &color)
void drawPoses(const std::string &prefix, const std::vector< Eigen::Matrix4f > &poses)
void drawPose(const std::string &name, const Eigen::Matrix4f &pose)
Vector3Ptr makeGlobalDirection(const Eigen::Vector3f &direction) const
void drawSphere(const std::string &name, const Eigen::Vector3f &position, float size, const DrawColor &color)
PosePtr makeGlobal(const Eigen::Matrix4f &pose) const
void setRobotColor(const std::string &name, const DrawColor &color)
Eigen::Vector3f makeGlobalDirectionEigen(const Eigen::Vector3f &direction) const
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
std::shared_ptr< DebugDrawerHelper > DebugDrawerHelperPtr
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
bool operator<(const DrawElement &rhs) const