Commit ceea67fa2b82620ef0b4b1e27573d02c6bb2e8bc

Authored by Paulo Henrique Junqueira Amorim
1 parent 2ce60186

ENH: Optimize importation of DICOM files

invesalius/control.py
@@ -328,7 +328,6 @@ class Controller(): @@ -328,7 +328,6 @@ class Controller():
328 def ImportMedicalImages(self, directory): 328 def ImportMedicalImages(self, directory):
329 # OPTION 1: DICOM? 329 # OPTION 1: DICOM?
330 patients_groups = dcm.GetDicomGroups(directory) 330 patients_groups = dcm.GetDicomGroups(directory)
331 -  
332 if len(patients_groups): 331 if len(patients_groups):
333 group = dcm.SelectLargerDicomGroup(patients_groups) 332 group = dcm.SelectLargerDicomGroup(patients_groups)
334 imagedata, dicom = self.OpenDicomGroup(group, 0, gui=True) 333 imagedata, dicom = self.OpenDicomGroup(group, 0, gui=True)
@@ -486,7 +485,6 @@ class Controller(): @@ -486,7 +485,6 @@ class Controller():
486 485
487 wl = float(dicom.image.level) 486 wl = float(dicom.image.level)
488 ww = float(dicom.image.window) 487 ww = float(dicom.image.window)
489 -  
490 self.matrix, self.filename = utils.dcm2memmap(filelist, size, 488 self.matrix, self.filename = utils.dcm2memmap(filelist, size,
491 orientation) 489 orientation)
492 self.Slice = sl.Slice() 490 self.Slice = sl.Slice()
invesalius/data/imagedata_utils.py
@@ -469,7 +469,7 @@ def dcm2memmap(files, slice_size, orientation): @@ -469,7 +469,7 @@ def dcm2memmap(files, slice_size, orientation):
469 shape = slice_size[1], len(files), slice_size[0] 469 shape = slice_size[1], len(files), slice_size[0]
470 else: 470 else:
471 shape = len(files), slice_size[1], slice_size[0] 471 shape = len(files), slice_size[1], slice_size[0]
472 - 472 + print shape
473 matrix = numpy.memmap(temp_file, mode='w+', dtype='int16', shape=shape) 473 matrix = numpy.memmap(temp_file, mode='w+', dtype='int16', shape=shape)
474 dcm_reader = vtkgdcm.vtkGDCMImageReader() 474 dcm_reader = vtkgdcm.vtkGDCMImageReader()
475 for n, f in enumerate(files): 475 for n, f in enumerate(files):
invesalius/invesalius.py
@@ -31,7 +31,7 @@ if sys.platform == 'win32': @@ -31,7 +31,7 @@ if sys.platform == 'win32':
31 import _winreg 31 import _winreg
32 else: 32 else:
33 import wxversion 33 import wxversion
34 - wxversion.ensureMinimal('2.8-unicode', optionsRequired=True) 34 + wxversion.ensureMinimal('2.8-unicode', optionsRequired=True)
35 wxversion.select('2.8-unicode', optionsRequired=True) 35 wxversion.select('2.8-unicode', optionsRequired=True)
36 36
37 import wx 37 import wx
invesalius/reader/dicom.py
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 # detalhes. 18 # detalhes.
19 #--------------------------------------------------------------------- 19 #---------------------------------------------------------------------
20 import time 20 import time
21 -import gdcm 21 +#import gdcm
22 #import vtkgdcm 22 #import vtkgdcm
23 import sys 23 import sys
24 24
@@ -91,15 +91,14 @@ class Parser(): @@ -91,15 +91,14 @@ class Parser():
91 def __init__(self): 91 def __init__(self):
92 self.filename = "" 92 self.filename = ""
93 self.encoding = "" 93 self.encoding = ""
94 - #self.vtkgdcm_reader = vtkgdcm.vtkGDCMImageReader()  
95 94
96 - def SetFileName(self, filename): 95 + #def SetFileName(self, filename):
97 """ 96 """
98 Set file name to be parsed given its filename (this should 97 Set file name to be parsed given its filename (this should
99 include the full path of the file of interest). 98 include the full path of the file of interest).
100 99
101 Return True/False if file could be read. 100 Return True/False if file could be read.
102 - """ 101 +
103 import os.path as path 102 import os.path as path
104 103
105 104
@@ -133,10 +132,15 @@ class Parser(): @@ -133,10 +132,15 @@ class Parser():
133 #self.vtkgdcm_reader = vtkgdcm_reader 132 #self.vtkgdcm_reader = vtkgdcm_reader
134 return True 133 return True
135 134
136 - return False 135 + return False"""
  136 +
  137 + #def GetImageData(self):
  138 + # return None#self.vtkgdcm_reader.GetOutput()
  139 +
137 140
138 - def GetImageData(self):  
139 - return None#self.vtkgdcm_reader.GetOutput() 141 + def SetDataImage(self, data_image, filename):
  142 + self.data_image = data_image
  143 + self.filename = filename
140 144
141 def __format_time(self,value): 145 def __format_time(self,value):
142 sp1 = value.split(".") 146 sp1 = value.split(".")
@@ -181,14 +185,7 @@ class Parser(): @@ -181,14 +185,7 @@ class Parser():
181 an image. (AXIAL, SAGITTAL, CORONAL, 185 an image. (AXIAL, SAGITTAL, CORONAL,
182 OBLIQUE or UNKNOWN) 186 OBLIQUE or UNKNOWN)
183 """ 187 """
184 - img = self.gdcm_reader.GetImage()  
185 - direc_cosines = img.GetDirectionCosines()  
186 - orientation = gdcm.Orientation()  
187 - try:  
188 - type = orientation.GetType(tuple(direc_cosines))  
189 - except TypeError:  
190 - type = orientation.GetType(direc_cosines)  
191 - label = orientation.GetLabel(type) 188 + label = self.data_image['invesalius']['orientation_label']
192 189
193 if (label): 190 if (label):
194 return label 191 return label
@@ -201,12 +198,7 @@ class Parser(): @@ -201,12 +198,7 @@ class Parser():
201 to the number of columns on the image. 198 to the number of columns on the image.
202 Return "" if not defined. 199 Return "" if not defined.
203 """ 200 """
204 - tag = gdcm.Tag(0x0028, 0x0011)  
205 - ds = self.gdcm_reader.GetFile().GetDataSet()  
206 - sf = gdcm.StringFilter()  
207 - sf.SetFile(self.gdcm_reader.GetFile())  
208 - data = sf.ToStringPair(tag)[1]  
209 - 201 + data = self.data_image['0028']['0011']
210 if (data): 202 if (data):
211 return int(str(data)) 203 return int(str(data))
212 return "" 204 return ""
@@ -218,12 +210,7 @@ class Parser(): @@ -218,12 +210,7 @@ class Parser():
218 to the number of rows on the image. 210 to the number of rows on the image.
219 Return "" if not defined. 211 Return "" if not defined.
220 """ 212 """
221 - tag = gdcm.Tag(0x0028, 0x0010)  
222 - ds = self.gdcm_reader.GetFile().GetDataSet()  
223 - sf = gdcm.StringFilter()  
224 - sf.SetFile(self.gdcm_reader.GetFile())  
225 - data = sf.ToStringPair(tag)[1]  
226 - 213 + data = self.data_image['0028']['0010']
227 if (data): 214 if (data):
228 return int(str(data)) 215 return int(str(data))
229 return "" 216 return ""
@@ -309,12 +296,9 @@ class Parser(): @@ -309,12 +296,9 @@ class Parser():
309 DICOM standard tag (0x0008,0x0022) was used. 296 DICOM standard tag (0x0008,0x0022) was used.
310 """ 297 """
311 # TODO: internationalize data 298 # TODO: internationalize data
312 - tag = gdcm.Tag(0x0008, 0x0022)  
313 - ds = self.gdcm_reader.GetFile().GetDataSet()  
314 - if ds.FindDataElement(tag):  
315 - date = ds.GetDataElement(tag).GetValue()  
316 - if (date) and (date != ''):  
317 - return self.__format_date(str(date)) 299 + date = self.data_image['0008']['0022']
  300 + if (date) and (date != ''):
  301 + return self.__format_date(str(date))
318 return "" 302 return ""
319 303
320 def GetAcquisitionNumber(self): 304 def GetAcquisitionNumber(self):
@@ -324,12 +308,9 @@ class Parser(): @@ -324,12 +308,9 @@ class Parser():
324 308
325 DICOM standard tag (0x0020, 0x0012) was used. 309 DICOM standard tag (0x0020, 0x0012) was used.
326 """ 310 """
327 - tag = gdcm.Tag(0x0020, 0x0012)  
328 - ds = self.gdcm_reader.GetFile().GetDataSet()  
329 - if ds.FindDataElement(tag):  
330 - data = ds.GetDataElement(tag).GetValue()  
331 - if (data):  
332 - return int(str(data)) 311 + data = self.data_image['0020']['0012']
  312 + if (data):
  313 + return int(str(data))
333 return "" 314 return ""
334 315
335 def GetAccessionNumber(self): 316 def GetAccessionNumber(self):
@@ -338,16 +319,13 @@ class Parser(): @@ -338,16 +319,13 @@ class Parser():
338 319
339 DICOM standard tag (0x0008, 0x0050) was used. 320 DICOM standard tag (0x0008, 0x0050) was used.
340 """ 321 """
341 - tag = gdcm.Tag(0x0008, 0x0050)  
342 - ds = self.gdcm_reader.GetFile().GetDataSet()  
343 - if ds.FindDataElement(tag):  
344 - data = ds.GetDataElement(tag).GetValue()  
345 - if (data):  
346 - try:  
347 - value = int(str(data))  
348 - except(ValueError): #Problem in the other\iCatDanielaProjeto  
349 - value = 0  
350 - return value 322 + data = self.data_image['0008']['0050']
  323 + if (data):
  324 + try:
  325 + value = int(str(data))
  326 + except(ValueError): #Problem in the other\iCatDanielaProjeto
  327 + value = 0
  328 + return value
351 return "" 329 return ""
352 330
353 def GetAcquisitionTime(self): 331 def GetAcquisitionTime(self):
@@ -358,12 +336,9 @@ class Parser(): @@ -358,12 +336,9 @@ class Parser():
358 336
359 DICOM standard tag (0x0008,0x0032) was used. 337 DICOM standard tag (0x0008,0x0032) was used.
360 """ 338 """
361 - tag = gdcm.Tag(0x0008, 0x0032)  
362 - ds = self.gdcm_reader.GetFile().GetDataSet()  
363 - if ds.FindDataElement(tag):  
364 - data = ds.GetDataElement(tag).GetValue()  
365 - if (data) and (data != ''):  
366 - return self.__format_time(str(data)) 339 + data = self.data_image['0008']['0032']
  340 + if (data) and (data != ''):
  341 + return self.__format_time(str(data))
367 return "" 342 return ""
368 343
369 def GetPatientAdmittingDiagnosis(self): 344 def GetPatientAdmittingDiagnosis(self):
@@ -388,33 +363,28 @@ class Parser(): @@ -388,33 +363,28 @@ class Parser():
388 Return image window center / level (related to brightness). 363 Return image window center / level (related to brightness).
389 This is an integer or a floating point. If the value can't 364 This is an integer or a floating point. If the value can't
390 be read, return "". 365 be read, return "".
391 -  
392 By default, only one level value is returned, according to 366 By default, only one level value is returned, according to
393 "preset" parameter. If no value is passed, WL_PRESET constant 367 "preset" parameter. If no value is passed, WL_PRESET constant
394 is used. In case one wishes to acquire a list with all 368 is used. In case one wishes to acquire a list with all
395 level values, one should set "multiple" parameter to True. 369 level values, one should set "multiple" parameter to True.
396 -  
397 Return "" if field is not defined. 370 Return "" if field is not defined.
398 -  
399 DICOM standard tag (0x0028,0x1050) was used. 371 DICOM standard tag (0x0028,0x1050) was used.
400 """ 372 """
401 -  
402 - tag = gdcm.Tag(0x0028, 0x1050)  
403 - ds = self.gdcm_reader.GetFile().GetDataSet()  
404 -  
405 - if ds.FindDataElement(tag):  
406 - data = str(ds.GetDataElement(tag).GetValue())  
407 - if (data):  
408 - # Usually 'data' is a number. However, in some DICOM  
409 - # files, there are several values separated by '\'.  
410 - # If multiple values are present for the "Window Center"  
411 - # we choose only one. As this should be paired to "Window  
412 - # Width", it is set based on WL_PRESET  
413 - value_list = [float(value) for value in data.split('\\')]  
414 - if multiple:  
415 - return value_list  
416 - else:  
417 - return value_list[preset] 373 + try:
  374 + data = self.data_image['0028']['1050']
  375 + except(KeyError):
  376 + return "300"
  377 + if (data):
  378 + # Usually 'data' is a number. However, in some DICOM
  379 + # files, there are several values separated by '\'.
  380 + # If multiple values are present for the "Window Center"
  381 + # we choose only one. As this should be paired to "Window
  382 + # Width", it is set based on WL_PRESET
  383 + value_list = [float(value) for value in data.split('\\')]
  384 + if multiple:
  385 + return value_list
  386 + else:
  387 + return value_list[preset]
418 return "300" 388 return "300"
419 389
420 def GetImageWindowWidth(self, preset=WL_PRESET, multiple=WL_MULT): 390 def GetImageWindowWidth(self, preset=WL_PRESET, multiple=WL_MULT):
@@ -432,24 +402,23 @@ class Parser(): @@ -432,24 +402,23 @@ class Parser():
432 402
433 DICOM standard tag (0x0028,0x1051) was used. 403 DICOM standard tag (0x0028,0x1051) was used.
434 """ 404 """
  405 + try:
  406 + data = self.data_image['0028']['1051']
  407 + except(KeyError):
  408 + return "2000"
435 409
436 - tag = gdcm.Tag(0x0028,0x1051)  
437 - ds = self.gdcm_reader.GetFile().GetDataSet()  
438 -  
439 - if ds.FindDataElement(tag):  
440 - data = str(ds.GetDataElement(tag).GetValue())  
441 - if (data):  
442 - # Usually 'data' is a number. However, in some DICOM  
443 - # files, there are several values separated by '\'.  
444 - # If multiple values are present for the "Window Center"  
445 - # we choose only one. As this should be paired to "Window  
446 - # Width", it is set based on WL_PRESET  
447 - value_list = [float(value) for value in data.split('\\')]  
448 -  
449 - if multiple:  
450 - return str(value_list)  
451 - else:  
452 - return str(value_list[preset]) 410 + if (data):
  411 + # Usually 'data' is a number. However, in some DICOM
  412 + # files, there are several values separated by '\'.
  413 + # If multiple values are present for the "Window Center"
  414 + # we choose only one. As this should be paired to "Window
  415 + # Width", it is set based on WL_PRESET
  416 + value_list = [float(value) for value in data.split('\\')]
  417 +
  418 + if multiple:
  419 + return str(value_list)
  420 + else:
  421 + return str(value_list[preset])
453 return "2000" 422 return "2000"
454 423
455 def GetImagePosition(self): 424 def GetImagePosition(self):
@@ -462,12 +431,12 @@ class Parser(): @@ -462,12 +431,12 @@ class Parser():
462 431
463 DICOM standard tag (0x0020, 0x0032) was used. 432 DICOM standard tag (0x0020, 0x0032) was used.
464 """ 433 """
465 - tag = gdcm.Tag(0x0020, 0x0032)  
466 - ds = self.gdcm_reader.GetFile().GetDataSet()  
467 - if ds.FindDataElement(tag):  
468 - data = str(ds.GetDataElement(tag).GetValue())  
469 - if (data):  
470 - return [eval(value) for value in data.split('\\')] 434 + try:
  435 + data = self.data_image['0020']['0032']
  436 + except(KeyError):
  437 + return ""
  438 + if (data):
  439 + return [eval(value) for value in data.split('\\')]
471 return "" 440 return ""
472 441
473 def GetImageLocation(self): 442 def GetImageLocation(self):
@@ -478,12 +447,9 @@ class Parser(): @@ -478,12 +447,9 @@ class Parser():
478 447
479 DICOM standard tag (0x0020, 0x0032) was used. 448 DICOM standard tag (0x0020, 0x0032) was used.
480 """ 449 """
481 - tag = gdcm.Tag(0x0020, 0x1041)  
482 - ds = self.gdcm_reader.GetFile().GetDataSet()  
483 - if ds.FindDataElement(tag):  
484 - data = str(ds.GetDataElement(tag).GetValue())  
485 - if (data):  
486 - return eval(data) 450 + data = self.data_image['0020']['1041']
  451 + if (data):
  452 + return eval(data)
487 return "" 453 return ""
488 454
489 def GetImageOffset(self): 455 def GetImageOffset(self):
@@ -493,12 +459,9 @@ class Parser(): @@ -493,12 +459,9 @@ class Parser():
493 459
494 DICOM standard tag (0x7fe0, 0x0010) was used. 460 DICOM standard tag (0x7fe0, 0x0010) was used.
495 """ 461 """
496 - tag = gdcm.Tag(0x7fe0, 0x0010)  
497 - ds = self.gdcm_reader.GetFile().GetDataSet()  
498 - if ds.FindDataElement(tag):  
499 - data = str(ds.GetDataElement(tag).GetValue())  
500 - if (data):  
501 - return int(data.split(':')[1]) 462 + data = self.data_image['7fe0']['0010']
  463 + if (data):
  464 + return int(data.split(':')[1])
502 return "" 465 return ""
503 466
504 467
@@ -510,12 +473,9 @@ class Parser(): @@ -510,12 +473,9 @@ class Parser():
510 473
511 DICOM standard tag (0x0020, 0x0011) was used. 474 DICOM standard tag (0x0020, 0x0011) was used.
512 """ 475 """
513 - tag = gdcm.Tag(0x0020, 0x0011)  
514 - ds = self.gdcm_reader.GetFile().GetDataSet()  
515 - if ds.FindDataElement(tag):  
516 - data = str(ds.GetDataElement(tag).GetValue())  
517 - if (data) and (data != '""') and (data != "None"):  
518 - return int(data) 476 + data = self.data_image['0020']['0011']
  477 + if (data) and (data != '""') and (data != "None"):
  478 + return int(data)
519 return "" 479 return ""
520 480
521 481
@@ -529,12 +489,9 @@ class Parser(): @@ -529,12 +489,9 @@ class Parser():
529 489
530 DICOM standard tag (0x0028, 0x0030) was used. 490 DICOM standard tag (0x0028, 0x0030) was used.
531 """ 491 """
532 - tag = gdcm.Tag(0x0028, 0x0030)  
533 - ds = self.gdcm_reader.GetFile().GetDataSet()  
534 - if ds.FindDataElement(tag):  
535 - data = str(ds.GetDataElement(tag).GetValue())  
536 - if (data):  
537 - return [eval(value) for value in data.split('\\')] 492 + data = self.data_image['0028']['0030']
  493 + if (data):
  494 + return [eval(value) for value in data.split('\\')]
538 return "" 495 return ""
539 496
540 def GetPatientWeight(self): 497 def GetPatientWeight(self):
@@ -544,12 +501,9 @@ class Parser(): @@ -544,12 +501,9 @@ class Parser():
544 501
545 DICOM standard tag (0x0010, 0x1030) was used. 502 DICOM standard tag (0x0010, 0x1030) was used.
546 """ 503 """
547 - tag = gdcm.Tag(0x0010, 0x1030)  
548 - ds = self.gdcm_reader.GetFile().GetDataSet()  
549 - if ds.FindDataElement(tag):  
550 - data = str(ds.GetDataElement(tag).GetValue())  
551 - if (data):  
552 - return float(data) 504 + data = self.data_image['0010']['1030']
  505 + if (data):
  506 + return float(data)
