Commit bff30dc2c20c1ca0a3d6ed47b4327e3454be0bd7
1 parent
1f3ac7c7
Exists in
master
and in
6 other branches
ENH: Text actors on slice_viewer (show zero under win32)
Showing
4 changed files
with
85 additions
and
11 deletions
Show diff stats
invesalius/constants.py
| ... | ... | @@ -34,9 +34,12 @@ TEXT_SIZE_LARGE = 16 |
| 34 | 34 | TEXT_COLOUR = (1,1,1) |
| 35 | 35 | |
| 36 | 36 | (X,Y) = (0.03, 0.97) |
| 37 | +(XZ, YZ) = (0.05, 0.93) | |
| 37 | 38 | TEXT_POS_LEFT_UP = (X, Y) |
| 38 | 39 | #------------------------------------------------------------------ |
| 39 | 40 | TEXT_POS_LEFT_DOWN = (X, 1-Y) # SetVerticalJustificationToBottom |
| 41 | + | |
| 42 | +TEXT_POS_LEFT_DOWN_ZERO = (X, 1-YZ) | |
| 40 | 43 | #------------------------------------------------------------------ |
| 41 | 44 | TEXT_POS_RIGHT_UP = (1-X, Y) # SetJustificationToRight |
| 42 | 45 | #------------------------------------------------------------------ |
| ... | ... | @@ -45,11 +48,14 @@ TEXT_POS_RIGHT_DOWN = (1-X, 1-Y) # SetVerticalJustificationToBottom & |
| 45 | 48 | #------------------------------------------------------------------ |
| 46 | 49 | TEXT_POS_HCENTRE_DOWN = (0.5, 1-Y) # SetJustificationToCentered |
| 47 | 50 | # ChildrticalJustificationToBottom |
| 51 | + | |
| 52 | +TEXT_POS_HCENTRE_DOWN_ZERO = (0.5, 1-YZ) | |
| 48 | 53 | #------------------------------------------------------------------ |
| 49 | 54 | TEXT_POS_HCENTRE_UP = (0.5, Y) # SetJustificationToCentered |
| 50 | 55 | #------------------------------------------------------------------ |
| 51 | 56 | TEXT_POS_VCENTRE_RIGHT = (1-X, 0.5) # SetVerticalJustificationToCentered |
| 52 | 57 | # SetJustificationToRight |
| 58 | +TEXT_POS_VCENTRE_RIGHT_ZERO = (1-XZ, 0.5) | |
| 53 | 59 | #------------------------------------------------------------------ |
| 54 | 60 | TEXT_POS_VCENTRE_LEFT = (X, 0.5) # SetVerticalJustificationToCentered |
| 55 | 61 | #------------------------------------------------------------------ | ... | ... |
invesalius/data/slice_data.py
| ... | ... | @@ -44,13 +44,12 @@ class SliceData(object): |
| 44 | 44 | def __create_text(self): |
| 45 | 45 | colour = const.ORIENTATION_COLOUR[self.orientation] |
| 46 | 46 | |
| 47 | - text = vu.Text() | |
| 47 | + text = vu.TextZero() | |
| 48 | 48 | text.SetColour(colour) |
| 49 | 49 | text.SetSize(const.TEXT_SIZE_LARGE) |
| 50 | - text.SetPosition(const.TEXT_POS_LEFT_DOWN) | |
| 51 | - text.SetVerticalJustificationToBottom() | |
| 50 | + text.SetPosition(const.TEXT_POS_LEFT_DOWN_ZERO) | |
| 51 | + #text.SetVerticalJustificationToBottom() | |
| 52 | 52 | text.SetValue(self.number) |
| 53 | - #text.ShadowOff() | |
| 54 | 53 | self.text = text |
| 55 | 54 | |
| 56 | 55 | def __create_line_actor(self, line): |
| ... | ... | @@ -139,6 +138,7 @@ class SliceData(object): |
| 139 | 138 | def SetNumber(self, number): |
| 140 | 139 | self.number = number |
| 141 | 140 | self.text.SetValue("%d" % self.number) |
| 141 | + self.text.SetPosition(const.TEXT_POS_LEFT_DOWN_ZERO) | |
| 142 | 142 | |
| 143 | 143 | def SetOrientation(self, orientation): |
| 144 | 144 | self.orientation = orientation | ... | ... |
invesalius/data/viewer_slice.py
| ... | ... | @@ -426,7 +426,7 @@ class Viewer(wx.Panel): |
| 426 | 426 | colour = const.ORIENTATION_COLOUR[self.orientation] |
| 427 | 427 | |
| 428 | 428 | # Window & Level text |
| 429 | - self.wl_text = vtku.Text() | |
| 429 | + self.wl_text = vtku.TextZero() | |
| 430 | 430 | self.SetWLText(proj.level, proj.window) |
| 431 | 431 | |
| 432 | 432 | |
| ... | ... | @@ -438,32 +438,32 @@ class Viewer(wx.Panel): |
| 438 | 438 | else: |
| 439 | 439 | values = [_('R'), _('L'), _('T'), _('B')] |
| 440 | 440 | |
| 441 | - left_text = vtku.Text() | |
| 441 | + left_text = vtku.TextZero() | |
| 442 | 442 | left_text.ShadowOff() |
| 443 | 443 | left_text.SetColour(colour) |
| 444 | 444 | left_text.SetPosition(const.TEXT_POS_VCENTRE_LEFT) |
| 445 | 445 | left_text.SetVerticalJustificationToCentered() |
| 446 | 446 | left_text.SetValue(values[0]) |
| 447 | 447 | |
| 448 | - right_text = vtku.Text() | |
| 448 | + right_text = vtku.TextZero() | |
| 449 | 449 | right_text.ShadowOff() |
| 450 | 450 | right_text.SetColour(colour) |
| 451 | - right_text.SetPosition(const.TEXT_POS_VCENTRE_RIGHT) | |
| 451 | + right_text.SetPosition(const.TEXT_POS_VCENTRE_RIGHT_ZERO) | |
| 452 | 452 | right_text.SetVerticalJustificationToCentered() |
| 453 | 453 | right_text.SetJustificationToRight() |
| 454 | 454 | right_text.SetValue(values[1]) |
| 455 | 455 | |
| 456 | - up_text = vtku.Text() | |
| 456 | + up_text = vtku.TextZero() | |
| 457 | 457 | up_text.ShadowOff() |
| 458 | 458 | up_text.SetColour(colour) |
| 459 | 459 | up_text.SetPosition(const.TEXT_POS_HCENTRE_UP) |
| 460 | 460 | up_text.SetJustificationToCentered() |
| 461 | 461 | up_text.SetValue(values[2]) |
| 462 | 462 | |
| 463 | - down_text = vtku.Text() | |
| 463 | + down_text = vtku.TextZero() | |
| 464 | 464 | down_text.ShadowOff() |
| 465 | 465 | down_text.SetColour(colour) |
| 466 | - down_text.SetPosition(const.TEXT_POS_HCENTRE_DOWN) | |
| 466 | + down_text.SetPosition(const.TEXT_POS_HCENTRE_DOWN_ZERO) | |
| 467 | 467 | down_text.SetJustificationToCentered() |
| 468 | 468 | down_text.SetVerticalJustificationToBottom() |
| 469 | 469 | down_text.SetValue(values[3]) | ... | ... |
invesalius/data/vtk_utils.py
| ... | ... | @@ -162,3 +162,71 @@ class Text(object): |
| 162 | 162 | |
| 163 | 163 | def Hide(self): |
| 164 | 164 | self.actor.VisibilityOff() |
| 165 | + | |
| 166 | +class TextZero(object): | |
| 167 | + def __init__(self): | |
| 168 | + | |
| 169 | + property = vtk.vtkTextProperty() | |
| 170 | + property.SetFontSize(const.TEXT_SIZE_LARGE) | |
| 171 | + property.SetFontFamilyToArial() | |
| 172 | + property.BoldOn() | |
| 173 | + property.ItalicOff() | |
| 174 | + #property.ShadowOn() | |
| 175 | + property.SetJustificationToLeft() | |
| 176 | + property.SetVerticalJustificationToTop() | |
| 177 | + property.SetColor(const.TEXT_COLOUR) | |
| 178 | + self.property = property | |
| 179 | + | |
| 180 | + actor = vtk.vtkTextActor() | |
| 181 | + actor.GetTextProperty().ShallowCopy(property) | |
| 182 | + actor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() | |
| 183 | + self.actor = actor | |
| 184 | + | |
| 185 | + def SetColour(self, colour): | |
| 186 | + self.property.SetColor(colour) | |
| 187 | + | |
| 188 | + def ShadowOff(self): | |
| 189 | + self.property.ShadowOff() | |
| 190 | + | |
| 191 | + def SetSize(self, size): | |
| 192 | + self.property.SetFontSize(size) | |
| 193 | + | |
| 194 | + def SetValue(self, value): | |
| 195 | + if isinstance(value, int) or isinstance(value, float): | |
| 196 | + value = str(value) | |
| 197 | + if sys.platform == 'win32': | |
| 198 | + value += "" # Otherwise 0 is not shown under win32 | |
| 199 | + # With some encoding in some dicom fields (like name) raises a | |
| 200 | + # UnicodeEncodeError because they have non-ascii characters. To avoid | |
| 201 | + # that we encode in utf-8. | |
| 202 | + self.actor.SetInput(value.encode("cp1252")) | |
| 203 | + | |
| 204 | + def SetPosition(self, position): | |
| 205 | + self.actor.GetPositionCoordinate().SetValue(position[0], | |
| 206 | + position[1]) | |
| 207 | + | |
| 208 | + def GetPosition(self, position): | |
| 209 | + self.actor.GetPositionCoordinate().GetValue() | |
| 210 | + | |
| 211 | + def SetJustificationToRight(self): | |
| 212 | + self.property.SetJustificationToRight() | |
| 213 | + | |
| 214 | + def SetJustificationToCentered(self): | |
| 215 | + self.property.SetJustificationToCentered() | |
| 216 | + | |
| 217 | + | |
| 218 | + def SetVerticalJustificationToBottom(self): | |
| 219 | + self.property.SetVerticalJustificationToBottom() | |
| 220 | + | |
| 221 | + def SetVerticalJustificationToCentered(self): | |
| 222 | + self.property.SetVerticalJustificationToCentered() | |
| 223 | + | |
| 224 | + def Show(self, value=1): | |
| 225 | + if value: | |
| 226 | + self.actor.VisibilityOn() | |
| 227 | + else: | |
| 228 | + self.actor.VisibilityOff() | |
| 229 | + | |
| 230 | + def Hide(self): | |
| 231 | + self.actor.VisibilityOff() | |
| 232 | + | ... | ... |