refactor(depth): keep DepthCameraObstacleLayer, drop the legacy depth clearing

Two depth-image clearing designs lived in this package: the frustum ray
clearing inherited from dev_cam_intel (DepthCameraData sources of
ObstacleLayer/VoxelLayer, frustum_* and column_* keys) and the observed_volume
evidence clearing (ROC) on top of it. Both are replaced on the robot by
DepthCameraObstacleLayer, a port of costmap_depth_camera that takes the
filtered PointCloud2 directly, so both are removed and the tree is rebuilt
from main (a63c084) plus the plugin.

- observation.h / observation_buffer: DepthFrustumConfig, DepthCameraObservation
  and the depth buffering API are gone; buffers hold point clouds only.
- ObstacleLayer/VoxelLayer: no frustum ray casting, column clearing or depth
  ray cache. A DepthCameraData source or frustum_clearing_enabled: true now
  fails at startup with a message pointing to DepthCameraObstacleLayer
  instead of silently dropping the camera; DepthCameraData reaching the layer
  through the gateway is ignored.
- copyParentParameters no longer forwards the frustum_* / column_* keys.
- ROC files (depth_evidence_store, depth_visibility, depth_frame_pairer) and
  their tests are not carried over; CloudProcessingConfig goes with them.
- PCL is needed by the plugin library only. The plugin test moves under
  BUILD_COSTMAP_TESTS; BUILD_DEPTH_MARKING_TESTS is gone.
- README documents DepthCameraObstacleLayer and its known limits.

The plugin code is unchanged from the version running on the KIT robot.
This commit is contained in:
2026-10-20 09:47:25 +07:00
parent 9a67eee148
commit b23ff27a3c
20 changed files with 222 additions and 3768 deletions

View File

