15 #include <mrpt/containers/yaml.h>
16 #include <mrpt/core/round.h>
24 const mrpt::containers::yaml& c)
40 mrpt::system::COutputLogger::setLoggerName(
"FilterDecimateAdaptive");
47 MRPT_LOG_DEBUG_STREAM(
"Loading these params:\n" << c);
63 "Input point cloud layer '%s' was not found.",
66 const auto& pc = *pcPtr;
69 mrpt::maps::CPointsMap::Ptr outPc =
74 outPc->reserve(outPc->size() + _.desired_output_point_count);
79 auto inputBbox = pc.boundingBox();
80 auto bboxSize = mrpt::math::TVector3Df(inputBbox.max - inputBbox.min);
81 mrpt::keep_max(bboxSize.x, _.assumed_minimum_pointcloud_bbox);
82 mrpt::keep_max(bboxSize.y, _.assumed_minimum_pointcloud_bbox);
83 mrpt::keep_max(bboxSize.z, _.assumed_minimum_pointcloud_bbox);
85 const float largest_dim = bboxSize.norm();
87 const float voxel_size = largest_dim / _.maximum_voxel_count_per_dimension;
97 bool exhausted =
false;
101 std::vector<DataPerVoxel> voxels;
104 std::size_t nTotalVoxels = 0;
109 if (!data.
indices.empty()) nTotalVoxels++;
110 if (data.
indices.size() < _.minimum_input_points_per_voxel)
return;
112 voxels.emplace_back().voxel = &data;
117 const size_t nVoxels = voxels.size();
118 size_t voxelIdxIncrement = 1;
121 voxelIdxIncrement = std::max<size_t>(
127 bool anyInsertInTheRound =
false;
131 auto& ith = voxels[i];
134 auto ptIdx = ith.voxel->indices[ith.nextIdx++];
135 outPc->insertPointFrom(pc, ptIdx);
136 anyInsertInTheRound =
true;
138 if (ith.nextIdx >= ith.voxel->indices.size()) ith.exhausted =
true;
141 i += voxelIdxIncrement;
145 i = (i + 123653 ) % nVoxels;
147 if (!anyInsertInTheRound)
155 anyInsertInTheRound =
false;
159 MRPT_LOG_DEBUG_STREAM(
160 "voxel_size=" << voxel_size <<
161 ", used voxels=" << nTotalVoxels);