From aefd974a410622be9d300330702a99e5b76a51f4 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Fri, 22 Mar 2013 14:43:05 -0300 Subject: [PATCH] Created a new interactor style to handle Linear measure --- invesalius/data/styles.py | 33 +++++++++++++++++++++++++++++++++ invesalius/data/viewer_slice.py | 25 ++++++------------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index 8db9bfa..a99c392 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -23,6 +23,12 @@ from wx.lib.pubsub import pub as Publisher import constants as const +ORIENTATIONS = { + "AXIAL": const.AXIAL, + "CORONAL": const.CORONAL, + "SAGITAL": const.SAGITAL, + } + class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage): def __init__(self): self.right_pressed = False @@ -216,6 +222,33 @@ class WWWLInteractorStyle(ZoomInteractorStyle): self.last_x, self.last_y = iren.GetLastEventPosition() +class LinearMeasure(ZoomInteractorStyle): + def __init__(self, orientation, slice_data): + ZoomInteractorStyle.__init__(self) + + self.orientation = orientation + self.slice_data = slice_data + + self.picker = vtk.vtkCellPicker() + + self.AddObserver("LeftButtonPressEvent", self.OnInsertLinearMeasurePoint) + + def OnInsertLinearMeasurePoint(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() + print x, y, z + if self.picker.GetViewProp(): + self.render_to_add = self.slice_data.renderer + Publisher.sendMessage("Add measurement point", + ((x, y,z), const.LINEAR, + ORIENTATIONS[self.orientation], + slice_number)) + Publisher.sendMessage('Update slice viewer') + class ViewerStyle: def __init__(self): self.interactor = None diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 9505a1c..ff08e8c 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -205,6 +205,12 @@ class Viewer(wx.Panel): self.interactor.SetInteractorStyle(style) self.interactor.Render() + elif state == const.STATE_MEASURE_DISTANCE: + style = styles.LinearMeasure(self.orientation, self.slice_data) + self.style = style + self.interactor.SetInteractorStyle(style) + self.interactor.Render() + else: self.state = state action = { @@ -242,10 +248,6 @@ class Viewer(wx.Panel): const.STATE_DEFAULT: { }, - const.STATE_MEASURE_DISTANCE: - { - "LeftButtonPressEvent": self.OnInsertLinearMeasurePoint - }, const.STATE_MEASURE_ANGLE: { "LeftButtonPressEvent": self.OnInsertAngularMeasurePoint @@ -1451,21 +1453,6 @@ class Viewer(wx.Panel): coord[index] = extent_min[index] return coord - def OnInsertLinearMeasurePoint(self, obj, evt): - x,y = self.interactor.GetEventPosition() - render = self.interactor.FindPokedRenderer(x, y) - slice_data = self.get_slice_data(render) - slice_number = slice_data.number - self.pick.Pick(x, y, 0, render) - x, y, z = self.pick.GetPickPosition() - print x, y, z - if self.pick.GetViewProp(): - self.render_to_add = slice_data.renderer - Publisher.sendMessage("Add measurement point", - ((x, y,z), const.LINEAR, ORIENTATIONS[self.orientation], - slice_number)) - self.interactor.Render() - def OnInsertAngularMeasurePoint(self, obj, evt): x,y = self.interactor.GetEventPosition() render = self.interactor.FindPokedRenderer(x, y) -- libgit2 0.21.2