Commit e5349ae2bcb47728d4148adde4547f6f2582b3d9

Authored by Thiago Franco de Moraes
1 parent 973bc3c1

Picking only the slice actor when adding measure

invesalius/data/measures.py
... ... @@ -10,6 +10,7 @@ import vtk
10 10 import constants as const
11 11 import project as prj
12 12 import session as ses
  13 +import utils
13 14  
14 15 TYPE = {const.LINEAR: _(u"Linear"),
15 16 const.ANGULAR: _(u"Angular"),
... ... @@ -26,6 +27,7 @@ class MeasureData:
26 27 """
27 28 Responsible to keep measures data.
28 29 """
  30 + __metaclass__= utils.Singleton
29 31 def __init__(self):
30 32 self.measures = {const.SURFACE: {},
31 33 const.AXIAL: {},
... ... @@ -34,7 +36,6 @@ class MeasureData:
34 36 self._list_measures = []
35 37  
36 38 def append(self, m):
37   - print m[0].location, m[0].slice_number
38 39 try:
39 40 self.measures[m[0].location][m[0].slice_number].append(m)
40 41 except KeyError:
... ...
invesalius/data/styles.py
... ... @@ -40,6 +40,8 @@ from scipy.ndimage import watershed_ift, generate_binary_structure
40 40 from skimage.morphology import watershed
41 41 from skimage import filter
42 42  
  43 +from .measures import MeasureData
  44 +
43 45 import watershed_process
44 46  
45 47 import utils
... ... @@ -350,28 +352,37 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
350 352 self.orientation = viewer.orientation
351 353 self.slice_data = viewer.slice_data
352 354  
  355 + self.measures = MeasureData()
  356 +
353 357 spacing = self.slice_data.actor.GetInput().GetSpacing()
354 358  
355 359 if self.orientation == "AXIAL":
356 360 self.radius = min(spacing[1], spacing[2]) * 0.8
  361 + self._ori = const.AXIAL
357 362  
358 363 elif self.orientation == 'CORONAL':
359 364 self.radius = min(spacing[0], spacing[1]) * 0.8
  365 + self._ori = const.CORONAL
360 366  
361 367 elif self.orientation == 'SAGITAL':
362 368 self.radius = min(spacing[1], spacing[2]) * 0.8
  369 + self._ori = const.SAGITAL
363 370  
364 371 self.picker = vtk.vtkCellPicker()
  372 + self.picker.PickFromListOn()
365 373  
366 374 self.AddObserver("LeftButtonPressEvent", self.OnInsertLinearMeasurePoint)
367 375  
368 376 def OnInsertLinearMeasurePoint(self, obj, evt):
369 377 iren = obj.GetInteractor()
370   - x,y = iren.GetEventPosition()
371   - render = iren.FindPokedRenderer(x, y)
  378 + mx,my = iren.GetEventPosition()
  379 + render = iren.FindPokedRenderer(mx, my)
372 380 slice_number = self.slice_data.number
373   - self.picker.Pick(x, y, 0, render)
  381 + self.picker.AddPickList(self.slice_data.actor)
  382 + self.picker.Pick(mx, my, 0, render)
374 383 x, y, z = self.picker.GetPickPosition()
  384 + self.picker.DeletePickList(self.slice_data.actor)
  385 +
375 386 if self.picker.GetViewProp():
376 387 Publisher.sendMessage("Add measurement point",
377 388 ((x, y,z), const.LINEAR,
... ... @@ -379,6 +390,7 @@ class LinearMeasureInteractorStyle(DefaultInteractorStyle):
379 390 slice_number, self.radius))
380 391 self.viewer.interactor.Render()
381 392  
  393 +
382 394 def CleanUp(self):
383 395 Publisher.sendMessage("Remove incomplete measurements")
384 396  
... ...
invesalius/utils.py
... ... @@ -23,6 +23,8 @@ import re
23 23 import locale
24 24 import math
25 25  
  26 +import numpy as np
  27 +
26 28 def format_time(value):
27 29 sp1 = value.split(".")
28 30 sp2 = value.split(":")
... ... @@ -418,3 +420,11 @@ def UpdateCheck():
418 420 if (last!=const.INVESALIUS_VERSION):
419 421 print " ...New update found!!! -> version:", last #, ", url=",url
420 422 wx.CallAfter(wx.CallLater, 1000, _show_update_info)
  423 +
  424 +
  425 +def vtkarray_to_numpy(m):
  426 + nm = np.zeros((4, 4))
  427 + for i in xrange(4):
  428 + for j in xrange(4):
  429 + nm[i, j] = m.GetElement(i, j)
  430 + return nm
... ...