From ab011cfdc6531b844dc38e14ed01c250cd11d262 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 | 299 ++++++++++---- cmake/compiler_options.cmake | 6 + doc/tutorial/writing.rst | 14 - examples/writing/tutorial.cpp | 2 +- filters/chipper/ChipperFilter.cpp | 8 + filters/chipper/ChipperFilter.hpp | 19 +- filters/colorization/ColorizationFilter.cpp | 16 +- filters/colorization/ColorizationFilter.hpp | 20 +- filters/crop/CropFilter.cpp | 10 + filters/crop/CropFilter.hpp | 15 +- filters/decimation/DecimationFilter.cpp | 13 +- filters/decimation/DecimationFilter.hpp | 12 +- filters/ferry/FerryFilter.cpp | 15 +- filters/ferry/FerryFilter.hpp | 18 +- filters/merge/CMakeLists.txt | 12 +- filters/merge/MergeFilter.cpp | 50 +++ filters/merge/MergeFilter.hpp | 14 +- filters/mortonorder/MortonOrderFilter.cpp | 12 +- filters/mortonorder/MortonOrderFilter.hpp | 16 +- filters/range/RangeFilter.cpp | 8 + filters/range/RangeFilter.hpp | 12 +- filters/reprojection/ReprojectionFilter.cpp | 15 +- filters/reprojection/ReprojectionFilter.hpp | 11 +- filters/sort/CMakeLists.txt | 12 +- filters/sort/SortFilter.cpp | 50 +++ filters/sort/SortFilter.hpp | 11 +- filters/splitter/SplitterFilter.cpp | 15 +- filters/splitter/SplitterFilter.hpp | 13 +- filters/stats/StatsFilter.cpp | 15 +- filters/stats/StatsFilter.hpp | 13 +- .../transformation/TransformationFilter.cpp | 12 +- .../transformation/TransformationFilter.hpp | 12 +- include/pdal/BufferReader.hpp | 5 +- include/pdal/Drivers.hpp | 54 --- include/pdal/Filter.hpp | 2 - include/pdal/Filters.hpp | 49 --- include/pdal/Kernel.hpp | 49 ++- include/pdal/KernelFactory.hpp | 48 +-- include/pdal/KernelInfo.hpp | 99 ----- include/pdal/KernelSupport.hpp | 3 +- include/pdal/Kernels.hpp | 44 --- include/pdal/PipelineManager.hpp | 10 +- include/pdal/PipelineReader.hpp | 6 +- include/pdal/PluginManager.hpp | 58 +++ include/pdal/Reader.hpp | 2 - include/pdal/Stage.hpp | 24 +- include/pdal/StageFactory.hpp | 70 +--- include/pdal/StageInfo.hpp | 175 --------- include/pdal/Writer.hpp | 14 +- include/pdal/pdal_macros.hpp | 147 +++---- include/pdal/plugin.h | 54 +++ io/bpf/BpfReader.cpp | 16 +- io/bpf/BpfReader.hpp | 18 +- io/bpf/BpfWriter.cpp | 18 +- io/bpf/BpfWriter.hpp | 20 +- io/faux/FauxReader.cpp | 23 +- io/faux/FauxReader.hpp | 13 +- io/las/LasReader.cpp | 19 +- io/las/LasReader.hpp | 19 +- io/las/LasWriter.cpp | 11 + io/las/LasWriter.hpp | 14 +- io/qfit/QfitReader.cpp | 15 +- io/qfit/QfitReader.hpp | 13 +- io/sbet/SbetReader.cpp | 9 + io/sbet/SbetReader.hpp | 13 +- io/sbet/SbetWriter.cpp | 9 + io/sbet/SbetWriter.hpp | 11 +- io/terrasolid/TerrasolidReader.cpp | 9 + io/terrasolid/TerrasolidReader.hpp | 15 +- io/text/TextWriter.cpp | 16 +- io/text/TextWriter.hpp | 22 +- kernels/delta/DeltaKernel.cpp | 9 +- kernels/delta/DeltaKernel.hpp | 14 +- kernels/diff/DiffKernel.cpp | 12 +- kernels/diff/DiffKernel.hpp | 14 +- kernels/info/InfoKernel.cpp | 11 +- kernels/info/InfoKernel.hpp | 20 +- kernels/pipeline/PipelineKernel.cpp | 11 +- kernels/pipeline/PipelineKernel.hpp | 13 +- kernels/random/RandomKernel.cpp | 13 +- kernels/random/RandomKernel.hpp | 11 +- kernels/sort/SortKernel.cpp | 14 +- kernels/sort/SortKernel.hpp | 11 +- kernels/translate/TranslateKernel.cpp | 21 +- kernels/translate/TranslateKernel.hpp | 11 +- pdal_defines.h.in | 2 + plugins/CMakeLists.txt | 7 +- plugins/attribute/filters/AttributeFilter.cpp | 10 +- plugins/attribute/filters/AttributeFilter.hpp | 13 +- plugins/cpd/kernel/Cpd.cpp | 16 +- plugins/cpd/kernel/Cpd.hpp | 8 +- plugins/cpd/test/CpdKernelTest.cpp | 16 +- plugins/greyhound/io/GreyhoundReader.cpp | 11 +- plugins/greyhound/io/GreyhoundReader.hpp | 8 +- plugins/hexbin/filters/HexBin.cpp | 9 +- plugins/hexbin/filters/HexBin.hpp | 8 +- plugins/hexbin/test/HexbinFilterTest.cpp | 4 +- plugins/icebridge/io/IcebridgeReader.cpp | 13 +- plugins/icebridge/io/IcebridgeReader.hpp | 11 +- .../icebridge/test/IcebridgeReaderTest.cpp | 2 +- plugins/mrsid/io/MrsidReader.cpp | 11 +- plugins/mrsid/io/MrsidReader.hpp | 10 +- plugins/nitf/io/NitfReader.cpp | 11 +- plugins/nitf/io/NitfReader.hpp | 8 +- plugins/nitf/io/NitfWriter.cpp | 10 +- plugins/nitf/io/NitfWriter.hpp | 8 +- plugins/nitf/test/NitfReaderTest.cpp | 10 +- plugins/nitf/test/NitfWriterTest.cpp | 4 +- plugins/oci/io/OciReader.cpp | 11 +- plugins/oci/io/OciReader.hpp | 10 +- plugins/oci/io/OciWriter.cpp | 11 +- plugins/oci/io/OciWriter.hpp | 10 +- plugins/oci/test/OCITest.cpp | 8 +- plugins/p2g/io/P2gWriter.cpp | 10 +- plugins/p2g/io/P2gWriter.hpp | 10 +- plugins/pcl/CMakeLists.txt | 1 + plugins/pcl/filters/GroundFilter.cpp | 12 +- plugins/pcl/filters/GroundFilter.hpp | 8 +- plugins/pcl/filters/PCLBlock.cpp | 30 +- plugins/pcl/filters/PCLBlock.hpp | 12 +- plugins/pcl/io/PCLVisualizer.cpp | 22 +- plugins/pcl/io/PCLVisualizer.hpp | 8 +- plugins/pcl/io/PcdReader.cpp | 11 +- plugins/pcl/io/PcdReader.hpp | 8 +- plugins/pcl/io/PcdWriter.cpp | 10 +- plugins/pcl/io/PcdWriter.hpp | 10 +- plugins/pcl/kernel/GroundKernel.cpp | 18 +- plugins/pcl/kernel/GroundKernel.hpp | 12 +- plugins/pcl/kernel/PCLKernel.cpp | 18 +- plugins/pcl/kernel/PCLKernel.hpp | 7 +- plugins/pcl/kernel/SmoothKernel.cpp | 17 +- plugins/pcl/kernel/SmoothKernel.hpp | 11 +- plugins/pcl/kernel/ViewKernel.cpp | 10 +- plugins/pcl/kernel/ViewKernel.hpp | 11 +- plugins/pcl/test/PCLBlockFilterTest.cpp | 18 +- plugins/pgpointcloud/io/PgReader.cpp | 12 +- plugins/pgpointcloud/io/PgReader.hpp | 11 +- plugins/pgpointcloud/io/PgWriter.cpp | 16 +- plugins/pgpointcloud/io/PgWriter.hpp | 11 +- .../test/PgpointcloudWriterTest.cpp | 10 +- plugins/python/filters/PredicateFilter.cpp | 11 +- plugins/python/filters/PredicateFilter.hpp | 10 +- plugins/python/filters/ProgrammableFilter.cpp | 11 +- plugins/python/filters/ProgrammableFilter.hpp | 10 +- plugins/python/test/PredicateFilterTest.cpp | 22 +- .../python/test/ProgrammableFilterTest.cpp | 8 +- plugins/rxp/io/RxpReader.cpp | 12 +- plugins/rxp/io/RxpReader.hpp | 10 +- plugins/sqlite/io/SQLiteReader.cpp | 11 +- plugins/sqlite/io/SQLiteReader.hpp | 9 +- plugins/sqlite/io/SQLiteWriter.cpp | 11 +- plugins/sqlite/io/SQLiteWriter.hpp | 7 +- plugins/sqlite/test/SQLiteTest.cpp | 6 +- src/CMakeLists.txt | 9 +- src/DynamicLibrary.cpp | 83 ++++ src/DynamicLibrary.h | 29 ++ src/Kernel.cpp | 58 ++- src/KernelFactory.cpp | 141 +++---- src/KernelInfo.cpp | 80 ---- src/KernelSupport.cpp | 6 +- src/PipelineManager.cpp | 19 +- src/PipelineReader.cpp | 18 +- src/PluginManager.cpp | 307 +++++++++++++++ src/Stage.cpp | 13 +- src/StageFactory.cpp | 366 ++++++------------ src/StageInfo.cpp | 159 -------- test/unit/LogTest.cpp | 18 +- test/unit/OptionsTest.cpp | 22 +- test/unit/PipelineManagerTest.cpp | 10 +- test/unit/filters/CropFilterTest.cpp | 14 +- test/unit/filters/DecimationFilterTest.cpp | 4 +- test/unit/filters/FerryFilterTest.cpp | 4 +- test/unit/filters/RangeFilterTest.cpp | 32 +- test/unit/filters/SplitterTest.cpp | 4 +- test/unit/filters/StatsFilterTest.cpp | 6 +- .../unit/filters/TransformationFilterTest.cpp | 8 +- test/unit/io/faux/FauxReaderTest.cpp | 2 +- test/unit/io/qfit/QFITReaderTest.cpp | 2 +- test/unit/io/sbet/SbetWriterTest.cpp | 2 +- 179 files changed, 2314 insertions(+), 2005 deletions(-) create mode 100644 filters/merge/MergeFilter.cpp create mode 100644 filters/sort/SortFilter.cpp delete mode 100644 include/pdal/Drivers.hpp delete mode 100644 include/pdal/Filters.hpp delete mode 100644 include/pdal/KernelInfo.hpp delete mode 100644 include/pdal/Kernels.hpp create mode 100644 include/pdal/PluginManager.hpp delete mode 100644 include/pdal/StageInfo.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 delete mode 100644 src/StageInfo.cpp diff --git a/apps/pdal.cpp b/apps/pdal.cpp index 6a8e802231..4ad0c3165b 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,17 +33,32 @@ * 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("------------------------------------------------------------------------------------------"); +std::string splitDriverName(std::string const& name) +{ + std::vector driverVec; + boost::algorithm::split(driverVec, name, + boost::algorithm::is_any_of("."), boost::algorithm::token_compress_on); + + return driverVec[1]; +} + void outputVersion() { std::cout << headline << std::endl; @@ -52,17 +67,23 @@ void outputVersion() std::cout << std::endl; } -void outputHelp(po::options_description const& options) +void outputHelp() { - 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; - std::map const& kernels = f.getKernelInfos(); - for (auto i = kernels.begin(); i != kernels.end(); ++i) - std::cout << " - " << i->second.getName() << std::endl; + KernelFactory f(false); + std::vector loaded_kernels = f.getKernelNames(); + + for (auto name : loaded_kernels) + std::cout << " - " << splitDriverName(name) << std::endl; std::cout << "See http://pdal.io/apps.html for more detail"; std::cout << std::endl; @@ -70,8 +91,8 @@ void outputHelp(po::options_description const& options) void outputDrivers() { - StageFactory f; - std::map const& drivers = f.getStageInfos(); + StageFactory f(false); + std::map sm = f.getStageMap(); std::ostringstream strm; @@ -88,21 +109,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 +139,226 @@ void outputDrivers() std::cout << strm.str() << std::endl; } -void outputOptions(std::string const& opt) +void outputOptions(std::string const& n) +{ + StageFactory f(false); + std::unique_ptr s = f.createStage(n); + + if (!s) + { + std::cerr << "Unable to create stage " << n << "\n"; + return; + } + + std::vector