| 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 PhactoriContourOperation(PhactoriOperationSpecifics): |
| 38 |
"""clip plane operation, adapter to the catalyst Contour filter |
| 39 |
|
| 40 |
PhactoriContourOperation is the phactori manager for working with the |
| 41 |
ParaView/Catalyst Contour() filter and its parameters, providing |
| 42 |
access and pipeline/input/output managment via the json, lexx/yacc, or soon |
| 43 |
yaml interface. The user may specify a named input to the filter, with the |
| 44 |
unnamed default being the incoming data mesh. i |
| 45 |
|
| 46 |
For information on the Contour() filter from ParaView, see the ParaView |
| 47 |
Documentation. The basic operation is to take a value and a variable and |
| 48 |
calculate an iso surface in the mesh corresponding to the value and create |
| 49 |
a 3D surface at that iso value. Multiple values can be specified in the same |
| 50 |
operation, resulting in multiple surface. |
| 51 |
|
| 52 |
The user must specify the variable to be used and one or more isosurface |
| 53 |
values. |
| 54 |
|
| 55 |
To add a PhactoriContourOperation to the incoming script, you add |
| 56 |
a sub-block to the "operation blocks" section of the data with the "type" |
| 57 |
key given a value of "contour". One complete but simple example script: |
| 58 |
|
| 59 |
:: |
| 60 |
|
| 61 |
{ |
| 62 |
"camera blocks":{"mycam1":{"type":"camera", "look direction":[1.0, 2.0, 3.0]}}, |
| 63 |
"representation blocks":{"rep_tmprtr":{"color by scalar":"temperature"}}, |
| 64 |
"imageset blocks":{ |
| 65 |
"temperature_contour_1":{ |
| 66 |
"operation":"myclipwithplane1", |
| 67 |
"camera":"mycam1", |
| 68 |
"representation":"rep_tmprtr", |
| 69 |
"image basedirectory":"CatalystOutput", |
| 70 |
"image basename":"contour1_temperature." |
| 71 |
} |
| 72 |
}, |
| 73 |
"operation blocks":{ |
| 74 |
"mycontour1":{ |
| 75 |
"type":"contour", |
| 76 |
"variable scalar":"temperature", |
| 77 |
"contour value":[100.0, 150.0, 200.0, 1000.0] |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
As an alternative to "contour value" you are allowed to specify a key |
| 83 |
"contour value sequence" with a start value, a step value, and an end value. |
| 84 |
Contour values will automatically be created from start, spacing by step, |
| 85 |
until a value greater than or equal to end is reached. For example: |
| 86 |
|
| 87 |
|
| 88 |
:: |
| 89 |
|
| 90 |
"contour value sequence": [100.0, 200.0, 1100.0] |
| 91 |
|
| 92 |
|
| 93 |
will get 100, 300, 500, 700, and 900. If it is 1101.0 for end, 1100.0 will |
| 94 |
also be used. |
| 95 |
|
| 96 |
""" |
| 97 |
|
| 98 |
def __init__(self): |
| 99 |
PhactoriOperationSpecifics.__init__(self) |
| 100 |
self.mVariableInfo = PhactoriVariableInfo() |
| 101 |
self.mContourValue = [0.0] |
| 102 |
|
| 103 |
#flag allows system to be set up to bypass this operation, especially |
| 104 |
#for testing camera settings against geometry without thresholds, |
| 105 |
#iso surfaces messing the tests up |
| 106 |
self.mBypassFlag = False |
| 107 |
|
| 108 |
def ParseParametersFromJson(self, inJson): |
| 109 |
|
| 110 |
self.mBypassFlag = getParameterFromBlock(inJson, 'bypass flag', |
| 111 |
self.mBypassFlag) |
| 112 |
if self.mBypassFlag == True: |
| 113 |
#this operation is bypassed: don't do other parsing |
| 114 |
return |
| 115 |
|
| 116 |
foundVariableFlag = self.mVariableInfo.\ |
| 117 |
ParseVariableNameAndVectorOrTensorComponent(inJson, 'variable ') |
| 118 |
|
| 119 |
if foundVariableFlag == False: |
| 120 |
errStr = """error! inJson has no variable info in |
| 121 |
PhactoriContourOperation.ParseParametersFromJson\n""" |
| 122 |
if PhactoriDbg(): |
| 123 |
myDebugPrint3(errStr) |
| 124 |
raise Exception(errStr) |
| 125 |
|
| 126 |
if 'contour value' in inJson: |
| 127 |
self.mContourValue = inJson['contour value'] |
| 128 |
elif 'contour value sequence' in inJson: |
| 129 |
seqCntrl = inJson['contour value sequence'] |
| 130 |
rStart = seqCntrl[0] |
| 131 |
rStep = seqCntrl[1] |
| 132 |
rEnd = seqCntrl[2] |
| 133 |
self.mContourValue = [] |
| 134 |
rVal = rStart |
| 135 |
if rEnd > rStart: |
| 136 |
if rStep <= 0.0: |
| 137 |
errStr = """error! bad contour value sequence in |
| 138 |
PhactoriContourOperation.ParseParametersFromJson\n""" |
| 139 |
if PhactoriDbg(): |
| 140 |
myDebugPrint3(errStr) |
| 141 |
raise Exception(errStr) |
| 142 |
while rVal < rEnd: |
| 143 |
self.mContourValue.append(rVal) |
| 144 |
rVal += rStep |
| 145 |
else: |
| 146 |
if rStep >= 0.0: |
| 147 |
errStr = """error! bad contour value sequence in |
| 148 |
PhactoriContourOperation.ParseParametersFromJson\n""" |
| 149 |
if PhactoriDbg(): |
| 150 |
myDebugPrint3(errStr) |
| 151 |
raise Exception(errStr) |
| 152 |
while rVal > rEnd: |
| 153 |
self.mContourValue.append(rVal) |
| 154 |
rVal += rStep |
| 155 |
else: |
| 156 |
errStr = """error! inJson has no 'contour value' or 'contour value sequence' key in |
| 157 |
PhactoriContourOperation.ParseParametersFromJson\n""" |
| 158 |
if PhactoriDbg(): |
| 159 |
myDebugPrint3(errStr) |
| 160 |
raise Exception(errStr) |
| 161 |
|
| 162 |
|
| 163 |
def CreateParaViewFilter(self, inInputFilter): |
| 164 |
"""create the clip plane filter for ParaView""" |
| 165 |
if PhactoriDbg(100): |
| 166 |
myDebugPrint3('PhactoriContourOperation.CreateParaViewFilter entered\n', 100) |
| 167 |
#info in block class should already be parsed and checked |
| 168 |
|
| 169 |
#if the operation bypass flag is set to true, we want this |
| 170 |
#operation to do nothing and just pass the input to the output |
| 171 |
if self.mBypassFlag == True: |
| 172 |
if PhactoriDbg(): |
| 173 |
myDebugPrint3("PhactoriContourOperation::CreateParaViewFilter\n" + |
| 174 |
"mBypassFlag was true, so paraview output filter is input filter") |
| 175 |
return inInputFilter |
| 176 |
|
| 177 |
savedActiveSource = GetActiveSource() |
| 178 |
SetActiveSource(inInputFilter) |
| 179 |
UpdatePipelineWithCurrentTimeArgument(inInputFilter) |
| 180 |
|
| 181 |
newParaViewFilter = Contour(Input = inInputFilter, |
| 182 |
PointMergeMethod="Uniform Binning") |
| 183 |
newParaViewFilter.ComputeScalars = 1 |
| 184 |
|
| 185 |
if PhactoriDbg(): |
| 186 |
myDebugPrint3(" contour filter is: " + str(newParaViewFilter) + "\n") |
| 187 |
newParaViewFilter.PointMergeMethod = "Uniform Binning" |
| 188 |
|
| 189 |
detectResult = self.mVariableInfo.DetectVariableType(inInputFilter, True) |
| 190 |
#if detectResult == False: |
| 191 |
#PutOperationOnListToDetectVariableTypeInFutureSteps() |
| 192 |
|
| 193 |
#hack to deal with how paraview/catalyst expects naming of threshold |
| 194 |
#variables which are vector components or magnitudes |
| 195 |
|
| 196 |
localVariableName = GetThresholdContourHackVariableNameString(self.mVariableInfo) |
| 197 |
|
| 198 |
newParaViewFilter.Isosurfaces = self.mContourValue |
| 199 |
|
| 200 |
if PhactoriDbg(): |
| 201 |
myDebugPrint3(' name for variable in threshold: ' + localVariableName + '\n') |
| 202 |
|
| 203 |
#for contour, if data type is 'element'/'CELLS', the contour filter will |
| 204 |
#(apparently) automatically add a cell-to-point filter |
| 205 |
newParaViewFilter.ContourBy = ['POINTS', localVariableName] |
| 206 |
|
| 207 |
if PhactoriDbg(): |
| 208 |
myDebugPrint3(" still okay\n") |
| 209 |
SetActiveSource(newParaViewFilter) |
| 210 |
SetActiveSource(savedActiveSource) |
| 211 |
|
| 212 |
#debugging contour error |
| 213 |
#if PhactoriDbg(): |
| 214 |
# newParaViewFilter.UpdatePipeline() |
| 215 |
# pointData = newParaViewFilter.PointData |
| 216 |
# numPointArrays = pointData.GetNumberOfArrays() |
| 217 |
# myDebugPrint3("number of point arrays: " + str(numPointArrays) + "\n" |
| 218 |
# "ComputeScalars: " + str(newParaViewFilter.ComputeScalars) + "\n") |
| 219 |
# for ii in range(numPointArrays): |
| 220 |
# onePointArray = pointData.GetArray(ii) |
| 221 |
# myDebugPrint3(str(ii) + ": " + onePointArray.GetName() + ": " + \ |
| 222 |
# str(onePointArray.GetNumberOfTuples()) + "\n") |
| 223 |
|
| 224 |
if PhactoriDbg(100): |
| 225 |
myDebugPrint3('PhactoriContourOperation.CreateParaViewFilter returning\n', 100) |
| 226 |
|
| 227 |
return newParaViewFilter |
| 228 |
#phactori_combine_to_single_python_file_subpiece_end_1 |