outlier_removing_points_processor.h
Go to the documentation of this file.
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_IO_OUTLIER_REMOVING_POINTS_PROCESSOR_H_
00018 #define CARTOGRAPHER_IO_OUTLIER_REMOVING_POINTS_PROCESSOR_H_
00019 
00020 #include "cartographer/common/lua_parameter_dictionary.h"
00021 #include "cartographer/io/points_processor.h"
00022 #include "cartographer/mapping/3d/hybrid_grid.h"
00023 
00024 namespace cartographer {
00025 namespace io {
00026 
00027 // Voxel filters the data and only passes on points that we believe are on
00028 // non-moving objects.
00029 class OutlierRemovingPointsProcessor : public PointsProcessor {
00030  public:
00031   constexpr static const char* kConfigurationFileActionName =
00032       "voxel_filter_and_remove_moving_objects";
00033 
00034   OutlierRemovingPointsProcessor(double voxel_size, double miss_per_hit_limit,
00035                                  PointsProcessor* next);
00036 
00037   static std::unique_ptr<OutlierRemovingPointsProcessor> FromDictionary(
00038       common::LuaParameterDictionary* dictionary, PointsProcessor* next);
00039 
00040   ~OutlierRemovingPointsProcessor() override {}
00041 
00042   OutlierRemovingPointsProcessor(const OutlierRemovingPointsProcessor&) =
00043       delete;
00044   OutlierRemovingPointsProcessor& operator=(
00045       const OutlierRemovingPointsProcessor&) = delete;
00046 
00047   void Process(std::unique_ptr<PointsBatch> batch) override;
00048   FlushResult Flush() override;
00049 
00050  private:
00051   // To reduce memory consumption by not having to keep all rays in memory, we
00052   // filter outliers in three phases each going over all data: First we compute
00053   // all voxels containing any hits, then we compute the rays passing through
00054   // each of these voxels, and finally we output all hits in voxels that are
00055   // considered obstructed.
00056   struct VoxelData {
00057     int hits = 0;
00058     int rays = 0;
00059   };
00060   enum class State {
00061     kPhase1,
00062     kPhase2,
00063     kPhase3,
00064   };
00065 
00066   // First phase counts the number of hits per voxel.
00067   void ProcessInPhaseOne(const PointsBatch& batch);
00068 
00069   // Second phase counts how many rays pass through each voxel. This is only
00070   // done for voxels that contain hits. This is to reduce memory consumption by
00071   // not adding data to free voxels.
00072   void ProcessInPhaseTwo(const PointsBatch& batch);
00073 
00074   // Third phase produces the output containing all inliers. We consider each
00075   // hit an inlier if it is inside a voxel that has a sufficiently high
00076   // hit-to-ray ratio.
00077   void ProcessInPhaseThree(std::unique_ptr<PointsBatch> batch);
00078 
00079   const double voxel_size_;
00080   const double miss_per_hit_limit_;
00081   PointsProcessor* const next_;
00082   State state_;
00083   mapping::HybridGridBase<VoxelData> voxels_;
00084 };
00085 
00086 }  // namespace io
00087 }  // namespace cartographer
00088 
00089 #endif  // CARTOGRAPHER_IO_OUTLIER_REMOVING_POINTS_PROCESSOR_H_


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35