Commit e7bc240bce789f3196fbe0e2b9e75e2fbdaee04c

Authored by Santiago Castro
1 parent e2c39d00
Exists in command-line

Add option --export

Showing 2 changed files with 46 additions and 32 deletions   Show diff stats
@@ -3,6 +3,7 @@ FROM ubuntu:16.04 @@ -3,6 +3,7 @@ FROM ubuntu:16.04
3 RUN apt-get update 3 RUN apt-get update
4 RUN apt-get install -y \ 4 RUN apt-get install -y \
5 cython \ 5 cython \
  6 + locales \
6 python-concurrent.futures \ 7 python-concurrent.futures \
7 python-gdcm \ 8 python-gdcm \
8 python-matplotlib \ 9 python-matplotlib \
@@ -15,10 +16,8 @@ RUN apt-get install -y \ @@ -15,10 +16,8 @@ RUN apt-get install -y \
15 python-skimage \ 16 python-skimage \
16 python-vtk6 \ 17 python-vtk6 \
17 python-vtkgdcm \ 18 python-vtkgdcm \
18 - python-wxgtk3.0 \  
19 - xvfb # For a virtual X server. 19 + python-wxgtk3.0
20 20
21 -RUN apt-get install -y locales  
22 RUN locale-gen en_US.UTF-8 21 RUN locale-gen en_US.UTF-8
23 ENV LANG en_US.UTF-8 22 ENV LANG en_US.UTF-8
24 ENV LANGUAGE en_US:en 23 ENV LANGUAGE en_US:en
@@ -271,10 +271,16 @@ def parse_comand_line(): @@ -271,10 +271,16 @@ def parse_comand_line():
271 dest="dicom_dir") 271 dest="dicom_dir")
272 272
273 parser.add_option("-s", "--save", 273 parser.add_option("-s", "--save",
274 - help="To save the project after an import.") 274 + help="Save the project after an import.")
  275 +
  276 + parser.add_option("-t", "--threshold",
  277 + help="Define the threshold for the export (e.g. 100-780).")
  278 +
  279 + parser.add_option("-e", "--export",
  280 + help="Export to STL.")
275 281
276 parser.add_option("-a", "--export-to-all", 282 parser.add_option("-a", "--export-to-all",
277 - help="To open a project and export it to STL for all mask presets.") 283 + help="Export to STL for all mask presets.")
278 284
279 options, args = parser.parse_args() 285 options, args = parser.parse_args()
280 return options, args 286 return options, args
@@ -295,7 +301,7 @@ def use_cmd_optargs(options, args): @@ -295,7 +301,7 @@ def use_cmd_optargs(options, args):
295 Publisher.sendMessage('Save project', os.path.abspath(options.save)) 301 Publisher.sendMessage('Save project', os.path.abspath(options.save))
296 exit(0) 302 exit(0)
297 303
298 - check_for_exporting(options) 304 + check_for_export(options)
299 305
300 return True 306 return True
301 307
@@ -307,48 +313,57 @@ def use_cmd_optargs(options, args): @@ -307,48 +313,57 @@ def use_cmd_optargs(options, args):
307 path_ = os.path.abspath(arg) 313 path_ = os.path.abspath(arg)
308 Publisher.sendMessage('Open project', path_) 314 Publisher.sendMessage('Open project', path_)
309 315
310 - check_for_exporting(options) 316 + check_for_export(options)
311 317
312 return True 318 return True
313 return False 319 return False
314 320
315 321
316 -def check_for_exporting(options):  
317 - if options.export_to_all: 322 +def check_for_export(options):
  323 + if options.export:
  324 + if not options.threshold:
  325 + print("Need option --threshold when using --export.")
  326 + exit(1)
  327 + threshold_range = tuple([int(n) for n in options.threshold.split('-')])
  328 + export(options.export, threshold_range)
  329 + elif options.export_to_all:
  330 + # noinspection PyBroadException
318 try: 331 try:
319 - method = {  
320 - 'algorithm': 'Default',  
321 - 'options': {},  
322 - }  
323 -  
324 - import invesalius.constants as const  
325 from invesalius.project import Project 332 from invesalius.project import Project
326 333
327 for threshold_name, threshold_range in Project().presets.thresh_ct.iteritems(): 334 for threshold_name, threshold_range in Project().presets.thresh_ct.iteritems():
328 if isinstance(threshold_range[0], int): 335 if isinstance(threshold_range[0], int):
329 - Publisher.sendMessage('Set threshold values', threshold_range)  
330 -  
331 - srf_options = {  
332 - 'index': 0,  
333 - 'name': '',  
334 - 'quality': _('Optimal *'),  
335 - 'fill': False,  
336 - 'keep_largest': False,  
337 - 'overwrite': False,  
338 - }  
339 - Publisher.sendMessage('Create surface from index',  
340 - {'method': method, 'options': srf_options})  
341 -  
342 - filename = u'{}-{}.stl'.format(options.export_to_all, threshold_name)  
343 - Publisher.sendMessage('Export surface to file', (filename, const.FILETYPE_STL))  
344 -  
345 - Publisher.sendMessage('Remove surfaces', [0]) 336 + path_ = u'{}-{}.stl'.format(options.export_to_all, threshold_name)
  337 + export(path_, threshold_range)
346 except: 338 except:
347 traceback.print_exc() 339 traceback.print_exc()
348 finally: 340 finally:
349 exit(0) 341 exit(0)
350 342
351 343
  344 +def export(path_, threshold_range):
  345 + import invesalius.constants as const
  346 +
  347 + Publisher.sendMessage('Set threshold values', threshold_range)
  348 +
  349 + surface_options = {
  350 + 'method': {
  351 + 'algorithm': 'Default',
  352 + 'options': {},
  353 + }, 'options': {
  354 + 'index': 0,
  355 + 'name': '',
  356 + 'quality': _('Optimal *'),
  357 + 'fill': False,
  358 + 'keep_largest': False,
  359 + 'overwrite': False,
  360 + }
  361 + }
  362 + Publisher.sendMessage('Create surface from index', surface_options)
  363 + Publisher.sendMessage('Export surface to file', (path_, const.FILETYPE_STL))
  364 + Publisher.sendMessage('Remove surfaces', [0])
  365 +
  366 +
352 def print_events(data): 367 def print_events(data):
353 """ 368 """
354 Print pubsub messages 369 Print pubsub messages