forked from dave3d/dicom2stl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseargs.py
120 lines (89 loc) · 4.9 KB
/
parseargs.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /usr/bin/env python
import argparse
class disableFilter(argparse.Action):
def __call__(self, parser, args, values, option_string=None):
# print("action, baby!", self.dest, values)
# print(args, type(args))
noval = 'no'+values
if isinstance(args.filters, type(None)):
args.filters = [noval]
else:
args.filters.append(noval)
class enableAnisotropic(argparse.Action):
def __init__(self, nargs=0, **kw):
super().__init__(nargs=nargs, **kw)
def __call__(self, parser, args, values, option_string=None):
# x = getattr(args, 'filters')
if isinstance(args.filters, type(None)):
args.filters = ['anisotropic']
# args.filters.append('anisotropic')
class enableLargest(argparse.Action):
def __init__(self, nargs=0, **kw):
super().__init__(nargs=nargs, **kw)
def __call__(self, parser, args, values, option_string=None):
x = getattr(args, 'filters')
x.append('largest')
def parseargs():
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*')
parser.add_argument('--verbose', '-v', action='store_true', default=False,
dest='verbose', help='Enable verbose messages')
parser.add_argument('--debug', '-D', action='store_true', default=False,
dest='debug',
help="""Enable debugging messages
""")
parser.add_argument('--output', '-o', action='store', dest='output',
default='result.stl',
help='Output file name (default=result.stl)')
parser.add_argument('--meta', '-m', action='store', dest='meta',
help='Output metadata file')
parser.add_argument('--ct', action='store_true', default=False,
dest='ctonly', help='Only allow CT Dicom as input')
parser.add_argument('--clean', '-c', action='store_true', default=False,
dest='clean', help='Clean up temp files')
parser.add_argument('--temp', '-T', action='store', dest='temp',
help='Temporary directory')
parser.add_argument('--search', '-s', action='store', dest='search',
help='Dicom series search string')
# Options that apply to the volumetric portion of the pipeline
vol_group = parser.add_argument_group('Volume options')
vol_group.add_argument('--type', '-t', action='store', dest='tissue',
choices=['skin', 'bone', 'soft_tissue', 'fat'],
help='CT tissue type')
vol_group.add_argument('--anisotropic', '-a', action=enableAnisotropic,
help='Apply anisotropic smoothing to the volume')
vol_group.add_argument('--isovalue', '-i', action='store', dest='isovalue',
type=float, default=0.0, help='Iso-surface value')
vol_group.add_argument('--double', '-d', action='store',
dest='double_threshold',
help="""Double threshold with 4 semicolon separated floats
""")
# Options that apply to the mesh processing portion of the pipeline
mesh_group = parser.add_argument_group('Mesh options')
mesh_group.add_argument('--largest', '-l', action=enableLargest,
help='Only keep the largest connected sub-mesh')
mesh_group.add_argument('--rotaxis', action='store', dest='rotaxis',
default='Y', choices=['X', 'Y', 'Z'],
help='Rotation axis (default=Y)')
mesh_group.add_argument('--rotangle', action='store', dest='rotangle',
type=float, default=0.0,
help='Rotation angle in degrees (default=180)')
mesh_group.add_argument('--smooth', action='store', dest='smooth',
type=int, default=25,
help='Mesh smoothing iterations (default=25)')
mesh_group.add_argument('--reduce', action='store', dest='reduce',
type=float, default=.9,
help='Mesh reduction factor (default=.9)')
# Filtering options
filter_group = parser.add_argument_group('Filtering options')
filter_group.add_argument('--enable', action='append', dest='filters',
choices=['anisotropic', 'shrink',
'median', 'largest', 'rotation'],
help='Enable filtering options')
filter_group.add_argument('--disable', action=disableFilter,
dest='filters',
choices=['anisotropic', 'shrink', 'median',
'largest', 'rotation'],
help='Disable filtering options')
args = parser.parse_args()
return args