Commit cdcc6888d3563c67dc9e3f3a0b539bf3dc65bf25

Authored by tatiana
1 parent f9dfc67d

ENH: Preview dicom frame

invesalius/data/imagedata_utils.py
@@ -173,13 +173,24 @@ def Read(filename): @@ -173,13 +173,24 @@ def Read(filename):
173 def View(imagedata): 173 def View(imagedata):
174 viewer = vtk.vtkImageViewer() 174 viewer = vtk.vtkImageViewer()
175 viewer.SetInput(imagedata) 175 viewer.SetInput(imagedata)
176 - viewer.SetZSlice(10)  
177 viewer.SetColorWindow(200) 176 viewer.SetColorWindow(200)
178 viewer.SetColorLevel(100) 177 viewer.SetColorLevel(100)
179 viewer.Render() 178 viewer.Render()
180 179
181 import time 180 import time
182 time.sleep(10) 181 time.sleep(10)
  182 +
  183 +def ViewGDCM(imagedata):
  184 + viewer = vtkgdcm.vtkImageColorViewer()
  185 + viewer.SetInput(reader.GetOutput())
  186 + viewer.SetColorWindow(500.)
  187 + viewer.SetColorLevel(50.)
  188 + viewer.Render()
  189 +
  190 + import time
  191 + time.sleep(5)
  192 +
  193 +
183 194
184 def ExtractVOI(imagedata,xi,xf,yi,yf,zi,zf): 195 def ExtractVOI(imagedata,xi,xf,yi,yf,zi,zf):
185 """ 196 """
invesalius/gui/dicom_preview_panel.py
@@ -37,21 +37,15 @@ NCOLS = 6 @@ -37,21 +37,15 @@ NCOLS = 6
37 MAX_VALUE = NCOLS*NROWS 37 MAX_VALUE = NCOLS*NROWS
38 38
39 39
40 -myEVT_SELECT = wx.NewEventType()  
41 -# This event occurs when the user select a preview  
42 -EVT_SELECT = wx.PyEventBinder(myEVT_SELECT, 1)  
43 -  
44 -myEVT_SELECT_SERIE = wx.NewEventType()  
45 -# This event occurs when the user select a preview  
46 -EVT_SELECT_SERIE = wx.PyEventBinder(myEVT_SELECT_SERIE, 1)  
47 -  
48 -  
49 -myEVT_CLICK = wx.NewEventType()  
50 -EVT_CLICK = wx.PyEventBinder(myEVT_CLICK, 1) 40 +STR_SIZE = "Image size: %d x %d"
  41 +STR_LOCAL = "Location: %.2f"
  42 +STR_PATIENT = "%s\n%s"
  43 +STR_ACQ = "%s %s\nMade in InVesalius"
51 44
52 class SingleImagePreview(wx.Panel): 45 class SingleImagePreview(wx.Panel):
53 def __init__(self, parent): 46 def __init__(self, parent):
54 wx.Panel.__init__(self, parent, -1) 47 wx.Panel.__init__(self, parent, -1)
  48 + self.__init_gui()
55 self.__init_vtk() 49 self.__init_vtk()
56 self.filelist = [] 50 self.filelist = []
57 self.current_index = 0 51 self.current_index = 0
@@ -65,28 +59,32 @@ class SingleImagePreview(wx.Panel): @@ -65,28 +59,32 @@ class SingleImagePreview(wx.Panel):
65 LEFT_UP = (X, Y) = const.TEXT_POSITION 59 LEFT_UP = (X, Y) = const.TEXT_POSITION
66 text_image_size = vtku.Text() 60 text_image_size = vtku.Text()
67 text_image_size.SetPosition(LEFT_UP) 61 text_image_size.SetPosition(LEFT_UP)
68 - text_image_size.SetValue("IMAGE SIZE") 62 + text_image_size.SetValue("image size")
  63 + self.text_image_size = text_image_size
69 64
70 LEFT_DOWN = (X, 1-Y) 65 LEFT_DOWN = (X, 1-Y)
71 text_image_location = vtku.Text() 66 text_image_location = vtku.Text()
72 text_image_location.SetVerticalJustificationToBottom() 67 text_image_location.SetVerticalJustificationToBottom()
73 text_image_location.SetPosition(LEFT_DOWN) 68 text_image_location.SetPosition(LEFT_DOWN)
74 - text_image_location.SetValue("IMAGE LOCAL")  
75 -  
76 - value = "ID PATIENT\n TEST" 69 + text_image_location.SetValue("localization")
  70 + self.text_image_location = text_image_location
  71 +
  72 + value = "id\nprotocol"
