From 6dbca98b38feba54921fe2a15d1f25498b63e6bc Mon Sep 17 00:00:00 2001 From: paulojamorim Date: Mon, 11 Apr 2011 18:09:22 +0000 Subject: [PATCH] FIX: Fixed problem change plane slices in volume view --- invesalius/data/slice_.py | 48 +++++++++++++++++++++++++++++++++++++----------- invesalius/data/viewer_slice.py | 28 +++++++++++++++------------- invesalius/data/viewer_volume.py | 151 +++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------- 3 files changed, 87 insertions(+), 140 deletions(-) diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 76a9940..983007c 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -114,6 +114,7 @@ class Slice(object): 'Change colour table from background image') ps.Publisher().subscribe(self.InputImageWidget, 'Input Image in the widget') + ps.Publisher().subscribe(self.OnExportMask,'Export mask to file') ps.Publisher().subscribe(self.OnCloseProject, 'Close project data') @@ -123,7 +124,8 @@ class Slice(object): ps.Publisher().subscribe(self.OnRemoveMasks, 'Remove masks') ps.Publisher().subscribe(self.OnDuplicateMasks, 'Duplicate masks') - + ps.Publisher().subscribe(self.UpdateSlice3D,'Update slice 3D') + def GetMaxSliceNumber(self, orientation): shape = self.matrix.shape @@ -661,17 +663,41 @@ class Slice(object): def InputImageWidget(self, pubsub_evt): - #widget = pubsub_evt.data - - #flip = vtk.vtkImageFlip() - #flip.SetInput(self.window_level.GetOutput()) - #flip.SetFilteredAxis(1) - #flip.FlipAboutOriginOn() - #flip.Update() - - #widget.SetInput(flip.GetOutput()) - pass + widget, orientation = pubsub_evt.data + original_orientation = Project().original_orientation + + img = self.buffer_slices[orientation].vtk_image + + cast = vtk.vtkImageCast() + cast.SetInput(img) + cast.SetOutputScalarTypeToDouble() + cast.ClampOverflowOn() + cast.Update() + + flip = vtk.vtkImageFlip() + flip.SetInput(cast.GetOutput()) + flip.SetFilteredAxis(1) + flip.FlipAboutOriginOn() + flip.Update() + widget.SetInput(flip.GetOutput()) + + def UpdateSlice3D(self, pubsub_evt): + widget, orientation = pubsub_evt.data + img = self.buffer_slices[orientation].vtk_image + + cast = vtk.vtkImageCast() + cast.SetInput(img) + cast.SetOutputScalarTypeToDouble() + cast.ClampOverflowOn() + cast.Update() + + flip = vtk.vtkImageFlip() + flip.SetInput(cast.GetOutput()) + flip.SetFilteredAxis(1) + flip.FlipAboutOriginOn() + flip.Update() + widget.SetInput(flip.GetOutput()) def CreateMask(self, imagedata=None, name=None, colour=None, opacity=None, threshold_range=None, diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 4078b58..59a9d7c 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -821,6 +821,7 @@ class Viewer(wx.Panel): ps.Publisher().subscribe(self.RemoveActors, ('Remove actors', ORIENTATIONS[self.orientation])) ps.Publisher().subscribe(self.ReloadActualSlice, 'Reload actual slice') + def SetDefaultCursor(self, pusub_evt): self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) @@ -1149,22 +1150,22 @@ class Viewer(wx.Panel): def UpdateSlice3D(self, pos): original_orientation = project.Project().original_orientation pos = self.scroll.GetThumbPosition() - if (self.orientation == "CORONAL") and \ - (original_orientation == const.AXIAL): - pos = abs(self.scroll.GetRange() - pos) - elif(self.orientation == "AXIAL") and \ - (original_orientation == const.CORONAL): - pos = abs(self.scroll.GetRange() - pos) - elif(self.orientation == "AXIAL") and \ - (original_orientation == const.SAGITAL): - pos = abs(self.scroll.GetRange() - pos) + #if (self.orientation == "CORONAL") and \ + # (original_orientation == const.AXIAL): + # pos = abs(self.scroll.GetRange() - pos) + #elif(self.orientation == "AXIAL") and \ + # (original_orientation == const.CORONAL): + # pos = abs(self.scroll.GetRange() - pos) + #elif(self.orientation == "AXIAL") and \ + # (original_orientation == const.SAGITAL): + # pos = abs(self.scroll.GetRange() - pos) ps.Publisher().sendMessage('Change slice from slice plane',\ (self.orientation, pos)) def OnScrollBar(self, evt=None): - pos = self.scroll.GetThumbPosition() + pos = self.scroll.GetThumbPosition() self.set_slice_number(pos) - + self.UpdateSlice3D(pos) if self.state == const.SLICE_STATE_CROSS: # Update other slice's cross according to the new focal point from # the actual orientation. @@ -1172,12 +1173,13 @@ class Viewer(wx.Panel): ps.Publisher().sendMessage('Update cross position', focal_point) ps.Publisher().sendMessage('Update slice viewer') else: - self.interactor.Render() + self.interactor.Render() if evt: evt.Skip() def OnScrollBarRelease(self, evt): - #self.UpdateSlice3D(self.pos) + pos = self.scroll.GetThumbPosition() + #self.UpdateSlice3D(pos) evt.Skip() def OnKeyDown(self, evt=None, obj=None): diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index e05f90b..5da9c91 100755 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -801,120 +801,69 @@ class SlicePlane: self.original_orientation = project.original_orientation self.Create() self.__bind_evt() - self.__bind_vtk_evt() def __bind_evt(self): ps.Publisher().subscribe(self.Enable, 'Enable plane') ps.Publisher().subscribe(self.Disable, 'Disable plane') ps.Publisher().subscribe(self.ChangeSlice, 'Change slice from slice plane') - def __bind_vtk_evt(self): - self.plane_x.AddObserver("InteractionEvent", self.PlaneEvent) - self.plane_y.AddObserver("InteractionEvent", self.PlaneEvent) - self.plane_z.AddObserver("InteractionEvent", self.PlaneEvent) - - def PlaneEvent(self, obj, evt): - number = obj.GetSliceIndex() - plane_axis = obj.GetPlaneOrientation() - if (self.original_orientation == const.AXIAL): - if (plane_axis == 0): - orientation = "SAGITAL" - elif(plane_axis == 1): - orientation = "CORONAL" - dimen = obj.GetInput().GetDimensions() - number = abs(dimen[0] - (number + 1)) - else: - orientation = "AXIAL" - - elif(self.original_orientation == const.SAGITAL): - if (plane_axis == 0): - orientation = "CORONAL" - elif(plane_axis == 1): - orientation = "AXIAL" - dimen = obj.GetInput().GetDimensions() - number = abs(dimen[0] - (number + 1)) - else: - orientation = "SAGITAL" - else: - if (plane_axis == 0): - orientation = "SAGITAL" - elif(plane_axis == 1): - orientation = "AXIAL" - dimen = obj.GetInput().GetDimensions() - number = abs(dimen[0] - (number + 1)) - else: - orientation = "CORONAL" - - if (obj.GetSlicePosition() != 0.0): - ps.Publisher().sendMessage(('Set scroll position', \ - orientation), number) - def Create(self): plane_x = self.plane_x = vtk.vtkImagePlaneWidget() - plane_x.DisplayTextOff() - ps.Publisher().sendMessage('Input Image in the widget', plane_x) + plane_x.InteractionOff() + ps.Publisher().sendMessage('Input Image in the widget', + (plane_x, 'SAGITAL')) plane_x.SetPlaneOrientationToXAxes() plane_x.TextureVisibilityOn() - plane_x.SetLeftButtonAction(1) + plane_x.SetLeftButtonAction(0) plane_x.SetRightButtonAction(0) - prop1 = plane_x.GetPlaneProperty() - prop1.SetColor(0, 0, 1) + plane_x.SetMiddleButtonAction(0) cursor_property = plane_x.GetCursorProperty() cursor_property.SetOpacity(0) plane_y = self.plane_y = vtk.vtkImagePlaneWidget() plane_y.DisplayTextOff() - ps.Publisher().sendMessage('Input Image in the widget', plane_y) + ps.Publisher().sendMessage('Input Image in the widget', + (plane_y, 'CORONAL')) plane_y.SetPlaneOrientationToYAxes() plane_y.TextureVisibilityOn() - plane_y.SetLeftButtonAction(1) + plane_y.SetLeftButtonAction(0) plane_y.SetRightButtonAction(0) + plane_y.SetMiddleButtonAction(0) prop1 = plane_y.GetPlaneProperty() - prop1.SetColor(0, 1, 0) cursor_property = plane_y.GetCursorProperty() cursor_property.SetOpacity(0) plane_z = self.plane_z = vtk.vtkImagePlaneWidget() - plane_z.DisplayTextOff() - ps.Publisher().sendMessage('Input Image in the widget', plane_z) + plane_z.InteractionOff() + ps.Publisher().sendMessage('Input Image in the widget', + (plane_z, 'AXIAL')) plane_z.SetPlaneOrientationToZAxes() plane_z.TextureVisibilityOn() - plane_z.SetLeftButtonAction(1) + plane_z.SetLeftButtonAction(0) plane_z.SetRightButtonAction(0) - prop1 = plane_z.GetPlaneProperty() - prop1.SetColor(1, 0, 0) + plane_z.SetMiddleButtonAction(0) + cursor_property = plane_z.GetCursorProperty() cursor_property.SetOpacity(0) - if(self.original_orientation == const.AXIAL): - prop3 = plane_z.GetPlaneProperty() - prop3.SetColor(1, 0, 0) - - prop1 = plane_x.GetPlaneProperty() - prop1.SetColor(0, 0, 1) - - prop2 = plane_y.GetPlaneProperty() - prop2.SetColor(0, 1, 0) - - elif(self.original_orientation == const.SAGITAL): - prop3 = plane_y.GetPlaneProperty() - prop3.SetColor(1, 0, 0) - prop1 = plane_z.GetPlaneProperty() - prop1.SetColor(0, 0, 1) - - prop2 = plane_x.GetPlaneProperty() - prop2.SetColor(0, 1, 0) - - else: - prop3 = plane_y.GetPlaneProperty() - prop3.SetColor(1, 0, 0) + prop3 = plane_z.GetPlaneProperty() + prop3.SetColor(1, 0, 0) + + selected_prop3 = plane_z.GetSelectedPlaneProperty() + selected_prop3.SetColor(1,0,0) + + prop1 = plane_x.GetPlaneProperty() + prop1.SetColor(0, 0, 1) - prop1 = plane_x.GetPlaneProperty() - prop1.SetColor(0, 0, 1) + selected_prop1 = plane_x.GetSelectedPlaneProperty() + selected_prop1.SetColor(0, 0, 1) + + prop2 = plane_y.GetPlaneProperty() + prop2.SetColor(0, 1, 0) - prop2 = plane_z.GetPlaneProperty() - prop2.SetColor(0, 1, 0) + selected_prop2 = plane_y.GetSelectedPlaneProperty() + selected_prop2.SetColor(0, 1, 0) ps.Publisher().sendMessage('Set Widget Interactor', plane_x) ps.Publisher().sendMessage('Set Widget Interactor', plane_y) @@ -999,42 +948,12 @@ class SlicePlane: def ChangeSlice(self, pubsub_evt = None): orientation, number = pubsub_evt.data - if (self.original_orientation == const.AXIAL): - if (orientation == "CORONAL"): - self.SetSliceNumber(number, "Y") - elif(orientation == "SAGITAL"): - self.SetSliceNumber(number, "X") - else: - self.SetSliceNumber(number, "Z") - - elif(self.original_orientation == const.SAGITAL): - if (orientation == "CORONAL"): - self.SetSliceNumber(number, "X") - elif(orientation == "SAGITAL"): - self.SetSliceNumber(number, "Z") - else: - self.SetSliceNumber(number, "Y") - - else: - if (orientation == "CORONAL"): - self.SetSliceNumber(number, "Z") - elif(orientation == "SAGITAL"): - self.SetSliceNumber(number, "X") - else: - self.SetSliceNumber(number, "Y") - - self.Render() - - def SetSliceNumber(self, number, axis): - if (axis == "X"): - self.plane_x.SetPlaneOrientationToXAxes() - self.plane_x.SetSliceIndex(number) - elif(axis == "Y"): - self.plane_y.SetPlaneOrientationToYAxes() - self.plane_y.SetSliceIndex(number) + if (orientation == "CORONAL"): + ps.Publisher().sendMessage('Update slice 3D', (self.plane_y,orientation)) + elif(orientation == "SAGITAL"): + ps.Publisher().sendMessage('Update slice 3D', (self.plane_x,orientation)) else: - self.plane_z.SetPlaneOrientationToZAxes() - self.plane_z.SetSliceIndex(number) + ps.Publisher().sendMessage('Update slice 3D', (self.plane_z,orientation)) def DeletePlanes(self): del self.plane_x -- libgit2 0.21.2