Package pyllar :: Module Plottable
[hide private]
[frames] | no frames]

Source Code for Module pyllar.Plottable

  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  
 
9 -class Plottable:
10
11 - def __init__(self):
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
22 - def AddToAxes(self):
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
35 - def GetBounds(self):
36 """ Get the bounding box of the actor. 37 """ 38 bounds = self.actor.GetBounds() 39 return array(bounds)
40 41
42 - def SetScale(self, scale):
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
50 - def UpdatePos(self, viewRange, viewCenter):
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 # pos = (actorCenter - viewCenter)/2 58 pos = -2 * viewCenter / viewRange 59 self.actor.SetPosition(pos)
60 61
62 - def SetDirection(self, dir):
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 # pos = self.actor.GetPosition() # get the original position 69 # self.actor.SetPosition(0, 0, 0) 70 pos = array(self.object.GetCenter()) # get the original position 71 self.object.SetCenter(0, 0, 0) 72 norm = cross(self.direction, dir) # normal vector of the rotation 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 # self.actor.SetOrientation(angle* norm) 78 # self.actor.RotateX(90) 79 self.direction = dir 80 # self.actor.SetPosition(pos) # reset the original position 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 # self.object.SetCenter(newPos) 84 85
86 - def SetColor(self, rgb):
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() # get the vtk.vtkProperty object 93 props.SetColor(rgb) 94 self.actor.SetProperty(props)
95 96
97 - def SetOpacity(self, opacitiy):
98 """ Set the opacity of the actor. 99 """ 100 props = self.actor.GetProperty() # get the vtk.vtkProperty object 101 props.SetOpacity(opacitiy) 102 self.actor.SetProperty(props)
103