Skip to content

Commit 9ebc64f

Browse files
committed
Remove getArrays/getMeshes/_vector_to_list in place of executor.getManagerConst().views()
1 parent 0f408b7 commit 9ebc64f

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

pdal/PyPipeline.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ PyArrayObject* viewToNumpyArray(PointViewPtr view)
177177
return array;
178178
}
179179

180-
std::vector<PyArrayObject*> getArrays(const PipelineExecutor* executor)
181-
{
182-
std::vector<PyArrayObject*> output;
183-
for (auto view: executor->getManagerConst().views())
184-
output.push_back(viewToNumpyArray(view));
185-
return output;
186-
}
187-
188180

189181
PyArrayObject* meshToNumpyArray(const TriangularMesh* mesh)
190182
{
@@ -237,14 +229,5 @@ PyArrayObject* meshToNumpyArray(const TriangularMesh* mesh)
237229
return array;
238230
}
239231

240-
241-
std::vector<PyArrayObject*> getMeshes(const PipelineExecutor* executor)
242-
{
243-
std::vector<PyArrayObject*> output;
244-
for (auto view: executor->getManagerConst().views())
245-
output.push_back(meshToNumpyArray(view->mesh()));
246-
return output;
247-
}
248-
249232
} // namespace python
250233
} // namespace pdal

pdal/PyPipeline.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ void readPipeline(PipelineExecutor* executor, std::string json);
4949
void addArrayReaders(PipelineExecutor* executor, std::vector<std::shared_ptr<Array>> arrays);
5050
PyArrayObject* viewToNumpyArray(PointViewPtr view);
5151
PyArrayObject* meshToNumpyArray(const TriangularMesh* mesh);
52-
std::vector<PyArrayObject*> getArrays(const PipelineExecutor* executor);
53-
std::vector<PyArrayObject*> getMeshes(const PipelineExecutor* executor);
5452

5553
} // namespace python
5654
} // namespace pdal

pdal/libpdalpython.pyx

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import json
55
from types import SimpleNamespace
66

7+
from cython.operator cimport dereference as deref
78
from cpython.ref cimport Py_DECREF
89
from libcpp cimport bool
910
from libcpp.memory cimport make_shared, shared_ptr
11+
from libcpp.set cimport set as cpp_set
1012
from libcpp.string cimport string
1113
from 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

7994
cdef 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+
93114
cdef 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

100121
cdef 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

Comments
 (0)