00001 /* 00002 * Copyright 2016 The Cartographer Authors 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CARTOGRAPHER_SENSOR_INTERNAL_VOXEL_FILTER_H_ 00018 #define CARTOGRAPHER_SENSOR_INTERNAL_VOXEL_FILTER_H_ 00019 00020 #include <bitset> 00021 00022 #include "absl/container/flat_hash_set.h" 00023 #include "cartographer/common/lua_parameter_dictionary.h" 00024 #include "cartographer/sensor/point_cloud.h" 00025 #include "cartographer/sensor/proto/adaptive_voxel_filter_options.pb.h" 00026 #include "cartographer/sensor/timed_point_cloud_data.h" 00027 00028 namespace cartographer { 00029 namespace sensor { 00030 00031 // Voxel filter for point clouds. For each voxel, the assembled point cloud 00032 // contains the first point that fell into it from any of the inserted point 00033 // clouds. 00034 class VoxelFilter { 00035 public: 00036 // 'size' is the length of a voxel edge. 00037 explicit VoxelFilter(float size) : resolution_(size) {} 00038 00039 VoxelFilter(const VoxelFilter&) = delete; 00040 VoxelFilter& operator=(const VoxelFilter&) = delete; 00041 00042 // Returns a voxel filtered copy of 'point_cloud'. 00043 PointCloud Filter(const PointCloud& point_cloud); 00044 00045 // Same for TimedPointCloud. 00046 TimedPointCloud Filter(const TimedPointCloud& timed_point_cloud); 00047 00048 // Same for RangeMeasurement. 00049 std::vector<TimedPointCloudOriginData::RangeMeasurement> Filter( 00050 const std::vector<TimedPointCloudOriginData::RangeMeasurement>& 00051 range_measurements); 00052 00053 private: 00054 using KeyType = std::bitset<3 * 32>; 00055 00056 static KeyType IndexToKey(const Eigen::Array3i& index); 00057 00058 Eigen::Array3i GetCellIndex(const Eigen::Vector3f& point) const; 00059 00060 float resolution_; 00061 absl::flat_hash_set<KeyType> voxel_set_; 00062 }; 00063 00064 proto::AdaptiveVoxelFilterOptions CreateAdaptiveVoxelFilterOptions( 00065 common::LuaParameterDictionary* const parameter_dictionary); 00066 00067 class AdaptiveVoxelFilter { 00068 public: 00069 explicit AdaptiveVoxelFilter( 00070 const proto::AdaptiveVoxelFilterOptions& options); 00071 00072 AdaptiveVoxelFilter(const AdaptiveVoxelFilter&) = delete; 00073 AdaptiveVoxelFilter& operator=(const AdaptiveVoxelFilter&) = delete; 00074 00075 PointCloud Filter(const PointCloud& point_cloud) const; 00076 00077 private: 00078 const proto::AdaptiveVoxelFilterOptions options_; 00079 }; 00080 00081 } // namespace sensor 00082 } // namespace cartographer 00083 00084 #endif // CARTOGRAPHER_SENSOR_INTERNAL_VOXEL_FILTER_H_