Skip to content

Commit

Permalink
Add MeshioFromData
Browse files Browse the repository at this point in the history
  • Loading branch information
luisfpereira committed Mar 4, 2025
1 parent a5cb06c commit cfc8bf0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions polpo/preprocessing/mesh/_meshio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ def apply(self, data):
mesh.write(path, **self.kwargs)

return path


class MeshioFromData(PreprocessingStep):
def __init__(self, cell_type="triangle"):
super().__init__()
self.cell_type = cell_type

def apply(self, mesh):
# TODO: also consider colors
if len(mesh) == 3:
vertices, faces, _ = mesh
else:
vertices, faces = mesh
_ = None
return meshio.Mesh(
points=vertices,
cells=[meshio.CellBlock(cell_type=self.cell_type, data=faces)],
)
5 changes: 5 additions & 0 deletions polpo/preprocessing/mesh/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
except ImportError:
pass

try:
from ._meshio import MeshioFromData # noqa:F401
except ImportError:
pass

from polpo.macro import create_to_classes_from_from
from polpo.preprocessing.base import PreprocessingStep

Expand Down

0 comments on commit cfc8bf0

Please sign in to comment.