diff --git a/invesalius/data/measures.py b/invesalius/data/measures.py index 0f052ed..145f511 100644 --- a/invesalius/data/measures.py +++ b/invesalius/data/measures.py @@ -657,20 +657,59 @@ class AngularMeasure(object): return (self.point_actor3, self.line_actor, self.text_actor) def SetPoint1(self, x, y, z): - self.points[0] = (x, y, z) - self.number_of_points = 1 - self.point_actor1 = self.representation.GetRepresentation(x, y, z) + if self.number_of_points == 0: + self.points[0] = (x, y, z) + self.number_of_points = 1 + self.point_actor1 = self.representation.GetRepresentation(x, y, z) + else: + self.points[0] = (x, y, z) + if len(self.points) == 3: + self.Remove() + self.point_actor1 = self.representation.GetRepresentation(*self.points[0]) + self.point_actor2 = self.representation.GetRepresentation(*self.points[1]) + self.point_actor3 = self.representation.GetRepresentation(*self.points[2]) + self.CreateMeasure() + else: + self.Remove() + self.point_actor1 = self.representation.GetRepresentation(*self.points[0]) + self.point_actor2 = self.representation.GetRepresentation(*self.points[1]) def SetPoint2(self, x, y, z): - self.number_of_points = 2 - self.points[1] = (x, y, z) - self.point_actor2 = self.representation.GetRepresentation(x, y, z) + if self.number_of_points == 1: + self.number_of_points = 2 + self.points[1] = (x, y, z) + self.point_actor2 = self.representation.GetRepresentation(x, y, z) + else: + self.points[1] = (x, y, z) + if len(self.points) == 3: + self.Remove() + self.point_actor1 = self.representation.GetRepresentation(*self.points[0]) + self.point_actor2 = self.representation.GetRepresentation(*self.points[1]) + self.point_actor3 = self.representation.GetRepresentation(*self.points[2]) + self.CreateMeasure() + else: + self.Remove() + self.point_actor1 = self.representation.GetRepresentation(*self.points[0]) + self.point_actor2 = self.representation.GetRepresentation(*self.points[1]) def SetPoint3(self, x, y, z): - self.number_of_points = 3 - self.points[2] = (x, y, z) - self.point_actor3 = self.representation.GetRepresentation(x, y, z) - self.CreateMeasure() + if self.number_of_points == 2: + self.number_of_points = 3 + self.points[2] = (x, y, z) + self.point_actor3 = self.representation.GetRepresentation(x, y, z) + self.CreateMeasure() + else: + self.points[2] = (x, y, z) + if len(self.points) == 3: + self.Remove() + self.point_actor1 = self.representation.GetRepresentation(*self.points[0]) + self.point_actor2 = self.representation.GetRepresentation(*self.points[1]) + self.point_actor3 = self.representation.GetRepresentation(*self.points[2]) + self.CreateMeasure() + else: + self.Remove() + self.point_actor1 = self.representation.GetRepresentation(*self.points[0]) + self.point_actor2 = self.representation.GetRepresentation(*self.points[1]) def CreateMeasure(self): self._draw_line() diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index ce3d54c..22dca7f 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -355,6 +355,8 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): self.measures = MeasureData() self.selected = None + self._type = const.LINEAR + spacing = self.slice_data.actor.GetInput().GetSpacing() if self.orientation == "AXIAL": @@ -372,6 +374,9 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): self.picker = vtk.vtkCellPicker() self.picker.PickFromListOn() + self._bind_events() + + def _bind_events(self): self.AddObserver("LeftButtonPressEvent", self.OnInsertLinearMeasurePoint) self.AddObserver("LeftButtonReleaseEvent", self.OnReleaseMeasurePoint) self.AddObserver("MouseMoveEvent", self.OnMoveMeasurePoint) @@ -387,7 +392,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): if self.picker.GetViewProp(): renderer = self.viewer.slice_data.renderer Publisher.sendMessage("Add measurement point", - ((x, y,z), const.LINEAR, + ((x, y,z), self._type, ORIENTATIONS[self.orientation], slice_number, self.radius)) Publisher.sendMessage('Reload actual slice %s' % self.orientation) @@ -411,6 +416,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): Publisher.sendMessage('Reload actual slice %s' % self.orientation) def CleanUp(self): + self.picker.PickFromListOff() Publisher.sendMessage("Remove incomplete measurements") def _get_pos_clicked(self): @@ -443,45 +449,10 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle): return (n, m, mr) return None -class AngularMeasureInteractorStyle(DefaultInteractorStyle): - """ - Interactor style responsible for insert angular measurements. - """ +class AngularMeasureInteractorStyle(LinearMeasureInteractorStyle): def __init__(self, viewer): - DefaultInteractorStyle.__init__(self, viewer) - - self.viewer = viewer - self.orientation = viewer.orientation - self.slice_data = viewer.slice_data - - spacing = self.slice_data.actor.GetInput().GetSpacing() - - if self.orientation == "AXIAL": - self.radius = min(spacing[1], spacing[2]) * 0.8 - - elif self.orientation == 'CORONAL': - self.radius = min(spacing[0], spacing[1]) * 0.8 - - elif self.orientation == 'SAGITAL': - self.radius = min(spacing[1], spacing[2]) * 0.8 - - self.picker = vtk.vtkCellPicker() - - self.AddObserver("LeftButtonPressEvent", self.OnInsertAngularMeasurePoint) - - def OnInsertAngularMeasurePoint(self, obj, evt): - iren = obj.GetInteractor() - x,y = iren.GetEventPosition() - render = iren.FindPokedRenderer(x, y) - slice_number = self.slice_data.number - self.picker.Pick(x, y, 0, render) - x, y, z = self.picker.GetPickPosition() - if self.picker.GetViewProp(): - Publisher.sendMessage("Add measurement point", - ((x, y,z), const.ANGULAR, - ORIENTATIONS[self.orientation], - slice_number, self.radius)) - self.viewer.interactor.Render() + LinearMeasureInteractorStyle.__init__(self, viewer) + self._type = const.ANGULAR class PanMoveInteractorStyle(DefaultInteractorStyle): -- libgit2 0.21.2