1 """ Abstract superclass for Pyllar plottable objects."""
2
3
4 from Figure import *
5 import vtk
6 from numpy import *
7 from Utils import *
8
10
12 """ Create an instance of Plottable.
13 """
14
15 self.mapper = vtk.vtkPolyDataMapper()
16 self.actor = vtk.vtkActor()
17 self.pos = array([0.0,0.0,0.0])
18 self.direction = array([0.0,0.0,1.0])
19 self.axes = Axes()
20
21
23 """ Add object to current axes.
24
25 This method should be called by all Plottable subclasses
26 in the __init__ method. This method will work for all
27 Plottables with only one actor. Otherwise, it has to be
28 overwritten in the subclass.
29 """
30 self.axes = gca()
31 self.axes.ren.AddActor(self.actor)
32 self.axes.AddChild(self)
33
34
36 """ Get the bounding box of the actor.
37 """
38 bounds = self.actor.GetBounds()
39 return array(bounds)
40
41
43 """ Set the scale of the actor.
44
45 The actor is scaled to fit into the normalized axes dimensions.
46 """
47 self.actor.SetScale(scale)
48
49
51 """ Set the position of the actor.
52
53 The position is with respect to the normalized
54 axes dimensions.
55 """
56 actorCenter = array(self.actor.GetPosition())
57
58 pos = -2 * viewCenter / viewRange
59 self.actor.SetPosition(pos)
60
61
63 """ set the direction vector.
64
65 The direction is a vector defining the axis of axismmetric
66 objects or z axis of data.
67 """
68
69
70 pos = array(self.object.GetCenter())
71 self.object.SetCenter(0, 0, 0)
72 norm = cross(self.direction, dir)
73 d = dot(self.direction, dir)
74 theta = arccos(d)
75 thetaDeg = rad2deg(theta)
76 self.actor.RotateWXYZ(thetaDeg, norm[0], norm[1], norm[2])
77
78
79 self.direction = dir
80
81 newPos = pos*cos(theta) + cross(norm, pos)*sin(theta) + dot(norm, pos)*norm*(1-cos(theta))
82 self.object.SetCenter(newPos[0], -newPos[1], -newPos[2])
83
84
85
87 """ Set the color as an RGB array.
88
89 For Plot3 class, the color can also be defined as a part
90 of the style string.
91 """
92 props = self.actor.GetProperty()
93 props.SetColor(rgb)
94 self.actor.SetProperty(props)
95
96
98 """ Set the opacity of the actor.
99 """
100 props = self.actor.GetProperty()
101 props.SetOpacity(opacitiy)
102 self.actor.SetProperty(props)
103