#ifndef ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_ #define ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_ #include #include #include #include #include #include #include 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& out) const; void erase(const VoxelKey& key); void eraseIf(const std::function& 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(static_cast(key.x)) * 73856093u) ^ (static_cast(static_cast(key.y)) * 19349663u) ^ (static_cast(key.z) * 83492791u); } }; struct Entry { std::array 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 entries_; }; } // namespace robot_costmap_2d #endif // ROBOT_COSTMAP_2D_DEPTH_EVIDENCE_STORE_H_