1 |
gross |
792 |
""" |
2 |
jongui |
839 |
@author: John Ngui |
3 |
|
|
@author: Lutz Gross |
4 |
gross |
792 |
""" |
5 |
|
|
|
6 |
jongui |
822 |
import vtk |
7 |
jongui |
828 |
from common import * |
8 |
jongui |
839 |
from colormap import ColorMap |
9 |
gross |
792 |
|
10 |
jongui |
828 |
class DataCollector(Common): |
11 |
jongui |
835 |
""" |
12 |
jongui |
839 |
Class that deals with data for the visualization. |
13 |
jongui |
835 |
""" |
14 |
gross |
792 |
|
15 |
jongui |
847 |
def __init__(self, scene, outline = True, cube_axes = True): |
16 |
jongui |
835 |
""" |
17 |
|
|
Initialize all the instance variables. |
18 |
|
|
|
19 |
jongui |
845 |
@type scene: L{Scene <scene.Scene>} object |
20 |
jongui |
839 |
@param scene: Scene in which components are to be added to |
21 |
jongui |
835 |
@type outline: Boolean (I{True or False}) |
22 |
|
|
@param outline: Determines the outline for the rendered object |
23 |
|
|
""" |
24 |
|
|
|
25 |
jongui |
839 |
self.scene = scene |
26 |
jongui |
847 |
self.outline = outline |
27 |
|
|
self.cube_axes = cube_axes |
28 |
jongui |
822 |
self.file_name = None |
29 |
jongui |
828 |
self.vtk_outline = None |
30 |
jongui |
827 |
self.vtk_xml_reader = None |
31 |
|
|
self.vtk_xml_reader_output = None |
32 |
jongui |
822 |
|
33 |
jongui |
845 |
def setFileName(self, file_name): |
34 |
jongui |
835 |
""" |
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 |
jongui |
822 |
self.file_name = file_name |
42 |
|
|
self.vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader() |
43 |
|
|
self.vtk_xml_reader.SetFileName(self.file_name) |
44 |
|
|
|
45 |
jongui |
827 |
if(self.outline == True): |
46 |
jongui |
828 |
self.setOutline() |
47 |
|
|
Common.setMapper(self, "self.vtk_outline.GetOutput()") |
48 |
|
|
Common.setActor(self) |
49 |
|
|
Common.addActor(self) |
50 |
jongui |
835 |
Common.setColor(self, 0, 0, 0) # Default outline is black |
51 |
jongui |
847 |
|
52 |
|
|
if(self.cube_axes == True): |
53 |
|
|
self.setCubeAxes() |
54 |
jongui |
827 |
|
55 |
jongui |
822 |
def getReader(self): |
56 |
jongui |
835 |
""" |
57 |
|
|
Return the file reader. |
58 |
|
|
|
59 |
|
|
@rtype: vtkXMLUnstructuredGridReader |
60 |
|
|
@return: VTK XML unstructured grid reader |
61 |
|
|
""" |
62 |
|
|
|
63 |
jongui |
822 |
return self.vtk_xml_reader |
64 |
|
|
|
65 |
jongui |
828 |
def setOutline(self): |
66 |
jongui |
835 |
""" |
67 |
|
|
Set the outline for the rendered object. |
68 |
|
|
""" |
69 |
|
|
|
70 |
jongui |
828 |
self.vtk_outline = vtk.vtkOutlineFilter() |
71 |
|
|
self.vtk_outline.SetInput(self.vtk_xml_reader.GetOutput()) |
72 |
jongui |
822 |
|
73 |
jongui |
847 |
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 |
jongui |
848 |
vtk_cube_axes.SetFontFactor(0.9) |
80 |
jongui |
827 |
|
81 |
jongui |
847 |
self.scene.getRenderer().AddActor(vtk_cube_axes) |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|