/[escript]/trunk/pyvisi/py_src/datacollector.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/datacollector.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 849 - (show annotations)
Fri Sep 15 07:11:55 2006 UTC (14 years ago) by jongui
File MIME type: text/x-python
File size: 2124 byte(s)
Optimized codes and modularized functions to make it more scalable. Partially 
integrated carpet into the existing modules.  

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

  ViewVC Help
Powered by ViewVC 1.1.26