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> std::unique_ptr<PcdWritingPointsProcessor>
PcdWritingPointsProcessor::FromDictionary( PcdWritingPointsProcessor::FromDictionary(
const FileWriterFactory& file_writer_factory, FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* const dictionary, common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) { PointsProcessor* const next) {
return common::make_unique<PcdWritingPointsProcessor>( return common::make_unique<PcdWritingPointsProcessor>(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -136,7 +136,7 @@ bool ContainedIn(
XRayPointsProcessor::XRayPointsProcessor( XRayPointsProcessor::XRayPointsProcessor(
const double voxel_size, const transform::Rigid3f& transform, const double voxel_size, const transform::Rigid3f& transform,
const std::vector<mapping::Floor>& floors, const string& output_filename, 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), : next_(next),
file_writer_factory_(file_writer_factory), file_writer_factory_(file_writer_factory),
floors_(floors), floors_(floors),
@ -151,7 +151,7 @@ XRayPointsProcessor::XRayPointsProcessor(
std::unique_ptr<XRayPointsProcessor> XRayPointsProcessor::FromDictionary( std::unique_ptr<XRayPointsProcessor> XRayPointsProcessor::FromDictionary(
const mapping::proto::Trajectory& trajectory, const mapping::proto::Trajectory& trajectory,
const FileWriterFactory& file_writer_factory, FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* const dictionary, common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) { PointsProcessor* const next) {
std::vector<mapping::Floor> floors; std::vector<mapping::Floor> floors;
@ -200,8 +200,8 @@ void XRayPointsProcessor::WriteVoxels(const Aggregation& aggregation,
const Eigen::Array3i cell_index = it.GetCellIndex(); const Eigen::Array3i cell_index = it.GetCellIndex();
const Eigen::Array2i pixel = voxel_index_to_pixel(cell_index); const Eigen::Array2i pixel = voxel_index_to_pixel(cell_index);
PixelData& pixel_data = image(pixel.y(), pixel.x()); PixelData& pixel_data = image(pixel.y(), pixel.x());
const auto& column_data = const auto& column_data = aggregation.column_data.at(
aggregation.column_data.at(std::make_pair(cell_index[1], cell_index[2])); std::make_pair(cell_index[1], cell_index[2]));
pixel_data.mean_r = column_data.sum_r / column_data.count; 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_g = column_data.sum_g / column_data.count;
pixel_data.mean_b = column_data.sum_b / 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, XRayPointsProcessor(double voxel_size, const transform::Rigid3f& transform,
const std::vector<mapping::Floor>& floors, const std::vector<mapping::Floor>& floors,
const string& output_filename, const string& output_filename,
const FileWriterFactory& file_writer_factory, FileWriterFactory file_writer_factory,
PointsProcessor* next); PointsProcessor* next);
static std::unique_ptr<XRayPointsProcessor> FromDictionary( static std::unique_ptr<XRayPointsProcessor> FromDictionary(
const mapping::proto::Trajectory& trajectory, const mapping::proto::Trajectory& trajectory,
const FileWriterFactory& file_writer_factory, FileWriterFactory file_writer_factory,
common::LuaParameterDictionary* dictionary, PointsProcessor* next); common::LuaParameterDictionary* dictionary, PointsProcessor* next);
~XRayPointsProcessor() override {} ~XRayPointsProcessor() override {}
@ -65,12 +65,13 @@ class XRayPointsProcessor : public PointsProcessor {
std::map<std::pair<int, int>, ColumnData> column_data; 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, void Insert(const PointsBatch& batch, const transform::Rigid3f& transform,
Aggregation* aggregation); Aggregation* aggregation);
PointsProcessor* const next_; PointsProcessor* const next_;
const FileWriterFactory& file_writer_factory_; FileWriterFactory file_writer_factory_;
// If empty, we do not separate into floors. // If empty, we do not separate into floors.
std::vector<mapping::Floor> floors_; std::vector<mapping::Floor> floors_;

View File

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

View File

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