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

Diff of /trunk/pyvisi/py_src/point.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1147 by ksteube, Wed May 16 06:39:11 2007 UTC revision 1148 by jongui, Wed May 16 22:45:33 2007 UTC
# Line 11  class PointSource: Line 11  class PointSource:
11      generated within the radius of a sphere.      generated within the radius of a sphere.
12      """      """
13    
14      def __init__(self, object):      def __init__(self):
15          """          """
16          Initialise the point source.          Initialise the point source.
17          """          """
18    
         self.__object = object  
19          self.__vtk_point_source = vtk.vtkPointSource()          self.__vtk_point_source = vtk.vtkPointSource()
20            self.__center = None
21    
22          self.__setupPointSource()      def _setupPointSource(self, object):
   
     def __setupPointSource(self):  
23          """          """
24          Setup the point source.          Setup the point source.
25    
26            @type object: vtkPolyData, etc
27            @param object: Used to define the location of the sphere
28          """          """
29    
30            self.__object = object
31    
32          # Default number of points to generate within the sphere is 10.          # Default number of points to generate within the sphere is 10.
33          self.setPointSourceNumberOfPoints(10)          self.setPointSourceNumberOfPoints(10)
         # Default center of the sphere is the center of the data object.  
         center = self.__object.GetCenter()  
         self.setPointSourceCenter(  
                 GlobalPosition(center[0], center[1], center[2]))  
   
34          # Default radius of the sphere is 0.5.          # Default radius of the sphere is 0.5.
35          self.setPointSourceRadius(0.5)          self.setPointSourceRadius(0.5)
         self.__vtk_point_source.Update()  
36    
37      def setPointSourceRadius(self, radius):      def setPointSourceRadius(self, radius):
38          """          """
# Line 47  class PointSource: Line 44  class PointSource:
44    
45          self.__vtk_point_source.SetRadius(radius)          self.__vtk_point_source.SetRadius(radius)
46    
47      def setPointSourceCenter(self, position):      # This method is used to delay the execution of setting the point source
48        # center.
49        def setPointSourceCenter(self, center):
50          """          """
51          Set the center of the sphere.          Save the sphere's center.
52                    
53          @type position: L{GLobalPosition <position.GlobalPosition>} object          @type center: L{GLobalPosition <position.GlobalPosition>} object
54          @param position: Center of the sphere          @param center: Center of the sphere
55          """          """
56            
57            self.__center = center
58    
59          self.__vtk_point_source.SetCenter(position._getGlobalPosition())      def _setPointSourceCenter(self):
60            """
61            Set the sphere's center.
62            """
63    
64            self.__vtk_point_source.SetCenter(self.__center._getGlobalPosition())
65    
66      def setPointSourceNumberOfPoints(self, points):      def setPointSourceNumberOfPoints(self, points):
67          """          """
# Line 68  class PointSource: Line 74  class PointSource:
74    
75          self.__vtk_point_source.SetNumberOfPoints(points)            self.__vtk_point_source.SetNumberOfPoints(points)  
76    
77      def _getOutput(self):      def _getPointSourceOutput(self):
78          """          """
79          Return the output of the point source.          Return the output of the point source.
80    
# Line 78  class PointSource: Line 84  class PointSource:
84    
85          return self.__vtk_point_source.GetOutput()          return self.__vtk_point_source.GetOutput()
86    
87        def _isPointSourceCenterSet(self):
 ###############################################################################  
   
   
 class StructuredPoints:  
     """  
     Class that defines the structured points.  
   
     @status: This class is currently not included because it does NOT appear  
     to work with second-order elements.  
     """  
       
     # NOTE: The algorithm of this class was extracted from Mayavi's  
     # online source code. Does NOT work for second-order (non-linear) elements.  
     def __init__(self, object):  
         """  
         Initialise the structured points.  
   
         @type object: vtkUnstructuredGrid, etc  
         @param object: Input for the structured points  
88          """          """
89            Return whether the center has been specified.
90    
91          self.__object = object          @rtype: Boolean
92          self.__vtk_structured_points = vtk.vtkStructuredPoints()          @return: True or False
         self.__setupStructuredPoints()  
   
     def __setupStructuredPoints(self):  
         """  
         Setup the structured points.  
