From 013eba4dcc4a2c221e85db053138922ed9ef257c Mon Sep 17 00:00:00 2001 From: Bradley J Chambers Date: Tue, 3 Feb 2015 16:01:04 -0500 Subject: [PATCH] Plugin framework refactoring This commit adds a new PluginManager that controls loading of all plugins, regardless of type (kernel vs. stage, static vs. shared). Subsequently, the StageFactory and KernelFactory classes are greatly simplified as there was significant redundant code. Macros are provided to simplify creation of each type of plugin, but are not explicitly required. Each plugin registers it's name, description, link, type, and will soon include a version. Dropped program_options in pdal.cpp and added ability to selectively load plugin types (or none at all). --- apps/pdal.cpp | 298 +++++++++++----- cmake/compiler_options.cmake | 6 + doc/tutorial/writing.rst | 9 +- filters/chipper/ChipperFilter.cpp | 12 + filters/chipper/ChipperFilter.hpp | 19 +- filters/colorization/ColorizationFilter.cpp | 22 +- filters/colorization/ColorizationFilter.hpp | 20 +- filters/crop/CropFilter.cpp | 15 + filters/crop/CropFilter.hpp | 15 +- filters/decimation/DecimationFilter.cpp | 16 +- filters/decimation/DecimationFilter.hpp | 11 +- filters/ferry/FerryFilter.cpp | 17 +- filters/ferry/FerryFilter.hpp | 18 +- filters/merge/CMakeLists.txt | 12 +- filters/merge/MergeFilter.cpp | 54 +++ filters/merge/MergeFilter.hpp | 14 +- filters/mortonorder/MortonOrderFilter.cpp | 15 +- filters/mortonorder/MortonOrderFilter.hpp | 16 +- filters/reprojection/ReprojectionFilter.cpp | 20 +- filters/reprojection/ReprojectionFilter.hpp | 11 +- filters/sort/CMakeLists.txt | 12 +- filters/sort/SortFilter.cpp | 54 +++ filters/sort/SortFilter.hpp | 11 +- filters/splitter/SplitterFilter.cpp | 15 +- filters/splitter/SplitterFilter.hpp | 13 +- filters/stats/StatsFilter.cpp | 17 +- filters/stats/StatsFilter.hpp | 13 +- .../transformation/TransformationFilter.cpp | 15 +- .../transformation/TransformationFilter.hpp | 12 +- include/pdal/BufferReader.hpp | 6 +- include/pdal/Drivers.hpp | 4 - include/pdal/Kernel.hpp | 49 ++- include/pdal/KernelFactory.hpp | 48 +-- include/pdal/KernelInfo.hpp | 99 ------ include/pdal/Kernels.hpp | 44 --- include/pdal/PluginManager.hpp | 57 +++ include/pdal/Stage.hpp | 18 +- include/pdal/StageFactory.hpp | 69 +--- include/pdal/StageInfo.hpp | 2 +- include/pdal/Writer.hpp | 2 +- include/pdal/pdal_macros.hpp | 140 +++----- include/pdal/plugin.h | 70 ++++ io/bpf/BpfReader.cpp | 18 +- io/bpf/BpfReader.hpp | 18 +- io/bpf/BpfWriter.cpp | 22 +- io/bpf/BpfWriter.hpp | 20 +- io/faux/FauxReader.cpp | 27 +- io/faux/FauxReader.hpp | 13 +- io/las/LasReader.cpp | 23 +- io/las/LasReader.hpp | 19 +- io/las/LasWriter.cpp | 15 + io/las/LasWriter.hpp | 14 +- io/qfit/QfitReader.cpp | 19 +- io/qfit/QfitReader.hpp | 13 +- io/sbet/SbetReader.cpp | 13 + io/sbet/SbetReader.hpp | 11 +- io/sbet/SbetWriter.cpp | 13 + io/sbet/SbetWriter.hpp | 9 +- io/terrasolid/TerrasolidReader.cpp | 13 + io/terrasolid/TerrasolidReader.hpp | 15 +- io/text/TextWriter.cpp | 18 +- io/text/TextWriter.hpp | 22 +- kernels/delta/DeltaKernel.cpp | 17 +- kernels/delta/DeltaKernel.hpp | 14 +- kernels/diff/DiffKernel.cpp | 18 +- kernels/diff/DiffKernel.hpp | 14 +- kernels/info/InfoKernel.cpp | 15 + kernels/info/InfoKernel.hpp | 18 +- kernels/pipeline/PipelineKernel.cpp | 17 +- kernels/pipeline/PipelineKernel.hpp | 13 +- kernels/random/RandomKernel.cpp | 15 + kernels/random/RandomKernel.hpp | 11 +- kernels/sort/SortKernel.cpp | 16 +- kernels/sort/SortKernel.hpp | 11 +- kernels/translate/TranslateKernel.cpp | 17 +- kernels/translate/TranslateKernel.hpp | 11 +- pdal_defines.h.in | 2 + plugins/CMakeLists.txt | 7 +- plugins/attribute/filters/AttributeFilter.cpp | 14 +- plugins/attribute/filters/AttributeFilter.hpp | 13 +- plugins/cpd/kernel/Cpd.cpp | 10 +- plugins/cpd/kernel/Cpd.hpp | 8 +- plugins/cpd/test/CpdKernelTest.cpp | 10 +- plugins/greyhound/io/GreyhoundReader.cpp | 13 +- plugins/greyhound/io/GreyhoundReader.hpp | 8 +- plugins/hexbin/filters/HexBin.cpp | 13 +- plugins/hexbin/filters/HexBin.hpp | 8 +- plugins/icebridge/io/IcebridgeReader.cpp | 11 +- plugins/icebridge/io/IcebridgeReader.hpp | 11 +- plugins/mrsid/io/MrsidReader.cpp | 11 +- plugins/mrsid/io/MrsidReader.hpp | 10 +- plugins/nitf/io/NitfReader.cpp | 13 +- plugins/nitf/io/NitfReader.hpp | 8 +- plugins/nitf/io/NitfWriter.cpp | 12 +- plugins/nitf/io/NitfWriter.hpp | 8 +- plugins/nitf/test/NitfReaderTest.cpp | 2 +- plugins/oci/io/OciReader.cpp | 13 +- plugins/oci/io/OciReader.hpp | 10 +- plugins/oci/io/OciWriter.cpp | 13 +- plugins/oci/io/OciWriter.hpp | 10 +- plugins/p2g/io/P2gWriter.cpp | 12 +- plugins/p2g/io/P2gWriter.hpp | 10 +- plugins/pcl/CMakeLists.txt | 1 + plugins/pcl/filters/GroundFilter.cpp | 14 +- plugins/pcl/filters/GroundFilter.hpp | 8 +- plugins/pcl/filters/PCLBlock.cpp | 30 +- plugins/pcl/filters/PCLBlock.hpp | 12 +- plugins/pcl/io/PCLVisualizer.cpp | 26 +- plugins/pcl/io/PCLVisualizer.hpp | 8 +- plugins/pcl/io/PcdReader.cpp | 13 +- plugins/pcl/io/PcdReader.hpp | 8 +- plugins/pcl/io/PcdWriter.cpp | 12 +- plugins/pcl/io/PcdWriter.hpp | 10 +- plugins/pcl/kernel/GroundKernel.cpp | 18 +- plugins/pcl/kernel/GroundKernel.hpp | 12 +- plugins/pcl/kernel/PCLKernel.cpp | 20 +- plugins/pcl/kernel/PCLKernel.hpp | 7 +- plugins/pcl/kernel/SmoothKernel.cpp | 19 +- plugins/pcl/kernel/SmoothKernel.hpp | 11 +- plugins/pcl/kernel/ViewKernel.cpp | 14 +- plugins/pcl/kernel/ViewKernel.hpp | 11 +- plugins/pcl/test/PCLBlockFilterTest.cpp | 16 +- plugins/pgpointcloud/io/PgReader.cpp | 13 +- plugins/pgpointcloud/io/PgReader.hpp | 11 +- plugins/pgpointcloud/io/PgWriter.cpp | 13 +- plugins/pgpointcloud/io/PgWriter.hpp | 11 +- plugins/python/filters/PredicateFilter.cpp | 13 +- plugins/python/filters/PredicateFilter.hpp | 10 +- plugins/python/filters/ProgrammableFilter.cpp | 13 +- plugins/python/filters/ProgrammableFilter.hpp | 10 +- plugins/rxp/io/RxpReader.cpp | 10 +- plugins/rxp/io/RxpReader.hpp | 10 +- plugins/sqlite/io/SQLiteReader.cpp | 12 +- plugins/sqlite/io/SQLiteReader.hpp | 9 +- plugins/sqlite/io/SQLiteWriter.cpp | 12 +- plugins/sqlite/io/SQLiteWriter.hpp | 7 +- src/CMakeLists.txt | 9 +- src/DynamicLibrary.cpp | 83 +++++ src/DynamicLibrary.h | 29 ++ src/Kernel.cpp | 23 +- src/KernelFactory.cpp | 139 +++----- src/KernelInfo.cpp | 80 ----- src/PluginManager.cpp | 243 +++++++++++++ src/StageFactory.cpp | 327 +++++------------- src/StageInfo.cpp | 2 + test/unit/LogTest.cpp | 18 +- test/unit/OptionsTest.cpp | 6 +- test/unit/io/faux/FauxReaderTest.cpp | 2 +- test/unit/io/qfit/QFITReaderTest.cpp | 2 +- test/unit/io/sbet/SbetWriterTest.cpp | 2 +- 150 files changed, 2263 insertions(+), 1318 deletions(-) create mode 100644 filters/merge/MergeFilter.cpp create mode 100644 filters/sort/SortFilter.cpp delete mode 100644 include/pdal/KernelInfo.hpp delete mode 100644 include/pdal/Kernels.hpp create mode 100644 include/pdal/PluginManager.hpp create mode 100644 include/pdal/plugin.h create mode 100755 src/DynamicLibrary.cpp create mode 100755 src/DynamicLibrary.h delete mode 100644 src/KernelInfo.cpp create mode 100644 src/PluginManager.cpp diff --git a/apps/pdal.cpp b/apps/pdal.cpp index 6a8e802231..8d6b169c1f 100644 --- a/apps/pdal.cpp +++ b/apps/pdal.cpp @@ -1,6 +1,6 @@ /****************************************************************************** * Copyright (c) 2013, Howard Butler (hobu.inc@gmail.com) -* Copyright (c) 2014, Bradley J Chambers (brad.chambers@gmail.com) +* Copyright (c) 2014-2015, Bradley J Chambers (brad.chambers@gmail.com) * * All rights reserved. * @@ -33,16 +33,23 @@ * OF SUCH DAMAGE. ****************************************************************************/ -//#include #include +#include #include #include +#include +#include +#include +#include +#include +#include + using namespace pdal; -namespace po = boost::program_options; std::string headline("------------------------------------------------------------------------------------------"); +static std::vector s_loaded_kernels; void outputVersion() { @@ -52,26 +59,32 @@ void outputVersion() std::cout << std::endl; } -void outputHelp(po::options_description const& options) +void outputHelp(bool no_plugins) { - std::cerr << "Usage: pdal [--debug] [--drivers] [--help] [--options[=]] [--version]" << std::endl; - std::cerr << options << std::endl; + std::cerr << "Usage: pdal [--debug] [--drivers] [--help] [--options[=]] [--version]\n"; + std::cerr << " --debug Show debug information\n"; + std::cerr << " --drivers Show drivers\n"; + std::cerr << " -h [ --help ] Print help message\n"; + std::cerr << " --options [=arg(=all)] Show driver options\n"; + std::cerr << " --version Show version info\n"; + std::cerr << "\n"; - std::cerr << "The most commonly used pdal commands are:" << std::endl; + std::cerr << "The most commonly used pdal commands are:\n"; + + KernelFactory f(no_plugins); + std::vector loaded_kernels = f.getKernelNames(); - KernelFactory f; - std::map const& kernels = f.getKernelInfos(); - for (auto i = kernels.begin(); i != kernels.end(); ++i) - std::cout << " - " << i->second.getName() << std::endl; + for (auto name : loaded_kernels) + std::cout << " - " << name << std::endl; std::cout << "See http://pdal.io/apps.html for more detail"; std::cout << std::endl; } -void outputDrivers() +void outputDrivers(bool no_plugins) { - StageFactory f; - std::map const& drivers = f.getStageInfos(); + StageFactory f(no_plugins); + std::map sm = f.getStageMap(); std::ostringstream strm; @@ -88,21 +101,21 @@ void outputDrivers() strm << std::left; - for (auto i = drivers.begin(); i != drivers.end(); ++i) + for (auto s : sm) { std::vector lines; - std::string description(i->second.getDescription()); + std::string description(s.second); description = boost::algorithm::erase_all_copy(description, "\n"); Utils::wordWrap(description, lines, description_column-1); if (lines.size() == 1) { - strm << std::setw(name_column) << i->second.getName() << " " + strm << std::setw(name_column) << s.first << " " << std::setw(description_column) << description << std::endl; } else { - strm << std::setw(name_column) << i->second.getName() << " " + strm << std::setw(name_column) << s.first << " " << lines[0] << std::endl; } @@ -118,108 +131,233 @@ void outputDrivers() std::cout << strm.str() << std::endl; } -void outputOptions(std::string const& opt) +void outputOptions(std::string const& n, bool no_plugins) { - StageFactory f; - std::cout << opt << std::endl; - std::cout << f.toRST(opt) << std::endl; + StageFactory f(no_plugins); + std::unique_ptr s = f.createStage(n); + std::vector