Commit e3682cbb2078fb7a4eb33221ab7b3adc60c87664

Authored by Thiago Franco de Moraes
2 parents 9abcd9d1 34cd93f5

Merge branch 'command-line' of git://github.com/xmartlabs/invesalius3 into xmartlabs-command-line

.dockerignore 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +.git*
  2 +.python-version
  3 +Dockerfile
... ...
Dockerfile 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +FROM ubuntu:16.04
  2 +
  3 +RUN apt-get update
  4 +RUN apt-get install -y \
  5 + cython \
  6 + python-concurrent.futures \
  7 + python-gdcm \
  8 + python-matplotlib \
  9 + python-nibabel \
  10 + python-numpy \
  11 + python-pil \
  12 + python-psutil \
  13 + python-scipy \
  14 + python-serial \
  15 + python-skimage \
  16 + python-vtk6 \
  17 + python-vtkgdcm \
  18 + python-wxgtk3.0 \
  19 + xvfb # For a virtual X server.
  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 +
  27 +WORKDIR /usr/local/app
  28 +
  29 +COPY . .
  30 +
  31 +RUN python setup.py build_ext --inplace
... ...
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
... ... @@ -245,6 +246,13 @@ def parse_comand_line():
245 246 parser.add_option("-i", "--import",
246 247 action="store",
247 248 dest="dicom_dir")
  249 +
  250 + parser.add_option("-s", "--save",
  251 + help="To save the project after an import.")
  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 +
248 256 options, args = parser.parse_args()
249 257  
250 258 # If debug argument...
... ... @@ -256,23 +264,65 @@ def parse_comand_line():
256 264 if options.dicom_dir:
257 265 import_dir = options.dicom_dir
258 266 Publisher.sendMessage('Import directory', import_dir)
  267 +
  268 + if options.save:
  269 + Publisher.sendMessage('Save project', os.path.abspath(options.save))
  270 + exit(0)
  271 +
  272 + check_for_exporting(options)
  273 +
259 274 return True
260 275  
261 276 # Check if there is a file path somewhere in what the user wrote
262 277 # In case there is, try opening as it was a inv3
263 278 else:
264   - i = len(args)
265   - while i:
266   - i -= 1
267   - file = args[i]
268   - if os.path.isfile(file):
269   - path = os.path.abspath(file)
270   - Publisher.sendMessage('Open project', path)
271   - 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 +
272 286 return True
273 287 return False
274 288  
275 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 +
276 326 def print_events(data):
277 327 """
278 328 Print pubsub messages
... ...
invesalius/control.py
... ... @@ -98,6 +98,8 @@ class Controller():
98 98  
99 99 Publisher.subscribe(self.SetBitmapSpacing, 'Set bitmap spacing')
100 100  
  101 + Publisher.subscribe(self.OnSaveProject, 'Save project')
  102 +
101 103 def SetBitmapSpacing(self, pubsub_evt):
102 104 proj = prj.Project()
103 105 proj.spacing = pubsub_evt.data
... ... @@ -335,6 +337,10 @@ class Controller():
335 337 session.OpenProject(filepath)
336 338 Publisher.sendMessage("Enable state project", True)
337 339  
  340 + def OnSaveProject(self, pubsub_evt):
  341 + path = pubsub_evt.data
  342 + self.SaveProject(path)
  343 +
338 344 def SaveProject(self, path=None):
339 345 Publisher.sendMessage('Begin busy cursor')
340 346 session = ses.Session()
... ...