4#include <Eigen/Geometry>
6#include <pcl/point_cloud.h>
7#include <pcl/point_types.h>
9#include <SimoxUtility/iterator/xy_index_range_iterator.h>
10#include <SimoxUtility/shapes/OrientedBox.h>
21 template <
typename EigenVectorT>
25 EigenVectorT point = EigenVectorT::Zero();
27 point.x() = laserScanStep.distance * std::cos(laserScanStep.angle);
28 point.y() = laserScanStep.distance * std::sin(laserScanStep.angle);
40 for (
const VirtualRobot::BoundingBox& bb : boundingBoxes)
42 const Eigen::Vector3f center((bb.getMin() + bb.getMax()) / 2);
43 const Eigen::Vector3f extents = (bb.getMax() - bb.getMin());
45 const auto box =
viz::Box(
"bb_" + std::to_string(i++))
48 .
color(0, 255, 0, 255);
67 colors(numCells.
x(),
std::vector<
Color>(numCells.y(),
Color::Zero()))
74 vertices.at(idx.x()).at(idx.y()) = position;
75 colors.at(idx.x()).at(idx.y()) = color;
79 apply(
const auto& posFn,
const auto& colorFn)
81 for (
int x = 0;
x < numCells.x();
x++)
83 for (
int y = 0; y < numCells.y(); y++)
85 const Eigen::Array2i idx{
x, y};
91 std::vector<std::vector<viz::data::Color>>
94 std::vector<std::vector<viz::data::Color>> colors(
95 numCells.x(), std::vector<viz::data::Color>(numCells.y(), viz::Color::black()));
100 auto xyIter = simox::iterator::XYIndexRangeIterator({numCells.x(), numCells.y()});
101 std::for_each(xyIter.begin(),
105 const auto& [x, y] = p;
106 colors[x][y] = toVizColor(this->colors[x][y]);
119 Eigen::Array2i numCells;
128 ARMARX_INFO <<
"Occupancy grid size " << Eigen::Array2i{grid.sizeX, grid.sizeY};
136 const auto pos2d = grid.getCentralPosition(idx.x(), idx.y());
137 return {pos2d.x(), pos2d.y(), 0.F};
145 if (grid.isOccupied(
static_cast<std::size_t
>(idx.x()),
146 static_cast<std::size_t
>(idx.y())))
150 return grid.isOccupied(
static_cast<std::size_t
>(idx.x()),
151 static_cast<std::size_t
>(idx.y()))
156 meshGrid.apply(posFn, colorFn);
159 .
position(Eigen::Vector3f{0.F, 0.F, boxPosZ})
160 .grid2D(meshGrid.getVertices(), meshGrid.getColors());
166 pcl::PointCloud<pcl::PointXYZ>
169 pcl::PointCloud<pcl::PointXYZ> cloud;
170 cloud.points.reserve(scan.size());
172 std::transform(scan.begin(),
174 std::back_inserter(cloud.points),
175 [&](
const auto& scanStep) -> pcl::PointXYZ
177 const auto rangePoint = toCartesian<Eigen::Vector3f>(scanStep);
180 pt.x = rangePoint.x();
181 pt.y = rangePoint.y();
182 pt.z = rangePoint.z();
187 cloud.width = scan.size();
189 cloud.is_dense =
true;
196 const std::string& frame,
197 const Eigen::Affine3f& scannerPose)
202 frames.insert(frame);
205 const int id = std::distance(std::begin(frames), frames.find(frame)) + 2;
211 .pointSizeInPixels(5)
212 .pointCloud(pointCloud.points,
viz::Color(simox::color::GlasbeyLUT::at(
id))));
220 for (
const auto& [_, pc] : clouds)
void drawBoundingBoxes(const std::vector< VirtualRobot::BoundingBox > &boundingBoxes)
void drawOccupancyGrid(const OccupancyGrid &grid, float boxPosZ)
void prepareScan(const LaserScan &scan, const std::string &frame, const Eigen::Affine3f &scannerPose)
std::vector< std::vector< Color > > ColorGrid
void apply(const auto &posFn, const auto &colorFn)
ColoredMeshGrid(Eigen::Array2i numCells)
const VertexGrid & getVertices() const
void setColoredVertex(const Eigen::Array2i &idx, const Position &position, const Color &color)
std::vector< std::vector< Position > > VertexGrid
std::vector< std::vector< viz::data::Color > > getColors()
CommitResult commit(StagedCommit const &commit)
DerivedT & color(Color color)
DerivedT & position(float x, float y, float z)
Layer layer(std::string const &name) const override
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
pcl::PointCloud< pcl::PointXYZ > toPointCloud(const LaserScan &scan)
EigenVectorT toCartesian(const LaserScanStep &laserScanStep)
This file offers overloads of toIce() and fromIce() functions for STL container types.
Box & size(Eigen::Vector3f const &s)