/[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 860 - (show annotations)
Thu Sep 28 08:17:29 2006 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 2496 byte(s)
- added sample drivers on how to use all of the currently available modules.
- completed the epydocs for all the currently available modules.
- added the rotation feature for camera and plane cutting.


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 visualization.
14 """
15
16 def __init__(self, scene, outline = True, cube_axes = True):
17 """
18 @type scene: L{Scene <scene.Scene>} object
19 @param scene: Scene in which components are to be added to
20 @type outline: Boolean (I{True or False})
21 @param outline: Places or removes an outline for the rendered object
22 @type cube_axes: Boolean ({True or False})
23 @param cube_axes: Places or removes a cube axes 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 file name from which data is to be read.
34 @type file_name: String
35 @param file_name: Name of the file to be read.
36 """
37
38 self.vtk_xml_reader.SetFileName(file_name)
39
40 # Set up the outline and cube axes only if true.
41 if(self.outline == True):
42 self.setOutline()
43 if(self.cube_axes == True):
44 self.setCubeAxes()
45
46 def setOutline(self):
47 """
48 Set up the outline for the rendered object.
49 """
50
51 self.vtk_outline = vtk.vtkOutlineFilter()
52 self.vtk_outline.SetInput(self.vtk_xml_reader.GetOutput())
53
54 Common.setMapperInput(self, self.vtk_outline.GetOutput())
55 Common.setActorInput(self)
56 Common.addActor(self)
57 # Default outline is black.
58 Common.setActorColor(self, BLACK)
59
60 def setCubeAxes(self):
61 """
62 Set up the cube axes for the rendered object.
63 """
64
65 vtk_cube_axes = vtk.vtkCubeAxesActor2D()
66 vtk_cube_axes.SetInput(self.getReader().GetOutput())
67 vtk_cube_axes.SetCamera(self.scene.getRenderer().GetActiveCamera())
68 # Formats the labes on the axes.
69 vtk_cube_axes.SetLabelFormat("%6.4g")
70 # Use the outer edges of the bounding box to draw the axes.
71 vtk_cube_axes.SetFlyModeToOuterEdges()
72 vtk_cube_axes.SetFontFactor(0.9)
73
74 # Style for the axes title and label.
75 style = Style()
76 style.setColor(BLACK)
77 style.shadowOn()
78
79 vtk_cube_axes.SetAxisTitleTextProperty(style.getStyle())
80 vtk_cube_axes.SetAxisLabelTextProperty(style.getStyle())
81
82 self.scene.getRenderer().AddActor(vtk_cube_axes)
83
84 def getReader(self):
85 """
86 Return the file reader.
87
88 @rtype: vtkXMLUnstructuredGridReader
89 @return: VTK XML unstructured grid reader that is used to read files.
90 """
91
92 return self.vtk_xml_reader
93

  ViewVC Help
Powered by ViewVC 1.1.26