Commit 1642e140925b6922b33693a00fa429d04c82bfe4
1 parent
15b299ff
Exists in
master
and in
6 other branches
ADD: Window and Level signal
Showing
1 changed file
with
44 additions
and
37 deletions
Show diff stats
invesalius/data/viewer_slice.py
@@ -65,7 +65,7 @@ class Viewer(wx.Panel): | @@ -65,7 +65,7 @@ class Viewer(wx.Panel): | ||
65 | 65 | ||
66 | self.__bind_events() | 66 | self.__bind_events() |
67 | self.__bind_events_wx() | 67 | self.__bind_events_wx() |
68 | - | 68 | + |
69 | 69 | ||
70 | def __init_gui(self): | 70 | def __init_gui(self): |
71 | 71 | ||
@@ -161,7 +161,7 @@ class Viewer(wx.Panel): | @@ -161,7 +161,7 @@ class Viewer(wx.Panel): | ||
161 | action[mode][event]) | 161 | action[mode][event]) |
162 | self.style = style | 162 | self.style = style |
163 | self.interactor.SetInteractorStyle(style) | 163 | self.interactor.SetInteractorStyle(style) |
164 | - | 164 | + |
165 | def EditorMode(self, pubsub_evt): | 165 | def EditorMode(self, pubsub_evt): |
166 | self.append_mode('EDITOR') | 166 | self.append_mode('EDITOR') |
167 | self.mouse_pressed = 0 | 167 | self.mouse_pressed = 0 |
@@ -171,7 +171,7 @@ class Viewer(wx.Panel): | @@ -171,7 +171,7 @@ class Viewer(wx.Panel): | ||
171 | self.append_mode('SPIN') | 171 | self.append_mode('SPIN') |
172 | self.mouse_pressed = 0 | 172 | self.mouse_pressed = 0 |
173 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) | 173 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZING)) |
174 | - | 174 | + |
175 | def ZoomMode(self, pubsub_evt): | 175 | def ZoomMode(self, pubsub_evt): |
176 | self.append_mode('ZOOM') | 176 | self.append_mode('ZOOM') |
177 | self.mouse_pressed = 0 | 177 | self.mouse_pressed = 0 |
@@ -188,20 +188,24 @@ class Viewer(wx.Panel): | @@ -188,20 +188,24 @@ class Viewer(wx.Panel): | ||
188 | ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) | 188 | ICON_IMAGE = wx.Image("../icons/tool_zoom.png",wx.BITMAP_TYPE_PNG) |
189 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) | 189 | self.interactor.SetCursor(wx.CursorFromImage(ICON_IMAGE)) |
190 | 190 | ||
191 | + def WindowLevelMode(self, pubsub_evt): | ||
192 | + #self.append_mode('WINDOWLEVEL') | ||
193 | + print "Window And Level" | ||
194 | + | ||
191 | def ChangeSliceMode(self, pubsub_evt): | 195 | def ChangeSliceMode(self, pubsub_evt): |
192 | self.append_mode('CHANGESLICE') | 196 | self.append_mode('CHANGESLICE') |
193 | self.mouse_pressed = 0 | 197 | self.mouse_pressed = 0 |
194 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) | 198 | self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
195 | 199 | ||
196 | def OnChangeSliceMove(self, evt, obj): | 200 | def OnChangeSliceMove(self, evt, obj): |
197 | - | 201 | + |
198 | min = 0 | 202 | min = 0 |
199 | max = self.actor.GetSliceNumberMax() | 203 | max = self.actor.GetSliceNumberMax() |
200 | - | 204 | + |
201 | if (self.mouse_pressed): | 205 | if (self.mouse_pressed): |
202 | position = self.interactor.GetLastEventPosition() | 206 | position = self.interactor.GetLastEventPosition() |
203 | scroll_position = self.scroll.GetThumbPosition() | 207 | scroll_position = self.scroll.GetThumbPosition() |
204 | - | 208 | + |
205 | if (position[1] > self.last_position) and\ | 209 | if (position[1] > self.last_position) and\ |
206 | (self.acum_achange_slice > min): | 210 | (self.acum_achange_slice > min): |
207 | self.acum_achange_slice -= 1 | 211 | self.acum_achange_slice -= 1 |
@@ -209,22 +213,22 @@ class Viewer(wx.Panel): | @@ -209,22 +213,22 @@ class Viewer(wx.Panel): | ||
209 | (self.acum_achange_slice < max): | 213 | (self.acum_achange_slice < max): |
210 | self.acum_achange_slice += 1 | 214 | self.acum_achange_slice += 1 |
211 | self.last_position = position[1] | 215 | self.last_position = position[1] |
212 | - | 216 | + |
213 | self.scroll.SetThumbPosition(self.acum_achange_slice) | 217 | self.scroll.SetThumbPosition(self.acum_achange_slice) |
214 | self.OnScrollBar() | 218 | self.OnScrollBar() |
215 | 219 | ||
216 | - | 220 | + |
217 | def OnChangeSliceClick(self, evt, obj): | 221 | def OnChangeSliceClick(self, evt, obj): |
218 | self.mouse_pressed = 1 | 222 | self.mouse_pressed = 1 |
219 | position = list(self.interactor.GetLastEventPosition()) | 223 | position = list(self.interactor.GetLastEventPosition()) |
220 | self.acum_achange_slice = self.scroll.GetThumbPosition() | 224 | self.acum_achange_slice = self.scroll.GetThumbPosition() |
221 | self.last_position = position[1] | 225 | self.last_position = position[1] |
222 | - | 226 | + |
223 | def OnPanMove(self, evt, obj): | 227 | def OnPanMove(self, evt, obj): |
224 | if (self.mouse_pressed): | 228 | if (self.mouse_pressed): |
225 | evt.Pan() | 229 | evt.Pan() |
226 | evt.OnRightButtonDown() | 230 | evt.OnRightButtonDown() |
227 | - | 231 | + |
228 | def OnPanClick(self, evt, obj): | 232 | def OnPanClick(self, evt, obj): |
229 | self.mouse_pressed = 1 | 233 | self.mouse_pressed = 1 |
230 | evt.StartPan() | 234 | evt.StartPan() |
@@ -237,12 +241,12 @@ class Viewer(wx.Panel): | @@ -237,12 +241,12 @@ class Viewer(wx.Panel): | ||
237 | def OnZoomClick(self, evt, obj): | 241 | def OnZoomClick(self, evt, obj): |
238 | self.mouse_pressed = 1 | 242 | self.mouse_pressed = 1 |
239 | evt.StartDolly() | 243 | evt.StartDolly() |
240 | - | 244 | + |
241 | def OnUnZoom(self, evt, obj): | 245 | def OnUnZoom(self, evt, obj): |
242 | self.ren.ResetCamera() | 246 | self.ren.ResetCamera() |
243 | self.ren.ResetCameraClippingRange() | 247 | self.ren.ResetCameraClippingRange() |
244 | self.Reposition() | 248 | self.Reposition() |
245 | - | 249 | + |
246 | def OnSpinMove(self, evt, obj): | 250 | def OnSpinMove(self, evt, obj): |
247 | if (self.mouse_pressed): | 251 | if (self.mouse_pressed): |
248 | evt.Spin() | 252 | evt.Spin() |
@@ -265,71 +269,71 @@ class Viewer(wx.Panel): | @@ -265,71 +269,71 @@ class Viewer(wx.Panel): | ||
265 | 269 | ||
266 | def Reposition(self): | 270 | def Reposition(self): |
267 | """ | 271 | """ |
268 | - Based on code of method Zoom in the | ||
269 | - vtkInteractorStyleRubberBandZoom, the of | 272 | + Based on code of method Zoom in the |
273 | + vtkInteractorStyleRubberBandZoom, the of | ||
270 | vtk 5.4.3 | 274 | vtk 5.4.3 |
271 | """ | 275 | """ |
272 | size = self.ren.GetSize() | 276 | size = self.ren.GetSize() |
273 | - | 277 | + |
274 | if (size[0] <= size[1] + 100): | 278 | if (size[0] <= size[1] + 100): |
275 | - | 279 | + |
276 | bound = self.actor.GetBounds() | 280 | bound = self.actor.GetBounds() |
277 | - | 281 | + |
278 | width = abs((bound[3] - bound[2]) * -1) | 282 | width = abs((bound[3] - bound[2]) * -1) |
279 | - height = abs((bound[1] - bound[0]) * -1) | ||
280 | - | ||
281 | - origin = self.ren.GetOrigin() | 283 | + height = abs((bound[1] - bound[0]) * -1) |
284 | + | ||
285 | + origin = self.ren.GetOrigin() | ||
282 | cam = self.ren.GetActiveCamera() | 286 | cam = self.ren.GetActiveCamera() |
283 | - | 287 | + |
284 | min = [] | 288 | min = [] |
285 | min.append(bound[0]) | 289 | min.append(bound[0]) |
286 | min.append(bound[2]) | 290 | min.append(bound[2]) |
287 | - | 291 | + |
288 | rbcenter = [] | 292 | rbcenter = [] |
289 | rbcenter.append(min[0] + 0.5 * width) | 293 | rbcenter.append(min[0] + 0.5 * width) |
290 | rbcenter.append(min[1] + 0.5 * height) | 294 | rbcenter.append(min[1] + 0.5 * height) |
291 | rbcenter.append(0) | 295 | rbcenter.append(0) |
292 | - | 296 | + |
293 | self.ren.SetDisplayPoint(rbcenter) | 297 | self.ren.SetDisplayPoint(rbcenter) |
294 | self.ren.DisplayToView() | 298 | self.ren.DisplayToView() |
295 | self.ren.ViewToWorld() | 299 | self.ren.ViewToWorld() |
296 | - | 300 | + |
297 | worldRBCenter = self.ren.GetWorldPoint() | 301 | worldRBCenter = self.ren.GetWorldPoint() |
298 | worldRBCenter = list(worldRBCenter) | 302 | worldRBCenter = list(worldRBCenter) |
299 | - | 303 | + |
300 | invw = 1.0/worldRBCenter[3] | 304 | invw = 1.0/worldRBCenter[3] |
301 | - | 305 | + |
302 | worldRBCenter[0] *= invw | 306 | worldRBCenter[0] *= invw |
303 | worldRBCenter[1] *= invw | 307 | worldRBCenter[1] *= invw |
304 | worldRBCenter[2] *= invw | 308 | worldRBCenter[2] *= invw |
305 | - | 309 | + |
306 | winCenter = [] | 310 | winCenter = [] |
307 | winCenter.append(origin[0] + 0.5 * size[0]) | 311 | winCenter.append(origin[0] + 0.5 * size[0]) |
308 | winCenter.append(origin[1] + 0.5 * size[1]) | 312 | winCenter.append(origin[1] + 0.5 * size[1]) |
309 | winCenter.append(0) | 313 | winCenter.append(0) |
310 | - | 314 | + |
311 | self.ren.SetDisplayPoint(winCenter) | 315 | self.ren.SetDisplayPoint(winCenter) |
312 | self.ren.DisplayToView() | 316 | self.ren.DisplayToView() |
313 | self.ren.ViewToWorld() | 317 | self.ren.ViewToWorld() |
314 | - | 318 | + |
315 | worldWinCenter = list(self.ren.GetWorldPoint()) | 319 | worldWinCenter = list(self.ren.GetWorldPoint()) |
316 | invw = 1.0/worldWinCenter[3] | 320 | invw = 1.0/worldWinCenter[3] |
317 | worldWinCenter[0] *= invw | 321 | worldWinCenter[0] *= invw |
318 | worldWinCenter[1] *= invw | 322 | worldWinCenter[1] *= invw |
319 | worldWinCenter[2] *= invw | 323 | worldWinCenter[2] *= invw |
320 | - | 324 | + |
321 | translation = [] | 325 | translation = [] |
322 | translation.append(worldRBCenter[0] - worldWinCenter[0]) | 326 | translation.append(worldRBCenter[0] - worldWinCenter[0]) |
323 | translation.append(worldRBCenter[1] - worldWinCenter[1]) | 327 | translation.append(worldRBCenter[1] - worldWinCenter[1]) |
324 | translation.append(worldRBCenter[2] - worldWinCenter[2]) | 328 | translation.append(worldRBCenter[2] - worldWinCenter[2]) |
325 | - | 329 | + |
326 | if (width > height): | 330 | if (width > height): |
327 | - cam.Zoom(size[0] / width) | 331 | + cam.Zoom(size[0] / width) |
328 | else: | 332 | else: |
329 | cam.Zoom(size[1] / height) | 333 | cam.Zoom(size[1] / height) |
330 | - | 334 | + |
331 | self.interactor.Render() | 335 | self.interactor.Render() |
332 | - | 336 | + |
333 | def ChangeBrushSize(self, pubsub_evt): | 337 | def ChangeBrushSize(self, pubsub_evt): |
334 | size = pubsub_evt.data | 338 | size = pubsub_evt.data |
335 | self._brush_cursor_size = size | 339 | self._brush_cursor_size = size |
@@ -570,10 +574,13 @@ class Viewer(wx.Panel): | @@ -570,10 +574,13 @@ class Viewer(wx.Panel): | ||
570 | 'Set Zoom Select Mode') | 574 | 'Set Zoom Select Mode') |
571 | ps.Publisher().subscribe(self.ZoomSelectMode, | 575 | ps.Publisher().subscribe(self.ZoomSelectMode, |
572 | 'Set Zoom Select Mode') | 576 | 'Set Zoom Select Mode') |
573 | - | 577 | + |
574 | ps.Publisher().subscribe(self.ChangeSliceMode, | 578 | ps.Publisher().subscribe(self.ChangeSliceMode, |
575 | 'Set Change Slice Mode') | 579 | 'Set Change Slice Mode') |
576 | - | 580 | + |
581 | + ps.Publisher().subscribe(self.WindowLevelMode, | ||
582 | + 'Bright and contrast adjustment') | ||
583 | + | ||
577 | def ChangeBrushOperation(self, pubsub_evt): | 584 | def ChangeBrushOperation(self, pubsub_evt): |
578 | print pubsub_evt.data | 585 | print pubsub_evt.data |
579 | self._brush_cursor_op = pubsub_evt.data | 586 | self._brush_cursor_op = pubsub_evt.data |
@@ -665,7 +672,7 @@ class Viewer(wx.Panel): | @@ -665,7 +672,7 @@ class Viewer(wx.Panel): | ||
665 | self.append_mode('EDITOR') | 672 | self.append_mode('EDITOR') |
666 | 673 | ||
667 | self.Reposition() | 674 | self.Reposition() |
668 | - | 675 | + |
669 | def __update_cursor_position(self, slice_data, position): | 676 | def __update_cursor_position(self, slice_data, position): |
670 | x, y, z = position | 677 | x, y, z = position |
671 | if (slice_data.cursor): | 678 | if (slice_data.cursor): |