15 #include <mrpt/containers/yaml.h>
16 #include <mrpt/core/round.h>
38 mrpt::system::COutputLogger::setLoggerName(
"FilterDecimateAdaptive");
45 MRPT_LOG_DEBUG_STREAM(
"Loading these params:\n" << c);
64 const auto& pc = *pcPtr;
67 mrpt::maps::CPointsMap::Ptr outPc =
72 outPc->reserve(outPc->size() + _.desired_output_point_count);
77 auto inputBbox = pc.boundingBox();
78 auto bboxSize = mrpt::math::TVector3Df(inputBbox.max - inputBbox.min);
79 mrpt::keep_max(bboxSize.x, _.assumed_minimum_pointcloud_bbox);
80 mrpt::keep_max(bboxSize.y, _.assumed_minimum_pointcloud_bbox);
81 mrpt::keep_max(bboxSize.z, _.assumed_minimum_pointcloud_bbox);
83 const float largest_dim = bboxSize.norm();
85 const float voxel_size = largest_dim / _.maximum_voxel_count_per_dimension;
95 bool exhausted =
false;
99 std::vector<DataPerVoxel> voxels;
102 std::size_t nTotalVoxels = 0;
106 if (!data.
indices.empty()) nTotalVoxels++;
107 if (data.
indices.size() < _.minimum_input_points_per_voxel)
return;
109 voxels.emplace_back().voxel = &data;
114 const size_t nVoxels = voxels.size();
115 size_t voxelIdxIncrement = 1;
118 voxelIdxIncrement = std::max<size_t>(
122 bool anyInsertInTheRound =
false;
126 auto& ith = voxels[i];
129 auto ptIdx = ith.voxel->indices[ith.nextIdx++];
130 outPc->insertPointFrom(pc, ptIdx);
131 anyInsertInTheRound =
true;
133 if (ith.nextIdx >= ith.voxel->indices.size()) ith.exhausted =
true;
136 i += voxelIdxIncrement;
140 i = (i + 123653 ) % nVoxels;
142 if (!anyInsertInTheRound)
150 anyInsertInTheRound =
false;
154 MRPT_LOG_DEBUG_STREAM(
155 "voxel_size=" << voxel_size <<
156 ", used voxels=" << nTotalVoxels);