Commit 9a149f944c2e96174e36515d0f07b4d8a2e123b1
1 parent
e9b40211
Exists in
master
and in
6 other branches
ADD: Single slice preview in import panel (under devel)
Showing
4 changed files
with
157 additions
and
5 deletions
Show diff stats
invesalius/data/vtk_utils.py
... | ... | @@ -113,7 +113,15 @@ class Text(object): |
113 | 113 | self.mapper.SetInput(str(value)) |
114 | 114 | |
115 | 115 | def SetPosition(self, position): |
116 | - self.actor.SetPositionCoordinate().SetValue(position) | |
116 | + self.actor.GetPositionCoordinate().SetValue(position[0], | |
117 | + position[1]) | |
118 | + | |
119 | + def SetJustificationToRight(self): | |
120 | + self.property.SetJustificationToRight() | |
121 | + | |
122 | + def SetVerticalJustificationToBottom(self): | |
123 | + self.property.SetVerticalJustificationToBottom() | |
124 | + | |
117 | 125 | |
118 | 126 | def Show(self, value=1): |
119 | 127 | if value: | ... | ... |
invesalius/gui/dicom_preview_panel.py
... | ... | @@ -22,14 +22,15 @@ |
22 | 22 | |
23 | 23 | #TODO: To create a beautiful API |
24 | 24 | import wx |
25 | -import vtk | |
26 | -import vtkgdcm | |
27 | - | |
28 | 25 | import wx.lib.agw.buttonpanel as bp |
26 | +import vtk | |
29 | 27 | from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor |
30 | -from reader import dicom_reader | |
28 | +import vtkgdcm | |
31 | 29 | |
32 | 30 | |
31 | +import constants as const | |
32 | +from reader import dicom_reader | |
33 | +import data.vtk_utils as vtku | |
33 | 34 | |
34 | 35 | NROWS = 3 |
35 | 36 | NCOLS = 6 |
... | ... | @@ -48,7 +49,105 @@ EVT_SELECT_SERIE = wx.PyEventBinder(myEVT_SELECT_SERIE, 1) |
48 | 49 | myEVT_CLICK = wx.NewEventType() |
49 | 50 | EVT_CLICK = wx.PyEventBinder(myEVT_CLICK, 1) |
50 | 51 | |
52 | +class SingleImagePreview(wx.Panel): | |
53 | + def __init__(self, parent): | |
54 | + wx.Panel.__init__(self, parent, -1) | |
55 | + self.__init_vtk() | |
56 | + self.filelist = [] | |
57 | + self.current_index = 0 | |
58 | + self.window_width = const.WINDOW_LEVEL["Bone"][0] | |
59 | + self.window_level = const.WINDOW_LEVEL["Bone"][1] | |
60 | + | |
61 | + def __init_vtk(self): | |
62 | + actor = vtk.vtkImageActor() | |
63 | + self.actor = actor | |
64 | + | |
65 | + LEFT_UP = (X, Y) = const.TEXT_POSITION | |
66 | + text_image_size = vtku.Text() | |
67 | + text_image_size.SetPosition(LEFT_UP) | |
68 | + text_image_size.SetValue("IMAGE SIZE") | |
69 | + | |
70 | + LEFT_DOWN = (X, 1-Y) | |
71 | + text_image_location = vtku.Text() | |
72 | + text_image_location.SetVerticalJustificationToBottom() | |
73 | + text_image_location.SetPosition(LEFT_DOWN) | |
74 | + text_image_location.SetValue("IMAGE LOCAL") | |
75 | + | |
76 | + value = "ID PATIENT\n TEST" | |
77 | + RIGHT_UP = (1-X, Y) | |
78 | + text_patient = vtku.Text() | |
79 | + text_patient.SetJustificationToRight() | |
80 | + text_patient.SetPosition(RIGHT_UP) | |
81 | + text_patient.SetValue(value) | |
82 | + | |
83 | + value = "DATE\n Made in InVesalius" | |
84 | + RIGHT_DOWN = (1-X, 1-Y) | |
85 | + text_acquisition = vtku.Text() | |
86 | + text_acquisition.SetJustificationToRight() | |
87 | + text_acquisition.SetVerticalJustificationToBottom() | |
88 | + text_acquisition.SetPosition(RIGHT_DOWN) | |
89 | + text_acquisition.SetValue(value) | |
90 | + | |
91 | + renderer = vtk.vtkRenderer() | |
92 | + renderer.AddActor(actor) | |
93 | + renderer.AddActor(text_image_size.actor) | |
94 | + renderer.AddActor(text_image_location.actor) | |
95 | + renderer.AddActor(text_patient.actor) | |
96 | + renderer.AddActor(text_acquisition.actor) | |
97 | + self.renderer = renderer | |
98 | + | |
99 | + style = vtk.vtkInteractorStyleImage() | |
100 | + | |
101 | + interactor = wxVTKRenderWindowInteractor(self, -1, | |
102 | + size=wx.Size(400,400)) | |
103 | + interactor.GetRenderWindow().AddRenderer(renderer) | |
104 | + interactor.SetInteractorStyle(style) | |
105 | + interactor.Render() | |
106 | + self.interactor = interactor | |
107 | + | |
108 | + sizer = wx.BoxSizer(wx.VERTICAL) | |
109 | + sizer.Add(interactor, 1, wx.GROW|wx.EXPAND) | |
110 | + sizer.Fit(self) | |
111 | + self.SetSizer(sizer) | |
112 | + self.Layout() | |
113 | + self.Update() | |
114 | + self.SetAutoLayout(1) | |
115 | + | |
116 | + | |
117 | + def SetDicomGroup(self, group): | |
118 | + self.dicom_list = group.GetHandSortedList() | |
119 | + self.current_index = 0 | |
120 | + self.ShowSlice() | |
51 | 121 | |
122 | + def ShowSlice(self): | |
123 | + index = self.current_index | |
124 | + dicom = self.dicom_list[index] | |
125 | + | |
126 | + filename = dicom.image.file | |
127 | + window_level = dicom.image.level | |
128 | + window_width = dicom.image.window | |
129 | + | |
130 | + reader = vtkgdcm.vtkGDCMImageReader() | |
131 | + reader.SetFileName(filename) | |
132 | + | |
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(colorer.GetOutput()) | |
140 | + #a.SetColorWindow(200) | |
141 | + #a.SetColorLevel(100) | |
142 | + a.Render() | |
143 | + import time | |
144 | + time.sleep(5) | |
145 | + | |
146 | + | |
147 | + self.actor.SetInput(colorer.GetOutput()) | |
148 | + #self.actor.SetInput(reader.GetOutput()) | |
149 | + self.renderer.ResetCamera() | |
150 | + self.interactor.Render() | |
52 | 151 | |
53 | 152 | |
54 | 153 | ... | ... |
invesalius/gui/frame.py
... | ... | @@ -122,6 +122,7 @@ class Frame(wx.Frame): |
122 | 122 | |
123 | 123 | aui_manager.AddPane(imp.Panel(self), wx.aui.AuiPaneInfo(). |
124 | 124 | Name("Import").Centre().Hide(). |
125 | + MaximizeButton(True).Floatable(True). | |
125 | 126 | Caption("Preview medical data to be reconstructed"). |
126 | 127 | CaptionVisible(True)) |
127 | 128 | ... | ... |
invesalius/gui/import_panel.py
... | ... | @@ -318,4 +318,48 @@ class SeriesPanel(wx.Panel): |
318 | 318 | class SlicePanel(wx.Panel): |
319 | 319 | def __init__(self, parent): |
320 | 320 | wx.Panel.__init__(self, parent, -1) |
321 | + self.__init_gui() | |
322 | + self.__bind_evt() | |
323 | + | |
324 | + def __bind_evt(self): | |
325 | + ps.Publisher().subscribe(self.ShowDicomSeries, 'Load dicom preview') | |
326 | + ps.Publisher().subscribe(self.SetDicomSeries, 'Load group into import panel') | |
327 | + ps.Publisher().subscribe(self.SetPatientSeries, 'Load patient into import panel') | |
328 | + | |
329 | + def __init_gui(self): | |
321 | 330 | self.SetBackgroundColour((255,255,255)) |
331 | + print "----------------------------" | |
332 | + self.dicom_preview = dpp.SingleImagePreview(self) | |
333 | + | |
334 | + sizer = wx.BoxSizer(wx.VERTICAL) | |
335 | + sizer.Add(self.dicom_preview, 1, wx.GROW|wx.EXPAND) | |
336 | + sizer.Fit(self) | |
337 | + self.SetSizer(sizer) | |
338 | + self.Layout() | |
339 | + self.Update() | |
340 | + self.SetAutoLayout(1) | |
341 | + self.sizer = sizer | |
342 | + | |
343 | + def SetPatientSeries(self, pubsub_evt): | |
344 | + patient = pubsub_evt.data | |
345 | + group = patient.GetGroups()[0] | |
346 | + self.dicom_preview.SetDicomGroup(group) | |
347 | + self.sizer.Layout() | |
348 | + self.Update() | |
349 | + | |
350 | + | |
351 | + def SetDicomSeries(self, pubsub_evt): | |
352 | + group = pubsub_evt.data | |
353 | + self.dicom_preview.SetDicomGroup(group) | |
354 | + self.sizer.Layout() | |
355 | + self.Update() | |
356 | + | |
357 | + | |
358 | + def ShowDicomSeries(self, pubsub_evt): | |
359 | + patient = pubsub_evt.data | |
360 | + group = patient.GetGroups()[0] | |
361 | + self.dicom_preview.SetDicomGroup(group) | |
362 | + self.sizer.Layout() | |
363 | + self.Update() | |
364 | + | |
365 | + | ... | ... |