11#include < pybind11/pybind11.h>
22#include < pybind11/stl.h>
33#include < pybind11/numpy.h>
4+ #include < iostream>
45
56#include < pdal/pdal_config.hpp>
67#include < pdal/StageFactory.hpp>
@@ -27,6 +28,72 @@ namespace pdal {
2728 );
2829 };
2930
31+ std::vector<py::dict> getDrivers () {
32+ py::gil_scoped_acquire acquire;
33+ std::vector<py::dict> drivers;
34+
35+ pdal::StageFactory f (false );
36+ pdal::PluginManager<pdal::Stage>::loadAll ();
37+ pdal::StringList stages = pdal::PluginManager<pdal::Stage>::names ();
38+
39+ pdal::StageExtensions& extensions = pdal::PluginManager<pdal::Stage>::extensions ();
40+ for (auto name : stages)
41+ {
42+ pdal::Stage *s = f.createStage (name);
43+ std::string description = pdal::PluginManager<Stage>::description (name);
44+ std::string link = pdal::PluginManager<Stage>::link (name);
45+ std::vector<std::string> extension_names = extensions.extensions (name);
46+
47+ py::dict d (
48+ " name" _a=name,
49+ " description" _a=description,
50+ " streamable" _a=s->pipelineStreamable (),
51+ " extensions" _a=extension_names
52+ );
53+ f.destroyStage (s);
54+ drivers.push_back (std::move (d));
55+ }
56+ return drivers;
57+
58+ };
59+
60+ std::vector<py::object> getOptions () {
61+ py::gil_scoped_acquire acquire;
62+ py::object json = py::module_::import (" json" );
63+ std::vector<py::object> stageOptions;
64+
65+ pdal::StageFactory f;
66+ pdal::PluginManager<pdal::Stage>::loadAll ();
67+ pdal::StringList stages = pdal::PluginManager<pdal::Stage>::names ();
68+
69+ for (auto name : stages)
70+ {
71+ if ( name == " filters.info" ) continue ;
72+ pdal::Stage *s = f.createStage (name);
73+ pdal::ProgramArgs args;
74+ s->addAllArgs (args);
75+ std::ostringstream ostr;
76+ args.dump3 (ostr);
77+ py::str pystring (ostr.str ());
78+ pystring.attr (" strip" );
79+
80+ py::object j;
81+
82+ try {
83+ j = json.attr (" loads" )(pystring);
84+ } catch (py::error_already_set &e) {
85+ std::cout << " failed:" << name << " '" << ostr.str () << " '" <<std::endl;
86+ continue ; // skip this one because we can't parse it
87+ }
88+
89+ f.destroyStage (s);
90+ py::list l = py::make_tuple ( name, pystring);
91+ stageOptions.push_back (std::move (l));
92+ }
93+ return stageOptions;
94+
95+ };
96+
3097 std::vector<py::dict> getDimensions () {
3198 py::object np = py::module_::import (" numpy" );
3299 py::object dtype = np.attr (" dtype" );
@@ -172,6 +239,8 @@ namespace pdal {
172239 .def (" _get_json" , &Pipeline::getJson)
173240 .def (" _del_executor" , &Pipeline::delExecutor);
174241 m.def (" getInfo" , &getInfo);
242+ m.def (" getDrivers" , &getDrivers);
243+ m.def (" getOptions" , &getOptions);
175244 m.def (" getDimensions" , &getDimensions);
176245 m.def (" infer_reader_driver" , &StageFactory::inferReaderDriver);
177246 m.def (" infer_writer_driver" , &StageFactory::inferWriterDriver);
0 commit comments