forked from PyMesh/PyMesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tet.py
executable file
·70 lines (63 loc) · 2.29 KB
/
tet.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
#!/usr/bin/env python
import argparse
import logging
import numpy as np
import os
import os.path
import pymesh
import sys
def parse_args():
parser = argparse.ArgumentParser(description="Tet mesh generation");
parser.add_argument("--engine", help="tet mesh engine",
choices = (
"cgal",
"cgal_no_features",
"cgal_implicit",
"tetgen",
"geogram",
"quartet",
"delpsc",
"vegafem",
"mmg",
"tetwild"),
default="tetgen");
parser.add_argument("--radius-edge-ratio",
help="Max radius to edge ratio",
type=float, default=2.0);
parser.add_argument("--cell-size", help="Max circumradius of tets",
type=float, default=-1.0);
parser.add_argument("--facet-distance",
help="Max distance between facet's circumcenter to the center of its Delaunay ball",
type=float, default=-1.0);
parser.add_argument("--feature-angle",
help="Angle threshold (in degrees) for feature extraction.",
type=float, default=120);
parser.add_argument("--log", type=str, help="Logging level",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
default="WARNING");
parser.add_argument("in_mesh", help="Input mesh");
parser.add_argument("out_mesh", help="Output mesh");
args = parser.parse_args();
return args;
def main():
args = parse_args();
numeric_level = getattr(logging, args.log, None);
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % loglevel);
logging.basicConfig(level=numeric_level);
logger = logging.getLogger("tet.py");
mesh = pymesh.load_mesh(args.in_mesh);
if mesh.vertex_per_face == 4:
logger.info("Spliting quad mesh into triangle mesh");
mesh = pymesh.quad_to_tri(mesh);
tet_mesh, t = pymesh.tetrahedralize(mesh,
args.cell_size,
args.radius_edge_ratio,
args.facet_distance,
args.feature_angle,
args.engine,
with_timing=True);
pymesh.save_mesh(args.out_mesh, tet_mesh);
logger.info("Running time: {}".format(t));
if __name__ == "__main__":
main();