44import json
55from types import SimpleNamespace
66
7+ from cython.operator cimport dereference as deref
78from cpython.ref cimport Py_DECREF
89from libcpp cimport bool
910from libcpp.memory cimport make_shared, shared_ptr
11+ from libcpp.set cimport set as cpp_set
1012from libcpp.string cimport string
1113from libcpp.vector cimport vector
1214
@@ -71,14 +73,28 @@ def infer_writer_driver(driver):
7173 return StageFactory.inferWriterDriver(driver)
7274
7375
74- cdef extern from " PyArray.hpp" namespace " pdal::python" :
75- cdef cppclass Array:
76- Array(np.PyArrayObject* ) except +
76+ cdef extern from " pdal/Mesh.hpp" namespace " pdal" :
77+ cdef cppclass TriangularMesh:
78+ pass
79+
80+
81+ cdef extern from " pdal/PointView.hpp" namespace " pdal" :
82+ cdef cppclass PointView:
83+ TriangularMesh* mesh()
84+
85+ ctypedef shared_ptr[PointView] PointViewPtr
86+ ctypedef cpp_set[PointViewPtr] PointViewSet
87+
88+
89+ cdef extern from " pdal/PipelineManager.hpp" namespace " pdal" :
90+ cdef cppclass PipelineManager:
91+ const PointViewSet& views() const
7792
7893
7994cdef extern from " pdal/PipelineExecutor.hpp" namespace " pdal" :
8095 cdef cppclass PipelineExecutor:
8196 PipelineExecutor(const char * ) except +
97+ const PipelineManager& getManagerConst() except +
8298 bool executed() except +
8399 int execute() except +
84100 bool validate() except +
@@ -90,11 +106,16 @@ cdef extern from "pdal/PipelineExecutor.hpp" namespace "pdal":
90106 void setLogLevel(int )
91107
92108
109+ cdef extern from " PyArray.hpp" namespace " pdal::python" :
110+ cdef cppclass Array:
111+ Array(np.PyArrayObject* ) except +
112+
113+
93114cdef extern from " PyPipeline.hpp" namespace " pdal::python" :
94115 void readPipeline(PipelineExecutor* , string) except +
95116 void addArrayReaders(PipelineExecutor* , vector[shared_ptr[Array]]) except +
96- vector[ np.PyArrayObject* ] getArrays(const PipelineExecutor * ) except +
97- vector[ np.PyArrayObject* ] getMeshes (const PipelineExecutor * ) except +
117+ np.PyArrayObject* viewToNumpyArray(PointViewPtr ) except +
118+ np.PyArrayObject* meshToNumpyArray (const TriangularMesh * ) except +
98119
99120
100121cdef class Pipeline:
@@ -146,15 +167,25 @@ cdef class Pipeline:
146167
147168 @property
148169 def arrays (self ):
149- if not self ._get_executor().executed():
170+ cdef PipelineExecutor* executor = self ._get_executor()
171+ if not executor.executed():
150172 raise RuntimeError (" call execute() before fetching arrays" )
151- return _vector_to_list(getArrays(self ._executor))
173+ output = []
174+ for view in executor.getManagerConst().views():
175+ output.append(< object > viewToNumpyArray(view))
176+ Py_DECREF(output[- 1 ])
177+ return output
152178
153179 @property
154180 def meshes (self ):
155- if not self ._get_executor().executed():
181+ cdef PipelineExecutor* executor = self ._get_executor()
182+ if not executor.executed():
156183 raise RuntimeError (" call execute() before fetching the mesh" )
157- return _vector_to_list(getMeshes(self ._executor))
184+ output = []
185+ for view in executor.getManagerConst().views():
186+ output.append(< object > meshToNumpyArray(deref(view).mesh()))
187+ Py_DECREF(output[- 1 ])
188+ return output
158189
159190 def execute (self ):
160191 return self ._get_executor().execute()
@@ -198,11 +229,3 @@ cdef class Pipeline:
198229 readPipeline(self ._executor, json_bytes)
199230 addArrayReaders(self ._executor, self ._inputs)
200231 return self ._executor
201-
202-
203- cdef _vector_to_list(vector[np.PyArrayObject* ] arrays):
204- output = []
205- for array in arrays:
206- output.append(< object > array)
207- Py_DECREF(output[- 1 ])
208- return output
0 commit comments