/[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 886 - (show annotations)
Thu Nov 2 01:34:58 2006 UTC (14 years, 1 month ago) by jongui
File MIME type: text/x-python
File size: 2827 byte(s)
- Fixed a couple of minor bugs but the bug relating to the plane normal still exists.
- Updated the documentation.

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 = False):
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 # The amount to pull back the axes from the corner to avoid overlaps.
74 vtk_cube_axes.SetCornerOffset(0.0)
75 # Makes the axes size to be constant (stay the size of the bounding
76 # box). Otherwise, the axes value can change depending on the
77 # viewport and can have many decimal places at times.
78 vtk_cube_axes.ScalingOff()
79
80 # Style for the axes title and label.
81 style = Style()
82 style.setColor(BLACK)
83 style.shadowOn()
84
85 vtk_cube_axes.SetAxisTitleTextProperty(style.getStyle())
86 vtk_cube_axes.SetAxisLabelTextProperty(style.getStyle())
87
88 self.scene.getRenderer().AddActor(vtk_cube_axes)
89
90 def getReader(self):
91 """
92 Return the file reader.
93
94 @rtype: vtkXMLUnstructuredGridReader
95 @return: VTK XML unstructured grid reader that is used to read files.
96 """
97
98 return self.vtk_xml_reader
99

  ViewVC Help
Powered by ViewVC 1.1.26