Salome HOME
Merge branch 'master' into V9_dev
[modules/med.git] / src / MEDCalc / exe / image2med / image2med.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Guillaume Boulant (EDF) 
21
22 from argparse import ArgumentParser
23 parser = ArgumentParser()
24 parser.add_agument("-i", "--imagefile", dest="imagefile",
25                   help="image file to convert", metavar="FILE")
26 parser.add_agument("-m", "--medfile", dest="medfile", default=None,
27                   help="output med file", metavar="FILE")
28 args = parser.parse_args()
29
30 import sys, os
31 if args.imagefile is None:
32     print("The image file must be specified")
33     sys.exit()
34 imagefile = args.imagefile
35 if not os.path.exists(imagefile):
36     print("The image file %s does not exists"%imagefile)
37     sys.exit()
38
39 if args.medfile is None:
40     basename = os.path.basename(imagefile)
41     medfile = basename[0:len(basename)-3] + "med"
42 else:
43     medfile = args.medfile
44
45 print("Convert image file %s to a med field saved in %s"%(imagefile,medfile))
46 from xmedimages import FieldBuilder
47 builder = FieldBuilder()    
48 builder.image2med(imagefile,medfile)