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