Commit 201ada86ca19e429aede3240257baa211ad111c7

Authored by tatiana
1 parent 4a13efb8

ADD: Orientation text actors in volume viewer

invesalius/constants.py
... ... @@ -27,7 +27,7 @@ from project import Project
27 27  
28 28 # VTK text
29 29 TEXT_SIZE = 14
30   -TEXT_SIZE_LARGE = 18
  30 +TEXT_SIZE_LARGE = 16
31 31 TEXT_COLOUR = (1,1,1)
32 32 (X,Y) = (0.03, 0.97)
33 33 TEXT_POS_LEFT_UP = (X, Y)
... ... @@ -36,6 +36,10 @@ TEXT_POS_LEFT_DOWN_SLC = (X, 1-0.93)
36 36 TEXT_POS_RIGHT_UP = (1-X, Y)
37 37 TEXT_POS_RIGHT_DOWN = (1-X, 1-Y)
38 38 TEXT_POSITION = TEXT_POS_LEFT_UP
  39 +TEXT_POS_HCENTRE_UP = (0.5, 0.97)
  40 +TEXT_POS_HCENTRE_DOWN = (0.5, 0.07)
  41 +TEXT_POS_VCENTRE_RIGHT = (0.95, 0.5)
  42 +TEXT_POS_VCENPRE_LEFT = (0.03, 0.5)
39 43  
40 44 # Slice orientation
41 45 AXIAL = 0
... ...
invesalius/data/slice_data.py
... ... @@ -34,11 +34,11 @@ class SliceData(object):
34 34 colour = const.ORIENTATION_COLOUR[self.orientation]
35 35  
36 36 text = vu.Text()
37   - text.BoldOn()
  37 + #text.BoldOn()
38 38 text.SetColour(colour)
39 39 text.SetPosition(const.TEXT_POS_LEFT_DOWN_SLC)
40 40 text.SetSize(const.TEXT_SIZE_LARGE)
41   - text.SetValue("%d" % self.number)
  41 + text.SetValue(self.number)
42 42 self.text = text
43 43  
44 44 def SetCursor(self, cursor):
... ...
invesalius/data/viewer_slice.py
... ... @@ -56,7 +56,7 @@ class Viewer(wx.Panel):
56 56 # The layout from slice_data, the first is number of cols, the second
57 57 # is the number of rows
58 58 self.layout = (1, 1)
59   -
  59 + self.orientation_texts = []
60 60 self.__init_gui()
61 61  
62 62 self.orientation = orientation
... ... @@ -109,15 +109,25 @@ class Viewer(wx.Panel):
109 109 def SetLayout(self, layout):
110 110 self.layout = layout
111 111 if layout == (1,1):
112   - self.wl_text.Show()
  112 + self.ShowTextActors()
113 113 else:
114   - self.wl_text.Hide()
115   -
  114 + self.HideTextActors()
  115 +
116 116 slice_ = sl.Slice()
117 117 self.LoadRenderers(slice_.GetOutput())
118 118 self.__configure_renderers()
119 119 self.__configure_scroll()
120 120  
  121 + def HideTextActors(self):
  122 + self.wl_text.Hide()
  123 + [t.Hide() for t in self.orientation_texts]
  124 +
  125 + def ShowTextActors(self):
  126 + self.wl_text.Show()
  127 + [t.Show() for t in self.orientation_texts]
  128 +
  129 +
  130 +
121 131 def __set_layout(self, pubsub_evt):
122 132 layout = pubsub_evt.data
123 133 self.SetLayout(layout)
... ... @@ -132,6 +142,7 @@ class Viewer(wx.Panel):
132 142 self.cam = ren.GetActiveCamera()
133 143 self.ren = ren
134 144  
  145 +