77 RIGHT_UP = (1-X, Y) 73 RIGHT_UP = (1-X, Y)
78 text_patient = vtku.Text() 74 text_patient = vtku.Text()
79 text_patient.SetJustificationToRight() 75 text_patient.SetJustificationToRight()
80 text_patient.SetPosition(RIGHT_UP) 76 text_patient.SetPosition(RIGHT_UP)
81 text_patient.SetValue(value) 77 text_patient.SetValue(value)
82 -  
83 - value = "DATE\n Made in InVesalius" 78 + self.text_patient = text_patient
  79 +
  80 + value = "date time\n Made in InVesalius"
84 RIGHT_DOWN = (1-X, 1-Y) 81 RIGHT_DOWN = (1-X, 1-Y)
85 text_acquisition = vtku.Text() 82 text_acquisition = vtku.Text()
86 text_acquisition.SetJustificationToRight() 83 text_acquisition.SetJustificationToRight()
87 text_acquisition.SetVerticalJustificationToBottom() 84 text_acquisition.SetVerticalJustificationToBottom()
88 text_acquisition.SetPosition(RIGHT_DOWN) 85 text_acquisition.SetPosition(RIGHT_DOWN)
89 text_acquisition.SetValue(value) 86 text_acquisition.SetValue(value)
  87 + self.text_acquisition = text_acquisition
90 88
91 renderer = vtk.vtkRenderer() 89 renderer = vtk.vtkRenderer()
92 renderer.AddActor(actor) 90 renderer.AddActor(actor)
@@ -98,8 +96,8 @@ class SingleImagePreview(wx.Panel): @@ -98,8 +96,8 @@ class SingleImagePreview(wx.Panel):
98 96
99 style = vtk.vtkInteractorStyleImage() 97 style = vtk.vtkInteractorStyleImage()
100 98
101 - interactor = wxVTKRenderWindowInteractor(self, -1,  
102 - size=wx.Size(400,400)) 99 + interactor = wxVTKRenderWindowInteractor(self.panel, -1,
  100 + size=wx.Size(380,380))
103 interactor.GetRenderWindow().AddRenderer(renderer) 101 interactor.GetRenderWindow().AddRenderer(renderer)
104 interactor.SetInteractorStyle(style) 102 interactor.SetInteractorStyle(style)
105 interactor.Render() 103 interactor.Render()
@@ -107,7 +105,23 @@ class SingleImagePreview(wx.Panel): @@ -107,7 +105,23 @@ class SingleImagePreview(wx.Panel):
107 105
108 sizer = wx.BoxSizer(wx.VERTICAL) 106 sizer = wx.BoxSizer(wx.VERTICAL)
109 sizer.Add(interactor, 1, wx.GROW|wx.EXPAND) 107 sizer.Add(interactor, 1, wx.GROW|wx.EXPAND)
  108 + sizer.Fit(self.panel)
  109 + self.panel.SetSizer(sizer)
  110 + self.Layout()
  111 + self.Update()
  112 +
  113 +
  114 + def __init_gui(self):
  115 + self.panel = wx.Panel(self, -1)
  116 + self.slider = wx.Slider(self, 100, 25, 1, 100, (30, 60), (250, -1),
  117 + wx.SL_HORIZONTAL | wx.SL_AUTOTICKS)
  118 + self.slider.SetTickFreq(1, 1)
  119 +
  120 + sizer = wx.BoxSizer(wx.VERTICAL)
  121 + sizer.Add(self.panel, 20, wx.GROW|wx.EXPAND)
  122 + sizer.Add(self.slider, 1, wx.GROW|wx.EXPAND)
110 sizer.Fit(self) 123 sizer.Fit(self)
  124 +
111 self.SetSizer(sizer) 125 self.SetSizer(sizer)
112 self.Layout() 126 self.Layout()
113 self.Update() 127 self.Update()
@@ -123,34 +137,56 @@ class SingleImagePreview(wx.Panel): @@ -123,34 +137,56 @@ class SingleImagePreview(wx.Panel):
123 index = self.current_index 137 index = self.current_index
124 dicom = self.dicom_list[index] 138 dicom = self.dicom_list[index]
125 139
  140 + # UPDATE GUI
  141 + ## Text related to size
  142 + value = STR_SIZE %(dicom.image.size[0], dicom.image.size[1])
  143 + self.text_image_size.SetValue(value)
  144 +
  145 + ## Text related to slice position
  146 + value = STR_LOCAL %(dicom.image.position[2])
  147 + self.text_image_location.SetValue(value)
  148 +
  149 + ## Text related to patient/ acquisiiton data
  150 + value = STR_PATIENT %(dicom.patient.id,\
  151 + dicom.acquisition.protocol_name)
  152 + self.text_patient.SetValue(value)
  153 +
  154 + ## Text related to acquisition date and time
  155 + value = STR_ACQ % (dicom.acquisition.date,
  156 + dicom.acquisition.time)
  157 + self.text_acquisition.SetValue(value)
  158 +
  159 + # READ FILE