553 return "" 507 return ""
554 508
555 def GetPatientHeight(self): 509 def GetPatientHeight(self):
@@ -559,12 +513,9 @@ class Parser(): @@ -559,12 +513,9 @@ class Parser():
559 513
560 DICOM standard tag (0x0010, 0x1030) was used. 514 DICOM standard tag (0x0010, 0x1030) was used.
561 """ 515 """
562 - tag = gdcm.Tag(0x0010, 0x1020)  
563 - ds = self.gdcm_reader.GetFile().GetDataSet()  
564 - if ds.FindDataElement(tag):  
565 - data = str(ds.GetDataElement(tag).GetValue())  
566 - if (data):  
567 - return float(data) 516 + data = self.data_image['0010']['1020']
  517 + if (data):
  518 + return float(data)
568 return "" 519 return ""
569 520
570 def GetPatientAddress(self): 521 def GetPatientAddress(self):
@@ -573,12 +524,9 @@ class Parser(): @@ -573,12 +524,9 @@ class Parser():
573 524
574 DICOM standard tag (0x0010, 0x1040) was used. 525 DICOM standard tag (0x0010, 0x1040) was used.
575 """ 526 """
576 - tag = gdcm.Tag(0x0010, 0x1040)  
577 - ds = self.gdcm_reader.GetFile().GetDataSet()  
578 - if ds.FindDataElement(tag):  
579 - data = str(ds.GetDataElement(tag).GetValue())  
580 - if (data):  
581 - return data 527 + data = self.data_image['0010']['1040']
  528 + if (data):
  529 + return data
582 return "" 530 return ""
583 531
584 def GetPatientMilitarRank(self): 532 def GetPatientMilitarRank(self):
@@ -588,12 +536,9 @@ class Parser(): @@ -588,12 +536,9 @@ class Parser():
588 536
589 DICOM standard tag (0x0010, 0x1080) was used. 537 DICOM standard tag (0x0010, 0x1080) was used.
590 """ 538 """
591 - tag = gdcm.Tag(0x0010,0x1080)  
592 - ds = self.gdcm_reader.GetFile().GetDataSet()  
593 - if ds.FindDataElement(tag):  
594 - data = str(ds.GetDataElement(tag).GetValue())  
595 - if (data):  
596 - return data 539 + data = self.data_image['0010']['1080']
  540 + if (data):
  541 + return data
597 return "" 542 return ""
598 543
599 def GetPatientMilitarBranch(self): 544 def GetPatientMilitarBranch(self):
@@ -605,12 +550,9 @@ class Parser(): @@ -605,12 +550,9 @@ class Parser():
605 550
606 DICOM standard tag (0x0010, 0x1081) was used. 551 DICOM standard tag (0x0010, 0x1081) was used.
607 """ 552 """
608 - tag = gdcm.Tag(0x0010,0x1081)  
609 - ds = self.gdcm_reader.GetFile().GetDataSet()  
610 - if ds.FindDataElement(tag):  
611 - data = str(ds.GetDataElement(tag).GetValue())  
612 - if (data):  
613 - return data 553 + data = self.data_image['0010']['1081']
  554 + if (data):
  555 + return data
614 return "" 556 return ""
615 557
616 def GetPatientCountry(self): 558 def GetPatientCountry(self):
@@ -621,12 +563,9 @@ class Parser(): @@ -621,12 +563,9 @@ class Parser():
621 563
622 DICOM standard tag (0x0010, 0x2150) was used. 564 DICOM standard tag (0x0010, 0x2150) was used.
623 """ 565 """
624 - tag = gdcm.Tag(0x0010,0x2150)  
625 - ds = self.gdcm_reader.GetFile().GetDataSet()  
626 - if ds.FindDataElement(tag):  
627 - data = str(ds.GetDataElement(tag).GetValue())  
628 - if (data):  
629 - return data 566 + data = self.data_image['0010']['2150']
  567 + if (data):
  568 + return data
630 return "" 569 return ""
631 570
632 def GetPatientRegion(self): 571 def GetPatientRegion(self):
@@ -637,12 +576,9 @@ class Parser(): @@ -637,12 +576,9 @@ class Parser():
637 576
638 DICOM standard tag (0x0010, 0x2152) was used. 577 DICOM standard tag (0x0010, 0x2152) was used.
639 """ 578 """
640 - tag = gdcm.Tag(0x0010,0x2152)  
641 - ds = self.gdcm_reader.GetFile().GetDataSet()  
642 - if ds.FindDataElement(tag):  
643 - data = str(ds.GetDataElement(tag).GetValue())  
644 - if (data):  
645 - return data 579 + data = self.data_image['0010']['2152']
  580 + if (data):
  581 + return data
646 return "" 582 return ""
647 583
648 def GetPatientTelephone(self): 584 def GetPatientTelephone(self):
@@ -652,12 +588,9 @@ class Parser(): @@ -652,12 +588,9 @@ class Parser():
652 588
653 DICOM standard tag (0x0010, 0x2154) was used. 589 DICOM standard tag (0x0010, 0x2154) was used.
654 """ 590 """
655 - tag = gdcm.Tag(0x0010,0x2154)  
656 - ds = self.gdcm_reader.GetFile().GetDataSet()  
657 - if ds.FindDataElement(tag):  
658 - data = str(ds.GetDataElement(tag).GetValue())  
659 - if (data):  
660 - return data 591 + data = self.data_image['0010']['2154']
  592 + if (data):
  593 + return data
661 return "" 594 return ""
662 595
663 def GetPatientResponsible(self): 596 def GetPatientResponsible(self):
@@ -668,12 +601,9 @@ class Parser(): @@ -668,12 +601,9 @@ class Parser():
668 601
669 DICOM standard tag (0x0010, 0x2297) was used. 602 DICOM standard tag (0x0010, 0x2297) was used.
670 """ 603 """
671 - tag = gdcm.Tag(0x0010,0x2297)  
672 - ds = self.gdcm_reader.GetFile().GetDataSet()  
673 - if ds.FindDataElement(tag):  
674 - data = str(ds.GetDataElement(tag).GetValue())  
675 - if (data):  
676 - return data 604 + data = self.data_image['0010']['2297']
  605 + if (data):
  606 + return data
677 return "" 607 return ""
678 608
679 def GetPatientResponsibleRole(self): 609 def GetPatientResponsibleRole(self):
@@ -684,12 +614,9 @@ class Parser(): @@ -684,12 +614,9 @@ class Parser():
684 614
685 DICOM standard tag (0x0010, 0x2298) was used. 615 DICOM standard tag (0x0010, 0x2298) was used.
686 """ 616 """
687 - tag = gdcm.Tag(0x0010,0x2298)  
688 - ds = self.gdcm_reader.GetFile().GetDataSet()  
689 - if ds.FindDataElement(tag):  
690 - data = str(ds.GetDataElement(tag).GetValue())  
691 - if (data):  
692 - return data 617 + data = self.data_image['0010']['2298']
  618 + if (data):
  619 + return data
693 return "" 620 return ""
694 621
695 def GetPatientResponsibleOrganization(self): 622 def GetPatientResponsibleOrganization(self):
@@ -700,12 +627,9 @@ class Parser(): @@ -700,12 +627,9 @@ class Parser():
700 627
701 DICOM standard tag (0x0010, 0x2299) was used. 628 DICOM standard tag (0x0010, 0x2299) was used.
702 """ 629 """
703 - tag = gdcm.Tag(0x0010,0x2299)  
704 - ds = self.gdcm_reader.GetFile().GetDataSet()  
705 - if ds.FindDataElement(tag):  
706 - data = str(ds.GetDataElement(tag).GetValue())  
707 - if (data):  
708 - return data 630 + data = self.data_image['0010']['2299']
  631 + if (data):
  632 + return data
709 return "" 633 return ""
710 634
711 def GetPatientMedicalCondition(self): 635 def GetPatientMedicalCondition(self):
@@ -716,12 +640,9 @@ class Parser(): @@ -716,12 +640,9 @@ class Parser():
716 640
717 DICOM standard tag (0x0010, 0x2000) was used. 641 DICOM standard tag (0x0010, 0x2000) was used.
718 """ 642 """
719 - tag = gdcm.Tag(0x0010,0x2000)  
720 - ds = self.gdcm_reader.GetFile().GetDataSet()  
721 - if ds.FindDataElement(tag):  
722 - data = str(ds.GetDataElement(tag).GetValue())  
723 - if (data):  
724 - return data 643 + data = self.data_image['0010']['2000']
  644 + if (data):
  645 + return data
725 return "" 646 return ""
726 647
727 def GetPatientContrastAllergies(self): 648 def GetPatientContrastAllergies(self):
@@ -732,12 +653,9 @@ class Parser(): @@ -732,12 +653,9 @@ class Parser():
732 653
733 DICOM standard tag (0x0008, 0x2110) was used. 654 DICOM standard tag (0x0008, 0x2110) was used.
734 """ 655 """
735 - tag = gdcm.Tag(0x0008, 0x2110)  
736 - ds = self.gdcm_reader.GetFile().GetDataSet()  
737 - if ds.FindDataElement(tag):  
738 - data = str(ds.GetDataElement(tag).GetValue())  
739 - if (data):  
740 - return data 656 + data = self.data_image['0008']['2110']
  657 + if (data):
  658 + return data
741 return "" 659 return ""
742 660
743 661
@@ -749,14 +667,11 @@ class Parser(): @@ -749,14 +667,11 @@ class Parser():
749 667
750 DICOM standard tag (0x0008, 0x0090) was used. 668 DICOM standard tag (0x0008, 0x0090) was used.
751 """ 669 """
752 - tag = gdcm.Tag(0x0008,0x0090)  
753 - ds = self.gdcm_reader.GetFile().GetDataSet()  
754 - if ds.FindDataElement(tag):  
755 - data = str(ds.GetDataElement(tag).GetValue())  
756 - if data == "None":  
757 - return ""  
758 - if (data):  
759 - return data 670 + data = self.data_image['0008']['0090']
  671 + if data == "None":
  672 + return ""
  673 + if (data):
  674 + return data
760 return "" 675 return ""
761 676
762 677
@@ -767,12 +682,9 @@ class Parser(): @@ -767,12 +682,9 @@ class Parser():
767 682
768 DICOM standard tag (0x0008, 0x0092) was used. 683 DICOM standard tag (0x0008, 0x0092) was used.
769 """ 684 """
770 - tag = gdcm.Tag(0x0008, 0x0092)  
771 - ds = self.gdcm_reader.GetFile().GetDataSet()  
772 - if ds.FindDataElement(tag):  
773 - data = str(ds.GetDataElement(tag).GetValue())  
774 - if (data):  
775 - return data 685 + data = self.data_image['0008']['0092']
  686 + if (data):
  687 + return data
