Commit fe2987186f0182cd771d3612cf971a6272cf0ae5

Authored by tatiana
1 parent e3d255a7

ENC: Gantry tilt dialog, dicom import enhacements

invesalius/control.py
@@ -9,6 +9,7 @@ import project as prj @@ -9,6 +9,7 @@ import project as prj
9 import data.imagedata_utils as utils 9 import data.imagedata_utils as utils
10 import data.surface as surface 10 import data.surface as surface
11 import data.volume as volume 11 import data.volume as volume
  12 +import gui.dialogs as dialog
12 import reader.dicom_reader as dcm 13 import reader.dicom_reader as dcm
13 import reader.analyze_reader as analyze 14 import reader.analyze_reader as analyze
14 15
@@ -52,9 +53,10 @@ class Controller(): @@ -52,9 +53,10 @@ class Controller():
52 proj.name = "Untitled" 53 proj.name = "Untitled"
53 54
54 if output: 55 if output:
55 - #acquisition_modality, tilt_value, orientation,window, level 56 + # In this case, there were DICOM files on the folder
56 imagedata, dicom = output 57 imagedata, dicom = output
57 - 58 +
  59 + # Set orientation
58 orientation = dicom.image.orientation_label 60 orientation = dicom.image.orientation_label
59 if (orientation == "CORONAL"): 61 if (orientation == "CORONAL"):
60 orientation = const.CORONAL 62 orientation = const.CORONAL
@@ -62,16 +64,20 @@ class Controller(): @@ -62,16 +64,20 @@ class Controller():
62 orientation = const.SAGITAL 64 orientation = const.SAGITAL
63 else: 65 else:
64 orientation = const.AXIAL 66 orientation = const.AXIAL
65 -  
66 - window = window = float(dicom.image.window)  
67 - level = level = float(dicom.image.level) 67 +
  68 + # Retrieve window, level, modalit
  69 + window = float(dicom.image.window)
  70 + level = float(dicom.image.level)
68 acquisition_modality = dicom.acquisition.modality 71 acquisition_modality = dicom.acquisition.modality
  72 +
  73 + # If there was gantry tilt, fix it:
69 tilt_value = dicom.acquisition.tilt 74 tilt_value = dicom.acquisition.tilt
70 if (tilt_value): 75 if (tilt_value):
71 - #TODO: Show dialog so user can set not other value  
72 - tilt_value *= -1 76 + # Tell user gantry tilt and fix, according to answer
  77 + message = "Fix gantry tilt applying the degrees bellow"
  78 + value = -1*tilt_value
  79 + tilt_value = dialog.ShowNumberDialog(message, value)
73 imagedata = utils.FixGantryTilt(imagedata, tilt_value) 80 imagedata = utils.FixGantryTilt(imagedata, tilt_value)
74 - print "Fixed Gantry Tilt", str(tilt_value)  
75 else: 81 else:
76 "No DICOM files were found. Trying to read with ITK..." 82 "No DICOM files were found. Trying to read with ITK..."
77 imagedata = analyze.ReadDirectory(dir_) 83 imagedata = analyze.ReadDirectory(dir_)
invesalius/reader/dicom.py
@@ -1198,7 +1198,7 @@ class Parser(): @@ -1198,7 +1198,7 @@ class Parser():
1198 .GetSliceThickness() 1198 .GetSliceThickness()
1199 if (data): 1199 if (data):
1200 return float(data) 1200 return float(data)
1201 - return None 1201 + return 0
1202 1202
1203 def GetImageConvolutionKernel(self): 1203 def GetImageConvolutionKernel(self):
1204 """ 1204 """
@@ -1684,22 +1684,28 @@ class Image(object): @@ -1684,22 +1684,28 @@ class Image(object):
1684 self.position = [1, 1, 1] 1684 self.position = [1, 1, 1]
1685 1685
1686 self.number = parser.GetImageNumber() 1686 self.number = parser.GetImageNumber()
  1687 + print "*****************"
1687 self.spacing = spacing = parser.GetPixelSpacing() 1688 self.spacing = spacing = parser.GetPixelSpacing()
  1689 + print "Spacing:", spacing
1688 self.orientation_label = parser.GetImageOrientationLabel() 1690 self.orientation_label = parser.GetImageOrientationLabel()
1689 self.file = parser.filename 1691 self.file = parser.filename
1690 1692
1691 - if (parser.GetImageThickness()):  
1692 - spacing.append(parser.GetImageThickness())  
1693 - else:  
1694 - try:  
1695 - spacing.append(1.5)  
1696 - except(AttributeError):  
1697 - spacing = [1, 1, 1]  
1698 -  
1699 - spacing[0] = round(spacing[0],2)  
1700 - spacing[1] = round(spacing[1],2)  
1701 - spacing[2] = round(spacing[2],2)  
1702 - self.spacing = spacing 1693 + if self.spacing:
  1694 + print "Thickness:", parser.GetImageThickness()
  1695 + # If the image is "alone", we set thickness as z axis
  1696 + if (parser.GetImageThickness()):
  1697 + spacing.append(parser.GetImageThickness())
  1698 + else:
  1699 + try:
  1700 + spacing.append(1.5)
  1701 + except(AttributeError):
  1702 + spacing = [1, 1, 1]
  1703 +
  1704 + # If there are too many float digits
  1705 + spacing[0] = round(spacing[0],2)
  1706 + spacing[1] = round(spacing[1],2)
  1707 + spacing[2] = round(spacing[2],2)
  1708 + self.spacing = spacing
1703 1709
1704 try: 1710 try:
1705 self.type = parser.GetImageType()[2] 1711 self.type = parser.GetImageType()[2]
invesalius/reader/dicom_grouper.py
@@ -78,7 +78,7 @@ class DicomGroups: @@ -78,7 +78,7 @@ class DicomGroups:
78 """ 78 """
79 return self.groups_dcm 79 return self.groups_dcm
80 80
81 - def GetSplitterTyoe(self): 81 + def GetSplitterType(self):
82 """ 82 """
83 Return Integer with the SplitterType 83 Return Integer with the SplitterType
84 0 option used the name of patient information, 84 0 option used the name of patient information,
@@ -347,4 +347,5 @@ class DicomGroups: @@ -347,4 +347,5 @@ class DicomGroups:
347 spacing = None 347 spacing = None
348 348
349 for information in self.groups_dcm[key][0]: 349 for information in self.groups_dcm[key][0]:
350 - information.image.spacing[2] = spacing 350 + if information.image.spacing:
  351 + information.image.spacing[2] = spacing