126 filename = dicom.image.file 160 filename = dicom.image.file
127 - window_level = dicom.image.level  
128 - window_width = dicom.image.window  
129 -  
130 reader = vtkgdcm.vtkGDCMImageReader() 161 reader = vtkgdcm.vtkGDCMImageReader()
131 reader.SetFileName(filename) 162 reader.SetFileName(filename)
132 163
133 - #colorer = vtk.vtkImageMapToWindowLevelColors()  
134 - #colorer.SetInput(reader.GetOutput())  
135 - #colorer.SetWindow(float(window_width))  
136 - #colorer.SetLevel(float(window_level))  
137 -  
138 - a = vtkgdcm.vtkImageColorViewer()  
139 - a.SetInput(reader.GetOutput())  
140 - a.SetColorWindow(float(window_width))  
141 - a.SetColorLevel(float(window_level))  
142 - a.Render()  
143 - import time  
144 - time.sleep(5)  
145 - 164 + # ADJUST CONTRAST
  165 + window_level = dicom.image.level
  166 + window_width = dicom.image.window
  167 + colorer = vtk.vtkImageMapToWindowLevelColors()
  168 + colorer.SetInput(reader.GetOutput())
  169 + colorer.SetWindow(float(window_width))
  170 + colorer.SetLevel(float(window_level))
146 171
147 - #self.actor.SetInput(colorer.GetOutput())  
148 - self.actor.SetInput(reader.GetOutput()) 172 + # PLOT IMAGE INTO VIEWER
  173 + self.actor.SetInput(colorer.GetOutput())
149 self.renderer.ResetCamera() 174 self.renderer.ResetCamera()
150 self.interactor.Render() 175 self.interactor.Render()
151 176
152 177
153 178
  179 +myEVT_SELECT = wx.NewEventType()
  180 +# This event occurs when the user select a preview
  181 +EVT_SELECT = wx.PyEventBinder(myEVT_SELECT, 1)
  182 +
  183 +myEVT_SELECT_SERIE = wx.NewEventType()
  184 +# This event occurs when the user select a preview
  185 +EVT_SELECT_SERIE = wx.PyEventBinder(myEVT_SELECT_SERIE, 1)
  186 +
  187 +myEVT_CLICK = wx.NewEventType()
  188 +EVT_CLICK = wx.PyEventBinder(myEVT_CLICK, 1)
  189 +
154 class PreviewEvent(wx.PyCommandEvent): 190 class PreviewEvent(wx.PyCommandEvent):
155 def __init__(self , evtType, id): 191 def __init__(self , evtType, id):
156 wx.PyCommandEvent.__init__(self, evtType, id) 192 wx.PyCommandEvent.__init__(self, evtType, id)
@@ -508,7 +544,6 @@ class DicomPreviewSeries(wx.Panel): @@ -508,7 +544,6 @@ class DicomPreviewSeries(wx.Panel):
508 self.nhidden_last_display = 0 544 self.nhidden_last_display = 0
509 group_list = patient.GetGroups() 545 group_list = patient.GetGroups()
510 self.group_list = group_list 546 self.group_list = group_list
511 - print "LEN:", len(group_list)  
512 n = 0 547 n = 0
513 for group in group_list: 548 for group in group_list:
514 info = (group.dicom.image.file, 549 info = (group.dicom.image.file,
@@ -530,11 +565,9 @@ class DicomPreviewSeries(wx.Panel): @@ -530,11 +565,9 @@ class DicomPreviewSeries(wx.Panel):
530 def _display_previews(self): 565 def _display_previews(self):
531 initial = self.displayed_position * NCOLS 566 initial = self.displayed_position * NCOLS
532 final = initial + MAX_VALUE 567 final = initial + MAX_VALUE
533 - print "len:", len(self.files)  
534 568
535 if len(self.files) < final: 569 if len(self.files) < final:
536 for i in xrange(final-len(self.files)): 570 for i in xrange(final-len(self.files)):
537 - print "hide ", i  
538 try: 571 try:
539 self.previews[-i-1].Hide() 572 self.previews[-i-1].Hide()
540 except IndexError: 573 except IndexError: