1 |
jongui |
943 |
""" |
2 |
|
|
@author: John NGUI |
3 |
|
|
""" |
4 |
|
|
|
5 |
|
|
import vtk |
6 |
|
|
|
7 |
|
|
class Clipper: |
8 |
|
|
""" |
9 |
|
|
Class that defines a clipper. |
10 |
|
|
""" |
11 |
|
|
|
12 |
jongui |
947 |
def __init__(self, object, plane): |
13 |
jongui |
943 |
""" |
14 |
|
|
Initialise the clipper. |
15 |
|
|
|
16 |
|
|
@type object: vtkUnstructuredGrid, etc |
17 |
|
|
@param object: Input for the clipper |
18 |
|
|
@type plane: vtkPlane |
19 |
jongui |
947 |
@param plane: Plane to clip the rendered object |
20 |
jongui |
943 |
""" |
21 |
|
|
|
22 |
|
|
self.__object = object |
23 |
jongui |
947 |
# True only if a plane is used to perform clipping. Will be false |
24 |
|
|
# for scalar clipping. |
25 |
|
|
if(plane != None): |
26 |
jongui |
943 |
self.__plane = plane |
27 |
|
|
|
28 |
|
|
self.__vtk_clipper = vtk.vtkClipDataSet() |
29 |
jongui |
947 |
self.__setupClipper() |
30 |
jongui |
943 |
|
31 |
jongui |
947 |
def __setupClipper(self): |
32 |
|
|
""" |
33 |
|
|
Setup the clipper. |
34 |
|
|
""" |
35 |
|
|
|
36 |
jongui |
943 |
self.__setInput() |
37 |
|
|
self.setInsideOutOn() |
38 |
|
|
self.__vtk_clipper.Update() |
39 |
|
|
|
40 |
|
|
def __setInput(self): |
41 |
|
|
""" |
42 |
|
|
Set the input for the clipper. |
43 |
|
|
""" |
44 |
|
|
|
45 |
|
|
self.__vtk_clipper.SetInput(self.__object) |
46 |
|
|
|
47 |
|
|
def _setClipFunction(self): |
48 |
|
|
""" |
49 |
jongui |
947 |
Set the clip function (using a plane). |
50 |
jongui |
943 |
""" |
51 |
|
|
|
52 |
|
|
self.__vtk_clipper.SetClipFunction(self.__plane) |
53 |
|
|
|
54 |
|
|
def setInsideOutOn(self): |
55 |
|
|
""" |
56 |
|
|
Clips the one side of the rendered object. |
57 |
|
|
""" |
58 |
|
|
|
59 |
|
|
self.__vtk_clipper.InsideOutOn() |
60 |
|
|
|
61 |
|
|
def setInsideOutOff(self): |
62 |
|
|
""" |
63 |
|
|
Clips the other side of the rendered object. |
64 |
|
|
""" |
65 |
|
|
|
66 |
|
|
self.__vtk_clipper.InsideOutOff() |
67 |
|
|
|
68 |
|
|
def setClipValue(self, value): |
69 |
|
|
""" |
70 |
|
|
Set the scalar clip value. |
71 |
|
|
|
72 |
|
|
@type value: Number |
73 |
|
|
@param value: Scalar clip value |
74 |
|
|
""" |
75 |
|
|
|
76 |
|
|
self.__vtk_clipper.SetValue(value) |
77 |
|
|
|
78 |
|
|
def _getOutput(self): |
79 |
|
|
""" |
80 |
|
|
Return the output of the clipper. |
81 |
|
|
|
82 |
|
|
@rtype: vtkUnstructuredGrid |
83 |
|
|
@return: Unstructured grid |
84 |
|
|
""" |
85 |
|
|
|
86 |
|
|
return self.__vtk_clipper.GetOutput() |
87 |
|
|
|