feat(depth): certify evidence points instead of whole voxels (phase 1)
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.
This commit is contained in:
86
include/robot_costmap_2d/depth_evidence_store.h
Normal file
86
include/robot_costmap_2d/depth_evidence_store.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#ifndef ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_
|
||||
#define ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace robot_costmap_2d
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Measured points that marked each voxel of a depth-only VoxelLayer.
|
||||
*
|
||||
* The observed_volume clearing certifies these points instead of the whole voxel box:
|
||||
* the occupancy of a depth-only layer is exactly what the camera saw, so the part of a
|
||||
* voxel the camera never saw carries no occupancy of its own. Keys use a
|
||||
* window-independent cell index, so a rolling origin shift needs no copy; callers drop
|
||||
* keys that left the window with eraseIf().
|
||||
*
|
||||
* Per voxel it keeps the 6 per-axis extreme points (min/max x, y, z) and fills the
|
||||
* remaining slots with the most recent points.
|
||||
*/
|
||||
class DepthEvidenceStore
|
||||
{
|
||||
public:
|
||||
static constexpr unsigned int kExtremeSlots = 6;
|
||||
static constexpr unsigned int kMaxPoints = 16;
|
||||
|
||||
struct VoxelKey
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
unsigned int z;
|
||||
bool operator==(const VoxelKey& other) const
|
||||
{
|
||||
return x == other.x && y == other.y && z == other.z;
|
||||
}
|
||||
};
|
||||
|
||||
explicit DepthEvidenceStore(unsigned int points_per_voxel = 8);
|
||||
|
||||
/// Clamped to [kExtremeSlots, kMaxPoints]; drops all stored evidence.
|
||||
void setPointsPerVoxel(unsigned int points_per_voxel);
|
||||
unsigned int pointsPerVoxel() const { return points_per_voxel_; }
|
||||
|
||||
/// Records a marking point [global frame, m]. fresh = true drops points left over from
|
||||
/// an earlier occupancy of the voxel (it was not MARKED before this point).
|
||||
void add(const VoxelKey& key, const Eigen::Vector3f& point, bool fresh);
|
||||
|
||||
/// Distinct evidence points of one voxel. Returns false when the voxel has none.
|
||||
bool points(const VoxelKey& key, std::vector<Eigen::Vector3d>& out) const;
|
||||
|
||||
void erase(const VoxelKey& key);
|
||||
void eraseIf(const std::function<bool(const VoxelKey&)>& predicate);
|
||||
void clear();
|
||||
std::size_t size() const { return entries_.size(); }
|
||||
|
||||
private:
|
||||
struct KeyHash
|
||||
{
|
||||
std::size_t operator()(const VoxelKey& key) const noexcept
|
||||
{
|
||||
return (static_cast<std::size_t>(static_cast<uint32_t>(key.x)) * 73856093u) ^
|
||||
(static_cast<std::size_t>(static_cast<uint32_t>(key.y)) * 19349663u) ^
|
||||
(static_cast<std::size_t>(key.z) * 83492791u);
|
||||
}
|
||||
};
|
||||
|
||||
struct Entry
|
||||
{
|
||||
std::array<Eigen::Vector3f, kMaxPoints> points;
|
||||
unsigned char count = 0; ///< valid slots, extremes included
|
||||
unsigned char next_recent = 0; ///< ring position among the recent slots
|
||||
};
|
||||
|
||||
unsigned int points_per_voxel_;
|
||||
std::unordered_map<VoxelKey, Entry, KeyHash> entries_;
|
||||
};
|
||||
|
||||
} // namespace robot_costmap_2d
|
||||
|
||||
#endif // ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_
|
||||
Reference in New Issue
Block a user