GDCM: ScanDirectory.py

GDCM 3.2.5

ScanDirectory.py
1
14
15import gdcm
16import sys,os
17
18class ProgressWatcher(gdcm.SimpleSubjectWatcher):
19 def ShowProgress(self, sender, event):
20 pe = gdcm.ProgressEvent.Cast(event)
21 print pe.GetProgress()
22 def EndFilter(self):
23 print "Yay ! I am done"
24
25if __name__ == "__main__":
26 directory = sys.argv[1]
27
28 # Define the set of tags we are interested in
29 t1 = gdcm.Tag(0x8,0x8);
30 t2 = gdcm.Tag(0x10,0x10);
31
32 # Iterate over directory
33 d = gdcm.Directory();
34 nfiles = d.Load( directory );
35 if(nfiles == 0): sys.exit(1);
36 # System.Console.WriteLine( "Files:\n" + d.toString() );
37
38 filenames = d.GetFilenames()
39
40 # Get rid of any Warning while parsing the DICOM files
41 gdcm.Trace.WarningOff()
42
43 # instantiate Scanner:
44 sp = gdcm.Scanner.New();
45 s = sp.__ref__()
46 w = ProgressWatcher(s, 'Watcher')
47
48 s.AddTag( t1 );
49 s.AddTag( t2 );
50 b = s.Scan( filenames );
51 if(not b): sys.exit(1);
52
53 print "success" ;
54 #print s
55
56 pttv = gdcm.PythonTagToValue( s.GetMapping( filenames[1] ) )
57 pttv.Start()
58 # iterate until the end:
59 while( not pttv.IsAtEnd() ):
60 # get current value for tag and associated value:
61 # if tag was not found, then it was simply not added to the internal std::map
62 # Warning value can be None
63 tag = pttv.GetCurrentTag()
64 value = pttv.GetCurrentValue()
65 print tag,"->",value
66 # increment iterator
67 pttv.Next()
68
69 sys.exit(0)
gdcm::Directory
Class for manipulation directories.
Definition gdcmDirectory.h:43
gdcm::Scanner::New
static SmartPointer< Scanner > New()
for wrapped language: instantiate a reference counted object
Definition gdcmScanner.h:157
gdcm::SimpleSubjectWatcher
SimpleSubjectWatcher.
Definition gdcmSimpleSubjectWatcher.h:32
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::Trace::WarningOff
static void WarningOff()