1 |
""" |
2 |
@author: John NGUI |
3 |
""" |
4 |
|
5 |
import vtk |
6 |
from actor import Actor2D |
7 |
from constant import Viewport, Color |
8 |
|
9 |
# NOTE: Actor2D was inherited to allow access to its public methods from |
10 |
# the driver. |
11 |
class Text2D(Actor2D): |
12 |
""" |
13 |
Class that defines a 2D text actor. A two-dimensional text is used to |
14 |
annotate the rendered object (i.e. inserting titles, authors and labels). |
15 |
""" |
16 |
|
17 |
def __init__(self, scene, text, viewport = Viewport.SOUTH_WEST): |
18 |
""" |
19 |
Initialise the 2D text actor. |
20 |
|
21 |
@type scene: L{Scene <scene.Scene>} object |
22 |
@param scene: Scene in which objects are to be rendered on |
23 |
@type text: String |
24 |
@param text: 2D text to be displayed |
25 |
@type viewport: L{Viewport <constant.Viewport>} constant |
26 |
@param viewport: Viewport in which objects are to be rendered on |
27 |
""" |
28 |
|
29 |
self.__scene = scene |
30 |
self.__text = text |
31 |
self.__viewport = viewport |
32 |
self._vtk_actor2D = vtk.vtkTextActor() |
33 |
|
34 |
self.__setupText2D() |
35 |
|
36 |
def __setupText2D(self): |
37 |
""" |
38 |
Setup the 2D text. |
39 |
""" |
40 |
|
41 |
self.__setInput() |
42 |
# Add the 2D text to the appropriate renderer. |
43 |
self.__scene._addActor2D(self.__viewport, self._vtk_actor2D) |
44 |
|
45 |
def __setInput(self): |
46 |
""" |
47 |
Set the input for the 2D text. |
48 |
""" |
49 |
|
50 |
self._vtk_actor2D.SetInput(self.__text) |
51 |
|
52 |
def setFontSize(self, size): |
53 |
""" |
54 |
Set the 2D text size. |
55 |
|
56 |
@type size: Number |
57 |
@param size: Size of the 2D text |
58 |
""" |
59 |
|
60 |
self._vtk_actor2D.GetTextProperty().SetFontSize(size) |
61 |
|
62 |
def setFontToTimes(self): |
63 |
""" |
64 |
Set the 2D text font type to Times New Roman. |
65 |
""" |
66 |
|
67 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToTimes() |
68 |
|
69 |
def setFontToArial(self): |
70 |
""" |
71 |
Set the 2D text font type to Arial. |
72 |
""" |
73 |
|
74 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToArial() |
75 |
|
76 |
def setFontToCourier(self): |
77 |
""" |
78 |
Set the 2D text front type to Courier. |
79 |
""" |
80 |
|
81 |
self._vtk_actor2D.GetTextProperty().SetFontFamilyToCourier() |
82 |
|
83 |
def boldOn(self): |
84 |
""" |
85 |
Bold the 2D text. |
86 |
""" |
87 |
|
88 |
self._vtk_actor2D.GetTextProperty().BoldOn() |
89 |
|
90 |
def shadowOn(self): |
91 |
""" |
92 |
Apply shadow onto the 2D text to ease visibility. |
93 |
""" |
94 |
|
95 |
self._vtk_actor2D.GetTextProperty().ShadowOn() |
96 |
|
97 |
def setColor(self, color): |
98 |
""" |
99 |
Set the color of the 2D text. |
100 |
|
101 |
@type color: L{Color <constant.Color>} constant |
102 |
@param color: 2D text color |
103 |
""" |
104 |
|
105 |
self._vtk_actor2D.GetTextProperty().SetColor(color) |
106 |
|