# cartographer/sensor/internal/voxel_filter.h ## Overview `VoxelFilter` downsamples point clouds by dividing space into 3D voxels and keeping one point per voxel (typically the first or centroid). ## Class: `cartographer::sensor::VoxelFilter` ### Construction ```cpp explicit VoxelFilter(float voxel_size); ``` - `voxel_size` — Voxel edge length in meters ### Filtering ```cpp PointCloud Filter(const PointCloud& point_cloud) const; ``` Returns downsampled point cloud. ### Algorithm 1. Compute voxel index for each point: `index = floor(point / voxel_size)` 2. Use hash map to track first point per voxel 3. Return collected points ### Complexity - Time: O(N) for N points - Space: O(M) for M occupied voxels ## Usage ```cpp // Create filter sensor::VoxelFilter filter(0.025f); // 2.5cm voxels // Filter point cloud sensor::PointCloud raw = lidar->GetScan(); sensor::PointCloud filtered = filter.Filter(raw); // Typical reduction: 100k points -> 10-20k points ``` ## Configuration Used in trajectory builder configs: ```lua TRAJECTORY_BUILDER_2D = { voxel_filter_size = 0.025, -- 2.5cm } TRAJECTORY_BUILDER_3D = { voxel_filter_size = 0.15, -- 15cm (3D lidars denser) } ``` ## See Also - [PointCloud](../point_cloud.md) — Input/output format - [RangeData](../range_data.md) — Uses filtered point clouds