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 
8 
10 {
11 
13  = default;
14 
16  const armarx::DebugDrawerTopic& debugDrawer, const std::string& layer) :
17  voxelgrid::Visualizer<Voxel>(debugDrawer, layer)
18  {}
19 
21  = default;
22 
23 
24  bool Visualizer::isVisible(const Visualizer::VoxelVisuData& visu) const
25  {
26  return !visu.voxel.isFree();
27  }
28 
30  {
31  armarx::DrawColor color {1, 1, 1, 1};
32 
33  const std::map<Label, float> density = visu.voxel.getDensity();
34 
35  const Eigen::Vector3f y = (visu.ori * Eigen::Vector3f::UnitY()) * visu.extents.y();
36  const Eigen::Vector3f posBase = visu.pos - y / 2;
37 
38  float sum = 0;
39  for (const auto& [label, fraction] : density)
40  {
41  const pcl::RGB rgb = pcl::GlasbeyLUT::at(static_cast<unsigned int>(label)
42  % pcl::GlasbeyLUT::size());
43 
44  color = drawer().toDrawColor(rgb, alpha, true);
45 
46  Eigen::Vector3f extents = visu.extents;
47  extents.y() *= fraction;
48 
49  const Eigen::Vector3f position = posBase + y * (sum + fraction / 2);
50  sum += fraction;
51 
52  ARMARX_CHECK_LESS_EQUAL(sum, 1 + 1e-6f);
53 
54  drawer().drawBox({getVoxelLayer(), visu.name + "_" + std::to_string(label)},
55  position, visu.ori, extents, color);
56  }
57  }
58 
59  float Visualizer::getAlpha() const
60  {
61  return alpha;
62  }
63 
65  {
68 
69  this->alpha = value;
70  }
71 
72 
73 }
visionx::voxelgrid::LabelDensity::Visualizer
Visualizer for label density voxel grids.
Definition: Visualizer.h:17
visionx::voxelgrid::LabelDensity::Visualizer::alpha
float alpha
Definition: Visualizer.h:41
armarx::DebugDrawerTopic
The DebugDrawerTopic wraps a DebugDrawerInterfacePrx and provides a more useful interface than the Ic...
Definition: DebugDrawerTopic.h:152
visionx::voxelgrid::Visualizer::VoxelVisuData
Information about a voxel about to-be-drawn.
Definition: Visualizer.hpp:96
visionx::voxelgrid::Visualizer::VoxelVisuData::pos
const Eigen::Vector3f & pos
The voxel.
Definition: Visualizer.hpp:104
visionx::voxelgrid::LabelDensity::Visualizer::Visualizer
Visualizer()
visionx::voxelgrid::Visualizer< Voxel >::drawer
armarx::DebugDrawerTopic & drawer()
Get the debug drawer.
Definition: Visualizer.hpp:122
armarx::DebugDrawerTopic::toDrawColor
static DrawColor toDrawColor(const ColorT &color, float alpha=1, bool byteToFloat=false)
Construct a DrawColor from the given color type.
Definition: DebugDrawerTopic.h:841
visionx::voxelgrid::Visualizer::VoxelVisuData::ori
const Eigen::Quaternionf & ori
The voxel's position.
Definition: Visualizer.hpp:105
visionx::voxelgrid::LabelDensity::Visualizer::setAlpha
void setAlpha(float value)
Set the alpha. Must be in [0, 1].
Definition: Visualizer.cpp:64
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
visionx::voxelgrid::LabelDensity::Visualizer::isVisible
virtual bool isVisible(const VoxelVisuData &voxelVisu) const override
Indicate whether a voxel shall be drawn.
visionx::voxelgrid::Visualizer< Voxel >::getVoxelLayer
std::string getVoxelLayer() const
Get the layer name.
Definition: Visualizer.hpp:132
visionx::voxelgrid::Visualizer::VoxelVisuData::voxel
const VoxelT & voxel
The voxel's index.
Definition: Visualizer.hpp:102
armarx::DebugDrawerTopic::drawBox
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.
Definition: DebugDrawerTopic.cpp:179
visionx::voxelgrid::LabelDensity::Voxel
Map of labels (object IDs) to number of points.
Definition: VoxelGrid.h:27
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
ARMARX_CHECK_LESS_EQUAL
#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...
Definition: ExpressionException.h:109
ExpressionException.h
visionx::voxelgrid::Visualizer::VoxelVisuData::extents
const Eigen::Vector3f & extents
The voxel's orientation.
Definition: Visualizer.hpp:106
Visualizer.h
visionx::voxelgrid::LabelDensity::Visualizer::getAlpha
float getAlpha() const
Get the alpha.
Definition: Visualizer.cpp:59
visionx::voxelgrid::Visualizer::VoxelVisuData::name
const std::string & name
The voxel grid.
Definition: Visualizer.hpp:99
visionx::voxelgrid::LabelDensity::Visualizer::~Visualizer
virtual ~Visualizer() override
Virtual destructor.
visionx::voxelgrid::LabelDensity
Definition: Visualizer.cpp:9
visionx::voxelgrid::LabelDensity::Visualizer::drawVoxel
virtual void drawVoxel(const VoxelVisuData &voxelVisu) override
Draw a voxel.