This commit is contained in:
trung09122002
2026-09-25 09:04:37 +07:00
parent d6f1afac31
commit 0093df0508
7 changed files with 139 additions and 5 deletions

View File

@@ -119,6 +119,13 @@ void NodeCloudFromSensorData(const rtabmap::SensorData& data,
const VoxelExportOptions& opt,
std::vector<float>* out);
// Danh dau o 2D bi chiem duoi moi voxel co tam trong [z_min, z_max] (tinh tu
// mat san). La LOP VAT CAN tu camera cho nhung thu LiDAR (0.22 m) khong cat
// ngang: mat ghe, khung giuong, ke thap. Chi THEM o bi chiem, khong xoa.
// Tra ve so o moi danh dau (truoc do trong/chua biet).
size_t MarkVoxelObstacles(const VoxelGrid& vg, double z_min, double z_max,
OccupancyGrid* grid);
// Hieu hai tap DA SAP XEP: `added` co trong `now` ma khong co trong `prev`,
// `removed` thi nguoc lai. O(n + m), mot luot.
//

View File

@@ -172,6 +172,32 @@ void DiffVoxelGrids(const std::vector<VoxelIndex>& prev,
for (; j < now.size(); ++j) added->push_back(now[j]);
}
size_t MarkVoxelObstacles(const VoxelGrid& vg, double z_min, double z_max,
OccupancyGrid* grid) {
if (grid->width == 0 || grid->height == 0 || grid->resolution <= 0.0f) return 0;
const double r = vg.resolution;
const double inv = 1.0 / grid->resolution;
size_t marked = 0;
for (const VoxelIndex& k : vg.cells) {
const double z = vg.origin_z + (k.z + 0.5) * r;
if (z < z_min || z > z_max) continue;
// Luoi 2D khong xoay (occupancy_export dat orientation = dong nhat), va
// hang 0 la ymin -- cung quy uoc voi RTAB-Map/map_server.
const double fx =
std::floor((vg.origin_x + (k.x + 0.5) * r - grid->origin.position.x) * inv);
const double fy =
std::floor((vg.origin_y + (k.y + 0.5) * r - grid->origin.position.y) * inv);
if (fx < 0.0 || fy < 0.0 || fx >= grid->width || fy >= grid->height) continue;
int8_t& c = grid->data[static_cast<size_t>(fy) * grid->width +
static_cast<size_t>(fx)];
if (c < 50) {
c = 100;
++marked;
}
}
return marked;
}
void NodeCloudFromSensorData(const rtabmap::SensorData& data,
const VoxelExportOptions& opt,
std::vector<float>* out) {