14 #include <mrpt/maps/CVoxelMap.h>
22 mrpt::system::COutputLogger::setLoggerName(
"QualityEvaluator_Voxels");
26 const mrpt::containers::yaml& params)
34 double loss(
double x,
double y)
49 return 1.5 +
x + y - 12 *
x *
x + 22 *
x * y - 12 * y * y;
55 const mrpt::poses::CPose3D& localPose,
56 [[maybe_unused]]
const Pairings& pairingsFromICP)
const
62 "Input global map was expected to contain a layer named '%s'",
67 "Input local map was expected to contain a layer named '%s'",
70 const mrpt::maps::CVoxelMap::Ptr globalVoxels =
71 std::dynamic_pointer_cast<mrpt::maps::CVoxelMap>(
75 "Input global map was expected to contain a layer named '%s' of "
79 const mrpt::maps::CVoxelMap::Ptr localVoxels =
80 std::dynamic_pointer_cast<mrpt::maps::CVoxelMap>(
85 "Input local map was expected to contain a layer named '%s' of "
95 auto& g =
const_cast<Bonxai::VoxelGrid<mrpt::maps::VoxelNodeOccupancy>&
>(
96 globalVoxels->grid());
97 auto& l =
const_cast<Bonxai::VoxelGrid<mrpt::maps::VoxelNodeOccupancy>&
>(
100 auto gAccessor = g.createAccessor();
101 auto lAccessor = l.createAccessor();
105 size_t dist_cells = 0;
107 auto lmbdPerLocalVoxel = [&](mrpt::maps::CVoxelMap::voxel_node_t& data,
108 const Bonxai::CoordT& coord)
111 const auto ptLocal = Bonxai::CoordToPos(coord, l.resolution);
112 const auto ptGlobal =
113 localPose.composePoint({ptLocal.x, ptLocal.y, ptLocal.z});
115 auto* cell = gAccessor.value(Bonxai::PosToCoord(
116 {ptGlobal.x, ptGlobal.y, ptGlobal.z}, g.inv_resolution));
119 const float localOcc = localVoxels->l2p(data.occupancy);
120 const float globalOcc = globalVoxels->l2p(cell->occupancy);
123 if (std::abs(globalOcc - 0.5
f) < 0.01
f ||
124 std::abs(localOcc - 0.5
f) < 0.01
f)
127 const double d = loss(localOcc, globalOcc);
133 l.forEachCell(lmbdPerLocalVoxel);
135 auto lmbdPerGlobalVoxel = [&](mrpt::maps::CVoxelMap::voxel_node_t& data,
136 const Bonxai::CoordT& coord)
139 const auto ptGlobal = Bonxai::CoordToPos(coord, l.resolution);
141 (-localPose).composePoint({ptGlobal.x, ptGlobal.y, ptGlobal.z});
143 auto* cell = lAccessor.value(Bonxai::PosToCoord(
144 {ptLocal.x, ptLocal.y, ptLocal.z}, l.inv_resolution));
147 const float localOcc = localVoxels->l2p(cell->occupancy);
148 const float globalOcc = globalVoxels->l2p(data.occupancy);
151 if (std::abs(globalOcc - 0.5
f) < 0.01f ||
152 std::abs(localOcc - 0.5
f) < 0.01f)
155 const double d = loss(localOcc, globalOcc);
160 g.forEachCell(lmbdPerGlobalVoxel);
170 MRPT_LOG_DEBUG_STREAM(
171 "dist: " << dist <<
" dist_cells: " << dist_cells