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

Source Code for Module pyllar.Cube

 1  """ The cube class for Pyllar.""" 
 2   
 3   
 4  from Plottable import Plottable 
 5  import vtk 
 6  from numpy import * 
 7   
8 -class Cube(Plottable):
9 """ The Cube class represents a right, rectangular prism in 3D space. 10 11 The Cube class does not necessarily create a cube, only if dx, dy, and dz are equal. 12 """ 13
14 - def __init__(self, x=0, y=0, z=0, dx=1, dy=1, dz=1):
15 """ Create an isntance of the Cube class. 16 17 x, y, and z are the coordinates of the center of the cube. 18 dx, dy, and dz are the thicknesses of the cube in each dimension. 19 """ 20 21 # create the object 22 self.object = vtk.vtkCubeSource() 23 self.object.SetCenter(x, y, z) 24 self.pos = array([x,y,z]) 25 self.direction = array([1.0,0.0,0.0]) 26 self.object.SetXLength(dx) 27 self.object.SetYLength(dy) 28 self.object.SetZLength(dz) 29 30 # create mapper 31 self.mapper = vtk.vtkPolyDataMapper() 32 self.mapper.SetInput(self.object.GetOutput()) 33 34 # create actor 35 self.actor = vtk.vtkActor() 36 self.actor.SetMapper(self.mapper) 37 # self.actor.SetOrigin(self.actor.GetPosition()) 38 39 # add to the axes 40 self.AddToAxes()
41 42 43 44
45 - def SetDirection(self, dir):
46 """ Set the direction vector (vector defining the z axis of the cube). 47 """ 48 49 self.direction = dir 50 self.object.SetDirection(dir)
51