Debian Codegraph @

packages/seacas/libraries/ioss/src/visualization/catalyst/phactori/Operation/PhactoriBoxClipOperation.py

raw
1 # Copyright(C) 1999-2020 National Technology & Engineering Solutions
2 # of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 # NTESS, the U.S. Government retains certain rights in this software.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 #
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 #
17 # * Neither the name of NTESS nor the names of its
18 # contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 from phactori import *
34 from paraview.simple import *
35
36 #phactori_combine_to_single_python_file_subpiece_begin_1
37 class PhactoriBoxClipOperation(PhactoriOperationSpecifics):
38 """clip operation with a clip type of "box", adapter to the catalyst filter
39
40 Phactori Adapter interface to the ParaView Clip filter with a clip type
41 of "box". Refere to the ParaView documentation for extensive
42 documentation of the clip filter.
43
44 To control the BoxClipOperation you have a section in the
45 "operation blocks" section of the phactori control script which looks like:
46
47 ::
48
49 "operation blocks":{
50 "myboxclip1":{
51 "type":"boxclip",
52 "center at absolute point":[1.1, -2.2, 3.5],
53 "absolute extents":[5.0, 6.2, 7.3]
54 }
55 }
56
57 "center at absolute point" may also be "center at relative point" or
58 "center at element" or "center at node" or "center at data point", as it is
59 a "phactori use point". "absolute extents" may be "relative extents" in
60 which case the extents of the clip box are determined relative to the size
61 of the bounding box of the data.
62
63 """
64
65 def __init__(self):
66 PhactoriOperationSpecifics.__init__(self)
67 self.mCenterPtInfo = PhactoriUserPointInfo()
68 self.mExtentsRelAbsFlag = [True, True, True]
69 self.mExtents = [0.5, 0.5, 0.5]
70 self.mRotations = [0.0, 0.0, 0.0]
71 self.mKeepInside = True
72 self.mCrinkleSetting = None
73
74 def ParseParametersFromJson(self, inJson):
75 if PhactoriDbg(100):
76 myDebugPrint3(
77 'PhactoriBoxClipOperation.ParseParametersFromJson entered\n', 100)
78 self.mCenterPtInfo.UserPointInfoParseParametersFromJson(
79 inJson, "center at ", "")
80
81 absExtentsKey = 'absolute extents'
82 relExtentsKey = 'relative extents'
83 if absExtentsKey in inJson:
84 self.mExtents = inJson[absExtentsKey]
85 self.mExtentsRelAbsFlag = [False, False, False]
86 elif relExtentsKey in inJson:
87 self.mExtents = inJson[relExtentsKey]
88 self.mExtentsRelAbsFlag = [True, True, True]
89 else:
90 self.mExtents = [0.5, 0.5, 0.5]
91 self.mExtentsRelAbsFlag = [True, True, True]
92
93 rotationsKey = 'rotations'
94 if rotationsKey in inJson:
95 self.mRotations = inJson[rotationsKey]
96
97 if 'keep inside box' in inJson:
98 self.mKeepInside = inJson['keep inside box']
99 else:
100 self.mKeepInside = True
101
102 if 'cut type' in inJson:
103 cutType = inJson['cut type']
104 self.mCrinkleSetting = 0
105 if cutType == 'smooth':
106 self.mCrinkleSetting = 0
107 elif cutType == 'crinkle':
108 self.mCrinkleSetting = 1
109 else:
110 if PhactoriDbg():
111 myDebugPrint3('ParseParametersFromJson warning: cut type \
112 should be smooth or crinkle, but is not, using smooth\n')
113 self.mCrinkleSetting = 0
114 else:
115 self.mCrinkleSetting = 0 #debatable default
116
117 #self.PrintSelf()
118 if PhactoriDbg(100):
119 myDebugPrint3('PhactoriBoxClipOperation.ParseParametersFromJson returning\n', 100)
120
121 def PrintSelf(self):
122 if PhactoriDbg(100):
123 myDebugPrint3('PhactoriBoxClipOperation.PrintSelf entered\nCenter Point:', 100)
124 self.mCenterPtInfo.PrintSelf()
125 if PhactoriDbg():
126 myDebugPrint3('mExtentsRelAbsFlag: ' + str(self.mExtentsRelAbsFlag) + '\n')
127 if PhactoriDbg():
128 myDebugPrint3('mExtents: ' + str(self.mExtents) + '\n')
129 if PhactoriDbg():
130 myDebugPrint3('mRotations: ' + str(self.mRotations) + '\n')
131 if PhactoriDbg():
132 myDebugPrint3('mKeepInside: ' + str(self.mKeepInside) + '\n')
133 if PhactoriDbg():
134 myDebugPrint3('mCrinkleSetting: ' + str(self.mCrinkleSetting) + '\n')
135
136 def CreateParaViewFilter(self, inInputFilter):
137 """create the box clip box for ParaView"""
138 if PhactoriDbg(100):
139 myDebugPrint3('PhactoriBoxClipOperation.CreateParaViewFilter entered\n', 100)
140 #info in block class should already be parsed and checked
141
142 savedActiveSource = GetActiveSource()
143
144 UpdatePipelineWithCurrentTimeArgument(inInputFilter)
145
146 if PhactoriDbg(100):
147 DebugPrintCellAndPointArrayInfo("data arrays coming into PhactoriBoxClipOperation.CreateParaViewFilter\n", inInputFilter, 100)
148
149 newParaViewFilter = Clip(Input = inInputFilter, ClipType = "Box")
150
151 viewBoundsArray = [None]
152 centerToUse = self.mCenterPtInfo.GetCurrentGeometricPointWithDisplacement(
153 inInputFilter, viewBoundsArray, True)
154
155 if PhactoriDbg():
156 myDebugPrint3(" about to find extents--absolute or calced from relative\n")
157 myViewBounds = viewBoundsArray[0]
158 if self.mExtentsRelAbsFlag[0]:
159 if myViewBounds == None:
160 myViewBounds = GetGlobalDataBoundsParallel(inInputFilter)
161 halfXExt = self.mExtents[0] * (myViewBounds[1] - myViewBounds[0]) * 0.5
162 if halfXExt <= 1e-20:
163 halfXExt = 0.001
164 else:
165 halfXExt = self.mExtents[0] * 0.5
166
167 if self.mExtentsRelAbsFlag[1]:
168 if myViewBounds == None:
169 myViewBounds = GetGlobalDataBoundsParallel(inInputFilter)
170 halfYExt = self.mExtents[1] * (myViewBounds[3] - myViewBounds[2]) * 0.5
171 if halfYExt <= 1e-20:
172 halfYExt = 0.001
173 else:
174 halfYExt = self.mExtents[1] * 0.5
175
176 if self.mExtentsRelAbsFlag[2]:
177 if myViewBounds == None:
178 myViewBounds = GetGlobalDataBoundsParallel(inInputFilter)
179 halfZExt = self.mExtents[2] * (myViewBounds[5] - myViewBounds[4]) * 0.5
180 if halfZExt <= 1e-20:
181 halfZExt = 0.001
182 else:
183 halfZExt = self.mExtents[2] * 0.5
184
185 if PhactoriDbg():
186 myDebugPrint3(" halfExtents: " + str(halfXExt) + ", " + str(halfYExt) + ", " + str(halfZExt) + "\n")
187
188 #newParaViewFilter.ClipType.Position = [centerToUse[0],
189 # centerToUse[1],
190 # centerToUse[2]]
191 #newParaViewFilter.ClipType.Bounds = [-halfXExt, halfXExt,
192 # -halfYExt, halfYExt, -halfZExt, halfZExt]
193 newParaViewFilter.ClipType.Position = [centerToUse[0] - halfXExt,
194 centerToUse[1] - halfYExt,
195 centerToUse[2] - halfZExt]
196 newParaViewFilter.ClipType.Length = [halfXExt * 2.0, halfYExt * 2.0, halfZExt * 2.0]
197 newParaViewFilter.ClipType.Rotation = [self.mRotations[0],
198 self.mRotations[1],
199 self.mRotations[2]]
200
201 newParaViewFilter.Crinkleclip = self.mCrinkleSetting
202 if gParaViewCatalystVersionFlag < 50502:
203 if self.mKeepInside:
204 newParaViewFilter.InsideOut = 1
205 else:
206 newParaViewFilter.InsideOut = 0
207 else:
208 if self.mKeepInside:
209 newParaViewFilter.Invert = 1
210 else:
211 newParaViewFilter.Invert = 0
212
213 SetActiveSource(newParaViewFilter)
214 SetActiveSource(savedActiveSource)
215
216 UpdatePipelineWithCurrentTimeArgument(newParaViewFilter)
217
218 if PhactoriDbg(100):
219 DebugPrintCellAndPointArrayInfo("data arrays coming out of PhactoriBoxClipOperation.CreateParaViewFilter\n", newParaViewFilter, 100)
220
221 if PhactoriDbg(100):
222 myDebugPrint3('PhactoriBoxClipOperation.CreateParaViewFilter returning\n', 100)
223
224 return newParaViewFilter
225
226 def MayChangeWithData(self):
227 if self.mCenterPtInfo.mMayChangeWithData == True:
228 return True
229 if self.mExtentsRelAbsFlag[0] == True:
230 return True
231 if self.mExtentsRelAbsFlag[1] == True:
232 return True
233 if self.mExtentsRelAbsFlag[2] == True:
234 return True
235 return False
236 #phactori_combine_to_single_python_file_subpiece_end_1