Skip to content

Commit 09d994c

Browse files
committed
Drop PyPipelineExecutor class, convert its methods to plain functions
1 parent 332186e commit 09d994c

File tree

3 files changed

+46
-48
lines changed

3 files changed

+46
-48
lines changed

pdal/PyPipeline.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* OF SUCH DAMAGE.
3333
****************************************************************************/
3434

35+
#include "PyArray.hpp"
3536
#include "PyPipeline.hpp"
3637

3738
#ifndef _WIN32
@@ -43,25 +44,33 @@
4344
#include <pdal/Stage.hpp>
4445
#include <pdal/pdal_features.hpp>
4546

46-
#include "PyArray.hpp"
47-
4847
namespace pdal
4948
{
5049
namespace python
5150
{
5251

53-
// Create a pipeline for writing data to PDAL
54-
PyPipelineExecutor::PyPipelineExecutor(std::string const& json,
55-
std::vector<Array*> arrays) : PipelineExecutor(json)
52+
53+
void readPipeline(PipelineExecutor* executor, std::string json)
5654
{
55+
std::stringstream strm(json);
56+
executor->getManager().readPipeline(strm);
57+
}
58+
59+
60+
void addArrayReaders(PipelineExecutor* executor, std::vector<Array*> arrays)
61+
{
62+
// Make the symbols in pdal_base global so that they're accessible
63+
// to PDAL plugins. Python dlopen's this extension with RTLD_LOCAL,
64+
// which means that without this, symbols in libpdal_base aren't available
65+
// for resolution of symbols on future runtime linking. This is an issue
66+
// on Alpine and other Linux variants that don't use UNIQUE symbols
67+
// for C++ template statics only. Without this, you end up with multiple
68+
// copies of template statics.
5769
#ifndef _WIN32
58-
// See comment in alternate constructor below.
5970
::dlopen("libpdal_base.so", RTLD_NOLOAD | RTLD_GLOBAL);
6071
#endif
6172

62-
PipelineManager& manager = getManager();
63-
std::stringstream strm(json);
64-
manager.readPipeline(strm);
73+
PipelineManager& manager = executor->getManager();
6574
std::vector<Stage *> roots = manager.roots();
6675
if (roots.size() != 1)
6776
throw pdal_error("Filter pipeline must contain a single root stage.");
@@ -100,20 +109,6 @@ PyPipelineExecutor::PyPipelineExecutor(std::string const& json,
100109
manager.validateStageOptions();
101110
}
102111

103-
// Create a pipeline for reading data from PDAL
104-
PyPipelineExecutor::PyPipelineExecutor(std::string const& json) : PipelineExecutor(json)
105-
{
106-
// Make the symbols in pdal_base global so that they're accessible
107-
// to PDAL plugins. Python dlopen's this extension with RTLD_LOCAL,
108-
// which means that without this, symbols in libpdal_base aren't available
109-
// for resolution of symbols on future runtime linking. This is an issue
110-
// on Alpine and other Linux variants that don't use UNIQUE symbols
111-
// for C++ template statics only. Without this, you end up with multiple
112-
// copies of template statics.
113-
#ifndef _WIN32
114-
::dlopen("libpdal_base.so", RTLD_NOLOAD | RTLD_GLOBAL);
115-
#endif
116-
}
117112

118113
inline PyObject* buildNumpyDescription(PointViewPtr view)
119114
{
@@ -182,10 +177,10 @@ PyArrayObject* viewToNumpyArray(PointViewPtr view)
182177
return array;
183178
}
184179

185-
std::vector<PyArrayObject*> PyPipelineExecutor::getArrays() const
180+
std::vector<PyArrayObject*> getArrays(const PipelineExecutor* executor)
186181
{
187182
std::vector<PyArrayObject*> output;
188-
for (auto view: getManagerConst().views())
183+
for (auto view: executor->getManagerConst().views())
189184
output.push_back(viewToNumpyArray(view));
190185
return output;
191186
}
@@ -243,10 +238,10 @@ PyArrayObject* meshToNumpyArray(const TriangularMesh* mesh)
243238
}
244239

245240

246-
std::vector<PyArrayObject*> PyPipelineExecutor::getMeshes() const
241+
std::vector<PyArrayObject*> getMeshes(const PipelineExecutor* executor)
247242
{
248243
std::vector<PyArrayObject*> output;
249-
for (auto view: getManagerConst().views())
244+
for (auto view: executor->getManagerConst().views())
250245
output.push_back(meshToNumpyArray(view->mesh()));
251246
return output;
252247
}

pdal/PyPipeline.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ namespace python
4545

4646
class Array;
4747

48-
class PyPipelineExecutor : public PipelineExecutor
49-
{
50-
public:
51-
PyPipelineExecutor(std::string const& json);
52-
PyPipelineExecutor(std::string const& json, std::vector<Array*> arrays);
53-
std::vector<PyArrayObject*> getArrays() const;
54-
std::vector<PyArrayObject*> getMeshes() const;
55-
};
48+
void readPipeline(PipelineExecutor* executor, std::string json);
49+
void addArrayReaders(PipelineExecutor* executor, std::vector<Array*> arrays);
50+
PyArrayObject* viewToNumpyArray(PointViewPtr view);
51+
PyArrayObject* meshToNumpyArray(const TriangularMesh* mesh);
52+
std::vector<PyArrayObject*> getArrays(const PipelineExecutor* executor);
53+
std::vector<PyArrayObject*> getMeshes(const PipelineExecutor* executor);
5654

5755
} // namespace python
5856
} // namespace pdal