135 146 def append_mode(self, mode):
136 147 if "ZOOM" in self.modes or "ZOOMSELECT" in self.modes:
137 148 self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
... ... @@ -381,6 +392,47 @@ class Viewer(wx.Panel):
381 392 proj = project.Project()
382 393 self.SetWLText(proj.level, proj.window)
383 394  
  395 + colour = const.ORIENTATION_COLOUR[self.orientation]
  396 +
  397 + #### Orientation text
  398 + if self.orientation == 'AXIAL':
  399 + values = ['R', 'L', 'A', 'P']
  400 + elif self.orientation == 'SAGITAL':
  401 + values = ['R', 'L', 'T', 'B']
  402 + else:
  403 + values = ['P', 'A', 'T', 'B']
  404 +
  405 + left_text = vtku.Text()
  406 + left_text.SetColour(colour)
  407 + left_text.ShadowOff()
  408 + left_text.SetPosition(const.TEXT_POS_VCENPRE_LEFT)
  409 + left_text.SetValue(values[0])
  410 +
  411 + right_text = vtku.Text()
  412 + right_text.SetColour(colour)
  413 + right_text.ShadowOff()
  414 + right_text.SetPosition(const.TEXT_POS_VCENTRE_RIGHT)
  415 + right_text.SetValue(values[1])
  416 +
  417 + up_text = vtku.Text()
  418 + up_text.SetColour(colour)
  419 + up_text.ShadowOff()
  420 + up_text.SetPosition(const.TEXT_POS_HCENTRE_UP)
  421 + up_text.SetValue(values[2])
  422 +
  423 + down_text = vtku.Text()
  424 + down_text.SetColour(colour)
  425 + down_text.ShadowOff()
  426 + down_text.SetPosition(const.TEXT_POS_HCENTRE_DOWN)
  427 + down_text.SetValue(values[3])
  428 +
  429 + self.orientation_texts = [left_text, right_text, up_text,
  430 + down_text]
  431 +
  432 + self.ren.AddActor(left_text.actor)
  433 + self.ren.AddActor(right_text.actor)
  434 + self.ren.AddActor(up_text.actor)
  435 + self.ren.AddActor(down_text.actor)
384 436  
385 437 def Reposition(self, slice_data):
386 438 """
... ...
invesalius/data/vtk_utils.py
... ... @@ -16,9 +16,10 @@
16 16 # PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
17 17 # detalhes.
18 18 #--------------------------------------------------------------------------
19   -import wx.lib.pubsub as ps
20   -import vtk
  19 +import sys
21 20  
  21 +import vtk
  22 +import wx.lib.pubsub as ps
22 23  
23 24 import constants as const
24 25 from gui.dialogs import ProgressDialog
... ... @@ -92,43 +93,39 @@ class Text(object):
92 93 property.SetFontFamilyToArial()
93 94 property.BoldOff()
94 95 property.ItalicOff()
95   - property.ShadowOff()
  96 + property.ShadowOn()
96 97 property.SetJustificationToLeft()
97 98 property.SetVerticalJustificationToTop()
98 99 property.SetColor(const.TEXT_COLOUR)
99 100 self.property = property
100 101  
101   - #mapper = vtk.vtkTextMapper()
102   - #mapper.SetTextProperty(property)
103   - #self.mapper = mapper
  102 + mapper = vtk.vtkTextMapper()
  103 + mapper.SetTextProperty(property)
  104 + self.mapper = mapper
104 105  
105 106 x, y = const.TEXT_POSITION
106   - #actor = vtk.vtkActor2D()
107   - #actor.SetMapper(mapper)
108   - #actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay()
109   - #actor.GetPositionCoordinate().SetValue(x,y)
110   - #self.actor = actor
111   -
112   - actor = vtk.vtkTextActor()
  107 + actor = vtk.vtkActor2D()
  108 + actor.SetMapper(mapper)
113 109 actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay()
114   - actor.GetPositionCoordinate().SetValue(x,y)
115   - actor.GetTextProperty().ShallowCopy(property)
  110 + actor.GetPositionCoordinate().SetValue(x,y)
116 111 self.actor = actor
117 112  
118   - def BoldOn(self):
119   - self.property.BoldOn()
120   - self.actor.GetTextProperty().ShallowCopy(self.property)
121   -
122 113 def SetColour(self, colour):
123 114 self.property.SetColor(colour)
124   - self.actor.GetTextProperty().ShallowCopy(self.property)
  115 +
  116 + def ShadowOff(self):
  117 + self.property.ShadowOff()
125 118  
126 119 def SetSize(self, size):
127 120 self.property.SetFontSize(size)
128   - self.actor.GetTextProperty().ShallowCopy(self.property)
129 121  
130 122 def SetValue(self, value):
131   - self.actor.SetInput(str(value))
  123 + if isinstance(value, int) or isinstance(value, float):
  124 + value = str(value)
  125 + if sys.platform == 'win32':
  126 + value += "" # Otherwise 0 is not shown under win32
  127 +
  128 + self.mapper.SetInput(str(value))
132 129  
133 130 def SetPosition(self, position):
134 131 self.actor.GetPositionCoordinate().SetValue(position[0],
... ... @@ -139,11 +136,10 @@ class Text(object):
139 136  
140 137 def SetJustificationToRight(self):
141 138 self.property.SetJustificationToRight()
142   - self.actor.GetTextProperty().ShallowCopy(self.property)
143 139  
144 140 def SetVerticalJustificationToBottom(self):
145 141 self.property.SetVerticalJustificationToBottom()
146   - self.actor.GetTextProperty().ShallowCopy(self.property)
  142 +
147 143  
148 144 def Show(self, value=1):
149 145 if value:
... ...