93          """          """
94    
95          b = self.__object.GetBounds()          if(self.__center != None):
96          self.__vtk_structured_points.SetOrigin(b[0], b[2], b[4])              return True
97          self.__l = [b[1] - b[0], b[3] - b[2], b[5] - b[4]]          else:
98          tot_len = float(self.__l[0] + self.__l[1] + self.__l[2])              return False
         npnt = pow(self.__object.GetNumberOfPoints(), 1. / 3.) + 0.5  
         self.__fac = 3.0*npnt / tot_len  
   
         # Default dimension is 1, 1, 1.  
         self.setDimension(1, 1, 1)  
   
     def __setExtent(self, x0, x1, y0, y1, z0, z1):  
         """  
         Set the extent in the order of x, y and z axes.  
   
         @type x0: Number  
         @param x0: Index of the first point on the x-axis  
         @type x1: Number  
         @param x1: Index of the last point on the x-axis  
         @type y0: Number  
         @param y0: Index of the first point on the y-axis  
         @type y1: Number  
         @param y1: Index of the last point on the y-axis  
         @type z0: Number  
         @param z0: Index of the first point on the z-axis  
         @type z1: Number  
         @param z1: Index of the last point on the z-axis  
         """  
   
         self.__vtk_structured_points.SetExtent(x0, x1, y0, y1, z0, z1)  
   
     def __setUpdateExtent(self, x0, x1, y0, y1, z0, z1):  
         """  
         Set the update extent in the oder of x, y and z axes.  
   
         @type x0: Number  
         @param x0: Index of the first point on the x-axis  
         @type x1: Number  
         @param x1: Index of the last point on the x-axis  
         @type y0: Number  
         @param y0: Index of the first point on the y-axis  
         @type y1: Number  
         @param y1: Index of the last point on the y-axis  
         @type z0: Number  
         @param z0: Index of the first point on the z-axis  
         @type z1: Number  
         @param z1: Index of the last point on the z-axis  
         """  
   
         self.__vtk_structured_points.SetUpdateExtent(x0, x1, y0, y1, z0, z1)  
   
     def setDimension(self, x, y, z):  
         """  
         Set the dimension on the x, y and z axes. The  
         smaller the dimension, the more points are populated.  
   
         @type x: Number  
         @param x: Dimension on the x-axis  
         @type y: Number  
         @param y: Dimension on the y-axis  
         @type z: Number  
         @param z: Dimension on the z-axis  
         """  
   
         self.__dims = [int((self.__l[0]*self.__fac)/x) + 1,  
                 int((self.__l[1] * self.__fac) / y) + 1,  
                 int((self.__l[2] * self.__fac) / z) + 1]  
   
         self.__setExtent(0, self.__dims[0] - 1, 0, self.__dims[1] - 1, 0,  
                 self.__dims[2] - 1)  
         self.__setUpdateExtent(0, self.__dims[0] - 1, 0, self.__dims[1] - 1, 0,  
                 self.__dims[2] - 1)  
   
         self.__vtk_structured_points.SetDimensions(self.__dims)  
         self.__setSpacing()  
   
     def __setSpacing(self):  
         """  
         Set the spacing (width, height and length) of the cells that make up  
         the dataset.  
         """  
   
         self.__dims = [max(1, x - 1) for x in self.__dims]  
         self.__l = [max(1e-3, x) for x in self.__l]  
         sp = [self.__l[0] / self.__dims[0], self.__l[1] / self.__dims[1],  
                 self.__l[2] / self.__dims[2]]  
   
         self.__vtk_structured_points.SetSpacing(sp)  
         # Update the changes made.  
         self.__vtk_structured_points.Update()  
   
     def _getStructuredPoints(self):  
         """  
         Return the structured points.  
   
         @rtype: vtkStructuredPoints  
         @return: Structured points  
         """  
   
         return self.__vtk_structured_points  
99    
100    
101  ##############################################################################  ##############################################################################
# Line 220  class MaskPoints: Line 108  class MaskPoints:
108      from being cluttered with arrows or ellipsoids.      from being cluttered with arrows or ellipsoids.
109      """      """
110    
111      def __init__(self, object):      def __init__(self):
112          """          """
113          Initialise the mask points.          Initialise the mask points.
   
         @type object: vtkDataSet (i.e. vtkUnstructuredGrid, etc)  
         @param object: Data source from which to mask points  
114          """          """
115    
         self.__object = object  
116          self.__vtk_mask_points = vtk.vtkMaskPoints()          self.__vtk_mask_points = vtk.vtkMaskPoints()
117    
118          self.__setupMaskPoints()      def _setupMaskPoints(self, object):
   
     def __setupMaskPoints(self):  
119          """          """
120          Setup the mask points.          Setup the mask points.
121    
122            @type object: vtkDataSet (i.e. vtkUnstructuredGrid, etc)
123            @param object: Data source from which to mask points
124          """          """
125    
126            self.__object = object
127          self.__setInput()          self.__setInput()
128    
129      def __setInput(self):      def __setInput(self):
# Line 271  class MaskPoints: Line 157  class MaskPoints:
157    
158          self.__vtk_mask_points.RandomModeOff()          self.__vtk_mask_points.RandomModeOff()
159            
160      def _getOutput(self):      def _getMaskPointsOutput(self):
161          """          """
162          Return the output of the masked points.          Return the output of the masked points.
163    

Legend:
Removed from v.1147  
changed lines
  Added in v.1148

  ViewVC Help
Powered by ViewVC 1.1.26