Commit d66bacece62858ea62e650462449be16998a5ba2
1 parent
7d09e69f
Exists in
master
and in
68 other branches
ADD: Planes with slices in volume or surface
Showing
2 changed files
with
106 additions
and
37 deletions
Show diff stats
invesalius/data/slice_.py
| @@ -58,6 +58,8 @@ class Slice(object): | @@ -58,6 +58,8 @@ class Slice(object): | ||
| 58 | 58 | ||
| 59 | ps.Publisher().subscribe(self.UpdateColourTableBackground,\ | 59 | ps.Publisher().subscribe(self.UpdateColourTableBackground,\ |
| 60 | 'Change colour table from background image') | 60 | 'Change colour table from background image') |
| 61 | + | ||
| 62 | + ps.Publisher().subscribe(self.InputImageWidget, 'Input Image in the widget') | ||
| 61 | 63 | ||
| 62 | def __set_current_mask_threshold_limits(self, pubsub_evt): | 64 | def __set_current_mask_threshold_limits(self, pubsub_evt): |
| 63 | thresh_min = pubsub_evt.data[0] | 65 | thresh_min = pubsub_evt.data[0] |
| @@ -427,7 +429,19 @@ class Slice(object): | @@ -427,7 +429,19 @@ class Slice(object): | ||
| 427 | thresh_min, thresh_max = self.window_level.GetOutput().GetScalarRange() | 429 | thresh_min, thresh_max = self.window_level.GetOutput().GetScalarRange() |
| 428 | self.lut_bg.SetTableRange(thresh_min, thresh_max) | 430 | self.lut_bg.SetTableRange(thresh_min, thresh_max) |
| 429 | 431 | ||
| 430 | - | 432 | + |
| 433 | + def InputImageWidget(self, pubsub_evt): | ||
| 434 | + widget = pubsub_evt.data | ||
| 435 | + | ||
| 436 | + flip = vtk.vtkImageFlip() | ||
| 437 | + flip.SetInput(self.window_level.GetOutput()) | ||
| 438 | + flip.SetFilteredAxis(1) | ||
| 439 | + flip.FlipAboutOriginOn() | ||
| 440 | + flip.Update() | ||
| 441 | + | ||
| 442 | + widget.SetInput(flip.GetOutput()) | ||
| 443 | + | ||
| 444 | + | ||
| 431 | def CreateMask(self, imagedata=None, name=None): | 445 | def CreateMask(self, imagedata=None, name=None): |
| 432 | 446 | ||
| 433 | future_mask = Mask() | 447 | future_mask = Mask() |
invesalius/data/viewer_volume.py
| @@ -71,7 +71,7 @@ class Viewer(wx.Panel): | @@ -71,7 +71,7 @@ class Viewer(wx.Panel): | ||
| 71 | 71 | ||
| 72 | self.__bind_events() | 72 | self.__bind_events() |
| 73 | self.__bind_events_wx() | 73 | self.__bind_events_wx() |
| 74 | - | 74 | + |
| 75 | 75 | ||
| 76 | def OnMove(self, obj, evt): | 76 | def OnMove(self, obj, evt): |
| 77 | if self.onclick and self.raycasting_volume: | 77 | if self.onclick and self.raycasting_volume: |
| @@ -234,17 +234,21 @@ class Viewer(wx.Panel): | @@ -234,17 +234,21 @@ class Viewer(wx.Panel): | ||
| 234 | self.text.SetValue("WL: %d WW: %d"%(wl, ww)) | 234 | self.text.SetValue("WL: %d WW: %d"%(wl, ww)) |
| 235 | self.ren.AddActor(self.text.actor) | 235 | self.ren.AddActor(self.text.actor) |
| 236 | self.ren.SetBackground(colour) | 236 | self.ren.SetBackground(colour) |
| 237 | - | ||
| 238 | - | 237 | + |
| 239 | if not (self.view_angle): | 238 | if not (self.view_angle): |
| 240 | self.SetViewAngle(const.VOL_FRONT) | 239 | self.SetViewAngle(const.VOL_FRONT) |
| 241 | else: | 240 | else: |
| 242 | self.ren.ResetCamera() | 241 | self.ren.ResetCamera() |
| 243 | self.ren.ResetCameraClippingRange() | 242 | self.ren.ResetCameraClippingRange() |
| 244 | 243 | ||
| 245 | - | ||
| 246 | self.UpdateRender() | 244 | self.UpdateRender() |
| 247 | 245 | ||
| 246 | + def LoadPlane(self): | ||
| 247 | + self.plane = SlicePlane() | ||
| 248 | + self.plane.EnableX() | ||
| 249 | + self.plane.EnableY() | ||
| 250 | + self.plane.EnableZ() | ||
| 251 | + | ||
| 248 | def ChangeBackgroundColour(self, pubsub_evt): | 252 | def ChangeBackgroundColour(self, pubsub_evt): |
| 249 | colour = pubsub_evt.data | 253 | colour = pubsub_evt.data |
| 250 | self.ren.SetBackground(colour) | 254 | self.ren.SetBackground(colour) |
| @@ -263,7 +267,6 @@ class Viewer(wx.Panel): | @@ -263,7 +267,6 @@ class Viewer(wx.Panel): | ||
| 263 | ren.ResetCamera() | 267 | ren.ResetCamera() |
| 264 | ren.ResetCameraClippingRange() | 268 | ren.ResetCameraClippingRange() |
| 265 | 269 | ||
| 266 | - | ||
| 267 | #self.ShowOrientationCube() | 270 | #self.ShowOrientationCube() |
| 268 | 271 | ||
| 269 | self.interactor.Render() | 272 | self.interactor.Render() |
| @@ -292,40 +295,92 @@ class Viewer(wx.Panel): | @@ -292,40 +295,92 @@ class Viewer(wx.Panel): | ||
| 292 | 295 | ||
| 293 | def UpdateRender(self, evt_pubsub=None): | 296 | def UpdateRender(self, evt_pubsub=None): |
| 294 | self.interactor.Render() | 297 | self.interactor.Render() |
| 295 | - | ||
| 296 | - def CreatePlanes(self): | ||
| 297 | - | ||
| 298 | - imagedata = self.imagedata | ||
| 299 | - ren = self.ren | ||
| 300 | - interactor = self.interactor | ||
| 301 | - | ||
| 302 | - import ivVolumeWidgets as vw | ||
| 303 | - axial_plane = vw.Plane() | ||
| 304 | - axial_plane.SetRender(ren) | ||
| 305 | - axial_plane.SetInteractor(interactor) | ||
| 306 | - axial_plane.SetOrientation(vw.AXIAL) | ||
| 307 | - axial_plane.SetInput(imagedata) | ||
| 308 | - axial_plane.Show() | ||
| 309 | - axial_plane.Update() | ||
| 310 | - | ||
| 311 | - coronal_plane = vw.Plane() | ||
| 312 | - coronal_plane.SetRender(ren) | ||
| 313 | - coronal_plane.SetInteractor(interactor) | ||
| 314 | - coronal_plane.SetOrientation(vw.CORONAL) | ||
| 315 | - coronal_plane.SetInput(imagedata) | ||
| 316 | - coronal_plane.Show() | ||
| 317 | - coronal_plane.Update() | ||
| 318 | - | ||
| 319 | - sagital_plane = vw.Plane() | ||
| 320 | - sagital_plane.SetRender(ren) | ||
| 321 | - sagital_plane.SetInteractor(interactor) | ||
| 322 | - sagital_plane.SetOrientation(vw.SAGITAL) | ||
| 323 | - sagital_plane.SetInput(imagedata) | ||
| 324 | - sagital_plane.Show() | ||
| 325 | - sagital_plane.Update() | ||
| 326 | 298 | ||
| 327 | def SetWidgetInteractor(self, evt_pubsub=None): | 299 | def SetWidgetInteractor(self, evt_pubsub=None): |
| 328 | evt_pubsub.data.SetInteractor(self.interactor._Iren) | 300 | evt_pubsub.data.SetInteractor(self.interactor._Iren) |
| 329 | 301 | ||
| 330 | def AppendActor(self, evt_pubsub=None): | 302 | def AppendActor(self, evt_pubsub=None): |
| 331 | self.ren.AddActor(evt_pubsub.data) | 303 | self.ren.AddActor(evt_pubsub.data) |
| 304 | + | ||
| 305 | + | ||
| 306 | + | ||
| 307 | + | ||
| 308 | +class SlicePlane: | ||
| 309 | + | ||
| 310 | + def __init__(self): | ||
| 311 | + | ||
| 312 | + self.Create() | ||
| 313 | + self.__bind_events() | ||
| 314 | + | ||
| 315 | + def __bind_events(self): | ||
| 316 | + self.plane_x.AddObserver("InteractionEvent", self.Update) | ||
| 317 | + | ||
| 318 | + def Create(self): | ||
| 319 | + | ||
| 320 | + plane_x = self.plane_x = vtk.vtkImagePlaneWidget() | ||
| 321 | + plane_x.DisplayTextOff() | ||
| 322 | + ps.Publisher().sendMessage('Input Image in the widget', plane_x) | ||
| 323 | + plane_x.SetPlaneOrientationToXAxes() | ||
| 324 | + plane_x.TextureVisibilityOn() | ||
| 325 | + plane_x.SetLeftButtonAction(1) | ||
| 326 | + plane_x.SetRightButtonAction(0) | ||
| 327 | + prop1 = plane_x.GetPlaneProperty() | ||
| 328 | + prop1.SetColor(0, 0, 1) | ||
| 329 | + cursor_property = plane_x.GetCursorProperty() | ||
| 330 | + cursor_property.SetOpacity(0) | ||
| 331 | + | ||
| 332 | + plane_y = self.plane_y = vtk.vtkImagePlaneWidget() | ||
| 333 | + plane_y.DisplayTextOff() | ||
| 334 | + ps.Publisher().sendMessage('Input Image in the widget', plane_y) | ||
| 335 | + plane_y.SetPlaneOrientationToYAxes() | ||
| 336 | + plane_y.TextureVisibilityOn() | ||
| 337 | + plane_y.SetLeftButtonAction(1) | ||
| 338 | + plane_y.SetRightButtonAction(0) | ||
| 339 | + prop1 = plane_y.GetPlaneProperty() | ||
| 340 | + prop1.SetColor(0, 1, 0) | ||
| 341 | + cursor_property = plane_y.GetCursorProperty() | ||
| 342 | + cursor_property.SetOpacity(0) | ||
| 343 | + | ||
| 344 | + plane_z = self.plane_z = vtk.vtkImagePlaneWidget() | ||
| 345 | + plane_z.DisplayTextOff() | ||
| 346 | + ps.Publisher().sendMessage('Input Image in the widget', plane_z) | ||
| 347 | + plane_z.SetPlaneOrientationToZAxes() | ||
| 348 | + plane_z.TextureVisibilityOn() | ||
| 349 | + plane_z.SetLeftButtonAction(1) | ||
| 350 | + plane_z.SetRightButtonAction(0) | ||
| 351 | + prop1 = plane_z.GetPlaneProperty() | ||
| 352 | + prop1.SetColor(1, 0, 0) | ||
| 353 | + cursor_property = plane_z.GetCursorProperty() | ||
| 354 | + cursor_property.SetOpacity(0) | ||
| 355 | + | ||
| 356 | + ps.Publisher().sendMessage('Set Widget Interactor', plane_x) | ||
| 357 | + ps.Publisher().sendMessage('Set Widget Interactor', plane_y) | ||
| 358 | + ps.Publisher().sendMessage('Set Widget Interactor', plane_z) | ||
| 359 | + | ||
| 360 | + def EnableX(self, evt_pubsub=None): | ||
| 361 | + self.plane_x.On() | ||
| 362 | + self.Update() | ||
| 363 | + | ||
| 364 | + def EnableY(self, evt_pubsub=None): | ||
| 365 | + self.plane_y.On() | ||
| 366 | + self.Update() | ||
| 367 | + | ||
| 368 | + def EnableZ(self, evt_pubsub=None): | ||
| 369 | + self.plane_z.On() | ||
| 370 | + self.Update() | ||
| 371 | + | ||
| 372 | + def DisableX(self, evt_pubsub=None): | ||
| 373 | + self.plane_x.Off() | ||
| 374 | + self.Update() | ||
| 375 | + | ||
| 376 | + def DisableY(self, evt_pubsub=None): | ||
| 377 | + self.plane_y.Off() | ||
| 378 | + self.Update() | ||
| 379 | + | ||
| 380 | + def DisableZ(self, evt_pubsub=None): | ||
| 381 | + self.plane_z.Off() | ||
| 382 | + self.Update() | ||
| 383 | + | ||
| 384 | + def Update(self, obj, evt): | ||
| 385 | + ps.Publisher().sendMessage('Render volume viewer', None) | ||
| 386 | + | ||
| 332 | \ No newline at end of file | 387 | \ No newline at end of file |