Commit 34cd93f5f83ca90c743f82d66165f1dcedc69c36
1 parent
9647607e
Exists in
xmartlabs-command-line
and in
1 other branch
Add command to import and export in STL to all available presets
Showing
2 changed files
with
56 additions
and
13 deletions
Show diff stats
Dockerfile
... | ... | @@ -18,10 +18,14 @@ RUN apt-get install -y \ |
18 | 18 | python-wxgtk3.0 \ |
19 | 19 | xvfb # For a virtual X server. |
20 | 20 | |
21 | +RUN apt-get install -y locales | |
22 | +RUN locale-gen en_US.UTF-8 | |
23 | +ENV LANG en_US.UTF-8 | |
24 | +ENV LANGUAGE en_US:en | |
25 | +ENV LC_ALL en_US.UTF-8 | |
26 | + | |
21 | 27 | WORKDIR /usr/local/app |
22 | 28 | |
23 | 29 | COPY . . |
24 | 30 | |
25 | 31 | RUN python setup.py build_ext --inplace |
26 | - | |
27 | -RUN Xvfb :10 -ac -screen 0 1024x768x24 & | ... | ... |
app.py
... | ... | @@ -24,6 +24,7 @@ import optparse as op |
24 | 24 | import os |
25 | 25 | import sys |
26 | 26 | import shutil |
27 | +import traceback | |
27 | 28 | |
28 | 29 | if sys.platform == 'win32': |
29 | 30 | import _winreg |
... | ... | @@ -247,10 +248,11 @@ def parse_comand_line(): |
247 | 248 | dest="dicom_dir") |
248 | 249 | |
249 | 250 | parser.add_option("-s", "--save", |
250 | - action="store", | |
251 | - dest="save", | |
252 | 251 | help="To save the project after an import.") |
253 | 252 | |
253 | + parser.add_option("-a", "--export-to-all", | |
254 | + help="To open a project and export it to STL for all mask presets.") | |
255 | + | |
254 | 256 | options, args = parser.parse_args() |
255 | 257 | |
256 | 258 | # If debug argument... |
... | ... | @@ -265,25 +267,62 @@ def parse_comand_line(): |
265 | 267 | |
266 | 268 | if options.save: |
267 | 269 | Publisher.sendMessage('Save project', os.path.abspath(options.save)) |
268 | - return True | |
270 | + exit(0) | |
271 | + | |
272 | + check_for_exporting(options) | |
269 | 273 | |
270 | 274 | return True |
271 | 275 | |
272 | 276 | # Check if there is a file path somewhere in what the user wrote |
273 | 277 | # In case there is, try opening as it was a inv3 |
274 | 278 | else: |
275 | - i = len(args) | |
276 | - while i: | |
277 | - i -= 1 | |
278 | - file = args[i] | |
279 | - if os.path.isfile(file): | |
280 | - path = os.path.abspath(file) | |
281 | - Publisher.sendMessage('Open project', path) | |
282 | - i = 0 | |
279 | + for arg in reversed(args): | |
280 | + if os.path.isfile(arg): | |
281 | + path_ = os.path.abspath(arg) | |
282 | + Publisher.sendMessage('Open project', path_) | |
283 | + | |
284 | + check_for_exporting(options) | |
285 | + | |
283 | 286 | return True |
284 | 287 | return False |
285 | 288 | |
286 | 289 | |
290 | +def check_for_exporting(options): | |
291 | + if options.export_to_all: | |
292 | + try: | |
293 | + method = { | |
294 | + 'algorithm': 'Default', | |
295 | + 'options': {}, | |
296 | + } | |
297 | + | |
298 | + import invesalius.constants as const | |
299 | + from invesalius.project import Project | |
300 | + | |
301 | + for threshold_name, threshold_range in Project().presets.thresh_ct.iteritems(): | |
302 | + if isinstance(threshold_range[0], int): | |
303 | + Publisher.sendMessage('Set threshold values', threshold_range) | |
304 | + | |
305 | + srf_options = { | |
306 | + 'index': 0, | |
307 | + 'name': '', | |
308 | + 'quality': _('Optimal *'), | |
309 | + 'fill': False, | |
310 | + 'keep_largest': False, | |
311 | + 'overwrite': False, | |
312 | + } | |
313 | + Publisher.sendMessage('Create surface from index', | |
314 | + {'method': method, 'options': srf_options}) | |
315 | + | |
316 | + filename = u'{}-{}.stl'.format(options.export_to_all, threshold_name) | |
317 | + Publisher.sendMessage('Export surface to file', (filename, const.FILETYPE_STL)) | |
318 | + | |
319 | + Publisher.sendMessage('Remove surfaces', [0]) | |
320 | + except: | |
321 | + traceback.print_exc() | |
322 | + finally: | |
323 | + exit(0) | |
324 | + | |
325 | + | |
287 | 326 | def print_events(data): |
288 | 327 | """ |
289 | 328 | Print pubsub messages | ... | ... |