28 #include <Eigen/Geometry>
30 #include <VirtualRobot/math/Helpers.h>
43 template <
typename VoxelT>
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;
89 return _debugDrawer.operator bool();
104 const Eigen::Vector3f&
pos;
119 virtual void drawVoxel(
const VoxelVisuData& visu);
134 return _layer +
"_voxels";
153 template <
typename VT>
157 template <
typename VT>
160 _debugDrawer(debugDrawer), _layer(layer)
162 using namespace std::chrono_literals;
163 _debugDrawer.setLayer(layer);
164 _debugDrawer.setShortSleepDuration(100ms);
167 template <
typename VT>
173 template <
typename VT>
176 _debugDrawer.
clearLayer(getVoxelLayer(), sleep);
179 template <
typename VT>
187 std::vector<Eigen::Vector3f> points;
188 float width = 0.025f;
189 armarx::DrawColor color {0, 1, 1, 1};
194 auto addLine = [&](
int x1,
int y1,
int z1,
int x2,
int y2,
int z2)
196 Eigen::Vector3f start = { bb.col(x1).x(), bb.col(y1).y(), bb.col(z1).z() };
197 Eigen::Vector3f end = { bb.col(x2).x(), bb.col(y2).y(), bb.col(z2).z() };
199 start = math::Helpers::TransformPosition(pose, start);
200 end = math::Helpers::TransformPosition(pose, end);
202 points.push_back({ start.x(), start.y(), start.z() });
203 points.push_back({ end.x(), end.y(), end.z() });
215 addLine(0, 0, 0, 1, 0, 0);
216 addLine(0, 0, 0, 0, 1, 0);
217 addLine(0, 0, 0, 0, 0, 1);
220 addLine(1, 1, 1, 0, 1, 1);
221 addLine(1, 1, 1, 1, 0, 1);
222 addLine(1, 1, 1, 1, 1, 0);
225 addLine(1, 0, 0, 1, 0, 1);
226 addLine(1, 0, 0, 1, 1, 0);
229 addLine(0, 1, 0, 1, 1, 0);
230 addLine(0, 1, 0, 0, 1, 1);
233 addLine(0, 0, 1, 1, 0, 1);
234 addLine(0, 0, 1, 0, 1, 1);
236 _debugDrawer.drawLineSet({_layer,
"edges"}, points, width, color);
240 template <
typename VT>
243 const armarx::DrawColor& colorEdges,
244 const armarx::DrawColor& colorStructure,
245 bool drawOriginVoxel)
252 armarx::DebugDrawerLineSet lines;
253 lines.lineWidth = lineWidth;
254 lines.colorNoIntensity = colorStructure;
255 lines.colorFullIntensity = colorEdges;
261 const Eigen::Vector3f & startLocal,
const Eigen::Vector3f & endLocal,
264 const Eigen::Vector3f start = math::Helpers::TransformPosition(pose, startLocal);
265 const Eigen::Vector3f end = math::Helpers::TransformPosition(pose, endLocal);
267 lines.points.push_back({ start.x(), start.y(), start.z() });
268 lines.points.push_back({ end.x(), end.y(), end.z() });
270 lines.intensities.push_back(intensity);
273 auto addEdge = [&](
int x1,
int y1,
int z1,
int x2,
int y2,
int z2)
275 const Eigen::Vector3f start = { bb.col(x1).x(), bb.col(y1).y(), bb.col(z1).z() };
276 const Eigen::Vector3f end = { bb.col(x2).x(), bb.col(y2).y(), bb.col(z2).z() };
277 addLine(start, end, 1);
289 addEdge(0, 0, 0, 1, 0, 0);
290 addEdge(0, 0, 0, 0, 1, 0);
291 addEdge(0, 0, 0, 0, 0, 1);
294 addEdge(1, 1, 1, 0, 1, 1);
295 addEdge(1, 1, 1, 1, 0, 1);
296 addEdge(1, 1, 1, 1, 1, 0);
299 addEdge(1, 0, 0, 1, 0, 1);
300 addEdge(1, 0, 0, 1, 1, 0);
303 addEdge(0, 1, 0, 1, 1, 0);
304 addEdge(0, 1, 0, 0, 1, 1);
307 addEdge(0, 0, 1, 1, 0, 1);
308 addEdge(0, 0, 1, 0, 1, 1);
310 const auto min = bb.col(0);
311 const auto max = bb.col(1);
313 auto addQuad = [&](
const Eigen::Vector3f & center,
int h1,
int h2,
float intensity = 0)
322 Eigen::Vector3f
A, B, C, D;
323 A = B = C = D = center;
337 addLine(
A, B, intensity);
338 addLine(B, C, intensity);
339 addLine(C, D, intensity);
340 addLine(D,
A, intensity);
345 Eigen::Vector3f center = center.Zero();
349 for (
int i = 0; i < 3; ++i)
351 int h1 = (i + 1) % 3;
352 int h2 = (i + 2) % 3;
359 index(i) = indicesMinMax[mm](i);
368 addQuad(center, h1, h2);
371 center(i) = shift / 2;
372 addQuad(center, h1, h2);
378 addQuad(center, h1, h2);
382 _debugDrawer.drawLineSet({_layer,
"structure"}, lines);
386 _debugDrawer.drawBox({_layer,
"origin_voxel"},
388 _debugDrawer.toDrawColor(colorEdges, .25));
393 template<
typename VoxelT>
401 for (std::size_t i = 0; i < grid.
numVoxels(); ++i)
403 const VoxelT& voxel = grid.
getVoxels()[i];
406 VoxelVisuData visu { grid,
"voxel_" +
std::to_string(i), i, voxel,
416 template<
typename VoxelT>
419 const armarx::DrawColor color { .5, .5, .5, 1 };
420 drawer().
drawBox({getVoxelLayer(), visu.name}, visu.pos, visu.ori, visu.extents, color);