GDCM 2.2.1

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

TestReader.py

This is a C++ example on how to use gdcm::Reader

1 ############################################################################
2 #
3 # Program: GDCM (Grassroots DICOM). A DICOM library
4 #
5 # Copyright (c) 2006-2011 Mathieu Malaterre
6 # All rights reserved.
7 # See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 #
9 # This software is distributed WITHOUT ANY WARRANTY; without even
10 # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 # PURPOSE. See the above copyright notice for more information.
12 #
13 ############################################################################
14
15 import gdcm
16 import os,sys
17
18 def TestRead(filename, verbose = False):
19 r = gdcm.Reader()
20 r.SetFileName( filename )
21 sucess = r.Read()
22 #if verbose: print r.GetFile()
23 if verbose: print(r.GetFile().GetDataSet())
24 return sucess
25
26 if __name__ == "__main__":
27 sucess = 0
28 try:
29 filename = os.sys.argv[1]
30 sucess += TestRead( filename, True )
31 except:
32 # loop over all files:
33 gdcm.Trace.DebugOff()
34 gdcm.Trace.WarningOff()
35 t = gdcm.Testing()
36 nfiles = t.GetNumberOfFileNames()
37 for i in range(0,nfiles):
38 filename = t.GetFileName(i)
39 sucess += TestRead( filename )
40
41
42 # Test succeed ?
43 sys.exit(sucess == 0)