776 return "" 688 return ""
777 689
778 def GetPhysicianeReferringTelephone(self): 690 def GetPhysicianeReferringTelephone(self):
@@ -782,12 +694,9 @@ class Parser(): @@ -782,12 +694,9 @@ class Parser():
782 694
783 DICOM standard tag (0x0008, 0x0094) was used. 695 DICOM standard tag (0x0008, 0x0094) was used.
784 """ 696 """
785 - tag = gdcm.Tag(0x0008, 0x0094)  
786 - ds = self.gdcm_reader.GetFile().GetDataSet()  
787 - if ds.FindDataElement(tag):  
788 - data = str(ds.GetDataElement(tag).GetValue())  
789 - if (data):  
790 - return data 697 + data = self.data_image['0008']['0094']
  698 + if (data):
  699 + return data
791 return "" 700 return ""
792 701
793 def GetProtocolName(self): 702 def GetProtocolName(self):
@@ -797,12 +706,9 @@ class Parser(): @@ -797,12 +706,9 @@ class Parser():
797 706
798 DICOM standard tag (0x0018, 0x1030) was used. 707 DICOM standard tag (0x0018, 0x1030) was used.
799 """ 708 """
800 - tag = gdcm.Tag(0x0018, 0x1030)  
801 - ds = self.gdcm_reader.GetFile().GetDataSet()  
802 - if ds.FindDataElement(tag):  
803 - data = str(ds.GetDataElement(tag).GetValue())  
804 - if (data):  
805 - return data 709 + data = self.data_image['0018']['1030']
  710 + if (data):
  711 + return data
806 return None 712 return None
807 713
808 def GetImageType(self): 714 def GetImageType(self):
@@ -814,15 +720,12 @@ class Parser(): @@ -814,15 +720,12 @@ class Parser():
814 720
815 Critical DICOM tag (0x0008, 0x0008). Cannot be editted. 721 Critical DICOM tag (0x0008, 0x0008). Cannot be editted.
816 """ 722 """
817 - tag = gdcm.Tag(0x0008, 0x0008)  
818 - ds = self.gdcm_reader.GetFile().GetDataSet()  
819 - if ds.FindDataElement(tag):  
820 - data = str(ds.GetDataElement(tag).GetValue())  
821 - if (data):  
822 - try:  
823 - return data.split('\\')  
824 - except(IndexError):  
825 - return [] 723 + data = self.data_image['0008']['0008']
  724 + if (data):
  725 + try:
  726 + return data.split('\\')
  727 + except(IndexError):
  728 + return []
826 return [] 729 return []
827 730
828 def GetSOPClassUID(self): 731 def GetSOPClassUID(self):
@@ -833,12 +736,9 @@ class Parser(): @@ -833,12 +736,9 @@ class Parser():
833 736
834 Critical DICOM tag (0x0008, 0x0016). Cannot be edited. 737 Critical DICOM tag (0x0008, 0x0016). Cannot be edited.
835 """ 738 """
836 - tag = gdcm.Tag(0x0008, 0x0016)  
837 - ds = self.gdcm_reader.GetFile().GetDataSet()  
838 - if ds.FindDataElement(tag):  
839 - data = str(ds.GetDataElement(tag).GetValue())  
840 - if (data):  
841 - return data 739 + data = self.data_image['0008']['0016']
  740 + if (data):
  741 + return data
842 return "" 742 return ""
843 743
844 def GetSOPInstanceUID(self): 744 def GetSOPInstanceUID(self):
@@ -849,12 +749,9 @@ class Parser(): @@ -849,12 +749,9 @@ class Parser():
849 749
850 Critical DICOM tag (0x0008, 0x0018). Cannot be edited. 750 Critical DICOM tag (0x0008, 0x0018). Cannot be edited.
851 """ 751 """
852 - tag = gdcm.Tag(0x0008, 0x0018)  
853 - ds = self.gdcm_reader.GetFile().GetDataSet()  
854 - if ds.FindDataElement(tag):  
855 - data = str(ds.GetDataElement(tag).GetValue())  
856 - if (data):  
857 - return data 752 + data = self.data_image['0008']['0018']
  753 + if (data):
  754 + return data
858 return "" 755 return ""
859 756
860 def GetSeriesDescription(self): 757 def GetSeriesDescription(self):
@@ -863,12 +760,9 @@ class Parser(): @@ -863,12 +760,9 @@ class Parser():
863 760
864 DICOM tag (0x0008, 0x1030). Cannot be edited. 761 DICOM tag (0x0008, 0x1030). Cannot be edited.
865 """ 762 """
866 - tag = gdcm.Tag(0x0008, 0x1030)  
867 - ds = self.gdcm_reader.GetFile().GetDataSet()  
868 - if ds.FindDataElement(tag):  
869 - data = str(ds.GetDataElement(tag).GetValue())  
870 - if (data):  
871 - return data 763 + data = self.data_image['0008']['1030']
  764 + if (data):
  765 + return data
872 return "" 766 return ""
873 767
874 def GetStudyInstanceUID(self): 768 def GetStudyInstanceUID(self):
@@ -879,12 +773,9 @@ class Parser(): @@ -879,12 +773,9 @@ class Parser():
879 773
880 Critical DICOM Tag (0x0020,0x000D). Cannot be edited. 774 Critical DICOM Tag (0x0020,0x000D). Cannot be edited.
881 """ 775 """
882 - tag = gdcm.Tag(0x0020,0x000D)  
883 - ds = self.gdcm_reader.GetFile().GetDataSet()  
884 - if ds.FindDataElement(tag):  
885 - data = str(ds.GetDataElement(tag).GetValue())  
886 - if (data):  
887 - return data 776 + data = self.data_image['0020']['000D']
  777 + if (data):
  778 + return data
888 return "" 779 return ""
889 780
890 def GetImagePatientOrientation(self): 781 def GetImagePatientOrientation(self):
@@ -898,12 +789,9 @@ class Parser(): @@ -898,12 +789,9 @@ class Parser():
898 789
899 Critical DICOM tag (0x0020,0x0037). Cannot be edited. 790 Critical DICOM tag (0x0020,0x0037). Cannot be edited.
900 """ 791 """
901 - tag = gdcm.Tag(0x0020,0x0037)  
902 - ds = self.gdcm_reader.GetFile().GetDataSet()  
903 - if ds.FindDataElement(tag):  
904 - data = str(ds.GetDataElement(tag).GetValue())  
905 - if (data):  
906 - return [float(value) for value in data.split('\\')] 792 + data = self.data_image['0020']['0037']
  793 + if (data):
  794 + return [float(value) for value in data.split('\\')]
