Commit 651829cef1fd79d2bd7b692b03fb3e2bcdf526bc

Authored by Thiago Franco de Moraes
1 parent dc3edb07

Improvements

invesalius/data/measures.py
... ... @@ -657,20 +657,59 @@ class AngularMeasure(object):
657 657 return (self.point_actor3, self.line_actor, self.text_actor)
658 658  
659 659 def SetPoint1(self, x, y, z):
660   - self.points[0] = (x, y, z)
661   - self.number_of_points = 1
662   - self.point_actor1 = self.representation.GetRepresentation(x, y, z)
  660 + if self.number_of_points == 0:
  661 + self.points[0] = (x, y, z)
  662 + self.number_of_points = 1
  663 + self.point_actor1 = self.representation.GetRepresentation(x, y, z)
  664 + else:
  665 + self.points[0] = (x, y, z)
  666 + if len(self.points) == 3:
  667 + self.Remove()
  668 + self.point_actor1 = self.representation.GetRepresentation(*self.points[0])
  669 + self.point_actor2 = self.representation.GetRepresentation(*self.points[1])
  670 + self.point_actor3 = self.representation.GetRepresentation(*self.points[2])
  671 + self.CreateMeasure()
  672 + else:
  673 + self.Remove()
  674 + self.point_actor1 = self.representation.GetRepresentation(*self.points[0])
  675 + self.point_actor2 = self.representation.GetRepresentation(*self.points[1])
663 676  
664 677 def SetPoint2(self, x, y, z):
665   - self.number_of_points = 2
666   - self.points[1] = (x, y, z)
667   - self.point_actor2 = self.representation.GetRepresentation(x, y, z)
  678 + if self.number_of_points == 1:
  679 + self.number_of_points = 2
  680 + self.points[1] = (x, y, z)
  681 + self.point_actor2 = self.representation.GetRepresentation(x, y, z)
  682 + else:
  683 + self.points[1] = (x, y, z)
  684 + if len(self.points) == 3:
  685 + self.Remove()
  686 + self.point_actor1 = self.representation.GetRepresentation(*self.points[0])
  687 + self.point_actor2 = self.representation.GetRepresentation(*self.points[1])
  688 + self.point_actor3 = self.representation.GetRepresentation(*self.points[2])
  689 + self.CreateMeasure()
  690 + else:
  691 + self.Remove()
  692 + self.point_actor1 = self.representation.GetRepresentation(*self.points[0])
  693 + self.point_actor2 = self.representation.GetRepresentation(*self.points[1])
668 694  
669 695 def SetPoint3(self, x, y, z):
670   - self.number_of_points = 3
671   - self.points[2] = (x, y, z)
672   - self.point_actor3 = self.representation.GetRepresentation(x, y, z)
673   - self.CreateMeasure()
  696 + if self.number_of_points == 2:
  697 + self.number_of_points = 3
  698 + self.points[2] = (x, y, z)
  699 + self.point_actor3 = self.representation.GetRepresentation(x, y, z)
  700 + self.CreateMeasure()
  701 + else:
  702 + self.points[2] = (x, y, z)
  703 + if len(self.points) == 3:
  704 + self.Remove()
  705 + self.point_actor1 = self.representation.GetRepresentation(*self.points[0])
  706 + self.point_actor2 = self.representation.GetRepresentation(*self.points[1])
  707 + self.point_actor3 = self.representation.GetRepresentation(*self.points[2])
  708 + self.CreateMeasure()
  709 + else:
  710 + self.Remove()
  711 + self.point_actor1 = self.representation.GetRepresentation(*self.points[0])
  712 + self.point_actor2 = self.representation.GetRepresentation(*self.points[1])
674 713  
675 714 def CreateMeasure(self):
676 715 self._draw_line()
... ...
invesalius/data/styles.py
... ... @@ -355,6 +355,8 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
355 355 self.measures = MeasureData()
356 356 self.selected = None
357 357  
  358 + self._type = const.LINEAR
  359 +
358 360 spacing = self.slice_data.actor.GetInput().GetSpacing()
359 361  
360 362 if self.orientation == "AXIAL":
... ... @@ -372,6 +374,9 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
372 374 self.picker = vtk.vtkCellPicker()
373 375 self.picker.PickFromListOn()
374 376  
  377 + self._bind_events()
  378 +
  379 + def _bind_events(self):
375 380 self.AddObserver("LeftButtonPressEvent", self.OnInsertLinearMeasurePoint)
376 381 self.AddObserver("LeftButtonReleaseEvent", self.OnReleaseMeasurePoint)
377 382 self.AddObserver("MouseMoveEvent", self.OnMoveMeasurePoint)
... ... @@ -387,7 +392,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
387 392 if self.picker.GetViewProp():
388 393 renderer = self.viewer.slice_data.renderer
389 394 Publisher.sendMessage("Add measurement point",
390   - ((x, y,z), const.LINEAR,
  395 + ((x, y,z), self._type,
391 396 ORIENTATIONS[self.orientation],
392 397 slice_number, self.radius))
393 398 Publisher.sendMessage('Reload actual slice %s' % self.orientation)
... ... @@ -411,6 +416,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
411 416 Publisher.sendMessage('Reload actual slice %s' % self.orientation)
412 417  
413 418 def CleanUp(self):
  419 + self.picker.PickFromListOff()
414 420 Publisher.sendMessage("Remove incomplete measurements")
415 421  
416 422 def _get_pos_clicked(self):
... ... @@ -443,45 +449,10 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
443 449 return (n, m, mr)
444 450 return None
445 451  
446   -class AngularMeasureInteractorStyle(DefaultInteractorStyle):
447   - """
448   - Interactor style responsible for insert angular measurements.
449   - """
  452 +class AngularMeasureInteractorStyle(LinearMeasureInteractorStyle):
450 453 def __init__(self, viewer):
451   - DefaultInteractorStyle.__init__(self, viewer)
452   -
453   - self.viewer = viewer
454   - self.orientation = viewer.orientation
455   - self.slice_data = viewer.slice_data
456   -
457   - spacing = self.slice_data.actor.GetInput().GetSpacing()
458   -
459   - if self.orientation == "AXIAL":
460   - self.radius = min(spacing[1], spacing[2]) * 0.8
461   -
462   - elif self.orientation == 'CORONAL':
463   - self.radius = min(spacing[0], spacing[1]) * 0.8
464   -
465   - elif self.orientation == 'SAGITAL':
466   - self.radius = min(spacing[1], spacing[2]) * 0.8
467   -
468   - self.picker = vtk.vtkCellPicker()
469   -
470   - self.AddObserver("LeftButtonPressEvent", self.OnInsertAngularMeasurePoint)
471   -
472   - def OnInsertAngularMeasurePoint(self, obj, evt):
473   - iren = obj.GetInteractor()
474   - x,y = iren.GetEventPosition()
475   - render = iren.FindPokedRenderer(x, y)
476   - slice_number = self.slice_data.number
477   - self.picker.Pick(x, y, 0, render)
478   - x, y, z = self.picker.GetPickPosition()
479   - if self.picker.GetViewProp():
480   - Publisher.sendMessage("Add measurement point",
481   - ((x, y,z), const.ANGULAR,
482   - ORIENTATIONS[self.orientation],
483   - slice_number, self.radius))
484   - self.viewer.interactor.Render()
  454 + LinearMeasureInteractorStyle.__init__(self, viewer)
  455 + self._type = const.ANGULAR
485 456  
486 457  
487 458 class PanMoveInteractorStyle(DefaultInteractorStyle):
... ...