1 |
jongui |
943 |
""" |
2 |
|
|
@author: John NGUI |
3 |
|
|
""" |
4 |
|
|
|
5 |
|
|
import vtk |
6 |
|
|
from constant import WarpMode |
7 |
|
|
|
8 |
|
|
class Warp: |
9 |
|
|
""" |
10 |
|
|
Class that defines the deformation of a scalar field. |
11 |
|
|
""" |
12 |
|
|
|
13 |
|
|
def __init__(self, object, warp_mode): |
14 |
|
|
""" |
15 |
|
|
Initialise the warp scalar/vector. |
16 |
|
|
|
17 |
|
|
@type object: vtkUnstructuredGrid, etc |
18 |
|
|
@param object: Input for the warp scalar |
19 |
|
|
@type warp_mode: L{WarpMode <constant.WarpMode>} constant |
20 |
|
|
@param warp_mode: Mode in which to deform the data |
21 |
|
|
""" |
22 |
|
|
|
23 |
|
|
self.__object = object |
24 |
|
|
|
25 |
|
|
if(warp_mode == WarpMode.SCALAR): # Deform data with scalar data. |
26 |
|
|
self.__vtk_warp = vtk.vtkWarpScalar() |
27 |
|
|
elif(warp_mode == WarpMode.VECTOR): # Deform data with vector data. |
28 |
|
|
self.__vtk_warp = vtk.vtkWarpVector() |
29 |
|
|
|
30 |
|
|
self.__setInput() |
31 |
|
|
|
32 |
|
|
def __setInput(self): |
33 |
|
|
""" |
34 |
|
|
Set the input for the warp scalar/vector. |
35 |
|
|
""" |
36 |
|
|
|
37 |
|
|
self.__vtk_warp.SetInput(self.__object) |
38 |
|
|
|
39 |
|
|
def setScaleFactor(self, scale_factor): |
40 |
|
|
""" |
41 |
|
|
Set the displacement scale factor. |
42 |
|
|
|
43 |
|
|
@type scale_factor: Number |
44 |
|
|
@param scale_factor: Size of the displacement |
45 |
|
|
""" |
46 |
|
|
|
47 |
|
|
self.__vtk_warp.SetScaleFactor(scale_factor) |
48 |
|
|
|
49 |
|
|
def _getOutput(self): |
50 |
|
|
""" |
51 |
|
|
Return the deformed scalar. |
52 |
|
|
|
53 |
|
|
@rtype: vtkPointSet |
54 |
|
|
@return: PointSet data |
55 |
|
|
""" |
56 |
|
|
|
57 |
|
|
return self.__vtk_warp.GetOutput() |
58 |
|
|
|