907 return [1.0, 0.0, 0.0, 0.0, 1.0, 0.0] 795 return [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
908 796
909 def GetImageColumnOrientation(self): 797 def GetImageColumnOrientation(self):
@@ -915,12 +803,9 @@ class Parser(): @@ -915,12 +803,9 @@ class Parser():
915 803
916 Critical DICOM tag (0x0020,0x0037). Cannot be edited. 804 Critical DICOM tag (0x0020,0x0037). Cannot be edited.
917 """ 805 """
918 - tag = gdcm.Tag(0x0020,0x0037)  
919 - ds = self.gdcm_reader.GetFile().GetDataSet()  
920 - if ds.FindDataElement(tag):  
921 - data = str(ds.GetDataElement(tag).GetValue())  
922 - if (data):  
923 - return [float(value) for value in data.split('\\')[3:6]] 806 + data = self.data_image['0020']['0037']
  807 + if (data):
  808 + return [float(value) for value in data.split('\\')[3:6]]
924 return [0.0, 1.0, 0.0] 809 return [0.0, 1.0, 0.0]
925 810
926 def GetImageRowOrientation(self): 811 def GetImageRowOrientation(self):
@@ -932,12 +817,9 @@ class Parser(): @@ -932,12 +817,9 @@ class Parser():
932 817
933 Critical DICOM tag (0x0020,0x0037). Cannot be edited. 818 Critical DICOM tag (0x0020,0x0037). Cannot be edited.
934 """ 819 """
935 - tag = gdcm.Tag(0x0020,0x0037)  
936 - ds = self.gdcm_reader.GetFile().GetDataSet()  
937 - if ds.FindDataElement(tag):  
938 - data = str(ds.GetDataElement(tag).GetValue())  
939 - if (data):  
940 - return [float(value) for value in data.split('\\')[0:3]] 820 + data = self.data_image['0020']['0037']
  821 + if (data):
  822 + return [float(value) for value in data.split('\\')[0:3]]
941 return [1.0, 0.0, 0.0] 823 return [1.0, 0.0, 0.0]
942 824
943 def GetFrameReferenceUID(self): 825 def GetFrameReferenceUID(self):
@@ -947,12 +829,9 @@ class Parser(): @@ -947,12 +829,9 @@ class Parser():
947 829
948 Critical DICOM tag (0x0020,0x0052). Cannot be edited. 830 Critical DICOM tag (0x0020,0x0052). Cannot be edited.
949 """ 831 """
950 - tag = gdcm.Tag(0x0020,0x0052)  
951 - ds = self.gdcm_reader.GetFile().GetDataSet()  
952 - if ds.FindDataElement(tag):  
953 - data = str(ds.GetDataElement(tag).GetValue())  
954 - if (data):  
955 - return data 832 + data = self.data_image['0020']['0052']
  833 + if (data):
  834 + return data
956 return "" 835 return ""
957 836
958 def GetImageSamplesPerPixel(self): 837 def GetImageSamplesPerPixel(self):
@@ -1026,12 +905,12 @@ class Parser(): @@ -1026,12 +905,12 @@ class Parser():
1026 905
1027 DICOM standard tag (0x0018, 0x1030) was used. 906 DICOM standard tag (0x0018, 0x1030) was used.
1028 """ 907 """
1029 - tag = gdcm.Tag(0x0018, 0x1030)  
1030 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1031 - if ds.FindDataElement(tag):  
1032 - data = str(ds.GetDataElement(tag).GetValue()) 908 + try:
  909 + data = self.data_image['0018']['1030']
1033 if (data): 910 if (data):
1034 return data 911 return data
  912 + except(KeyError):
  913 + return ""
1035 return "" 914 return ""
1036 915
1037 def GetAcquisionSequence(self): 916 def GetAcquisionSequence(self):
@@ -1050,12 +929,9 @@ class Parser(): @@ -1050,12 +929,9 @@ class Parser():
1050 929
1051 Critical DICOM tag (0x0018, 0x0020). Cannot be edited. 930 Critical DICOM tag (0x0018, 0x0020). Cannot be edited.
1052 """ 931 """
1053 - tag = gdcm.Tag(0x0018, 0x0020)  
1054 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1055 - if ds.FindDataElement(tag):  
1056 - data = str(ds.GetDataElement(tag).GetValue())  
1057 - if (data):  
1058 - return data 932 + data = self.data_image['0018']['0020']
  933 + if (data):
  934 + return data
1059 return "" 935 return ""
1060 936
1061 def GetInstitutionName(self): 937 def GetInstitutionName(self):
@@ -1065,14 +941,10 @@ class Parser(): @@ -1065,14 +941,10 @@ class Parser():
1065 941
1066 DICOM standard tag (0x0008, 0x0080) was used. 942 DICOM standard tag (0x0008, 0x0080) was used.
1067 """ 943 """
1068 - tag = gdcm.Tag(0x0008, 0x0080)  
1069 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1070 - if ds.FindDataElement(tag):  
1071 - data = str(ds.GetDataElement(tag).GetValue())  
1072 - if (data): 944 + data = self.data_image['0008']['0080']
  945 + if (data):
1073 return data 946 return data
1074 -  
1075 - 0x0008, 0x0081 947 + return ""
1076 948
1077 def GetInstitutionAddress(self): 949 def GetInstitutionAddress(self):
1078 """ 950 """
@@ -1083,12 +955,9 @@ class Parser(): @@ -1083,12 +955,9 @@ class Parser():
1083 955
1084 DICOM standard tag (0x0008, 0x0081) was used. 956 DICOM standard tag (0x0008, 0x0081) was used.
1085 """ 957 """
1086 - tag = gdcm.Tag(0x0008, 0x0081)  
1087 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1088 - if ds.FindDataElement(tag):  
1089 - data = str(ds.GetDataElement(tag).GetValue())  
1090 - if (data):  
1091 - return data 958 + data = self.data_image['0008']['0081']
  959 + if (data):
  960 + return data
1092 return "" 961 return ""
1093 962
1094 def GetStudyInstanceUID(self): 963 def GetStudyInstanceUID(self):
@@ -1099,12 +968,9 @@ class Parser(): @@ -1099,12 +968,9 @@ class Parser():
1099 968
1100 Critical DICOM tag (0x0020, 0x000D). Cannot be edited. 969 Critical DICOM tag (0x0020, 0x000D). Cannot be edited.
1101 """ 970 """
1102 - tag = gdcm.Tag(0x0020, 0x000D)  
1103 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1104 - if ds.FindDataElement(tag):  
1105 - data = str(ds.GetDataElement(tag).GetValue())  
1106 - if (data):  
1107 - return data 971 + data = self.data_image['0020']['000D']
  972 + if (data):
  973 + return data
1108 return "" 974 return ""
1109 975
1110 def GetPatientOccupation(self): 976 def GetPatientOccupation(self):
@@ -1114,12 +980,9 @@ class Parser(): @@ -1114,12 +980,9 @@ class Parser():
1114 980
1115 DICOM standard tag (0x0010,0x2180) was used. 981 DICOM standard tag (0x0010,0x2180) was used.
1116 """ 982 """
1117 - tag = gdcm.Tag(0x0010, 0x2180)  
1118 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1119 - if ds.FindDataElement(tag):  
1120 - data = str(ds.GetDataElement(tag).GetValue())  
1121 - if (data):  
1122 - return data 983 + data = self.data_image['0010']['2180']
  984 + if (data):
  985 + return data
1123 return "" 986 return ""
1124 987
1125 def _GetPixelRepresentation(self): 988 def _GetPixelRepresentation(self):
@@ -1147,13 +1010,13 @@ class Parser(): @@ -1147,13 +1010,13 @@ class Parser():
1147 1010
1148 DICOM standard tag (0x0028, 0x0100) was used. 1011 DICOM standard tag (0x0028, 0x0100) was used.
1149 """ 1012 """
1150 - tag = gdcm.Tag(0x0028, 0x0100)  
1151 - sf = gdcm.StringFilter()  
1152 - sf.SetFile(self.gdcm_reader.GetFile())  
1153 - res = sf.ToStringPair(tag)  
1154 -  
1155 - if (res[1]):  
1156 - return int(res[1]) 1013 + #tag = gdcm.Tag(0x0028, 0x0100)
  1014 + #sf = gdcm.StringFilter()
  1015 + #sf.SetFile(self.gdcm_reader.GetFile())
  1016 + #res = sf.ToStringPair(tag)
  1017 + data = self.data_image['0028']['0100']
  1018 + if (data):
  1019 + return int(data)
1157 return "" 1020 return ""
1158 1021
1159 1022
@@ -1166,12 +1029,9 @@ class Parser(): @@ -1166,12 +1029,9 @@ class Parser():
1166 DICOM standard tag (0x0010,0x0030) was used. 1029 DICOM standard tag (0x0010,0x0030) was used.
1167 """ 1030 """
1168 # TODO: internationalize data 1031 # TODO: internationalize data
1169 - tag = gdcm.Tag(0x0010, 0x0030)  
1170 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1171 - if ds.FindDataElement(tag):  
1172 - data = ds.GetDataElement(tag).GetValue()  
1173 - if (data) and (data != 'None'):  
1174 - return self.__format_date(str(data)) 1032 + data = self.data_image['0010']['0030']
  1033 + if (data) and (data != 'None'):
  1034 + return self.__format_date(str(data))
1175 return "" 1035 return ""
1176 1036
1177 1037
@@ -1182,12 +1042,9 @@ class Parser(): @@ -1182,12 +1042,9 @@ class Parser():
1182 1042
1183 DICOM standard tag (0x0020,0x0010) was used. 1043 DICOM standard tag (0x0020,0x0010) was used.
1184 """ 1044 """
1185 - tag = gdcm.Tag(0x0020, 0x0010)  
1186 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1187 - if ds.FindDataElement(tag):  
1188 - data = ds.GetDataElement(tag).GetValue()  
1189 - if (data):  
1190 - return str(data) 1045 + data = self.data_image['0020']['0010']
  1046 + if (data):
  1047 + return str(data)
1191 return "" 1048 return ""
1192 1049
1193 def GetAcquisitionGantryTilt(self): 1050 def GetAcquisitionGantryTilt(self):
@@ -1198,14 +1055,9 @@ class Parser(): @@ -1198,14 +1055,9 @@ class Parser():
1198 1055
1199 DICOM standard tag (0x0018,0x1120) was used. 1056 DICOM standard tag (0x0018,0x1120) was used.
1200 """ 1057 """
1201 - tag = gdcm.Tag(0x0018, 0x1120)  
1202 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1203 - if ds.FindDataElement(tag):  
1204 - data = ds.GetDataElement(tag).GetValue()  
1205 -  
1206 - if (data):  
1207 - return float(str(data))  
1208 - 1058 + data = self.data_image['0018']['1120']
  1059 + if (data):
  1060 + return float(str(data))
1209 return 0.0 1061 return 0.0
1210 1062
1211 def GetPatientGender(self): 1063 def GetPatientGender(self):
@@ -1218,13 +1070,9 @@ class Parser(): @@ -1218,13 +1070,9 @@ class Parser():
1218 1070
1219 DICOM standard tag (0x0010,0x0040) was used. 1071 DICOM standard tag (0x0010,0x0040) was used.
1220 """ 1072 """
1221 - tag = gdcm.Tag(0x0010, 0x0040)  
1222 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1223 - if ds.FindDataElement(tag):  
1224 - data = ds.GetDataElement(tag).GetValue()  
1225 -  
1226 - if (data):  
1227 - return str(data) 1073 + data = self.data_image['0010']['0040']
  1074 + if (data):
  1075 + return str(data)
1228 return "" 1076 return ""
1229 1077
1230 def GetPatientAge(self): 1078 def GetPatientAge(self):
@@ -1235,17 +1083,13 @@ class Parser(): @@ -1235,17 +1083,13 @@ class Parser():
1235 1083
1236 DICOM standard tag (0x0010, 0x1010) was used. 1084 DICOM standard tag (0x0010, 0x1010) was used.
1237 """ 1085 """
1238 - tag = gdcm.Tag(0x0010, 0x1010)  
1239 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1240 - if ds.FindDataElement(tag):  
1241 - data = str(ds.GetDataElement(tag).GetValue())  
1242 -  
1243 - if (data):  
1244 - age = (data.split('Y')[0])  
1245 - try:  
1246 - return int(age)  
1247 - except ValueError:  
1248 - return age 1086 + data = self.data_image['0010']['0010']
  1087 + if (data):
  1088 + age = (data.split('Y')[0])
  1089 + try:
  1090 + return int(age)
  1091 + except ValueError:
  1092 + return age
1249 return "" 1093 return ""
1250 1094
1251 def GetPatientName(self): 1095 def GetPatientName(self):
@@ -1255,16 +1099,12 @@ class Parser(): @@ -1255,16 +1099,12 @@ class Parser():
1255 1099
1256 DICOM standard tag (0x0010,0x0010) was used. 1100 DICOM standard tag (0x0010,0x0010) was used.
1257 """ 1101 """
1258 - tag = gdcm.Tag(0x0010, 0x0010)  
1259 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1260 - if ds.FindDataElement(tag):  
1261 - data = str(ds.GetDataElement(tag).GetValue())  
1262 -  
1263 - if (data):  
1264 - name = data.strip()  
1265 - encoding = self.GetEncoding()  
1266 - # Returns a unicode decoded in the own dicom encoding  
1267 - return name.decode(encoding) 1102 + data = self.data_image['0010']['0010']
  1103 + if (data):
  1104 + name = data.strip()
  1105 + encoding = self.GetEncoding()
  1106 + # Returns a unicode decoded in the own dicom encoding
  1107 + return name.decode(encoding)
1268 return "" 1108 return ""
1269 1109
1270 def GetPatientID(self): 1110 def GetPatientID(self):
@@ -1275,15 +1115,11 @@ class Parser(): @@ -1275,15 +1115,11 @@ class Parser():
1275 1115
1276 DICOM standard tag (0x0010,0x0020) was used. 1116 DICOM standard tag (0x0010,0x0020) was used.
1277 """ 1117 """
1278 - tag = gdcm.Tag(0x0010, 0x0020)  
1279 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1280 - if ds.FindDataElement(tag):  
1281 - data = str(ds.GetDataElement(tag).GetValue())  
1282 -  
1283 - if (data):  
1284 - encoding = self.GetEncoding()  
1285 - # Returns a unicode decoded in the own dicom encoding  
1286 - return data.decode(encoding) 1118 + data = self.data_image['0010']['0020']
  1119 + if (data):
  1120 + encoding = self.GetEncoding()
  1121 + # Returns a unicode decoded in the own dicom encoding
  1122 + return data.decode(encoding)
1287 return "" 1123 return ""
1288 1124
1289 1125
@@ -1295,13 +1131,9 @@ class Parser(): @@ -1295,13 +1131,9 @@ class Parser():
1295 1131
1296 DICOM standard tag (0x0018,0x1151) was used. 1132 DICOM standard tag (0x0018,0x1151) was used.
1297 """ 1133 """
1298 - tag = gdcm.Tag(0x0018, 0x1151)  
1299 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1300 - if ds.FindDataElement(tag):  
1301 - data = str(ds.GetDataElement(tag).GetValue())  
1302 -  
1303 - if (data):  
1304 - return data 1134 + data = self.data_image['0018']['1151']
  1135 + if (data):
  1136 + return data
1305 return "" 1137 return ""
1306 1138
1307 def GetExposureTime(self): 1139 def GetExposureTime(self):
@@ -1312,13 +1144,9 @@ class Parser(): @@ -1312,13 +1144,9 @@ class Parser():
1312 1144
1313 DICOM standard tag (0x0018, 0x1152) was used. 1145 DICOM standard tag (0x0018, 0x1152) was used.
1314 """ 1146 """
1315 - tag = gdcm.Tag(0x0018, 0x1152)  
1316 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1317 - if ds.FindDataElement(tag):  
1318 - data = str(ds.GetDataElement(tag).GetValue())  
1319 -  
1320 - if (data):  
1321 - return float(data) 1147 + data = self.data_image['0018']['1152']
  1148 + if (data):
  1149 + return float(data)
1322 return "" 1150 return ""
1323 1151
1324 def GetEquipmentKVP(self): 1152 def GetEquipmentKVP(self):
@@ -1329,13 +1157,9 @@ class Parser(): @@ -1329,13 +1157,9 @@ class Parser():
1329 1157
1330 DICOM standard tag (0x0018,0x0060) was used. 1158 DICOM standard tag (0x0018,0x0060) was used.
1331 """ 1159 """
1332 - tag = gdcm.Tag(0x0018, 0x0060)  
1333 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1334 - if ds.FindDataElement(tag):  
1335 - data = str(ds.GetDataElement(tag).GetValue())  
1336 -  
1337 - if (data):  
1338 - return float(data) 1160 + data = self.data_image['0018']['0060']
  1161 + if (data):
  1162 + return float(data)
1339 return "" 1163 return ""
1340 1164
1341 def GetImageThickness(self): 1165 def GetImageThickness(self):
@@ -1346,12 +1170,9 @@ class Parser(): @@ -1346,12 +1170,9 @@ class Parser():
1346 1170
1347 DICOM standard tag (0x0018,0x0050) was used. 1171 DICOM standard tag (0x0018,0x0050) was used.
1348 """ 1172 """
1349 - tag = gdcm.Tag(0x0018, 0x0050)  
1350 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1351 - if ds.FindDataElement(tag):  
1352 - data = str(ds.GetDataElement(tag).GetValue())  
1353 - if (data):  
1354 - return float(data) 1173 + data = self.data_image['0018']['0050']
  1174 + if (data):
  1175 + return float(data)
1355 return 0 1176 return 0
1356 1177
1357 def GetImageConvolutionKernel(self): 1178 def GetImageConvolutionKernel(self):
@@ -1364,13 +1185,9 @@ class Parser(): @@ -1364,13 +1185,9 @@ class Parser():
1364 1185
1365 DICOM standard tag (0x0018,0x1210) was used. 1186 DICOM standard tag (0x0018,0x1210) was used.
1366 """ 1187 """
1367 - tag = gdcm.Tag(0x0018, 0x1210)  
1368 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1369 - if ds.FindDataElement(tag):  
1370 - data = str(ds.GetDataElement(tag).GetValue())  
1371 -  
1372 - if (data):  
1373 - return data 1188 + data = self.data_image['0018']['1210']
  1189 + if (data):
  1190 + return data
1374 return "" 1191 return ""
1375 1192
1376 def GetEquipmentInstitutionName(self): 1193 def GetEquipmentInstitutionName(self):
@@ -1381,13 +1198,9 @@ class Parser(): @@ -1381,13 +1198,9 @@ class Parser():
1381 1198
1382 DICOM standard tag (0x0008,0x0080) was used. 1199 DICOM standard tag (0x0008,0x0080) was used.
1383 """ 1200 """
1384 - tag = gdcm.Tag(0x0008, 0x0080)  
1385 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1386 - if ds.FindDataElement(tag):  
1387 - data = str(ds.GetDataElement(tag).GetValue())  
1388 -  
1389 - if (data):  
1390 - return data 1201 + data = self.data_image['0008']['0080']
  1202 + if (data):
  1203 + return data
1391 return "" 1204 return ""
1392 1205
1393 def GetStationName(self): 1206 def GetStationName(self):
@@ -1398,13 +1211,9 @@ class Parser(): @@ -1398,13 +1211,9 @@ class Parser():
1398 1211
1399 DICOM standard tag (0x0008, 0x1010) was used. 1212 DICOM standard tag (0x0008, 0x1010) was used.
1400 """ 1213 """
1401 - tag = gdcm.Tag(0x0008, 0x1010)  
1402 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1403 - if ds.FindDataElement(tag):  
1404 - data = str(ds.GetDataElement(tag).GetValue())  
1405 -  
1406 - if (data):  
1407 - return data 1214 + data = self.data_image['0008']['1010']
  1215 + if (data):
  1216 + return data
1408 return "" 1217 return ""
1409 1218
1410 def GetManufacturerModelName(self): 1219 def GetManufacturerModelName(self):
@@ -1415,13 +1224,9 @@ class Parser(): @@ -1415,13 +1224,9 @@ class Parser():
1415 1224
1416 DICOM standard tag (0x0008,0x1090) was used. 1225 DICOM standard tag (0x0008,0x1090) was used.
1417 """ 1226 """
1418 - tag = gdcm.Tag(0x0008, 0x1090)  
1419 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1420 - if ds.FindDataElement(tag):  
1421 - data = str(ds.GetDataElement(tag).GetValue())  
1422 -  
1423 - if (data):  
1424 - return data 1227 + data = self.data_image['0008']['1090']
  1228 + if (data):
  1229 + return data
1425 return "" 1230 return ""
1426 1231
1427 def GetEquipmentManufacturer(self): 1232 def GetEquipmentManufacturer(self):
@@ -1431,13 +1236,9 @@ class Parser(): @@ -1431,13 +1236,9 @@ class Parser():
1431 1236
1432 DICOM standard tag (0x0008, 0x1010) was used. 1237 DICOM standard tag (0x0008, 0x1010) was used.
1433 """ 1238 """
1434 - tag = gdcm.Tag(0x0008, 0x1010)  
1435 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1436 - if ds.FindDataElement(tag):  
1437 - data = str(ds.GetDataElement(tag).GetValue())  
1438 -  
1439 - if (data):  
1440 - return data 1239 + data = self.data_image['0008']['1010']
  1240 + if (data):
  1241 + return data
1441 return "" 1242 return ""
1442 1243
1443 def GetAcquisitionModality(self): 1244 def GetAcquisitionModality(self):
@@ -1449,13 +1250,9 @@ class Parser(): @@ -1449,13 +1250,9 @@ class Parser():
1449 1250
1450 DICOM standard tag (0x0008,0x0060) was used. 1251 DICOM standard tag (0x0008,0x0060) was used.
1451 """ 1252 """
1452 - tag = gdcm.Tag(0x0008, 0x0060)  
1453 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1454 - if ds.FindDataElement(tag):  
1455 - data = str(ds.GetDataElement(tag).GetValue())  
1456 -  
1457 - if (data):  
1458 - return data 1253 + data = self.data_image['0008']['0060']
  1254 + if (data):
  1255 + return data
1459 return "" 1256 return ""
1460 1257
1461 1258
@@ -1466,13 +1263,13 @@ class Parser(): @@ -1466,13 +1263,13 @@ class Parser():
1466 1263
1467 DICOM standard tag (0x0020,0x0013) was used. 1264 DICOM standard tag (0x0020,0x0013) was used.
1468 """ 1265 """
1469 - tag = gdcm.Tag(0x0020, 0x0013)  
1470 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1471 - if ds.FindDataElement(tag):  
1472 - data = str(ds.GetDataElement(tag).GetValue()) 1266 + try:
  1267 + data = self.data_image['0020']['0013']
  1268 + except(KeyError):
  1269 + return ""
1473 1270
1474 - if (data):  
1475 - return int(data) 1271 + if (data):
  1272 + return int(data)
1476 return "" 1273 return ""
1477 1274
1478 def GetStudyDescription(self): 1275 def GetStudyDescription(self):
@@ -1482,15 +1279,13 @@ class Parser(): @@ -1482,15 +1279,13 @@ class Parser():
1482 1279
1483 DICOM standard tag (0x0008,0x1030) was used. 1280 DICOM standard tag (0x0008,0x1030) was used.
1484 """ 1281 """
1485 - tag = gdcm.Tag(0x0008, 0x1030)  
1486 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1487 - if ds.FindDataElement(tag):  
1488 - data = str(ds.GetDataElement(tag).GetValue())  
1489 - 1282 + try:
  1283 + data = self.data_image['0008']['1030']
1490 if (data): 1284 if (data):
1491 encoding = self.GetEncoding() 1285 encoding = self.GetEncoding()
1492 return data.decode(encoding) 1286 return data.decode(encoding)
1493 - return "" 1287 + except(KeyError):
  1288 + return ""
1494 1289
1495 def GetStudyAdmittingDiagnosis(self): 1290 def GetStudyAdmittingDiagnosis(self):
1496 """ 1291 """
@@ -1515,27 +1310,27 @@ class Parser(): @@ -1515,27 +1310,27 @@ class Parser():
1515 Return a string with a description of the series. 1310 Return a string with a description of the series.
1516 DICOM standard tag (0x0008, 0x103E) was used. 1311 DICOM standard tag (0x0008, 0x103E) was used.
1517 """ 1312 """
1518 - tag = gdcm.Tag(0x0008, 0x103E)  
1519 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1520 - if ds.FindDataElement(tag):  
1521 - data = str(ds.GetDataElement(tag).GetValue()) 1313 + try:
  1314 + data = self.data_image['0008']['103E']
1522 if data == "None": 1315 if data == "None":
1523 return _("unnamed") 1316 return _("unnamed")
1524 if (data): 1317 if (data):
1525 return data 1318 return data
1526 - return _("unnamed") 1319 + except(KeyError):
  1320 + return _("unnamed")
1527 1321
1528 def GetImageTime(self): 1322 def GetImageTime(self):
1529 """ 1323 """
1530 Return the image time. 1324 Return the image time.
1531 DICOM standard tag (0x0008,0x0033) was used. 1325 DICOM standard tag (0x0008,0x0033) was used.
1532 """ 1326 """
1533 - tag = gdcm.Tag(0x0008, 0x0033)  
1534 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1535 - if ds.FindDataElement(tag):  
1536 - date = str(ds.GetDataElement(tag).GetValue())  
1537 - if (date) and (date != 'None'):  
1538 - return self.__format_time(date) 1327 + try:
  1328 + data = self.data_image['0008']['0033']
  1329 + except(KeyError):
  1330 + return ""
  1331 +
  1332 + if (data) and (data != 'None'):
  1333 + return self.__format_time(data)
1539 return "" 1334 return ""
1540 1335
1541 def GetAcquisitionTime(self): 1336 def GetAcquisitionTime(self):
@@ -1543,12 +1338,9 @@ class Parser(): @@ -1543,12 +1338,9 @@ class Parser():
1543 Return the acquisition time. 1338 Return the acquisition time.
1544 DICOM standard tag (0x0008,0x032) was used. 1339 DICOM standard tag (0x0008,0x032) was used.
1545 """ 1340 """
1546 - tag = gdcm.Tag(0x0008, 0x0032)  
1547 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1548 - if ds.FindDataElement(tag):  
1549 - data = str(ds.GetDataElement(tag).GetValue())  
1550 - if (data):  
1551 - return self.__format_time(data) 1341 + data = self.data_image['0008']['0032']
  1342 + if (data):
  1343 + return self.__format_time(data)
1552 return "" 1344 return ""
1553 1345
1554 def GetSerieNumber(self): 1346 def GetSerieNumber(self):
@@ -1556,12 +1348,9 @@ class Parser(): @@ -1556,12 +1348,9 @@ class Parser():
1556 Return the serie number 1348 Return the serie number
1557 DICOM standard tag (0x0020, 0x0011) was used. 1349 DICOM standard tag (0x0020, 0x0011) was used.
1558 """ 1350 """
1559 - tag = gdcm.Tag(0x0020, 0x0011)  
1560 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1561 - if ds.FindDataElement(tag):  
1562 - data = str(ds.GetDataElement(tag).GetValue())  
1563 - if (data):  
1564 - return data 1351 + data = self.data_image['0020']['0011']
  1352 + if (data):
  1353 + return data
1565 return "" 1354 return ""
1566 1355
1567 def GetEncoding(self): 1356 def GetEncoding(self):
@@ -1569,18 +1358,18 @@ class Parser(): @@ -1569,18 +1358,18 @@ class Parser():
1569 Return the dicom encoding 1358 Return the dicom encoding
1570 DICOM standard tag (0x0008, 0x0005) was used. 1359 DICOM standard tag (0x0008, 0x0005) was used.
1571 """ 1360 """
1572 - tag = gdcm.Tag(0x0008, 0x0005)  
1573 - ds = self.gdcm_reader.GetFile().GetDataSet()  
1574 - if ds.FindDataElement(tag):  
1575 - encoding = str(ds.GetDataElement(tag).GetValue()) 1361 + try:
  1362 + encoding = self.data_image['0008']['0005']
  1363 + except(KeyError):
  1364 + return 'ISO_IR_100'
1576 1365
1577 - if encoding != None and encoding != "None": 1366 + if encoding != None and encoding != "None":
1578 1367
1579 - #Problem with 0051 anonymized  
1580 - if (encoding.split(":"))[0] == "Loaded":  
1581 - return 'ISO_IR 100'  
1582 - else:  
1583 - return encoding 1368 + #Problem with 0051 anonymized
  1369 + if (encoding.split(":"))[0] == "Loaded":
  1370 + return 'ISO_IR 100'
  1371 + else:
  1372 + return encoding
1584 return 'ISO_IR 100' 1373 return 'ISO_IR 100'
1585 1374
1586 1375
@@ -1924,7 +1713,7 @@ class Image(object): @@ -1924,7 +1713,7 @@ class Image(object):
1924 self.time = parser.GetImageTime() 1713 self.time = parser.GetImageTime()
1925 self.type = parser.GetImageType() 1714 self.type = parser.GetImageType()
1926 self.size = (parser.GetDimensionX(), parser.GetDimensionY()) 1715 self.size = (parser.GetDimensionX(), parser.GetDimensionY())
1927 - self.imagedata = parser.GetImageData() 1716 + #self.imagedata = parser.GetImageData()
1928 self.bits_allocad = parser._GetBitsAllocated() 1717 self.bits_allocad = parser._GetBitsAllocated()
1929 1718
1930 if (parser.GetImageThickness()): 1719 if (parser.GetImageThickness()):
invesalius/reader/dicom_grouper.py
@@ -96,7 +96,7 @@ class DicomGroup: @@ -96,7 +96,7 @@ class DicomGroup:
96 return False 96 return False
97 else: 97 else:
98 self.slices_dict[dicom.image.number] = dicom 98 self.slices_dict[dicom.image.number] = dicom
99 - self.nslices += 1 99 + self.nslices += 1
100 return True 100 return True
101 101
102 def GetList(self): 102 def GetList(self):
invesalius/reader/dicom_reader.py
@@ -31,6 +31,12 @@ import dicom @@ -31,6 +31,12 @@ import dicom
31 import dicom_grouper 31 import dicom_grouper
32 import session 32 import session
33 33
  34 +import glob
  35 +import utils
  36 +
  37 +
  38 +import plistlib
  39 +
34 def ReadDicomGroup(dir_): 40 def ReadDicomGroup(dir_):
35 41
36 patient_group = GetDicomGroups(dir_) 42 patient_group = GetDicomGroups(dir_)
@@ -73,6 +79,7 @@ def SortFiles(filelist, dicom): @@ -73,6 +79,7 @@ def SortFiles(filelist, dicom):
73 79
74 return filelist 80 return filelist
75 81
  82 +"""
76 class LoadDicom(threading.Thread): 83 class LoadDicom(threading.Thread):
77 def __init__(self, grouper, q, l): 84 def __init__(self, grouper, q, l):
78 threading.Thread.__init__(self) 85 threading.Thread.__init__(self)
@@ -87,66 +94,242 @@ class LoadDicom(threading.Thread): @@ -87,66 +94,242 @@ class LoadDicom(threading.Thread):
87 if not filepath: 94 if not filepath:
88 break 95 break
89 parser = dicom.Parser() 96 parser = dicom.Parser()
90 - if parser.SetFileName(filepath): 97 + #if parser.SetFileName(filepath):
91 dcm = dicom.Dicom() 98 dcm = dicom.Dicom()
92 self.l.acquire() 99 self.l.acquire()
93 dcm.SetParser(parser) 100 dcm.SetParser(parser)
94 grouper.AddFile(dcm) 101 grouper.AddFile(dcm)
95 self.l.release() 102 self.l.release()
  103 +"""
  104 +
  105 +"""
  106 +class LoadDicom():
  107 + def __init__(self, grouper, dicom_dict):
  108 + self.grouper = grouper
  109 + self.dicom_dict = dicom_dict
  110 +
  111 + def Start(self):
  112 + images = self.dicom_dict['data']
  113 +
  114 + grouper = self.grouper
  115 +
  116 + for x in images.keys():
  117 + data_image = images[x]
  118 + parser = dicom.Parser()
  119 + parser.SetDataImage(data_image)
  120 +
  121 + dcm = dicom.Dicom()
  122 + dcm.SetParser(parser)
  123 + grouper.AddFile(dcm)
  124 +
  125 +
  126 + #while 1:
  127 + #filepath = path
  128 + #if not filepath:
  129 + # break
  130 + #parser = dicom.Parser()
  131 + #if parser.SetFileName(filepath):
  132 + # dcm = dicom.Dicom()
  133 + # dcm.SetParser(parser)
  134 + # grouper.AddFile(dcm)
  135 +"""
96 136
97 137
98 -def yGetDicomGroups(directory, recursive=True, gui=True): 138 +def GetImageOrientationLabel(filename):
  139 + """
  140 + Return Label regarding the orientation of
  141 + an image. (AXIAL, SAGITTAL, CORONAL,
  142 + OBLIQUE or UNKNOWN)
  143 + """
  144 + gdcm_reader = gdcm.ImageReader()
  145 + gdcm_reader.SetFileName(filename)
  146 +
  147 + img = gdcm_reader.GetImage()
  148 + direc_cosines = img.GetDirectionCosines()
  149 + orientation = gdcm.Orientation()
  150 + try:
  151 + type = orientation.GetType(tuple(direc_cosines))
  152 + except TypeError:
  153 + type = orientation.GetType(direc_cosines)
  154 + label = orientation.GetLabel(type)
  155 +
  156 + if (label):
  157 + return label
  158 + else:
  159 + return ""
  160 +
  161 +
  162 +def GetDicomGroups(directory, recursive=True, gui=True):
99 """ 163 """
100 Return all full paths to DICOM files inside given directory. 164 Return all full paths to DICOM files inside given directory.
101 """ 165 """
102 nfiles = 0 166 nfiles = 0
103 # Find total number of files 167 # Find total number of files
104 if recursive: 168 if recursive:
105 - for dirpath, dirnames, filenames in os.walk(directory):  
106 - nfiles += len(filenames)  
107 - else:  
108 - dirpath, dirnames, filenames = os.walk(directory)  
109 - nfiles = len(filenames)  
110 -  
111 - counter = 0  
112 - grouper = dicom_grouper.DicomPatientGrouper()  
113 - q = Queue.Queue()  
114 - l = threading.Lock()  
115 - threads = []  
116 - for i in xrange(cpu_count()):  
117 - t = LoadDicom(grouper, q, l)  
118 - t.start()  
119 - threads.append(t)  
120 - # Retrieve only DICOM files, splited into groups  
121 - if recursive:  
122 - for dirpath, dirnames, filenames in os.walk(directory):  
123 - for name in filenames:  
124 - filepath = os.path.join(dirpath, name)  
125 - counter += 1  
126 - if gui:  
127 - yield (counter,nfiles)  
128 - q.put(filepath) 169 +
  170 + folders = [f[0] for f in os.walk(directory)]
  171 +
  172 + tag_labels = {}
  173 + main_dict = {}
  174 + dict_file = {}
  175 +
  176 + for folder in folders:
  177 + files = glob.glob(os.path.join(folder, "*"))
  178 +
  179 + for filename in files:
  180 +
  181 + # Read file
  182 + reader = gdcm.Reader()
  183 + reader.SetFileName(filename)
  184 +
  185 + if (reader.Read()):
  186 +
  187 + file = reader.GetFile()
  188 +
  189 + # Retrieve data set
  190 + dataSet = file.GetDataSet()
  191 +
  192 + # Retrieve header
  193 + header = file.GetHeader()
  194 + stf = gdcm.StringFilter()
  195 +
  196 + field_dict = {}
  197 + data_dict = {}
  198 +
  199 +
  200 + tag = gdcm.Tag(0x0008, 0x0005)
  201 + ds = reader.GetFile().GetDataSet()
  202 + if ds.FindDataElement(tag):
  203 + encoding = str(ds.GetDataElement(tag).GetValue())
  204 + if not(encoding != None and encoding != "None" and encoding != "Loaded"):
  205 + encoding = "ISO_IR 100"
  206 + else:
  207 + encoding = "ISO_IR_100"
  208 + # Iterate through the Header
  209 + iterator = header.GetDES().begin()
  210 + while (not iterator.equal(header.GetDES().end())):
  211 + dataElement = iterator.next()
  212 + stf.SetFile(file)
  213 + tag = dataElement.GetTag()
  214 + data = stf.ToStringPair(tag)
  215 + stag = tag.PrintAsPipeSeparatedString()
  216 +
  217 + group = stag.split("|")[0][1:]
  218 + field = stag.split("|")[1][:-1]
  219 + tag_labels[stag] = data[0]
  220 +
  221 + if not group in data_dict.keys():
  222 + data_dict[group] = {}
  223 +
  224 + if not(utils.VerifyInvalidPListCharacter(data[1])):
  225 + data_dict[group][field] = data[1].decode(encoding)
  226 + else:
  227 + data_dict[group][field] = "Invalid Character"
  228 +
  229 +
  230 + # Iterate through the Data set
  231 + iterator = dataSet.GetDES().begin()
  232 + while (not iterator.equal(dataSet.GetDES().end())):
  233 + dataElement = iterator.next()
  234 +
  235 + stf.SetFile(file)
  236 + tag = dataElement.GetTag()
  237 + data = stf.ToStringPair(tag)
  238 + stag = tag.PrintAsPipeSeparatedString()
  239 +
  240 + group = stag.split("|")[0][1:]
  241 + field = stag.split("|")[1][:-1]
  242 + tag_labels[stag] = data[0]
  243 +
  244 + if not group in data_dict.keys():
  245 + data_dict[group] = {}
  246 +
  247 + if not(utils.VerifyInvalidPListCharacter(data[1])):
  248 + data_dict[group][field] = data[1].decode(encoding)
  249 + else:
  250 + data_dict[group][field] = "Invalid Character"
  251 +
  252 +
  253 +
  254 + # ---------- Refactory --------------------------------------
  255 + data_dict['invesalius'] = {'orientation_label' : GetImageOrientationLabel(filename)}
  256 +
  257 + # -------------------------------------------------------------
  258 +
  259 + dict_file[os.path.abspath(filename)] = data_dict
  260 +
  261 + main_dict = dict(
  262 + data = dict_file,
  263 + labels = tag_labels)
  264 +
  265 + #plistlib.writePlist(main_dict, ".//teste.plist")
  266 +
  267 + images = main_dict['data']
  268 + grouper = dicom_grouper.DicomPatientGrouper()
  269 +
  270 + for x in images.keys():
  271 + data_image = images[x]
  272 +
  273 + if (data_image['0002']['0002'] != "1.2.840.10008.1.3.10"): #DICOMDIR
  274 + parser = dicom.Parser()
  275 + parser.SetDataImage(data_image, x)
  276 +
  277 + dcm = dicom.Dicom()
  278 + dcm.SetParser(parser)
  279 + grouper.AddFile(dcm)
  280 +
  281 + grouper.Update()
  282 +
  283 +
  284 +
  285 + return grouper.GetPatientsGroups()
  286 + #print "_____________________________________"
  287 + #print dirpath
  288 + #nfiles += len(filenames)
129 else: 289 else:
130 - dirpath, dirnames, filenames = os.walk(directory)  
131 - for name in filenames:  
132 - filepath = str(os.path.join(dirpath, name))  
133 - counter += 1  
134 - if gui:  
135 - yield (counter,nfiles)  
136 - q.put(filepath) 290 + pass
  291 + #dirpath, dirnames, filenames = os.walk(directory)
  292 + #nfiles = len(filenames)
137 293
138 - for t in threads:  
139 - q.put(0) 294 + #counter = 0
  295 + #grouper = dicom_grouper.DicomPatientGrouper()
  296 + #q = Queue.Queue()
  297 + #l = threading.Lock()
  298 + #threads = []
  299 + #for i in xrange(cpu_count()):
  300 + # t = LoadDicom(grouper, q, l)
  301 + # t.start()
  302 + # threads.append(t)
  303 + ## Retrieve only DICOM files, splited into groups
  304 + #if recursive:
  305 + # for dirpath, dirnames, filenames in os.walk(directory):
  306 + # for name in filenames:
  307 + # filepath = os.path.join(dirpath, name)
  308 + # counter += 1
  309 + # if gui:
  310 + # yield (counter,nfiles)
  311 + # q.put(filepath)
  312 + #else:
  313 + # dirpath, dirnames, filenames = os.walk(directory)
  314 + # for name in filenames:
  315 + # filepath = str(os.path.join(dirpath, name))
  316 + # counter += 1
  317 + # if gui:
  318 + # yield (counter,nfiles)
  319 + # q.put(filepath)
140 320
141 - for t in threads:  
142 - t.join() 321 + #for t in threads:
  322 + # q.put(0)
143 323
144 - #TODO: Is this commented update necessary?  
145 - #grouper.Update()  
146 - yield grouper.GetPatientsGroups() 324 + #for t in threads:
  325 + # t.join()
147 326
148 -def GetDicomGroups(directory, recursive=True):  
149 - return yGetDicomGroups(directory, recursive, gui=False).next() 327 + ##TODO: Is this commented update necessary?
  328 + ##grouper.Update()
  329 + #yield grouper.GetPatientsGroups()
  330 +
  331 +#def GetDicomGroups(directory, recursive=True):
  332 +# return yGetDicomGroups(directory, recursive, gui=False).next()
150 333
151 334
152 class ProgressDicomReader: 335 class ProgressDicomReader:
@@ -158,7 +341,7 @@ class ProgressDicomReader: @@ -158,7 +341,7 @@ class ProgressDicomReader:
158 self.stoped = True 341 self.stoped = True
159 342
160 def SetWindowEvent(self, frame): 343 def SetWindowEvent(self, frame):
161 - self.frame = frame 344 + self.frame = frame
162 345
163 def SetDirectoryPath(self, path,recursive=True): 346 def SetDirectoryPath(self, path,recursive=True):
164 self.running = True 347 self.running = True
@@ -193,4 +376,5 @@ class ProgressDicomReader: @@ -193,4 +376,5 @@ class ProgressDicomReader:
193 #the load, ensure that dicomdialog is closed 376 #the load, ensure that dicomdialog is closed
194 if(self.stoped): 377 if(self.stoped):
195 self.UpdateLoadFileProgress(None) 378 self.UpdateLoadFileProgress(None)
196 - self.stoped = False 379 + self.stoped = False
  380 +
invesalius/utils.py
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 import platform 19 import platform
20 import sigar 20 import sigar
21 import sys 21 import sys
22 - 22 +import re
23 23
24 def debug(error_str): 24 def debug(error_str):
25 """ 25 """
@@ -79,6 +79,21 @@ def next_copy_name(original_name, names_list): @@ -79,6 +79,21 @@ def next_copy_name(original_name, names_list):
79 return next_copy 79 return next_copy
80 80
81 81
  82 +def VerifyInvalidPListCharacter(text):
  83 + #print text
  84 + #text = unicode(text)
  85 +
  86 + _controlCharPat = re.compile(
  87 + r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
  88 + r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
  89 + m = _controlCharPat.search(text)
  90 +
  91 + if m is not None:
  92 + return True
  93 + else:
  94 + False
  95 +
  96 +
82 #http://www.garyrobinson.net/2004/03/python_singleto.html 97 #http://www.garyrobinson.net/2004/03/python_singleto.html
83 # Gary Robinson 98 # Gary Robinson
84 class Singleton(type): 99 class Singleton(type):