#ifndef VSLAM_VOXEL_EXPORT_H #define VSLAM_VOXEL_EXPORT_H // Xuat BAN DO VOXEL 3D tu do thi RTAB-Map, cho khung 3D cua web UI. // // Khac occupancy_export.cc o mot cho ban le: o day KHONG dung // rtabmap::OccupancyGrid. `BuildFromCache` ep Grid/3D="false" ngay trong ham // (occupancy_export.cc) va do la dung cho duong 2D -- no chieu moi thu xuong // mot mat phang. Ban do 3D phai lay o BI CHIEM o he cuc bo cua tung node roi // tu bien doi bang pose DA TOI UU. // // ⚠️ Chinh vi dung pose da toi uu ma ban do 3D tu NAN lai sau moi vong dong: // khong co buoc "sua ban do" nao ca, ta dung lai tu dau tu do thi moi. Doi // lai, sau mot lan toi uu thi gan nhu MOI voxel doi chi so -- xem `epoch` // trong VoxelGrid va luat 35% o phia web. // // ⚠️ `data.uncompressData()` la BAT BUOC truoc khi doc gridObstacleCellsRaw(). // Quen no thi moi node tra ve ma tran RONG, va trieu chung la "1990 node, 0 o" // -- y het cai bay da co trong occupancy_export.h. #include #include #include #include "vslam/vslam_common.h" namespace rtabmap { class Rtabmap; } namespace vslam { struct VoxelExportOptions { // Kich thuoc o PHAT. Doc lap voi Grid/CellSize (0.05) cua SLAM: lam tho // them mot bac cat bon lan so voxel ma mat rat it hinh dang. double emit_size_m = 0.10; // Cat san va tran. z do tu base_footprint = mat san. double z_min = 0.05; double z_max = 2.00; // Tran cung. Cham tran thi cat bot va bat `truncated` chu khong am tham // nuot: mot ban do 3D thieu mot nua trong im lang la kieu hong te nhat. size_t max_cells = 150000; // Gom bao nhieu khoa thi sort+unique mot lan. Doi bo nho dinh lay so lan // tron: 2M khoa = 16 MB tam thoi. size_t flush_every = 2000000; }; // Gom diem -> tap voxel. KHONG chua kieu nao cua RTAB-Map, nen test duoc ma // khong can mot Rtabmap dang chay -- do la ly do no tach rieng khoi // ExportVoxelGrid. class VoxelAccumulator { public: explicit VoxelAccumulator(const VoxelExportOptions& opt); // Toa do trong frame MAP, met. void AddPoint(double x, double y, double z); // Sort + unique lan cuoi roi do ra `out`. `out->cells` da sap xep. void Finish(VoxelGrid* out); // So diem bi bo vi ra ngoai dai int16. Khac 0 nghia la ban do vuot +-3 km // hoac resolution bi dat sai. size_t clamped() const { return clamped_; } // So diem bi cat vi nam ngoai [z_min, z_max]. size_t z_rejected() const { return z_rejected_; } private: void Flush(); VoxelExportOptions opt_; double inv_size_ = 10.0; std::vector scratch_; std::vector acc_; // luon o trang thai da sort+unique size_t clamped_ = 0; size_t z_rejected_ = 0; }; // Quet toan bo pose da toi uu va dung lai tap voxel tu dau. // // `out->epoch` KHONG duoc dat o day -- nguoi goi quan ly vong doi epoch, vi // chi ho moi biet tap truoc do la gi. StatusResponse ExportVoxelGrid(rtabmap::Rtabmap& slam, const VoxelExportOptions& opt, VoxelGrid* out); // Hieu hai tap DA SAP XEP: `added` co trong `now` ma khong co trong `prev`, // `removed` thi nguoc lai. O(n + m), mot luot. // // Tach ra de test duoc va de nguoi goi quyet dinh gui delta hay gui lai ca // tap dua tren ti le thay doi. void DiffVoxelGrids(const std::vector& prev, const std::vector& now, std::vector* added, std::vector* removed); } // namespace vslam #endif // VSLAM_VOXEL_EXPORT_H