Commit aefd974a410622be9d300330702a99e5b76a51f4
1 parent
13f819f7
Exists in
interactor_style
Created a new interactor style to handle Linear measure
Showing
2 changed files
with
39 additions
and
19 deletions
Show diff stats
invesalius/data/styles.py
@@ -23,6 +23,12 @@ from wx.lib.pubsub import pub as Publisher | @@ -23,6 +23,12 @@ from wx.lib.pubsub import pub as Publisher | ||
23 | 23 | ||
24 | import constants as const | 24 | import constants as const |
25 | 25 | ||
26 | +ORIENTATIONS = { | ||
27 | + "AXIAL": const.AXIAL, | ||
28 | + "CORONAL": const.CORONAL, | ||
29 | + "SAGITAL": const.SAGITAL, | ||
30 | + } | ||
31 | + | ||
26 | class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage): | 32 | class BaseImageInteractorStyle(vtk.vtkInteractorStyleImage): |
27 | def __init__(self): | 33 | def __init__(self): |
28 | self.right_pressed = False | 34 | self.right_pressed = False |
@@ -216,6 +222,33 @@ class WWWLInteractorStyle(ZoomInteractorStyle): | @@ -216,6 +222,33 @@ class WWWLInteractorStyle(ZoomInteractorStyle): | ||
216 | self.last_x, self.last_y = iren.GetLastEventPosition() | 222 | self.last_x, self.last_y = iren.GetLastEventPosition() |
217 | 223 | ||
218 | 224 | ||
225 | +class LinearMeasure(ZoomInteractorStyle): | ||
226 | + def __init__(self, orientation, slice_data): | ||
227 | + ZoomInteractorStyle.__init__(self) | ||
228 | + | ||
229 | + self.orientation = orientation | ||
230 | + self.slice_data = slice_data | ||
231 | + | ||
232 | + self.picker = vtk.vtkCellPicker() | ||
233 | + | ||
234 | + self.AddObserver("LeftButtonPressEvent", self.OnInsertLinearMeasurePoint) | ||
235 | + | ||
236 | + def OnInsertLinearMeasurePoint(self, obj, evt): | ||
237 | + iren = obj.GetInteractor() | ||
238 | + x,y = iren.GetEventPosition() | ||
239 | + render = iren.FindPokedRenderer(x, y) | ||
240 | + slice_number = self.slice_data.number | ||
241 | + self.picker.Pick(x, y, 0, render) | ||
242 | + x, y, z = self.picker.GetPickPosition() | ||
243 | + print x, y, z | ||
244 | + if self.picker.GetViewProp(): | ||
245 | + self.render_to_add = self.slice_data.renderer | ||
246 | + Publisher.sendMessage("Add measurement point", | ||
247 | + ((x, y,z), const.LINEAR, | ||
248 | + ORIENTATIONS[self.orientation], | ||
249 | + slice_number)) | ||
250 | + Publisher.sendMessage('Update slice viewer') | ||
251 | + | ||
219 | class ViewerStyle: | 252 | class ViewerStyle: |
220 | def __init__(self): | 253 | def __init__(self): |
221 | self.interactor = None | 254 | self.interactor = None |
invesalius/data/viewer_slice.py
@@ -205,6 +205,12 @@ class Viewer(wx.Panel): | @@ -205,6 +205,12 @@ class Viewer(wx.Panel): | ||
205 | self.interactor.SetInteractorStyle(style) | 205 | self.interactor.SetInteractorStyle(style) |
206 | self.interactor.Render() | 206 | self.interactor.Render() |
207 | 207 | ||
208 | + elif state == const.STATE_MEASURE_DISTANCE: | ||
209 | + style = styles.LinearMeasure(self.orientation, self.slice_data) | ||
210 | + self.style = style | ||
211 | + self.interactor.SetInteractorStyle(style) | ||
212 | + self.interactor.Render() | ||
213 | + | ||
208 | else: | 214 | else: |
209 | self.state = state | 215 | self.state = state |
210 | action = { | 216 | action = { |
@@ -242,10 +248,6 @@ class Viewer(wx.Panel): | @@ -242,10 +248,6 @@ class Viewer(wx.Panel): | ||
242 | const.STATE_DEFAULT: | 248 | const.STATE_DEFAULT: |
243 | { | 249 | { |
244 | }, | 250 | }, |
245 | - const.STATE_MEASURE_DISTANCE: | ||
246 | - { | ||
247 | - "LeftButtonPressEvent": self.OnInsertLinearMeasurePoint | ||
248 | - }, | ||
249 | const.STATE_MEASURE_ANGLE: | 251 | const.STATE_MEASURE_ANGLE: |
250 | { | 252 | { |
251 | "LeftButtonPressEvent": self.OnInsertAngularMeasurePoint | 253 | "LeftButtonPressEvent": self.OnInsertAngularMeasurePoint |
@@ -1451,21 +1453,6 @@ class Viewer(wx.Panel): | @@ -1451,21 +1453,6 @@ class Viewer(wx.Panel): | ||
1451 | coord[index] = extent_min[index] | 1453 | coord[index] = extent_min[index] |
1452 | return coord | 1454 | return coord |
1453 | 1455 | ||
1454 | - def OnInsertLinearMeasurePoint(self, obj, evt): | ||
1455 | - x,y = self.interactor.GetEventPosition() | ||
1456 | - render = self.interactor.FindPokedRenderer(x, y) | ||
1457 | - slice_data = self.get_slice_data(render) | ||
1458 | - slice_number = slice_data.number | ||
1459 | - self.pick.Pick(x, y, 0, render) | ||
1460 | - x, y, z = self.pick.GetPickPosition() | ||
1461 | - print x, y, z | ||
1462 | - if self.pick.GetViewProp(): | ||
1463 | - self.render_to_add = slice_data.renderer | ||
1464 | - Publisher.sendMessage("Add measurement point", | ||
1465 | - ((x, y,z), const.LINEAR, ORIENTATIONS[self.orientation], | ||
1466 | - slice_number)) | ||
1467 | - self.interactor.Render() | ||
1468 | - | ||
1469 | def OnInsertAngularMeasurePoint(self, obj, evt): | 1456 | def OnInsertAngularMeasurePoint(self, obj, evt): |
1470 | x,y = self.interactor.GetEventPosition() | 1457 | x,y = self.interactor.GetEventPosition() |
1471 | render = self.interactor.FindPokedRenderer(x, y) | 1458 | render = self.interactor.FindPokedRenderer(x, y) |