-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
282 lines (232 loc) · 12.5 KB
/
main.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import os
import sys
import shutil
import argparse
from processing import *
def get_parameters(datatype):
""""Parameters specific to each tested data type:
* TAVF: (T)ime-averaged wall shear stress, (A)ge of blood, bipolar (V)oltage, and (F)ibrosis
* scalar: Generic type used for a single scalar field
* contact-catheter force (force)
* late gadolinium enhancement (lge)
* local activation time (lat)
These parameters can be modified to fit new data."""
if datatype == 'tavf':
return dict(restorenans = False,
sourcearrays = ['tawss', 'age', 'bv', 'fibr'],
targetarrays = ['tawss', 'age', 'bv', 'fibr'],
colormaps = ['erdc_rainbow','BuRd', 'hsv', 'fibrosis'],
value_range = [[0.,255.],[0.,255.],[0.,255.],[0.,255.]],
# parameters used if a paired_unfold_disk is provided
paired_arrays = ['','','',''],
paired_colormaps = ['','','',''],
paired_range = [['',''],['',''],['',''],['','']],
pvends = 1, # Enforce the centerline to reach the end boundary of the surface.
# Appends a segment at the end of the centerline to reach the seed point.
# Useful for a blunt vein. Turn on or off (1|0)
skippointsfactor = 0.05, # percentage of points to ignore at beginning of centerline
clspacing = 0.4, # resample the centerline with this spacing
maxslope = 5, # anything above this is ostium
highslope = 1.2, # above this slope we start counting
bumpcriterion = 0.1, #ostium if slope higher than highslope and above bump criterion # Hint: Adjust if only small part of PV is recognised
threshold_value = '', # disables thresholding
quantification_range=[[50,150],[50,150],[50,150],[50,150]])
elif datatype == 'scalar':
return dict(restorenans = False,
sourcearrays = ['Scalar_field'],
targetarrays = ['Scalar_field'],
colormaps = ['erdc_rainbow'],
value_range = [[0,1]], # for colormap
# parameters used if a paired_unfold_disk is provided
paired_arrays = [''],
paired_colormaps = [''],
paired_range = [['','']],
pvends = 1,
skippointsfactor = 0.05, # percentage of points to ignore at beginning of centerline
clspacing = 0.4, # resample the centerline with this spacing
maxslope = 5, # anything above this is ostium
highslope = 1.2, # above this slope we start counting
bumpcriterion = 0.05, # ostium if slope higher than highslope and above bump criterion
threshold_value = '', # threshold value for Scalar_field average
quantification_range=[[0,1]])
elif datatype == 'force':
return dict(restorenans = False,
sourcearrays = ['FTI'],
targetarrays = ['FTI'],
colormaps = ['erdc_rainbow_grey'],
value_range = [[0,800]], # for colormap
# parameters used if a paired_unfold_disk is provided
paired_arrays = [''],
paired_colormaps = [''],
paired_range = [['','']],
pvends = 1,
skippointsfactor = 0.05, # percentage of points to ignore at beginning of centerline
clspacing = 0.4, # resample the centerline with this spacing
maxslope = 5, # anything above this is ostium
highslope = 1.2, # above this slope we start counting
bumpcriterion = 0.05, # ostium if slope higher than highslope and above bump criterion
threshold_value = 100, # threshold value for FTI average
quantification_range=[[0,800]])
elif datatype == 'lge':
return dict(restorenans = False,
sourcearrays = ['scalars'],
targetarrays = ['lge'],
colormaps = ['YlOrRd'],
value_range = [['','']], # with empty values, the min and max will be computed from array
# parameters used if a paired_unfold_disk is provided
paired_arrays = ['FTI'],
paired_colormaps = ['erdc_rainbow_grey'],
paired_range = [[0,800]],
#pvends = 1,
pvends = 1,
skippointsfactor = 0.1, # percentage of points to ignore at beginning of centerline
clspacing = 0.4, # resample the centerline with this spacing
maxslope = 5, # anything above this is ostium
highslope = 1.2, # above this slope we start counting
bumpcriterion = 0.05, # ostium if slope higher than highslope and above bump criterion
threshold_value = 0.5, # threshold value for lge segmentation
quantification_range=[["",""]])
elif datatype == 'lat':
return dict(restorenans = True,
sourcearrays = ['CS_LAT','HRA_LAT'],
targetarrays = ['CS_LAT','HRA_LAT'],
colormaps = ['erdc_rainbow_inv',
'erdc_rainbow_inv'],
value_range = [[0,160],[0,160]],
# parameters used if a paired_unfold_disk is provided
paired_arrays = ['',''],
paired_colormaps = ['',''],
paired_range = [['',''],['','']],
pvends = 0, # Enforce the centerline to reach the end boundary of the surface.
# Appends a segment at the end of the centerline to reach the seed point.
# Useful for a blunt vein. Turn on or off (1|0)
skippointsfactor = 0.1, # percentage of points to ignore at beginning of centerline
clspacing = 0.4, # resample the centerline with this spacing
maxslope = 5, # anything above this is ostium
highslope = 1.2, # above this slope we start counting
bumpcriterion = 0.05, # ostium if slope higher than highslope and above bump criterion
threshold_value = '', # disables thresholding
quantification_range=[[0,160]])
else:
print("Unrecognised data type")
def extend_arguments_dictionary(args_dict):
"""Default variables """
FULL_PATH = os.getcwd()
args_dict['atlaspath']= os.path.join(FULL_PATH,'./atlas')
args_dict['fileroot']= os.path.dirname(args_dict['meshfile'])
args_dict['filenameroot'] = os.path.splitext(os.path.basename(args_dict['meshfile']))[0]
if args_dict['use_laa_seed'] and args_dict['pvcliptype'] == 'long':
print("WARNING: LAA seed only available with short PVs. Switching configuration.")
args_dict['pvcliptype'] = 'short'
if args_dict['pvcliptype'] == 'short':
args_dict['pvdist'] = 2 # length of PVs to keep
elif args_dict['pvcliptype'] == 'long':
args_dict['pvdist'] = 10 # length of PVs to keep
else:
print("Unrecognised pvcliptype")
args_dict.update( get_parameters(args_dict['datatype']) )
return args_dict
def main(args):
# Appends other variables to arguments
args_dict = extend_arguments_dictionary(vars(args))
# Run the pipeline
# Steps can be skipped if input data already exists
if not args_dict['skip_standardization']:
run_standardization(args_dict['meshfile'],
args_dict['atlaspath'],
args_dict['pvdist'],
args_dict['maxslope'],
args_dict['clspacing'],
args_dict['skippointsfactor'],
args_dict['highslope'],
args_dict['bumpcriterion'],
args_dict['pvends'],
args_dict['use_seed_selector'],
args_dict['use_laa_seed'],
args_dict['visualize'])
if not args_dict['skip_currents']:
run_currents(args_dict['meshfile'],
args_dict['atlaspath'],
args_dict['mitral_clip_type'],
args_dict['pvcliptype'],
args_dict['use_similarity'],
args_dict['use_laa_seed'],
args_dict['visualize'])
if not args_dict['skip_sum']:
for arrayind in range(len(args_dict['targetarrays'])):
run_sum(args_dict['meshfile'],
args_dict['atlaspath'],
args_dict['pvcliptype'],
args_dict['use_glyphs'],
args_dict['restorenans'],
args_dict['sourcearrays'][arrayind],
args_dict['targetarrays'][arrayind],
args_dict['colormaps'][arrayind],
args_dict['value_range'][arrayind],
args_dict['visualize'])
if not args_dict['skip_quantification']:
for arrayind in range(len(args_dict['targetarrays'])):
unfoldiskfile = os.path.join(args_dict['fileroot'],
args_dict['filenameroot'] +
'_' +
args_dict['targetarrays'][arrayind] +
'_disk_uniform.vtp')
# quantifies extent
run_quantification(args_dict['atlaspath'],
unfoldiskfile,
args_dict['datatype'],
args_dict['targetarrays'][arrayind],
args_dict['colormaps'][arrayind],
args_dict['threshold_value'],
args_dict['quantification_range'][arrayind],
args_dict['paired_unfold_disk'],
args_dict['paired_arrays'][arrayind],
args_dict['paired_colormaps'][arrayind],
args_dict['paired_range'][arrayind])
#quantifies average values
run_quantification(args_dict['atlaspath'],
unfoldiskfile,
args_dict['datatype'],
args_dict['targetarrays'][arrayind],
args_dict['colormaps'][arrayind],
'', # disables thresholding
args_dict['quantification_range'][arrayind])
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = 'Standardized unfold map')
parser.add_argument("--meshfile", type=str,
help="Full path to mesh file in VTK format", required=True)
parser.add_argument("--datatype", type=str,
help="Data type to process: tavf | scalar | force | lge | lat", required=True)
# optional inputs
parser.add_argument("--pvcliptype", type=str, default='long',
help="How to clip the pulmonary veins: short | long" )
parser.add_argument("--paired_unfold_disk", type=str, default='',
help="Full path to a paired unfold disk. The edges of the current unfold " +
"will be overlaid on the paired unfold disk" )
parser.add_argument("--mitral_clip_type", type=str, default='auto',
help="The algorithm will compute a mitral plane based on the body and PVs centroids. " +
"If the meshfile already contains a mitral plane clip, use the 'manual' option to preserve it" )
parser.add_argument("--use_seed_selector", action='store_true', default=False,
help="Seed selection will always run for a new case. " +
"To select new seeds, activate this flag")
parser.add_argument("--use_laa_seed", action='store_true', default=False,
help="Activate seed for appendage")
parser.add_argument("--use_similarity", action='store_true', default=False,
help="The method uses an affine transform " +
"to initialize mesh registration. " +
"Activate this flag to use a similarity transform")
parser.add_argument("--use_glyphs", action='store_true', default=False,
help="Activate glyph on visualization. " +
"Recommended for spare measurements (e.g. some lat meshes)")
parser.add_argument('--visualize', action='store_true', default=False,
help="Activate visualization")
parser.add_argument('--skip_standardization', action='store_true', default=False,
help="Skip run_standardization step")
parser.add_argument('--skip_currents', action='store_true', default=False,
help="Skip run_currents step")
parser.add_argument('--skip_sum',action='store_true', default=False,
help="Skip run_sum step")
parser.add_argument('--skip_quantification', action='store_true', default=False,
help="Skip run_quantification step")
args = parser.parse_args()
main(args)