From 201ada86ca19e429aede3240257baa211ad111c7 Mon Sep 17 00:00:00 2001 From: tatiana Date: Thu, 19 Nov 2009 16:06:14 +0000 Subject: [PATCH] ADD: Orientation text actors in volume viewer --- invesalius/constants.py | 6 +++++- invesalius/data/slice_data.py | 4 ++-- invesalius/data/viewer_slice.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- invesalius/data/vtk_utils.py | 44 ++++++++++++++++++++------------------------ 4 files changed, 83 insertions(+), 31 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index cd2616f..0eeaf6b 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -27,7 +27,7 @@ from project import Project # VTK text TEXT_SIZE = 14 -TEXT_SIZE_LARGE = 18 +TEXT_SIZE_LARGE = 16 TEXT_COLOUR = (1,1,1) (X,Y) = (0.03, 0.97) TEXT_POS_LEFT_UP = (X, Y) @@ -36,6 +36,10 @@ TEXT_POS_LEFT_DOWN_SLC = (X, 1-0.93) TEXT_POS_RIGHT_UP = (1-X, Y) TEXT_POS_RIGHT_DOWN = (1-X, 1-Y) TEXT_POSITION = TEXT_POS_LEFT_UP +TEXT_POS_HCENTRE_UP = (0.5, 0.97) +TEXT_POS_HCENTRE_DOWN = (0.5, 0.07) +TEXT_POS_VCENTRE_RIGHT = (0.95, 0.5) +TEXT_POS_VCENPRE_LEFT = (0.03, 0.5) # Slice orientation AXIAL = 0 diff --git a/invesalius/data/slice_data.py b/invesalius/data/slice_data.py index 0c9e48c..b73b800 100644 --- a/invesalius/data/slice_data.py +++ b/invesalius/data/slice_data.py @@ -34,11 +34,11 @@ class SliceData(object): colour = const.ORIENTATION_COLOUR[self.orientation] text = vu.Text() - text.BoldOn() + #text.BoldOn() text.SetColour(colour) text.SetPosition(const.TEXT_POS_LEFT_DOWN_SLC) text.SetSize(const.TEXT_SIZE_LARGE) - text.SetValue("%d" % self.number) + text.SetValue(self.number) self.text = text def SetCursor(self, cursor): diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 29b31a9..3696b76 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -56,7 +56,7 @@ class Viewer(wx.Panel): # The layout from slice_data, the first is number of cols, the second # is the number of rows self.layout = (1, 1) - + self.orientation_texts = [] self.__init_gui() self.orientation = orientation @@ -109,15 +109,25 @@ class Viewer(wx.Panel): def SetLayout(self, layout): self.layout = layout if layout == (1,1): - self.wl_text.Show() + self.ShowTextActors() else: - self.wl_text.Hide() - + self.HideTextActors() + slice_ = sl.Slice() self.LoadRenderers(slice_.GetOutput()) self.__configure_renderers() self.__configure_scroll() + def HideTextActors(self): + self.wl_text.Hide() + [t.Hide() for t in self.orientation_texts] + + def ShowTextActors(self): + self.wl_text.Show() + [t.Show() for t in self.orientation_texts] + + + def __set_layout(self, pubsub_evt): layout = pubsub_evt.data self.SetLayout(layout) @@ -132,6 +142,7 @@ class Viewer(wx.Panel): self.cam = ren.GetActiveCamera() self.ren = ren + def append_mode(self, mode): if "ZOOM" in self.modes or "ZOOMSELECT" in self.modes: self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) @@ -381,6 +392,47 @@ class Viewer(wx.Panel): proj = project.Project() self.SetWLText(proj.level, proj.window) + colour = const.ORIENTATION_COLOUR[self.orientation] + + #### Orientation text + if self.orientation == 'AXIAL': + values = ['R', 'L', 'A', 'P'] + elif self.orientation == 'SAGITAL': + values = ['R', 'L', 'T', 'B'] + else: + values = ['P', 'A', 'T', 'B'] + + left_text = vtku.Text() + left_text.SetColour(colour) + left_text.ShadowOff() + left_text.SetPosition(const.TEXT_POS_VCENPRE_LEFT) + left_text.SetValue(values[0]) + + right_text = vtku.Text() + right_text.SetColour(colour) + right_text.ShadowOff() + right_text.SetPosition(const.TEXT_POS_VCENTRE_RIGHT) + right_text.SetValue(values[1]) + + up_text = vtku.Text() + up_text.SetColour(colour) + up_text.ShadowOff() + up_text.SetPosition(const.TEXT_POS_HCENTRE_UP) + up_text.SetValue(values[2]) + + down_text = vtku.Text() + down_text.SetColour(colour) + down_text.ShadowOff() + down_text.SetPosition(const.TEXT_POS_HCENTRE_DOWN) + down_text.SetValue(values[3]) + + self.orientation_texts = [left_text, right_text, up_text, + down_text] + + self.ren.AddActor(left_text.actor) + self.ren.AddActor(right_text.actor) + self.ren.AddActor(up_text.actor) + self.ren.AddActor(down_text.actor) def Reposition(self, slice_data): """ diff --git a/invesalius/data/vtk_utils.py b/invesalius/data/vtk_utils.py index 06393c1..efffa4b 100644 --- a/invesalius/data/vtk_utils.py +++ b/invesalius/data/vtk_utils.py @@ -16,9 +16,10 @@ # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais # detalhes. #-------------------------------------------------------------------------- -import wx.lib.pubsub as ps -import vtk +import sys +import vtk +import wx.lib.pubsub as ps import constants as const from gui.dialogs import ProgressDialog @@ -92,43 +93,39 @@ class Text(object): property.SetFontFamilyToArial() property.BoldOff() property.ItalicOff() - property.ShadowOff() + property.ShadowOn() property.SetJustificationToLeft() property.SetVerticalJustificationToTop() property.SetColor(const.TEXT_COLOUR) self.property = property - #mapper = vtk.vtkTextMapper() - #mapper.SetTextProperty(property) - #self.mapper = mapper + mapper = vtk.vtkTextMapper() + mapper.SetTextProperty(property) + self.mapper = mapper x, y = const.TEXT_POSITION - #actor = vtk.vtkActor2D() - #actor.SetMapper(mapper) - #actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() - #actor.GetPositionCoordinate().SetValue(x,y) - #self.actor = actor - - actor = vtk.vtkTextActor() + actor = vtk.vtkActor2D() + actor.SetMapper(mapper) actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() - actor.GetPositionCoordinate().SetValue(x,y) - actor.GetTextProperty().ShallowCopy(property) + actor.GetPositionCoordinate().SetValue(x,y) self.actor = actor - def BoldOn(self): - self.property.BoldOn() - self.actor.GetTextProperty().ShallowCopy(self.property) - def SetColour(self, colour): self.property.SetColor(colour) - self.actor.GetTextProperty().ShallowCopy(self.property) + + def ShadowOff(self): + self.property.ShadowOff() def SetSize(self, size): self.property.SetFontSize(size) - self.actor.GetTextProperty().ShallowCopy(self.property) def SetValue(self, value): - self.actor.SetInput(str(value)) + if isinstance(value, int) or isinstance(value, float): + value = str(value) + if sys.platform == 'win32': + value += "" # Otherwise 0 is not shown under win32 + + self.mapper.SetInput(str(value)) def SetPosition(self, position): self.actor.GetPositionCoordinate().SetValue(position[0], @@ -139,11 +136,10 @@ class Text(object): def SetJustificationToRight(self): self.property.SetJustificationToRight() - self.actor.GetTextProperty().ShallowCopy(self.property) def SetVerticalJustificationToBottom(self): self.property.SetVerticalJustificationToBottom() - self.actor.GetTextProperty().ShallowCopy(self.property) + def Show(self, value=1): if value: -- libgit2 0.21.2