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>
24 EigenVectorT point = EigenVectorT::Zero();
26 point.x() = laserScanStep.distance * std::cos(laserScanStep.angle);
27 point.y() = laserScanStep.distance * std::sin(laserScanStep.angle);
41 for (
const VirtualRobot::BoundingBox& bb : boundingBoxes)
43 const Eigen::Vector3f center((bb.getMin() + bb.getMax()) / 2);
44 const Eigen::Vector3f extents = (bb.getMax() - bb.getMin());
50 .
color(0, 255, 0, 255);
69 colors(numCells.x(),
std::vector<
Color>(numCells.y(),
Color::Zero()))
76 vertices.at(idx.x()).at(idx.y()) = position;
77 colors.at(idx.x()).at(idx.y()) = color;
80 void apply(
const auto& posFn,
const auto& colorFn)
82 for (
int x = 0; x < numCells.x(); x++)
84 for (
int y = 0; y < numCells.y(); y++)
86 const Eigen::Array2i idx{x, y};
92 std::vector<std::vector<viz::data::Color>>
getColors()
94 std::vector<std::vector<viz::data::Color>> colors(
102 auto xyIter = simox::iterator::XYIndexRangeIterator({numCells.x(), numCells.y()});
103 std::for_each(xyIter.begin(),
107 const auto& [x, y] = p;
108 colors[x][y] = toVizColor(this->colors[x][y]);
120 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());
168 pcl::PointCloud<pcl::PointXYZ> cloud;
169 cloud.points.reserve(scan.size());
173 std::back_inserter(cloud.points),
174 [&](
const auto & scanStep) -> pcl::PointXYZ
176 const auto rangePoint = toCartesian<Eigen::Vector3f>(scanStep);
179 pt.x = rangePoint.x();
180 pt.y = rangePoint.y();
181 pt.z = rangePoint.z();
186 cloud.width = scan.size();
188 cloud.is_dense =
true;
194 const std::string& frame,
195 const Eigen::Affine3f& scannerPose)
200 frames.insert(frame);
203 const int id =
std::distance(std::begin(frames), frames.find(frame)) + 2;
209 .pointSizeInPixels(5)
210 .pointCloud(pointCloud.points,
viz::Color(simox::color::GlasbeyLUT::at(
id))));
217 for (
const auto& [_,
pc] : clouds)