1 |
""" |
2 |
@author: John Ngui |
3 |
@author: Lutz Gross |
4 |
""" |
5 |
|
6 |
import vtk |
7 |
from common import * |
8 |
from colormap import ColorMap |
9 |
|
10 |
class DataCollector(Common): |
11 |
""" |
12 |
Class that deals with data for the visualization. |
13 |
""" |
14 |
|
15 |
def __init__(self, scene, outline = True, cube_axes = True): |
16 |
""" |
17 |
Initialize all the instance variables. |
18 |
|
19 |
@type scene: L{Scene <scene.Scene>} object |
20 |
@param scene: Scene in which components are to be added to |
21 |
@type outline: Boolean (I{True or False}) |
22 |
@param outline: Determines the outline for the rendered object |
23 |
""" |
24 |
|
25 |
self.scene = scene |
26 |
self.outline = outline |
27 |
self.cube_axes = cube_axes |
28 |
self.file_name = None |
29 |
self.vtk_outline = None |
30 |
self.vtk_xml_reader = None |
31 |
self.vtk_xml_reader_output = None |
32 |
|
33 |
def setFileName(self, file_name): |
34 |
""" |
35 |
Set up the file reader and set the file name. |
36 |
|
37 |
@type file_name: String |
38 |
@param file_name: Name of the file to be read. |
39 |
""" |
40 |
|
41 |
self.file_name = file_name |
42 |
self.vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader() |
43 |
self.vtk_xml_reader.SetFileName(self.file_name) |
44 |
|
45 |
if(self.outline == True): |
46 |
self.setOutline() |
47 |
Common.setMapper(self, "self.vtk_outline.GetOutput()") |
48 |
Common.setActor(self) |
49 |
Common.addActor(self) |
50 |
Common.setColor(self, 0, 0, 0) # Default outline is black |
51 |
|
52 |
if(self.cube_axes == True): |
53 |
self.setCubeAxes() |
54 |
|
55 |
def getReader(self): |
56 |
""" |
57 |
Return the file reader. |
58 |
|
59 |
@rtype: vtkXMLUnstructuredGridReader |
60 |
@return: VTK XML unstructured grid reader |
61 |
""" |
62 |
|
63 |
return self.vtk_xml_reader |
64 |
|
65 |
def setOutline(self): |
66 |
""" |
67 |
Set the outline for the rendered object. |
68 |
""" |
69 |
|
70 |
self.vtk_outline = vtk.vtkOutlineFilter() |
71 |
self.vtk_outline.SetInput(self.vtk_xml_reader.GetOutput()) |
72 |
|
73 |
def setCubeAxes(self): |
74 |
vtk_cube_axes = vtk.vtkCubeAxesActor2D() |
75 |
vtk_cube_axes.SetInput(self.vtk_xml_reader.GetOutput()) |
76 |
vtk_cube_axes.SetCamera(self.scene.getRenderer().GetActiveCamera()) |
77 |
vtk_cube_axes.SetLabelFormat("%6.4g") |
78 |
vtk_cube_axes.SetFlyModeToClosestTriad() |
79 |
vtk_cube_axes.SetFontFactor(0.8) |
80 |
|
81 |
self.scene.getRenderer().AddActor(vtk_cube_axes) |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|