14 #include <mrpt/containers/yaml.h>
15 #include <mrpt/maps/CSimplePointsMap.h>
16 #include <mrpt/math/ops_containers.h>
17 #include <mrpt/obs/CObservation2DRangeScan.h>
18 #include <mrpt/random/RandomGenerators.h>
26 const mrpt::containers::yaml& c)
37 c.has(
"bounding_box_min") && c[
"bounding_box_min"].isSequence() &&
38 c[
"bounding_box_min"].asSequence().size() == 3);
40 c.has(
"bounding_box_max") && c[
"bounding_box_max"].isSequence() &&
41 c[
"bounding_box_max"].asSequence().size() == 3);
43 const auto bboxMin = c[
"bounding_box_min"].toStdVector<
double>();
44 const auto bboxMax = c[
"bounding_box_max"].toStdVector<
double>();
46 for (
int i = 0; i < 3; i++)
59 MRPT_LOG_DEBUG_STREAM(
"Loading these params:\n" << c);
77 mrpt::maps::CPointsMap::Ptr outPc;
79 itLy != inOut.
layers.end())
81 outPc = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(itLy->second);
84 "Layer '%s' must be of point cloud type.",
89 outPc = mrpt::maps::CSimplePointsMap::Create();
94 mrpt::maps::CPointsMap::Ptr pcPtr;
96 itLy != inOut.
layers.end())
98 pcPtr = std::dynamic_pointer_cast<mrpt::maps::CPointsMap>(itLy->second);
101 "Layer '%s' must be of point cloud type.",
110 "Input layer '%s' not found on input map.",
120 const auto& pc = *pcPtr;
123 outPc->reserve(outPc->size() + pc.size() / 10);
128 const auto& xs = pc.getPointsBufferRef_x();
129 const auto& ys = pc.getPointsBufferRef_y();
130 const auto& zs = pc.getPointsBufferRef_z();
132 auto rng = mrpt::random::CRandomGenerator();
135 size_t nonEmptyVoxels = 0;
138 if (vxl_pts.indices.empty())
continue;
145 auto mean = mrpt::math::TPoint3Df(0, 0, 0);
146 const float inv_n = (1.0f / vxl_pts.indices.size());
147 for (
size_t i = 0; i < vxl_pts.indices.size(); i++)
149 const auto pt_idx = vxl_pts.indices[i];
150 mean.x += xs[pt_idx];
151 mean.y += ys[pt_idx];
152 mean.z += zs[pt_idx];
157 outPc->insertPointFast(mean.x, mean.y, mean.z);
162 const auto idxInVoxel =
163 rng.drawUniform64bit() % vxl_pts.indices.size();
165 const auto pt_idx = vxl_pts.indices.at(idxInVoxel);
166 outPc->insertPointFast(xs[pt_idx], ys[pt_idx], zs[pt_idx]);
169 MRPT_LOG_DEBUG_STREAM(
"Voxel counts: total=" << nonEmptyVoxels);