28 #include <Eigen/Geometry>
30 #include <VirtualRobot/math/Helpers.h>
42 template <
typename VoxelT>
50 const std::string& voxelLayer =
"VoxelGrid");
71 const armarx::DrawColor& colorEdges = {0, .5, 1, 1},
72 const armarx::DrawColor& colorStructure = {0, 1, 1, 1},
73 bool drawOriginVoxel =
false);
79 this->_debugDrawer = debugDrawer;
91 return _debugDrawer.operator bool();
105 const Eigen::Vector3f&
pos;
120 virtual void drawVoxel(
const VoxelVisuData& visu);
139 return _layer +
"_voxels";
154 template <
typename VT>
159 template <
typename VT>
161 const std::string& layer) :
162 _debugDrawer(debugDrawer), _layer(layer)
164 using namespace std::chrono_literals;
165 _debugDrawer.setLayer(layer);
166 _debugDrawer.setShortSleepDuration(100ms);
169 template <
typename VT>
176 template <
typename VT>
180 _debugDrawer.
clearLayer(getVoxelLayer(), sleep);
183 template <
typename VT>
192 std::vector<Eigen::Vector3f> points;
193 float width = 0.025f;
194 armarx::DrawColor color{0, 1, 1, 1};
199 auto addLine = [&](
int x1,
int y1,
int z1,
int x2,
int y2,
int z2)
201 Eigen::Vector3f start = {bb.col(x1).x(), bb.col(y1).y(), bb.col(z1).z()};
202 Eigen::Vector3f end = {bb.col(x2).x(), bb.col(y2).y(), bb.col(z2).z()};
204 start = math::Helpers::TransformPosition(pose, start);
205 end = math::Helpers::TransformPosition(pose, end);
207 points.push_back({start.x(), start.y(), start.z()});
208 points.push_back({end.x(), end.y(), end.z()});
220 addLine(0, 0, 0, 1, 0, 0);
221 addLine(0, 0, 0, 0, 1, 0);
222 addLine(0, 0, 0, 0, 0, 1);
225 addLine(1, 1, 1, 0, 1, 1);
226 addLine(1, 1, 1, 1, 0, 1);
227 addLine(1, 1, 1, 1, 1, 0);
230 addLine(1, 0, 0, 1, 0, 1);
231 addLine(1, 0, 0, 1, 1, 0);
234 addLine(0, 1, 0, 1, 1, 0);
235 addLine(0, 1, 0, 0, 1, 1);
238 addLine(0, 0, 1, 1, 0, 1);
239 addLine(0, 0, 1, 0, 1, 1);
241 _debugDrawer.drawLineSet({_layer,
"edges"}, points, width, color);
244 template <
typename VT>
248 const armarx::DrawColor& colorEdges,
249 const armarx::DrawColor& colorStructure,
250 bool drawOriginVoxel)
257 armarx::DebugDrawerLineSet lines;
258 lines.lineWidth = lineWidth;
259 lines.colorNoIntensity = colorStructure;
260 lines.colorFullIntensity = colorEdges;
265 auto addLine = [&](
const Eigen::Vector3f& startLocal,
266 const Eigen::Vector3f& endLocal,
269 const Eigen::Vector3f start = math::Helpers::TransformPosition(pose, startLocal);
270 const Eigen::Vector3f end = math::Helpers::TransformPosition(pose, endLocal);
272 lines.points.push_back({start.x(), start.y(), start.z()});
273 lines.points.push_back({end.x(), end.y(), end.z()});
275 lines.intensities.push_back(intensity);
278 auto addEdge = [&](
int x1,
int y1,
int z1,
int x2,
int y2,
int z2)
280 const Eigen::Vector3f start = {bb.col(x1).x(), bb.col(y1).y(), bb.col(z1).z()};
281 const Eigen::Vector3f end = {bb.col(x2).x(), bb.col(y2).y(), bb.col(z2).z()};
282 addLine(start, end, 1);
294 addEdge(0, 0, 0, 1, 0, 0);
295 addEdge(0, 0, 0, 0, 1, 0);
296 addEdge(0, 0, 0, 0, 0, 1);
299 addEdge(1, 1, 1, 0, 1, 1);
300 addEdge(1, 1, 1, 1, 0, 1);
301 addEdge(1, 1, 1, 1, 1, 0);
304 addEdge(1, 0, 0, 1, 0, 1);
305 addEdge(1, 0, 0, 1, 1, 0);
308 addEdge(0, 1, 0, 1, 1, 0);
309 addEdge(0, 1, 0, 0, 1, 1);
312 addEdge(0, 0, 1, 1, 0, 1);
313 addEdge(0, 0, 1, 0, 1, 1);
315 const auto min = bb.col(0);
316 const auto max = bb.col(1);
318 auto addQuad = [&](
const Eigen::Vector3f& center,
int h1,
int h2,
float intensity = 0)
327 Eigen::Vector3f
A, B, C, D;
328 A = B = C = D = center;
342 addLine(
A, B, intensity);
343 addLine(B, C, intensity);
344 addLine(C, D, intensity);
345 addLine(D,
A, intensity);
350 Eigen::Vector3f center = center.Zero();
355 for (
int i = 0; i < 3; ++i)
357 int h1 = (i + 1) % 3;
358 int h2 = (i + 2) % 3;
360 for (
int mm : {0, 1})
362 index(i) = indicesMinMax[mm](i);
371 addQuad(center, h1, h2);
374 center(i) = shift / 2;
375 addQuad(center, h1, h2);
381 addQuad(center, h1, h2);
385 _debugDrawer.drawLineSet({_layer,
"structure"}, lines);
389 _debugDrawer.drawBox({_layer,
"origin_voxel"},
393 _debugDrawer.toDrawColor(colorEdges, .25));
397 template <
typename VoxelT>
406 for (std::size_t i = 0; i < grid.
numVoxels(); ++i)
408 const VoxelT& voxel = grid.
getVoxels()[i];
411 VoxelVisuData visu{grid,
426 template <
typename VoxelT>
430 const armarx::DrawColor color{.5, .5, .5, 1};
431 drawer().
drawBox({getVoxelLayer(), visu.name}, visu.pos, visu.ori, visu.extents, color);