From bff30dc2c20c1ca0a3d6ed47b4327e3454be0bd7 Mon Sep 17 00:00:00 2001 From: tatiana Date: Tue, 26 Jan 2010 23:33:51 +0000 Subject: [PATCH] ENH: Text actors on slice_viewer (show zero under win32) --- invesalius/constants.py | 6 ++++++ invesalius/data/slice_data.py | 8 ++++---- invesalius/data/viewer_slice.py | 14 +++++++------- invesalius/data/vtk_utils.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 576b956..a0f9e08 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -34,9 +34,12 @@ TEXT_SIZE_LARGE = 16 TEXT_COLOUR = (1,1,1) (X,Y) = (0.03, 0.97) +(XZ, YZ) = (0.05, 0.93) TEXT_POS_LEFT_UP = (X, Y) #------------------------------------------------------------------ TEXT_POS_LEFT_DOWN = (X, 1-Y) # SetVerticalJustificationToBottom + +TEXT_POS_LEFT_DOWN_ZERO = (X, 1-YZ) #------------------------------------------------------------------ TEXT_POS_RIGHT_UP = (1-X, Y) # SetJustificationToRight #------------------------------------------------------------------ @@ -45,11 +48,14 @@ TEXT_POS_RIGHT_DOWN = (1-X, 1-Y) # SetVerticalJustificationToBottom & #------------------------------------------------------------------ TEXT_POS_HCENTRE_DOWN = (0.5, 1-Y) # SetJustificationToCentered # ChildrticalJustificationToBottom + +TEXT_POS_HCENTRE_DOWN_ZERO = (0.5, 1-YZ) #------------------------------------------------------------------ TEXT_POS_HCENTRE_UP = (0.5, Y) # SetJustificationToCentered #------------------------------------------------------------------ TEXT_POS_VCENTRE_RIGHT = (1-X, 0.5) # SetVerticalJustificationToCentered # SetJustificationToRight +TEXT_POS_VCENTRE_RIGHT_ZERO = (1-XZ, 0.5) #------------------------------------------------------------------ TEXT_POS_VCENTRE_LEFT = (X, 0.5) # SetVerticalJustificationToCentered #------------------------------------------------------------------ diff --git a/invesalius/data/slice_data.py b/invesalius/data/slice_data.py index 240c787..e07cf74 100644 --- a/invesalius/data/slice_data.py +++ b/invesalius/data/slice_data.py @@ -44,13 +44,12 @@ class SliceData(object): def __create_text(self): colour = const.ORIENTATION_COLOUR[self.orientation] - text = vu.Text() + text = vu.TextZero() text.SetColour(colour) text.SetSize(const.TEXT_SIZE_LARGE) - text.SetPosition(const.TEXT_POS_LEFT_DOWN) - text.SetVerticalJustificationToBottom() + text.SetPosition(const.TEXT_POS_LEFT_DOWN_ZERO) + #text.SetVerticalJustificationToBottom() text.SetValue(self.number) - #text.ShadowOff() self.text = text def __create_line_actor(self, line): @@ -139,6 +138,7 @@ class SliceData(object): def SetNumber(self, number): self.number = number self.text.SetValue("%d" % self.number) + self.text.SetPosition(const.TEXT_POS_LEFT_DOWN_ZERO) def SetOrientation(self, orientation): self.orientation = orientation diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 1afc316..3545e7d 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -426,7 +426,7 @@ class Viewer(wx.Panel): colour = const.ORIENTATION_COLOUR[self.orientation] # Window & Level text - self.wl_text = vtku.Text() + self.wl_text = vtku.TextZero() self.SetWLText(proj.level, proj.window) @@ -438,32 +438,32 @@ class Viewer(wx.Panel): else: values = [_('R'), _('L'), _('T'), _('B')] - left_text = vtku.Text() + left_text = vtku.TextZero() left_text.ShadowOff() left_text.SetColour(colour) left_text.SetPosition(const.TEXT_POS_VCENTRE_LEFT) left_text.SetVerticalJustificationToCentered() left_text.SetValue(values[0]) - right_text = vtku.Text() + right_text = vtku.TextZero() right_text.ShadowOff() right_text.SetColour(colour) - right_text.SetPosition(const.TEXT_POS_VCENTRE_RIGHT) + right_text.SetPosition(const.TEXT_POS_VCENTRE_RIGHT_ZERO) right_text.SetVerticalJustificationToCentered() right_text.SetJustificationToRight() right_text.SetValue(values[1]) - up_text = vtku.Text() + up_text = vtku.TextZero() up_text.ShadowOff() up_text.SetColour(colour) up_text.SetPosition(const.TEXT_POS_HCENTRE_UP) up_text.SetJustificationToCentered() up_text.SetValue(values[2]) - down_text = vtku.Text() + down_text = vtku.TextZero() down_text.ShadowOff() down_text.SetColour(colour) - down_text.SetPosition(const.TEXT_POS_HCENTRE_DOWN) + down_text.SetPosition(const.TEXT_POS_HCENTRE_DOWN_ZERO) down_text.SetJustificationToCentered() down_text.SetVerticalJustificationToBottom() down_text.SetValue(values[3]) diff --git a/invesalius/data/vtk_utils.py b/invesalius/data/vtk_utils.py index 71983ed..5d8fd2c 100644 --- a/invesalius/data/vtk_utils.py +++ b/invesalius/data/vtk_utils.py @@ -162,3 +162,71 @@ class Text(object): def Hide(self): self.actor.VisibilityOff() + +class TextZero(object): + def __init__(self): + + property = vtk.vtkTextProperty() + property.SetFontSize(const.TEXT_SIZE_LARGE) + property.SetFontFamilyToArial() + property.BoldOn() + property.ItalicOff() + #property.ShadowOn() + property.SetJustificationToLeft() + property.SetVerticalJustificationToTop() + property.SetColor(const.TEXT_COLOUR) + self.property = property + + actor = vtk.vtkTextActor() + actor.GetTextProperty().ShallowCopy(property) + actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() + self.actor = actor + + def SetColour(self, colour): + self.property.SetColor(colour) + + def ShadowOff(self): + self.property.ShadowOff() + + def SetSize(self, size): + self.property.SetFontSize(size) + + def SetValue(self, value): + if isinstance(value, int) or isinstance(value, float): + value = str(value) + if sys.platform == 'win32': + value += "" # Otherwise 0 is not shown under win32 + # With some encoding in some dicom fields (like name) raises a + # UnicodeEncodeError because they have non-ascii characters. To avoid + # that we encode in utf-8. + self.actor.SetInput(value.encode("cp1252")) + + def SetPosition(self, position): + self.actor.GetPositionCoordinate().SetValue(position[0], + position[1]) + + def GetPosition(self, position): + self.actor.GetPositionCoordinate().GetValue() + + def SetJustificationToRight(self): + self.property.SetJustificationToRight() + + def SetJustificationToCentered(self): + self.property.SetJustificationToCentered() + + + def SetVerticalJustificationToBottom(self): + self.property.SetVerticalJustificationToBottom() + + def SetVerticalJustificationToCentered(self): + self.property.SetVerticalJustificationToCentered() + + def Show(self, value=1): + if value: + self.actor.VisibilityOn() + else: + self.actor.VisibilityOff() + + def Hide(self): + self.actor.VisibilityOff() + -- libgit2 0.21.2