Visualizer.cpp
Go to the documentation of this file.
1#include "Visualizer.h"
2
3#include <pcl/common/colors.h>
4#include <pcl/point_types.h> // for pcl::RGB
5
7
9{
10
11 Visualizer::Visualizer() = default;
12
13 Visualizer::Visualizer(const armarx::DebugDrawerTopic& debugDrawer, const std::string& layer) :
14 voxelgrid::Visualizer<Voxel>(debugDrawer, layer)
15 {
16 }
17
18 Visualizer::~Visualizer() = default;
19
20 bool
21 Visualizer::isVisible(const Visualizer::VoxelVisuData& visu) const
22 {
23 return !visu.voxel.isFree();
24 }
25
26 void
27 Visualizer::drawVoxel(const Visualizer::VoxelVisuData& visu)
28 {
29 armarx::DrawColor color{1, 1, 1, 1};
30
31 const std::map<Label, float> density = visu.voxel.getDensity();
32
33 const Eigen::Vector3f y = (visu.ori * Eigen::Vector3f::UnitY()) * visu.extents.y();
34 const Eigen::Vector3f posBase = visu.pos - y / 2;
35
36 float sum = 0;
37 for (const auto& [label, fraction] : density)
38 {
39 const pcl::RGB rgb =
40 pcl::GlasbeyLUT::at(static_cast<unsigned int>(label) % pcl::GlasbeyLUT::size());
41
42 color = drawer().toDrawColor(rgb, alpha, true);
43
44 Eigen::Vector3f extents = visu.extents;
45 extents.y() *= fraction;
46
47 const Eigen::Vector3f position = posBase + y * (sum + fraction / 2);
48 sum += fraction;
49
50 ARMARX_CHECK_LESS_EQUAL(sum, 1 + 1e-6f);
51
52 drawer().drawBox({getVoxelLayer(), visu.name + "_" + std::to_string(label)},
53 position,
54 visu.ori,
55 extents,
56 color);
57 }
58 }
59
60 float
62 {
63 return alpha;
64 }
65
66 void
68 {
71
72 this->alpha = value;
73 }
74
75
76} // namespace visionx::voxelgrid::LabelDensity
The DebugDrawerTopic wraps a DebugDrawerInterfacePrx and provides a more useful interface than the Ic...
static DrawColor toDrawColor(const ColorT &color, float alpha=1, bool byteToFloat=false)
Construct a DrawColor from the given color type.
void drawBox(const VisuID &id, const Eigen::Vector3f &position, const Eigen::Quaternionf &orientation, const Eigen::Vector3f &extents, const DrawColor &color=DEFAULTS.colorBox, bool ignoreLengthScale=false)
Draw a box.
void setAlpha(float value)
Set the alpha. Must be in [0, 1].
virtual ~Visualizer() override
Virtual destructor.
virtual void drawVoxel(const VoxelVisuData &voxelVisu) override
virtual bool isVisible(const VoxelVisuData &voxelVisu) const override
Indicate whether a voxel shall be drawn.
Map of labels (object IDs) to number of points.
Definition VoxelGrid.h:27
armarx::DebugDrawerTopic & drawer()
#define ARMARX_CHECK_LESS_EQUAL(lhs, rhs)
This macro evaluates whether lhs is less or equal (<=) rhs and if it turns out to be false it will th...