@@ -49,7 +49,6 @@
#include <robot_sensor_msgs/PointCloud2.h>
#include <robot_sensor_msgs/point_cloud_conversion.h>
#include <robot_costmap_2d/obstacle_layer.h>
#include <robot_costmap_2d/depth_evidence_store.h>
#include <robot_voxel_grid/voxel_grid.h>
#include <limits>
@@ -58,9 +57,6 @@
namespace robot_costmap_2d
{
class DepthVisibilityChecker;
enum class DepthObservation;
class VoxelLayer : public ObstacleLayer
{
public:
@@ -77,17 +73,12 @@ public:
double* max_x, double* max_y);
void updateOrigin(double new_origin_x, double new_origin_y);
// Diagnostic snapshot; caller must hold the layer/update lock, as with getCharMap().
VoxelGrid voxelSnapshot();
bool isDiscretized()
{
return true;
}
virtual void matchSize();
virtual void reset();
/// Recovery clear. Also drops the voxels and evidence points of the cleared cells: the
/// base class only writes the 2D cells, and the next column update re-derived the obstacle.
void clearArea(int start_x, int start_y, int end_x, int end_y, bool invert_area = false) override;
LayerType getType() const override
{
@@ -103,103 +94,15 @@ private:
void clearNonLethal(double wx, double wy, double w_size_x, double w_size_y, bool clear_no_info);
virtual void raytraceFreespace(const robot_costmap_2d::Observation& clearing_observation, double* min_x, double* min_y,
double* max_x, double* max_y);
// bool raytraceDepthFrustum(double* min_x, double* min_y, double* max_x, double* max_y);
bool raytraceDepthFrustum(const robot_costmap_2d::DepthCameraObservation& observation,
double* min_x, double* min_y, double* max_x, double* max_y);
bool readDepthMeters(const robot_sensor_msgs::Image& depth, unsigned int u, unsigned int v,
double& depth_m, bool& is_valid) const;
void updateDepthRayCache(unsigned int width, unsigned int height, unsigned int pixel_step,
double fx, double fy, double cx, double cy);
bool clipRaytraceEndpoint(double ox, double oy, double oz, double& wx, double& wy, double& wz);
bool clearVoxelRay(double ox, double oy, double oz, double wx, double wy, double wz,
double raytrace_range, unsigned int cell_raytrace_range,
double* min_x, double* min_y, double* max_x, double* max_y);
bool clearDepthColumns(double ox, double oy, double cover_distance, double far_distance,
double min_range, double max_range, double skip_dist,
double* min_x, double* min_y, double* max_x, double* max_y);
bool clipColumnSegment(double& sx, double& sy, double& ex, double& ey) const;
/// Paired depth marking: the checker of the same frame gates marking at the image
/// border and the store records evidence points. Null for every other source.
struct PairedMarking
{
const DepthVisibilityChecker* checker;
const DepthFrustumConfig* config;
};
void markObservation(const Observation& observation, double* min_x, double* min_y,
double* max_x, double* max_y, const PairedMarking* paired = nullptr);
void processPairedDepth(double* min_x, double* min_y, double* max_x, double* max_y);
struct VisibilityCounts
{
uint64_t free{0}, unknown{0}, surface{0}, frames{0};
uint64_t by_evidence{0}; ///< decisions made from evidence points
uint64_t border_dropped{0}; ///< marking points dropped at the image border
/// re-observe-or-clear outcomes per voxel and frame
uint64_t confirmed{0}, occluded{0}, seen_through{0}, no_return{0}, out_of_view{0};
} visibility_counts_;
/// Re-observe-or-clear: applies one frame's observation to the voxel's miss count.
/// Returns true when the voxel is to be freed.
bool reobserveFrees(DepthObservation observation, const DepthEvidenceStore::VoxelKey& key,
const DepthFrustumConfig& config);
/// Window-independent key: local cell index plus the cells the rolling origin moved.
DepthEvidenceStore::VoxelKey evidenceKey(unsigned int x, unsigned int y, unsigned int z) const
{
return {static_cast<int>(x) + evidence_offset_x_, static_cast<int>(y) + evidence_offset_y_, z};
}
/// Drops evidence of voxels that left the window or are no longer MARKED.
void pruneDepthEvidence();
/// Frees every voxel of the column and its evidence points; the 2D cell is left to the caller.
void clearDepthColumn(unsigned int x, unsigned int y);
/// Paired depth only: the voxels under the footprint, which ObstacleLayer frees in 2D only.
void clearFootprintVoxels();
DepthEvidenceStore depth_evidence_;
int evidence_offset_x_ = 0;
int evidence_offset_y_ = 0;
uint64_t frames_since_evidence_prune_ = 0;
bool publish_voxel_;
robot_voxel_grid::VoxelGrid robot_voxel_grid_;
double z_resolution_, origin_z_;
/// Scratch for the full-column clearing pass (config lives per observation
/// source in DepthFrustumConfig): per depth-image pixel column, the nearest
/// return inside the obstacle height band certifies "no obstacle in this
/// direction closer than d". Cells along that 2D beam get their whole voxel
/// column cleared, removing marked voxels the per-pixel 3D rays cannot
/// reach (above the vertical FOV at close range).
struct DepthColumnStat
{
double min_band_dist = -1.0; ///< horizontal distance of nearest in-band return; < 0 = none
double azimuth = 0.0; ///< beam direction in the global frame
double best_row_delta = std::numeric_limits<double>::infinity();
bool has_ray = false; ///< column had at least one readable pixel
bool in_border = false; ///< column lies in a left/right no-disparity strip
};
std::vector<DepthColumnStat> depth_column_stats_;
unsigned int unknown_threshold_, mark_threshold_, size_z_;
robot_sensor_msgs::PointCloud clearing_endpoints_;
std::vector<unsigned char> rolling_costmap_scratch_;
std::vector<unsigned int> rolling_voxel_scratch_;
struct DepthRay
{
unsigned int u;
unsigned int v;
unsigned int col; ///< pixel-column index in the cache (border column included)
double x;
double y;
double z;
};
std::vector<DepthRay> depth_ray_cache_;
unsigned int cached_column_count_ = 0;
unsigned int cached_depth_width_ = 0;
unsigned int cached_depth_height_ = 0;
unsigned int cached_depth_pixel_step_ = 0;
double cached_fx_ = 0.0;
double cached_fy_ = 0.0;
double cached_cx_ = 0.0;
double cached_cy_ = 0.0;
inline bool worldToMap3DFloat(double wx, double wy, double wz, double& mx, double& my, double& mz)
{
if (wx < origin_x_ || wy < origin_y_ || wz < origin_z_)