pdal/libpdalpython.pyx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# cython: c_string_type=unicode, c_string_encoding=utf8
33

44
import json
5+
from types import SimpleNamespace
6+
57
from cpython.ref cimport Py_DECREF
68
from libcpp.vector cimport vector
79
from libcpp.string cimport string
810
from libc.stdint cimport int64_t
911
from libcpp cimport bool
10-
from types import SimpleNamespace
1112

1213
import numpy as np
1314
cimport numpy as np
@@ -60,34 +61,38 @@ cdef extern from "PyArray.hpp" namespace "pdal::python":
6061
Array(np.ndarray) except +
6162

6263

63-
cdef extern from "PyPipeline.hpp" namespace "pdal::python":
64-
cdef cppclass PyPipelineExecutor:
65-
PyPipelineExecutor(const char*) except +
66-
PyPipelineExecutor(const char*, vector[Array*]&) except +
64+
cdef extern from "pdal/PipelineExecutor.hpp" namespace "pdal":
65+
cdef cppclass PipelineExecutor:
66+
PipelineExecutor(const char*) except +
6767
bool executed() except +
6868
int64_t execute() except +
6969
bool validate() except +
7070
string getPipeline() except +
7171
string getMetadata() except +
7272
string getSchema() except +
7373
string getLog() except +
74-
vector[np.PyArrayObject*] getArrays() except +
75-
vector[np.PyArrayObject*] getMeshes() except +
7674
int getLogLevel()
7775
void setLogLevel(int)
7876

7977

78+
cdef extern from "PyPipeline.hpp" namespace "pdal::python":
79+
void readPipeline(PipelineExecutor*, string) except +
80+
void addArrayReaders(PipelineExecutor*, vector[Array *]) except +
81+
vector[np.PyArrayObject*] getArrays(const PipelineExecutor* executor) except +
82+
vector[np.PyArrayObject*] getMeshes(const PipelineExecutor* executor) except +
83+
84+
8085
cdef class Pipeline:
81-
cdef PyPipelineExecutor* _executor
86+
cdef PipelineExecutor* _executor
8287
cdef vector[Array *] _arrays;
8388

8489
def __cinit__(self, unicode json, list arrays=None):
90+
self._executor = new PipelineExecutor(json.encode('UTF-8'))
91+
readPipeline(self._executor, json.encode('UTF-8'))
8592
if arrays is not None:
8693
for array in arrays:
8794
self._arrays.push_back(new Array(array))
88-
self._executor = new PyPipelineExecutor(json.encode('UTF-8'), self._arrays)
89-
else:
90-
self._executor = new PyPipelineExecutor(json.encode('UTF-8'))
95+
addArrayReaders(self._executor, self._arrays)
9196

9297
def __dealloc__(self):
9398
for array in self._arrays:
@@ -120,13 +125,13 @@ cdef class Pipeline:
120125
def __get__(self):
121126
if not self._executor.executed():
122127
raise RuntimeError("call execute() before fetching arrays")
123-
return self._vector_to_list(self._executor.getArrays())
128+
return self._vector_to_list(getArrays(self._executor))
124129

125130
property meshes:
126131
def __get__(self):
127132
if not self._executor.executed():
128133
raise RuntimeError("call execute() before fetching the mesh")
129-
return self._vector_to_list(self._executor.getMeshes())
134+
return self._vector_to_list(getMeshes(self._executor))
130135

131136
def execute(self):
132137
return self._executor.execute()

0 commit comments

Comments
 (0)