forked from nschloe/meshio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_cli.py
106 lines (84 loc) · 2.36 KB
/
_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
Convert a mesh file to another.
"""
import sys
import numpy
from .__about__ import __copyright__, __version__
from ._helpers import input_filetypes, output_filetypes, read, write
def _get_version_text():
return "\n".join(
[
"meshio {} [Python {}.{}.{}]".format(
__version__,
sys.version_info.major,
sys.version_info.minor,
sys.version_info.micro,
),
__copyright__,
]
)
def main(argv=None):
# Parse command line arguments.
parser = _get_parser()
args = parser.parse_args(argv)
# read mesh data
mesh = read(args.infile, file_format=args.input_format)
print(mesh)
if args.prune:
mesh.prune()
if (
args.prune_z_0
and mesh.points.shape[1] == 3
and numpy.all(numpy.abs(mesh.points[:, 2]) < 1.0e-13)
):
mesh.points = mesh.points[:, :2]
# Some converters (like VTK) require `points` to be contiguous.
mesh.points = numpy.ascontiguousarray(mesh.points)
# write it out
write(args.outfile, mesh, file_format=args.output_format)
return
def _get_parser():
"""Parse input options."""
import argparse
parser = argparse.ArgumentParser(
description=("Convert between mesh formats."),
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument("infile", type=str, help="mesh file to be read from")
parser.add_argument(
"--input-format",
"-i",
type=str,
choices=input_filetypes,
help="input file format",
default=None,
)
parser.add_argument(
"--output-format",
"-o",
type=str,
choices=output_filetypes,
help="output file format",
default=None,
)
parser.add_argument("outfile", type=str, help="mesh file to be written to")
parser.add_argument(
"--prune",
"-p",
action="store_true",
help="remove lower order cells, remove orphaned nodes",
)
parser.add_argument(
"--prune-z-0",
"-z",
action="store_true",
help="remove third (z) dimension if all points are 0",
)
parser.add_argument(
"--version",
"-v",
action="version",
version=_get_version_text(),
help="display version information",
)
return parser