1 |
ksteube |
1147 |
""" |
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 |
jongui |
1154 |
annotate the rendered object (i.e. inserting titles, authors and labels). |
15 |
ksteube |
1147 |
""" |
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.__text = text |
30 |
|
|
self.__viewport = viewport |
31 |
|
|
self._vtk_actor2D = vtk.vtkTextActor() |
32 |
|
|
|
33 |
jongui |
1158 |
self.__setupText2D(scene) |
34 |
ksteube |
1147 |
|
35 |
jongui |
1158 |
def __setupText2D(self, scene): |
36 |
ksteube |
1147 |
""" |
37 |
|
|
Setup the 2D text. |
38 |
jongui |
1158 |
|
39 |
|
|
@type scene: L{Scene <scene.Scene>} object |
40 |
|
|
@param scene: Scene in which objects are to be rendered on |
41 |
ksteube |
1147 |
""" |
42 |
|
|
|
43 |
|
|
self.__setInput() |
44 |
jongui |
1189 |
self.setColor(Color.BLACK) |
45 |
ksteube |
1147 |
# Add the 2D text to the appropriate renderer. |
46 |
jongui |
1158 |
scene._addActor2D(self.__viewport, self._vtk_actor2D) |
47 |
ksteube |
1147 |
|
48 |
|
|
def __setInput(self): |
49 |
|
|
""" |
50 |
|
|
Set the input for the 2D text. |
51 |
|
|
""" |
52 |
|
|
|
53 |
|
|
self._vtk_actor2D.SetInput(self.__text) |
54 |
|
|
|
55 |
|
|
def setFontSize(self, size): |
56 |
|
|
""" |
57 |
|
|
Set the 2D text size. |
58 |
|
|
|
59 |
|
|
@type size: Number |
60 |
|
|
@param size: Size of the 2D text |
61 |
|
|
""" |
62 |
|
|
|
63 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontSize(size) |
64 |
|
|
|
65 |
|
|
def setFontToTimes(self): |
66 |
|
|
""" |
67 |
|
|
Set the 2D text font type to Times New Roman. |
68 |
|
|
""" |
69 |
|
|
|
70 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontFamilyToTimes() |
71 |
|
|
|
72 |
|
|
def setFontToArial(self): |
73 |
|
|
""" |
74 |
|
|
Set the 2D text font type to Arial. |
75 |
|
|
""" |
76 |
|
|
|
77 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontFamilyToArial() |
78 |
|
|
|
79 |
|
|
def setFontToCourier(self): |
80 |
|
|
""" |
81 |
|
|
Set the 2D text front type to Courier. |
82 |
|
|
""" |
83 |
|
|
|
84 |
|
|
self._vtk_actor2D.GetTextProperty().SetFontFamilyToCourier() |
85 |
|
|
|
86 |
|
|
def boldOn(self): |
87 |
|
|
""" |
88 |
|
|
Bold the 2D text. |
89 |
|
|
""" |
90 |
|
|
|
91 |
|
|
self._vtk_actor2D.GetTextProperty().BoldOn() |
92 |
|
|
|
93 |
|
|
def shadowOn(self): |
94 |
|
|
""" |
95 |
|
|
Apply shadow onto the 2D text to ease visibility. |
96 |
|
|
""" |
97 |
|
|
|
98 |
|
|
self._vtk_actor2D.GetTextProperty().ShadowOn() |
99 |
|
|
|
100 |
|
|
def setColor(self, color): |
101 |
|
|
""" |
102 |
|
|
Set the color of the 2D text. |
103 |
|
|
|
104 |
|
|
@type color: L{Color <constant.Color>} constant |
105 |
|
|
@param color: 2D text color |
106 |
|
|
""" |
107 |
|
|
|
108 |
|
|
self._vtk_actor2D.GetTextProperty().SetColor(color) |
109 |
|
|
|