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