Always take std::function<> by value. (#188)

Taking it by reference increases the chance of dangling references
without a significant performance gain.
master
Holger Rapp 2017-01-26 11:35:09 +01:00 committed by GitHub
parent f047ad35c1
commit 2dd912f5e7
10 changed files with 20 additions and 19 deletions

View File

@ -79,7 +79,7 @@ void WriteBinaryPcdPointColor(const Color& color,
std::unique_ptr<PcdWritingPointsProcessor>
PcdWritingPointsProcessor::FromDictionary(
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) {
return common::make_unique<PcdWritingPointsProcessor>(

View File

@ -31,7 +31,7 @@ class PcdWritingPointsProcessor : public PointsProcessor {
PointsProcessor* next);
static std::unique_ptr<PcdWritingPointsProcessor> FromDictionary(
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* dictionary, PointsProcessor* next);
~PcdWritingPointsProcessor() override {}

View File

@ -70,7 +70,7 @@ void WriteBinaryPlyPointColor(const Color& color,
std::unique_ptr<PlyWritingPointsProcessor>
PlyWritingPointsProcessor::FromDictionary(
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) {
return common::make_unique<PlyWritingPointsProcessor>(

View File

@ -29,7 +29,7 @@ class PlyWritingPointsProcessor : public PointsProcessor {
PointsProcessor* next);
static std::unique_ptr<PlyWritingPointsProcessor> FromDictionary(
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* dictionary, PointsProcessor* next);
~PlyWritingPointsProcessor() override {}

View File

@ -46,11 +46,11 @@ void RegisterPlainPointsProcessor(
template <typename PointsProcessorType>
void RegisterFileWritingPointsProcessor(
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
PointsProcessorPipelineBuilder* const builder) {
builder->Register(
PointsProcessorType::kConfigurationFileActionName,
[&file_writer_factory](
[file_writer_factory](
common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
return PointsProcessorType::FromDictionary(file_writer_factory,
@ -60,7 +60,7 @@ void RegisterFileWritingPointsProcessor(
void RegisterBuiltInPointsProcessors(
const mapping::proto::Trajectory& trajectory,
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
PointsProcessorPipelineBuilder* builder) {
RegisterPlainPointsProcessor<CountingPointsProcessor>(builder);
RegisterPlainPointsProcessor<FixedRatioSamplingPointsProcessor>(builder);
@ -79,7 +79,7 @@ void RegisterBuiltInPointsProcessors(
// different building levels we walked on to separate the images.
builder->Register(
XRayPointsProcessor::kConfigurationFileActionName,
[&trajectory, &file_writer_factory](
[&trajectory, file_writer_factory](
common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) -> std::unique_ptr<PointsProcessor> {
return XRayPointsProcessor::FromDictionary(

View File

@ -62,7 +62,7 @@ class PointsProcessorPipelineBuilder {
// 'builder'.
void RegisterBuiltInPointsProcessors(
const mapping::proto::Trajectory& trajectory,
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
PointsProcessorPipelineBuilder* builder);
} // namespace io

View File

@ -136,7 +136,7 @@ bool ContainedIn(
XRayPointsProcessor::XRayPointsProcessor(
const double voxel_size, const transform::Rigid3f& transform,
const std::vector<mapping::Floor>& floors, const string& output_filename,
const FileWriterFactory& file_writer_factory, PointsProcessor* const next)
FileWriterFactory file_writer_factory, PointsProcessor* const next)
: next_(next),
file_writer_factory_(file_writer_factory),
floors_(floors),
@ -151,7 +151,7 @@ XRayPointsProcessor::XRayPointsProcessor(
std::unique_ptr<XRayPointsProcessor> XRayPointsProcessor::FromDictionary(
const mapping::proto::Trajectory& trajectory,
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) {
std::vector<mapping::Floor> floors;
@ -200,8 +200,8 @@ void XRayPointsProcessor::WriteVoxels(const Aggregation& aggregation,
const Eigen::Array3i cell_index = it.GetCellIndex();
const Eigen::Array2i pixel = voxel_index_to_pixel(cell_index);
PixelData& pixel_data = image(pixel.y(), pixel.x());
const auto& column_data =
aggregation.column_data.at(std::make_pair(cell_index[1], cell_index[2]));
const auto& column_data = aggregation.column_data.at(
std::make_pair(cell_index[1], cell_index[2]));
pixel_data.mean_r = column_data.sum_r / column_data.count;
pixel_data.mean_g = column_data.sum_g / column_data.count;
pixel_data.mean_b = column_data.sum_b / column_data.count;

View File

@ -39,12 +39,12 @@ class XRayPointsProcessor : public PointsProcessor {
XRayPointsProcessor(double voxel_size, const transform::Rigid3f& transform,
const std::vector<mapping::Floor>& floors,
const string& output_filename,
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
PointsProcessor* next);
static std::unique_ptr<XRayPointsProcessor> FromDictionary(
const mapping::proto::Trajectory& trajectory,
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* dictionary, PointsProcessor* next);
~XRayPointsProcessor() override {}
@ -65,12 +65,13 @@ class XRayPointsProcessor : public PointsProcessor {
std::map<std::pair<int, int>, ColumnData> column_data;
};
void WriteVoxels(const Aggregation& aggregation, FileWriter* const file_writer);
void WriteVoxels(const Aggregation& aggregation,
FileWriter* const file_writer);
void Insert(const PointsBatch& batch, const transform::Rigid3f& transform,
Aggregation* aggregation);
PointsProcessor* const next_;
const FileWriterFactory& file_writer_factory_;
FileWriterFactory file_writer_factory_;
// If empty, we do not separate into floors.
std::vector<mapping::Floor> floors_;

View File

@ -27,7 +27,7 @@ XyzWriterPointsProcessor::XyzWriterPointsProcessor(
std::unique_ptr<XyzWriterPointsProcessor>
XyzWriterPointsProcessor::FromDictionary(
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) {
return common::make_unique<XyzWriterPointsProcessor>(

View File

@ -36,7 +36,7 @@ class XyzWriterPointsProcessor : public PointsProcessor {
XyzWriterPointsProcessor(std::unique_ptr<FileWriter>, PointsProcessor* next);
static std::unique_ptr<XyzWriterPointsProcessor> FromDictionary(
const FileWriterFactory& file_writer_factory,
FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* dictionary, PointsProcessor* next);
~XyzWriterPointsProcessor() override {}