The whole-voxel rule never clears a voxel whose box crosses the image edge. A person bending over to lift an object leaves high voxels at the top edge of the image: in the 2026-10-15 lift bag 0 of 54 phantom cells cleared. - DepthEvidenceStore keeps, per marked voxel, the 6 per-axis extreme points plus the most recent ones, keyed by a window-independent cell index. - DepthVisibilityChecker::classifyPoints: Free only when every evidence point projects with a full patch inside the usable image and sees valid depth behind it; any surface in front keeps it, invalid depth keeps it. - Paired marking drops points within depth_marking_border_px of the image edge, so every kept point can be re-checked from the pose that saw it. - Voxels without evidence keep the whole-voxel rule; evidence is erased on clear, pruned on rolling shift and every 50 frames. - New keys depth_evidence_points_enabled (default false), depth_evidence_points_per_voxel (8, 6..16), depth_marking_border_px (must be > depth_projection_margin_px when enabled); startup log and counters (by_evidence, border_dropped_points, evidence_voxels). - Tests: depth_evidence_store_test; checker and layer tests for the image top cut, border drop, rolling shift and a still-visible object.
95 lines
3.5 KiB
C++
95 lines
3.5 KiB
C++
#include <robot_costmap_2d/depth_evidence_store.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
using robot_costmap_2d::DepthEvidenceStore;
|
|
|
|
namespace
|
|
{
|
|
bool contains(const std::vector<Eigen::Vector3d>& points, const Eigen::Vector3d& point)
|
|
{
|
|
return std::any_of(points.begin(), points.end(),
|
|
[&](const Eigen::Vector3d& p) { return (p - point).norm() < 1e-6; });
|
|
}
|
|
} // namespace
|
|
|
|
TEST(DepthEvidenceStore, FirstPointIsTheOnlyEvidence)
|
|
{
|
|
DepthEvidenceStore store(8);
|
|
std::vector<Eigen::Vector3d> points;
|
|
EXPECT_FALSE(store.points({1, 2, 3}, points));
|
|
store.add({1, 2, 3}, Eigen::Vector3f(1.f, 2.f, .3f), false);
|
|
ASSERT_TRUE(store.points({1, 2, 3}, points));
|
|
ASSERT_EQ(points.size(), 1u);
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(1.0, 2.0, 0.3)));
|
|
EXPECT_FALSE(store.points({1, 2, 4}, points));
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, KeepsAxisExtremesWhenFull)
|
|
{
|
|
DepthEvidenceStore store(6); // extremes only, no recent slots
|
|
const DepthEvidenceStore::VoxelKey key{0, 0, 0};
|
|
store.add(key, Eigen::Vector3f(.02f, .02f, .02f), false);
|
|
store.add(key, Eigen::Vector3f(.00f, .03f, .03f), false); // new min x
|
|
store.add(key, Eigen::Vector3f(.04f, .01f, .01f), false); // new max x, min y, min z
|
|
store.add(key, Eigen::Vector3f(.02f, .02f, .02f), false); // inside: changes nothing
|
|
std::vector<Eigen::Vector3d> points;
|
|
ASSERT_TRUE(store.points(key, points));
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(.00, .03, .03)));
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(.04, .01, .01)));
|
|
EXPECT_LE(points.size(), 6u);
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, RecentSlotsRotate)
|
|
{
|
|
DepthEvidenceStore store(7); // one recent slot
|
|
const DepthEvidenceStore::VoxelKey key{0, 0, 0};
|
|
store.add(key, Eigen::Vector3f(.0f, .0f, .0f), false);
|
|
store.add(key, Eigen::Vector3f(.04f, .04f, .04f), false);
|
|
store.add(key, Eigen::Vector3f(.01f, .02f, .03f), false);
|
|
store.add(key, Eigen::Vector3f(.03f, .02f, .01f), false);
|
|
std::vector<Eigen::Vector3d> points;
|
|
ASSERT_TRUE(store.points(key, points));
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(.03, .02, .01)));
|
|
EXPECT_FALSE(contains(points, Eigen::Vector3d(.01, .02, .03)));
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, FreshVoxelDropsOldEvidence)
|
|
{
|
|
DepthEvidenceStore store(8);
|
|
const DepthEvidenceStore::VoxelKey key{5, -3, 2};
|
|
store.add(key, Eigen::Vector3f(1.f, 1.f, .2f), false);
|
|
store.add(key, Eigen::Vector3f(1.04f, 1.04f, .24f), true);
|
|
std::vector<Eigen::Vector3d> points;
|
|
ASSERT_TRUE(store.points(key, points));
|
|
ASSERT_EQ(points.size(), 1u);
|
|
EXPECT_TRUE(contains(points, Eigen::Vector3d(1.04, 1.04, .24)));
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, EraseEraseIfClearAndNonFinite)
|
|
{
|
|
DepthEvidenceStore store(8);
|
|
store.add({0, 0, 0}, Eigen::Vector3f(0.f, 0.f, 0.f), false);
|
|
store.add({1, 0, 0}, Eigen::Vector3f(.05f, 0.f, 0.f), false);
|
|
store.add({2, 0, 0}, Eigen::Vector3f(.1f, 0.f, 0.f), false);
|
|
store.add({3, 0, 0}, Eigen::Vector3f(std::nanf(""), 0.f, 0.f), false);
|
|
EXPECT_EQ(store.size(), 3u);
|
|
store.erase({0, 0, 0});
|
|
EXPECT_EQ(store.size(), 2u);
|
|
store.eraseIf([](const DepthEvidenceStore::VoxelKey& key) { return key.x == 2; });
|
|
std::vector<Eigen::Vector3d> points;
|
|
EXPECT_TRUE(store.points({1, 0, 0}, points));
|
|
EXPECT_FALSE(store.points({2, 0, 0}, points));
|
|
store.clear();
|
|
EXPECT_EQ(store.size(), 0u);
|
|
}
|
|
|
|
TEST(DepthEvidenceStore, CapacityIsClamped)
|
|
{
|
|
EXPECT_EQ(DepthEvidenceStore(2).pointsPerVoxel(), DepthEvidenceStore::kExtremeSlots);
|
|
EXPECT_EQ(DepthEvidenceStore(100).pointsPerVoxel(), DepthEvidenceStore::kMaxPoints);
|
|
}
|