Skip to content

Commit 9383e27

Browse files
committed
Move libpdalpython.Pipeline.get_meshio to pure Python Pipeline
1 parent de359ad commit 9383e27

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
- name: Dependencies
4040
shell: bash -l {0}
41-
run: mamba install --yes --quiet -c conda-forge scikit-build numpy python=${{ matrix.python-version }} cython pdal pytest
41+
run: mamba install --yes --quiet -c conda-forge scikit-build numpy python=${{ matrix.python-version }} cython pdal pytest meshio
4242

4343
- name: Install
4444
shell: bash -l {0}
@@ -78,7 +78,7 @@ jobs:
7878
shell: cmd /C CALL "{0}"
7979
run: |
8080
call conda activate test
81-
conda install --yes --quiet -c conda-forge scikit-build numpy python=${{ matrix.python-version }} cython pdal pytest
81+
conda install --yes --quiet -c conda-forge scikit-build numpy python=${{ matrix.python-version }} cython pdal pytest meshio
8282
8383
- name: Install
8484
shell: cmd /C CALL "{0}"
@@ -121,7 +121,7 @@ jobs:
121121

122122
- name: Dependencies
123123
shell: bash -l {0}
124-
run: mamba install --yes --quiet -c conda-forge scikit-build numpy python=${{ matrix.python-version }} cython pdal pytest
124+
run: mamba install --yes --quiet -c conda-forge scikit-build numpy python=${{ matrix.python-version }} cython pdal
125125

126126
- name: sdist
127127
shell: bash -l {0}

pdal/libpdalpython.pyx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ from libcpp.set cimport set as cpp_set
1212
from libcpp.string cimport string
1313
from libcpp.vector cimport vector
1414

15-
import numpy as np
1615
cimport numpy as np
1716
np.import_array()
1817

@@ -192,23 +191,6 @@ cdef class Pipeline:
192191
Py_DECREF(output[-1])
193192
return output
194193

195-
def get_meshio(self, idx):
196-
try:
197-
from meshio import Mesh
198-
except ModuleNotFoundError:
199-
raise RuntimeError(
200-
"The get_meshio function can only be used if you have installed meshio. "
201-
"Try pip install meshio"
202-
)
203-
array = self.arrays[idx]
204-
mesh = self.meshes[idx]
205-
if len(mesh) == 0:
206-
return None
207-
return Mesh(
208-
np.stack((array["X"], array["Y"], array["Z"]), 1),
209-
[("triangle", np.stack((mesh["A"], mesh["B"], mesh["C"]), 1))],
210-
)
211-
212194
#========= validation & execution methods ============================================
213195

214196
def validate(self):

pdal/pipeline.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
from typing import Any, Container, Dict, Iterator, List, Optional, Sequence, Union, cast
77

88
import numpy as np
9+
try:
10+
from meshio import Mesh
11+
except ModuleNotFoundError:
12+
Mesh = None
913

1014
from . import libpdalpython
1115

@@ -75,6 +79,21 @@ def __copy__(self) -> Pipeline:
7579
clone |= self
7680
return clone
7781

82+
def get_meshio(self, idx: int) -> Mesh:
83+
if Mesh is None:
84+
raise RuntimeError(
85+
"The get_meshio function can only be used if you have installed meshio. "
86+
"Try pip install meshio"
87+
)
88+
array = self.arrays[idx]
89+
mesh = self.meshes[idx]
90+
if len(mesh) == 0:
91+
return None
92+
return Mesh(
93+
np.stack((array["X"], array["Y"], array["Z"]), 1),
94+
[("triangle", np.stack((mesh["A"], mesh["B"], mesh["C"]), 1))],
95+
)
96+
7897
@property
7998
def _json(self) -> str:
8099
options_list = []

test/test_pipeline.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,12 @@ def test_mesh(self, filename):
324324
assert str(m.dtype) == "[('A', '<u4'), ('B', '<u4'), ('C', '<u4')]"
325325
assert len(m) == 134
326326
assert m[0][0] == 29
327+
328+
@pytest.mark.parametrize("filename", ["mesh.json", "mesh.py"])
329+
def test_meshio(self, filename):
330+
r = get_pipeline(filename)
331+
r.execute()
332+
mesh = r.get_meshio(0)
333+
triangles = mesh.cells_dict["triangle"]
334+
assert len(triangles) == 134
335+
assert triangles[0][0] == 29

0 commit comments

Comments
 (0)