| 1 |
# Copyright(C) 1999-2020, 2024 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 PhactoriSliceWithPlaneOperation(PhactoriPlaneOpBase): |
| 38 |
"""slice with plane operation, adapter to the catalyst filter |
| 39 |
|
| 40 |
PhactoriSliceWithPlaneOperation is the phactori manager for working with the |
| 41 |
ParaView/Catalyst SliceWithPlane() 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. |
| 45 |
|
| 46 |
For information on the SliceWithPlane() filter from ParaView, see the |
| 47 |
ParaView Documentation. |
| 48 |
|
| 49 |
Our experience has been that as of ParaView 5.8 there are some mesh |
| 50 |
geometries where the paraview Slice() filter with a plane slice type will |
| 51 |
crash while SliceWithPlane() behaves correctly. |
| 52 |
|
| 53 |
The user must define the plane with a point and normal or with three points. |
| 54 |
There are defaults which will be used if the user does not supply some or |
| 55 |
all of the definition. PhactoriSliceWithPlaneOperation is a child class of |
| 56 |
PhactoriPlaneOpBase, along with PhactoriSliceOperation and |
| 57 |
PhactoriClipPlaneOperation. Check the documentation for PhactoriPlaneOpBase |
| 58 |
for the many options for defining the plane point(s), including absolute or |
| 59 |
relative 3D points, dynamic data-driven point locations, or collocating with |
| 60 |
mesh nodes or elements (or offset therefrom). |
| 61 |
|
| 62 |
To add a PhactoriSliceWithPlaneOperation to the incoming script, you add |
| 63 |
a sub-block to the "operation blocks" section of the data with the "type" |
| 64 |
key given a value of "slicewithplane". One complete but simple example |
| 65 |
script: |
| 66 |
|
| 67 |
:: |
| 68 |
|
| 69 |
{ |
| 70 |
"camera blocks":{"myslicecam1":{"type":"camera", "look direction":[1.0, 2.0, 3.0]}}, |
| 71 |
"representation blocks":{"rep_tmprtr":{"color by scalar":"temperature"}}, |
| 72 |
"imageset blocks":{ |
| 73 |
"temperature_on_slice_1":{ |
| 74 |
"operation":"myslicewithplane1", |
| 75 |
"camera":"myslicecam1", |
| 76 |
"representation":"rep_tmprtr", |
| 77 |
"image basedirectory":"CatalystOutput", |
| 78 |
"image basename":"slice1_temperature." |
| 79 |
} |
| 80 |
}, |
| 81 |
"operation blocks":{ |
| 82 |
"myslicewithplane1":{ |
| 83 |
"type":"slicewithplane", |
| 84 |
"relative point on plane":[0.1, -0.2, 0.3], |
| 85 |
"plane normal":[1.0, 2.0, 3.0] |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
the plane normal does not need to be a unit vector: Phactori will normalize |
| 91 |
it for you (again, see PhactoriClipPlaneOperation) |
| 92 |
|
| 93 |
A minimalist example script using all default behavior will produce 8 images |
| 94 |
with autogenerated names with 6 axis aligned views and 2 diagonal xyz views |
| 95 |
colored by block index number (cylically). |
| 96 |
|
| 97 |
:: |
| 98 |
|
| 99 |
{ "camera blocks":{}, |
| 100 |
"representation blocks":{}, |
| 101 |
"imageset blocks":{"slice_1_imageset":{"operation":"myslicewithplane1"}}, |
| 102 |
"operation blocks":{"myslicewithplane1":{"type":"slicewithplane"}} } |
| 103 |
|
| 104 |
""" |
| 105 |
|
| 106 |
def CreateParaViewFilter(self, inInputFilter): |
| 107 |
|
| 108 |
#don't need our own init code at this point, but this is how it would be |
| 109 |
#added |
| 110 |
#def __init__(self): |
| 111 |
# MySuperClass.__init__(self) |
| 112 |
|
| 113 |
"""create the slice plane filter for ParaView""" |
| 114 |
if PhactoriDbg(100): |
| 115 |
myDebugPrint3('PhactoriSliceWithPlaneOperation.CreateParaViewFilter entered\n', 100) |
| 116 |
#info in block class should already be parsed and checked |
| 117 |
|
| 118 |
savedActiveSource = GetActiveSource() |
| 119 |
|
| 120 |
newParaViewFilter = SliceWithPlane(Input=inInputFilter) |
| 121 |
global gParaViewCatalystVersionFlag |
| 122 |
if gParaViewCatalystVersionFlag < 51100: |
| 123 |
newParaViewFilter.Plane = 'Plane' |
| 124 |
else: |
| 125 |
newParaViewFilter.PlaneType = 'Plane' |
| 126 |
|
| 127 |
self.UpdateSlice(inInputFilter, newParaViewFilter) |
| 128 |
|
| 129 |
SetActiveSource(newParaViewFilter) |
| 130 |
SetActiveSource(savedActiveSource) |
| 131 |
|
| 132 |
if PhactoriDbg(100): |
| 133 |
myDebugPrint3('PhactoriSliceWithPlaneOperation.CreateParaViewFilter returning\n', 100) |
| 134 |
|
| 135 |
return newParaViewFilter |
| 136 |
|
| 137 |
def DoUpdateDueToChangeInData(self, inIncomingPvFilter, |
| 138 |
outOutgoingPvFilter): |
| 139 |
"""the PhactoriSliceWithPlaneOperation may need to update if the point on |
| 140 |
the slice plane was tied to a node, element, or variable min/max |
| 141 |
location""" |
| 142 |
if PhactoriDbg(): |
| 143 |
myDebugPrint3("PhactoriSliceWithPlaneOperation::" |
| 144 |
"DoUpdateDueToChangeInData override executing\n") |
| 145 |
|
| 146 |
if self.MayChangeWithData() == False: |
| 147 |
if PhactoriDbg(): |
| 148 |
myDebugPrint3("PhactoriSliceWithPlanePlaneOperation::" |
| 149 |
"DoUpdateDueToChangeInData returning (absolute point or points)\n") |
| 150 |
return |
| 151 |
|
| 152 |
self.UpdateSlice(inIncomingPvFilter, outOutgoingPvFilter) |
| 153 |
|
| 154 |
if PhactoriDbg(): |
| 155 |
myDebugPrint3("PhactoriSliceWithPlanePlaneOperation::" |
| 156 |
"DoUpdateDueToChangeInData override returning\n") |
| 157 |
|
| 158 |
def UpdateSlice(self, inIncomingPvFilter, ioOutgoingPvFilter): |
| 159 |
"""using the current info on the slice, get all the paraview stuff |
| 160 |
set up correctly""" |
| 161 |
|
| 162 |
if PhactoriDbg(): |
| 163 |
myDebugPrint3("PhactoriSliceWithPlanePlaneOperation::UpdateSlice entered\n") |
| 164 |
|
| 165 |
originToUse = [0,0,0] |
| 166 |
normalToUse = [0,1,0] |
| 167 |
self.CalculateUpdatedOriginAndNormal( |
| 168 |
inIncomingPvFilter, originToUse, normalToUse) |
| 169 |
|
| 170 |
if PhactoriDbg(): |
| 171 |
myDebugPrint3(' updateslice using normal: ' + \ |
| 172 |
str(normalToUse) + '\n') |
| 173 |
myDebugPrint3(' updateslice using origin: ' + str(originToUse) + '\n') |
| 174 |
global gParaViewCatalystVersionFlag |
| 175 |
if gParaViewCatalystVersionFlag < 51100: |
| 176 |
ioOutgoingPvFilter.Plane.Normal = normalToUse |
| 177 |
ioOutgoingPvFilter.Plane.Origin = originToUse |
| 178 |
else: |
| 179 |
ioOutgoingPvFilter.PlaneType.Normal = normalToUse |
| 180 |
ioOutgoingPvFilter.PlaneType.Origin = originToUse |
| 181 |
|
| 182 |
if PhactoriDbg(): |
| 183 |
myDebugPrint3("PhactoriSliceWithPlanePlaneOperation::UpdateSlice returning\n") |
| 184 |
|
| 185 |
#phactori_combine_to_single_python_file_subpiece_end_1 |