pyNIBS 0.2024.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. pyNIBS-0.2024.8.dist-info/LICENSE +623 -0
  2. pyNIBS-0.2024.8.dist-info/METADATA +723 -0
  3. pyNIBS-0.2024.8.dist-info/RECORD +107 -0
  4. pyNIBS-0.2024.8.dist-info/WHEEL +5 -0
  5. pyNIBS-0.2024.8.dist-info/top_level.txt +1 -0
  6. pynibs/__init__.py +34 -0
  7. pynibs/coil.py +1367 -0
  8. pynibs/congruence/__init__.py +15 -0
  9. pynibs/congruence/congruence.py +1108 -0
  10. pynibs/congruence/ext_metrics.py +257 -0
  11. pynibs/congruence/stimulation_threshold.py +318 -0
  12. pynibs/data/configuration_exp0.yaml +59 -0
  13. pynibs/data/configuration_linear_MEP.yaml +61 -0
  14. pynibs/data/configuration_linear_RT.yaml +61 -0
  15. pynibs/data/configuration_sigmoid4.yaml +68 -0
  16. pynibs/data/network mapping configuration/configuration guide.md +238 -0
  17. pynibs/data/network mapping configuration/configuration_TEMPLATE.yaml +42 -0
  18. pynibs/data/network mapping configuration/configuration_for_testing.yaml +43 -0
  19. pynibs/data/network mapping configuration/configuration_modelTMS.yaml +43 -0
  20. pynibs/data/network mapping configuration/configuration_reg_isi_05.yaml +43 -0
  21. pynibs/data/network mapping configuration/output_documentation.md +185 -0
  22. pynibs/data/network mapping configuration/recommendations_for_accuracy_threshold.md +77 -0
  23. pynibs/data/neuron/models/L23_PC_cADpyr_biphasic_v1.csv +1281 -0
  24. pynibs/data/neuron/models/L23_PC_cADpyr_monophasic_v1.csv +1281 -0
  25. pynibs/data/neuron/models/L4_LBC_biphasic_v1.csv +1281 -0
  26. pynibs/data/neuron/models/L4_LBC_monophasic_v1.csv +1281 -0
  27. pynibs/data/neuron/models/L4_NBC_biphasic_v1.csv +1281 -0
  28. pynibs/data/neuron/models/L4_NBC_monophasic_v1.csv +1281 -0
  29. pynibs/data/neuron/models/L4_SBC_biphasic_v1.csv +1281 -0
  30. pynibs/data/neuron/models/L4_SBC_monophasic_v1.csv +1281 -0
  31. pynibs/data/neuron/models/L5_TTPC2_cADpyr_biphasic_v1.csv +1281 -0
  32. pynibs/data/neuron/models/L5_TTPC2_cADpyr_monophasic_v1.csv +1281 -0
  33. pynibs/expio/Mep.py +1518 -0
  34. pynibs/expio/__init__.py +8 -0
  35. pynibs/expio/brainsight.py +979 -0
  36. pynibs/expio/brainvis.py +71 -0
  37. pynibs/expio/cobot.py +239 -0
  38. pynibs/expio/exp.py +1876 -0
  39. pynibs/expio/fit_funs.py +287 -0
  40. pynibs/expio/localite.py +1987 -0
  41. pynibs/expio/signal_ced.py +51 -0
  42. pynibs/expio/visor.py +624 -0
  43. pynibs/freesurfer.py +502 -0
  44. pynibs/hdf5_io/__init__.py +10 -0
  45. pynibs/hdf5_io/hdf5_io.py +1857 -0
  46. pynibs/hdf5_io/xdmf.py +1542 -0
  47. pynibs/mesh/__init__.py +3 -0
  48. pynibs/mesh/mesh_struct.py +1394 -0
  49. pynibs/mesh/transformations.py +866 -0
  50. pynibs/mesh/utils.py +1103 -0
  51. pynibs/models/_TMS.py +211 -0
  52. pynibs/models/__init__.py +0 -0
  53. pynibs/muap.py +392 -0
  54. pynibs/neuron/__init__.py +2 -0
  55. pynibs/neuron/neuron_regression.py +284 -0
  56. pynibs/neuron/util.py +58 -0
  57. pynibs/optimization/__init__.py +5 -0
  58. pynibs/optimization/multichannel.py +278 -0
  59. pynibs/optimization/opt_mep.py +152 -0
  60. pynibs/optimization/optimization.py +1445 -0
  61. pynibs/optimization/workhorses.py +698 -0
  62. pynibs/pckg/__init__.py +0 -0
  63. pynibs/pckg/biosig/biosig4c++-1.9.5.src_fixed.tar.gz +0 -0
  64. pynibs/pckg/libeep/__init__.py +0 -0
  65. pynibs/pckg/libeep/pyeep.so +0 -0
  66. pynibs/regression/__init__.py +11 -0
  67. pynibs/regression/dual_node_detection.py +2375 -0
  68. pynibs/regression/regression.py +2984 -0
  69. pynibs/regression/score_types.py +0 -0
  70. pynibs/roi/__init__.py +2 -0
  71. pynibs/roi/roi.py +895 -0
  72. pynibs/roi/roi_structs.py +1233 -0
  73. pynibs/subject.py +1009 -0
  74. pynibs/tensor_scaling.py +144 -0
  75. pynibs/tests/data/InstrumentMarker20200225163611937.xml +19 -0
  76. pynibs/tests/data/TriggerMarkers_Coil0_20200225163443682.xml +14 -0
  77. pynibs/tests/data/TriggerMarkers_Coil1_20200225170337572.xml +6373 -0
  78. pynibs/tests/data/Xdmf.dtd +89 -0
  79. pynibs/tests/data/brainsight_niiImage_nifticoord.txt +145 -0
  80. pynibs/tests/data/brainsight_niiImage_nifticoord_largefile.txt +1434 -0
  81. pynibs/tests/data/brainsight_niiImage_niifticoord_mixedtargets.txt +47 -0
  82. pynibs/tests/data/create_subject_testsub.py +332 -0
  83. pynibs/tests/data/data.hdf5 +0 -0
  84. pynibs/tests/data/geo.hdf5 +0 -0
  85. pynibs/tests/test_coil.py +474 -0
  86. pynibs/tests/test_elements2nodes.py +100 -0
  87. pynibs/tests/test_hdf5_io/test_xdmf.py +61 -0
  88. pynibs/tests/test_mesh_transformations.py +123 -0
  89. pynibs/tests/test_mesh_utils.py +143 -0
  90. pynibs/tests/test_nnav_imports.py +101 -0
  91. pynibs/tests/test_quality_measures.py +117 -0
  92. pynibs/tests/test_regressdata.py +289 -0
  93. pynibs/tests/test_roi.py +17 -0
  94. pynibs/tests/test_rotations.py +86 -0
  95. pynibs/tests/test_subject.py +71 -0
  96. pynibs/tests/test_util.py +24 -0
  97. pynibs/tms_pulse.py +34 -0
  98. pynibs/util/__init__.py +4 -0
  99. pynibs/util/dosing.py +233 -0
  100. pynibs/util/quality_measures.py +562 -0
  101. pynibs/util/rotations.py +340 -0
  102. pynibs/util/simnibs.py +763 -0
  103. pynibs/util/util.py +727 -0
  104. pynibs/visualization/__init__.py +2 -0
  105. pynibs/visualization/para.py +4372 -0
  106. pynibs/visualization/plot_2D.py +137 -0
  107. pynibs/visualization/render_3D.py +347 -0
@@ -0,0 +1,4372 @@
1
+ """
2
+ Plot functions using Paraview. Needs paraview environment and explicit import via
3
+ import pynibs.visualization.para
4
+ """
5
+ import os
6
+ import copy
7
+ import h5py
8
+ import shutil
9
+ import numpy as np
10
+ from PIL import Image
11
+ from PIL import ImageChops
12
+ from paraview.simple import *
13
+ import xml.etree.ElementTree as ET
14
+
15
+
16
+ def ResetSession():
17
+ """
18
+ Resets Paraview session (needed if multiple plots are generated successively)
19
+ """
20
+ pxm = servermanager.ProxyManager()
21
+ pxm.UnRegisterProxies()
22
+ del pxm
23
+ Disconnect()
24
+ Connect()
25
+
26
+ def b2rcw(cmin_input, cmax_input):
27
+ """
28
+ BLUEWHITERED Blue, white, and red color map.
29
+ This function is designed to generate a blue to red colormap. The color of the colorbar is from blue to white and
30
+ then to red, corresponding to the data values from negative to zero to positive, respectively.
31
+ The color white always correspondes to value zero. The brightness of blue and red will change according to your
32
+ setting, so that the brightness of the color corresponded to the color of his opposite number.
33
+ e.g. b2rcw(-3,6) is from light blue to deep red
34
+ e.g. b2rcw(-3,3) is from deep blue to deep red
35
+
36
+ Parameters
37
+ ----------
38
+ cmin_input : float
39
+ Minimum value of data
40
+ cmax_input : float
41
+ Maximum value of data
42
+
43
+ Returns
44
+ -------
45
+ newmap : nparray of float [N_RGB x 3]
46
+ """
47
+
48
+ # check the input
49
+ if cmin_input >= cmax_input:
50
+ raise ValueError('input error, the color range must be from a smaller one to a larger one')
51
+
52
+ # color configuration : from blue to light blue to white untill to red
53
+ red_top = np.array([1, 0, 0])
54
+ white_middle= np.array([1, 1, 1])
55
+ blue_bottom = np.array([0, 0, 1])
56
+
57
+ # color interpolation
58
+ color_num = 250
59
+ color_input = np.vstack((blue_bottom, white_middle, red_top))
60
+ oldsteps = np.array([-1,0,1])
61
+ newsteps = np.linspace(-1, 1, color_num)
62
+
63
+ newmap_all = np.zeros((color_num,3))*np.nan
64
+
65
+ for j in range(3):
66
+ newmap_all[:, j] = np.min(np.vstack((np.max(
67
+ np.vstack((np.interp(newsteps, oldsteps, color_input[:, j]), np.zeros(color_num))), axis=0),
68
+ np.ones(color_num))), axis=0)
69
+
70
+ if (cmin_input < 0) & (cmax_input > 0):
71
+
72
+ if np.abs(cmin_input) < cmax_input:
73
+ # |--------|---------|--------------------|
74
+ # -cmax cmin 0 cmax [cmin,cmax]
75
+
76
+ start_point = int(np.ceil((cmin_input+cmax_input)/2.0/cmax_input*color_num)-1)
77
+ newmap = newmap_all[start_point:color_num, :]
78
+
79
+ elif np.abs(cmin_input) >= cmax_input:
80
+ # |------------------|------|--------------|
81
+ # cmin 0 cmax -cmin [cmin,cmax]
82
+
83
+ end_point = int(np.round((cmax_input-cmin_input)/2.0/np.abs(cmin_input)*color_num)-1)
84
+ newmap = newmap_all[1:end_point, :]
85
+
86
+ elif cmin_input >= 0:
87
+
88
+ # |-----------------|-------|-------------|
89
+ # -cmax 0 cmin cmax [cmin,cmax]
90
+
91
+ start_point = int(np.round((cmin_input+cmax_input)/2.0/cmax_input*color_num)-1)
92
+ newmap = newmap_all[start_point:color_num, :]
93
+
94
+ elif cmax_input <= 0:
95
+ # |------------|------|--------------------|
96
+ # cmin cmax 0 -cmin [cmin,cmax]
97
+
98
+ end_point = int(np.round((cmax_input-cmin_input)/2.0/np.abs(cmin_input)*color_num)-1)
99
+ newmap = newmap_all[1:end_point, :]
100
+
101
+ return newmap
102
+
103
+
104
+ def crop_data_hdf5_to_datarange(ps):
105
+ """
106
+ Crops the data (quantity) in .hdf5 data file to datarange and overwrites the original .hdf5 data file pointed by
107
+ the .xdmf file.
108
+
109
+ Parameters
110
+ ----------
111
+ ps : dict
112
+ Plot settings dictionary created with create_plotsettings_dict(plot_function)
113
+
114
+ Returns
115
+ -------
116
+ fn_hdf5 : str
117
+ Filename (incl. path) of data .hdf5 file (read from .xmdf file)
118
+ <File> : .hdf5 file
119
+ *_backup.hdf5 backup file of original .hdf5 data file
120
+ <File> .hdf5 file
121
+ Cropped data
122
+ """
123
+
124
+ fn_hdf5_end = []
125
+ key_hdf5 = []
126
+
127
+ # Read .xdmf input file
128
+ tree = ET.parse(ps['fname_in'][0])
129
+ root = tree.getroot()
130
+
131
+ if type(ps['quantity']) == list:
132
+ quantity = ps['quantity'][0]
133
+ else:
134
+ quantity = ps['quantity']
135
+
136
+ # Get .hdf5 data filename and hdf5 key of 'quantity'
137
+ for data_attribute in root.iter('Attribute'):
138
+ if data_attribute.get('Name') == quantity:
139
+ location = data_attribute[0].text[1: -1]
140
+ fn_hdf5_end, key_hdf5 = location.split(':')
141
+
142
+ if not fn_hdf5_end:
143
+ raise AttributeError('ps[\'quantity\'] not found in .hdf5 dataset')
144
+
145
+ fn_hdf5 = os.path.join(os.path.split(ps['fname_in'][0])[0], fn_hdf5_end)
146
+
147
+ # Backup original .hdf5 datafile *_backup.hdf5
148
+ shutil.copyfile(fn_hdf5, os.path.splitext(fn_hdf5)[0] + '_backup' + os.path.splitext(fn_hdf5)[1])
149
+
150
+ # Read 'quantity' data from .hdf5
151
+ f = h5py.File(fn_hdf5, 'r')
152
+ data = f[key_hdf5][:]
153
+ f.close()
154
+
155
+ if ps["calculator"] is not None:
156
+ calc_expre = ps["calculator"]
157
+ calc_expre = calc_expre.replace("{}", "data")
158
+ calc_expre = calc_expre.replace("^", "**")
159
+ calc_expre = calc_expre.replace("sin", "np.sin")
160
+ calc_expre = calc_expre.replace("cos", "np.cos")
161
+
162
+ # crop data to datarange
163
+ data_calc = eval(calc_expre)
164
+
165
+ else:
166
+ data_calc = data
167
+
168
+ data_cropped = copy.deepcopy(data_calc)
169
+
170
+ if ps['datarange'][0] is None:
171
+ ps['datarange'][0] = np.min(data_calc)
172
+
173
+ if ps['datarange'][1] is None:
174
+ ps['datarange'][1] = np.max(data_calc)
175
+
176
+ delta_range = float(ps['datarange'][1]) - float(ps['datarange'][0])
177
+
178
+ data_cropped[data_calc < float(ps['datarange'][0])] = float(ps['datarange'][0])
179
+ data_cropped[data_calc > float(ps['datarange'][1])] = float(ps['datarange'][1]) - delta_range/1000
180
+
181
+ # Overwrite and save dataset with cropped data
182
+ f = h5py.File(fn_hdf5, 'r+')
183
+ del f[key_hdf5]
184
+ f.create_dataset(name=key_hdf5, data=data_cropped)
185
+ f.close()
186
+
187
+ return fn_hdf5
188
+
189
+
190
+ def crop_image(fname_image, fname_image_cropped):
191
+ """
192
+ Remove surrounding empty space around an image. This implemenation
193
+ assumes that the surrounding space has the same colour as the top leftmost
194
+ pixel.
195
+
196
+ Parameters
197
+ ----------
198
+ fname_image : str
199
+ Filename of image to be cropped
200
+
201
+ Returns
202
+ -------
203
+ <File> : .png file
204
+ Cropped image file saved as "fname_image_cropped"
205
+ """
206
+ im = Image.open(fname_image)
207
+
208
+ bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
209
+ diff = ImageChops.difference(im, bg)
210
+ bbox = diff.getbbox()
211
+
212
+ if not bbox:
213
+ im_cropped = im
214
+ else:
215
+ im_cropped = im.crop(bbox)
216
+
217
+ im_cropped.save(fname_image_cropped)
218
+
219
+
220
+ def surface_vector_plot(ps):
221
+ """
222
+ Generate plot with Paraview from data in .hdf5 file(s).
223
+
224
+ Parameters
225
+ ----------
226
+ ps : dict
227
+ Plot settings dict initialized with create_plot_settings_dict(plotfunction_type='surface_vector_plot')
228
+
229
+ Returns
230
+ -------
231
+ <File> : .png file
232
+ Generated plot
233
+ """
234
+
235
+ if type(ps['quantity']) is list:
236
+ quantity = ps['quantity'][0]
237
+ else:
238
+ quantity = ps['quantity']
239
+
240
+ # add whitespace if colorbar label is not given (empty colorbar labels are plotted wrong)
241
+ if ps['colorbar_label'] is None or ps['colorbar_label']=='':
242
+ ps['colorbar_label'] = ' '
243
+
244
+ if type(ps['fname_in']) is str:
245
+ ps['fname_in'] = [ps['fname_in']]
246
+
247
+ _, ext = os.path.splitext(ps['fname_in'][0])
248
+
249
+ # make .xdmf file if .hdf5 file is provided
250
+ if ext == '.hdf5':
251
+ mode = 'hdf5'
252
+ fname_load = os.path.join(os.path.splitext(ps['fname_in'][0]), '.xdmf')
253
+
254
+ if len(ps['fname_in']) == 1:
255
+ write_xdmf(hdf5_fn = ps['fname_in'][0], hdf5_geo_fn=None, overwrite_xdmf=True)
256
+ elif len(ps['fname_in']) == 2:
257
+ write_xdmf(hdf5_fn = ps['fname_in'][0], hdf5_geo_fn = ps['fname_in'][1], overwrite_xdmf=True)
258
+ else:
259
+ raise Exception('Please specify either one .hdf5 file containing data and geometry or two .hdf5 files,'
260
+ 'whereas the first contains the data and the second the geometry!')
261
+ elif ext == '.xdmf':
262
+ mode = 'xdmf'
263
+ fname_load = ps['fname_in']
264
+
265
+ else:
266
+ raise Exception('Please check file type and extension!')
267
+
268
+ # crop data to datarange and temporarily save it to to avoid graphics bug
269
+ ps['fname_in'] = fname_load
270
+
271
+ fn_data_hdf5 = crop_data_hdf5_to_datarange(ps)
272
+ data_cropped = True
273
+
274
+ # set target for interpolation
275
+ if ps['interpolate']:
276
+ target = 'POINTS'
277
+ else:
278
+ target = 'CELLS'
279
+
280
+ # create a new 'Xdmf3ReaderT' for data
281
+ p = paraview.simple.Xdmf3ReaderT(FileName=[fname_load[0]])
282
+ renderView = GetActiveViewOrCreate('RenderView')
283
+
284
+ label_datasets = p.CellArrays
285
+ N_datasets = len(label_datasets)
286
+
287
+ if len(ps['datarange']) == 1 and ps['datarange'][0] == None:
288
+ datarange = [None, None]
289
+
290
+ # set surface smoothing
291
+ if ps["surface_smoothing"]:
292
+ # create a new 'Extract Surface'
293
+ p = paraview.simple.ExtractSurface(Input=p)
294
+
295
+ # create a new 'Generate Surface Normals'
296
+ p = paraview.simple.GenerateSurfaceNormals(Input=p)
297
+
298
+ # Properties modified on generateSurfaceNormals1
299
+ p.FeatureAngle = 50.0
300
+
301
+ # set calculator
302
+ # if ps["calculator"] is not None:
303
+ # # create a new 'Calculator'
304
+ # ps["calculator"] = ps["calculator"].replace("{}", ps["quantity"])
305
+ # Hide(p, renderView)
306
+ # p = paraview.simple.Calculator(Input=p)
307
+ # p.AttributeType = 'Cell Data'
308
+ # exec('p.Function = "' + ps["calculator"] + '"')
309
+ # ps["quantity"] = "Result"
310
+ # quantity = "Result"
311
+
312
+ # get data ranges of included datasets
313
+ if None in ps['datarange']:
314
+ datarange_temp = servermanager.Fetch(p).GetBlock(0).GetCellData().GetArray(quantity).GetRange(0)
315
+
316
+ if ps['datarange'][0] is None:
317
+ ps['datarange'][0] = datarange_temp[0]
318
+
319
+ if ps['datarange'][1] is None:
320
+ ps['datarange'][1] = datarange_temp[1]
321
+
322
+ # check if curvature data exists
323
+ if np.any([True for label in ['curve', 'curv', 'curvature'] if label in label_datasets]):
324
+ curve_exists = True
325
+ curve_label = [label for label in ['curve', 'curv'] if label in ['curv', 'test']]
326
+ else:
327
+ curve_exists = False
328
+ curve_label = ['']
329
+
330
+ renderView = GetActiveViewOrCreate('RenderView')
331
+
332
+ pLUT = GetColorTransferFunction(quantity)
333
+ # pLUT.LockDataRange = 0 # not in v5.8 anymore
334
+ pLUT.InterpretValuesAsCategories = 0
335
+ pLUT.ShowCategoricalColorsinDataRangeOnly = 0
336
+ pLUT.RescaleOnVisibilityChange = 0
337
+ pLUT.EnableOpacityMapping = 0
338
+ #pLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 0.50000500005, 0.865003, 0.865003, 0.865003,
339
+ # 1.0000100001, 0.705882, 0.0156863, 0.14902]
340
+ pLUT.UseLogScale = 0
341
+ pLUT.ColorSpace = 'Diverging'
342
+ pLUT.UseBelowRangeColor = 0
343
+ pLUT.BelowRangeColor = [0.0, 0.0, 0.0]
344
+ pLUT.UseAboveRangeColor = 0
345
+ pLUT.AboveRangeColor = [1.0, 1.0, 1.0]
346
+ pLUT.NanColor = ps['NanColor']
347
+ pLUT.Discretize = 1
348
+ pLUT.NumberOfTableValues = 256
349
+ pLUT.ScalarRangeInitialized = 1.0
350
+ pLUT.HSVWrap = 0
351
+ pLUT.VectorComponent = 0
352
+ pLUT.VectorMode = 'Magnitude'
353
+ pLUT.AllowDuplicateScalars = 1
354
+ pLUT.Annotations = []
355
+ pLUT.ActiveAnnotatedValues = []
356
+ pLUT.IndexedColors = []
357
+
358
+ # show data in view
359
+ pDisplay = Show(p, renderView)
360
+
361
+ # trace defaults for the display properties.
362
+ pDisplay.Representation = 'Surface'
363
+ pDisplay.AmbientColor = [1.0, 1.0, 1.0]
364
+ pDisplay.ColorArrayName = ['POINTS', ps['domain_label']]
365
+ pDisplay.DiffuseColor = [1.0, 1.0, 1.0]
366
+ pDisplay.LookupTable = pLUT
367
+ pDisplay.MapScalars = 1
368
+ pDisplay.InterpolateScalarsBeforeMapping = 1
369
+ pDisplay.Opacity = 1.0
370
+ pDisplay.PointSize = 2.0
371
+ pDisplay.LineWidth = 1.0
372
+ pDisplay.Interpolation = 'Gouraud'
373
+ pDisplay.Specular = 0.0
374
+ pDisplay.SpecularColor = [1.0, 1.0, 1.0]
375
+ pDisplay.SpecularPower = 100.0
376
+ pDisplay.Ambient = 0.0
377
+ pDisplay.Diffuse = 1.0
378
+ pDisplay.EdgeColor = [0.0, 0.0, 0.5]
379
+ pDisplay.BackfaceRepresentation = 'Follow Frontface'
380
+ pDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
381
+ pDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
382
+ pDisplay.BackfaceOpacity = 1.0
383
+ pDisplay.Position = [0.0, 0.0, 0.0]
384
+ pDisplay.Scale = [1.0, 1.0, 1.0]
385
+ pDisplay.Orientation = [0.0, 0.0, 0.0]
386
+ pDisplay.Origin = [0.0, 0.0, 0.0]
387
+ pDisplay.Pickable = 1
388
+ pDisplay.Texture = None
389
+ pDisplay.Triangulate = 0
390
+ pDisplay.NonlinearSubdivisionLevel = 1
391
+ pDisplay.OSPRayUseScaleArray = 0
392
+ pDisplay.OSPRayScaleArray = ps["quantity"]
393
+ pDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
394
+ pDisplay.GlyphType = 'Arrow'
395
+ pDisplay.SelectionCellLabelBold = 0
396
+ pDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
397
+ pDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
398
+ pDisplay.SelectionCellLabelFontSize = 18
399
+ pDisplay.SelectionCellLabelItalic = 0
400
+ pDisplay.SelectionCellLabelJustification = 'Left'
401
+ pDisplay.SelectionCellLabelOpacity = 1.0
402
+ pDisplay.SelectionCellLabelShadow = 0
403
+ pDisplay.SelectionPointLabelBold = 0
404
+ pDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
405
+ pDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
406
+ pDisplay.SelectionPointLabelFontSize = 18
407
+ pDisplay.SelectionPointLabelItalic = 0
408
+ pDisplay.SelectionPointLabelJustification = 'Left'
409
+ pDisplay.SelectionPointLabelOpacity = 1.0
410
+ pDisplay.SelectionPointLabelShadow = 0
411
+ # pDisplay.ScalarOpacityUnitDistance = 4.008392218456473 # surface_smoothing
412
+ # pDisplay.SelectMapper = 'Projected tetra' # surface_smoothing
413
+ pDisplay.GaussianRadius = 0.0
414
+ pDisplay.ShaderPreset = 'Sphere'
415
+ pDisplay.Emissive = 0
416
+ pDisplay.ScaleByArray = 0
417
+ pDisplay.SetScaleArray = ['POINTS', ps["quantity"]]
418
+ pDisplay.ScaleTransferFunction = 'PiecewiseFunction'
419
+ pDisplay.OpacityByArray = 0
420
+ pDisplay.OpacityArray = ['POINTS', ps["quantity"]]
421
+ pDisplay.OpacityTransferFunction = 'PiecewiseFunction'
422
+
423
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
424
+ pDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
425
+
426
+ # init the 'Arrow' selected for 'GlyphType'
427
+ pDisplay.GlyphType.TipResolution = 6
428
+ pDisplay.GlyphType.TipRadius = 0.1
429
+ pDisplay.GlyphType.TipLength = 0.35
430
+ pDisplay.GlyphType.ShaftResolution = 6
431
+ pDisplay.GlyphType.ShaftRadius = 0.03
432
+ pDisplay.GlyphType.Invert = 0
433
+
434
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
435
+ pDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
436
+
437
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
438
+ pDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
439
+
440
+ # reset view to fit data
441
+ renderView.ResetCamera()
442
+
443
+ # show color bar/color legend
444
+ pDisplay.SetScalarBarVisibility(renderView, False)
445
+
446
+ # get opacity transfer function/opacity map for 'tissuetype'
447
+ pPWF = GetOpacityTransferFunction('tissuetype')
448
+ pPWF.Points = [0.0, 0.0, 0.5, 0.0, 1.0000100001, 1.0, 0.5, 0.0]
449
+ pPWF.AllowDuplicateScalars = 1
450
+ pPWF.ScalarRangeInitialized = 1
451
+
452
+ # =============================================================================
453
+ # threshold data to choose surface to plot data on
454
+ # =============================================================================
455
+ # create a new 'Threshold'
456
+
457
+ t1 = paraview.simple.Threshold(Input=p)
458
+ t1.Scalars = ['POINTS', ps['domain_label']]
459
+ t1.ThresholdRange = [ps['domain_IDs'], ps['domain_IDs']]
460
+ t1.AllScalars = 1
461
+ t1.UseContinuousCellRange = 0
462
+
463
+ if ps['interpolate']:
464
+ t1i = paraview.simple.CellDatatoPointData(Input=t1)
465
+ t1i.PassCellData = 0
466
+ t1i.PieceInvariant = 0
467
+ # show data in view
468
+ t1Display = Show(t1i, renderView)
469
+ else:
470
+ # show data in view
471
+ t1Display = Show(t1, renderView)
472
+
473
+ # trace defaults for the display properties.
474
+ t1Display.Representation = 'Surface'
475
+ t1Display.AmbientColor = [1.0, 1.0, 1.0]
476
+ t1Display.ColorArrayName = ['POINTS', ps['domain_label']]
477
+ t1Display.DiffuseColor = [1.0, 1.0, 1.0]
478
+ t1Display.LookupTable = pLUT
479
+ t1Display.MapScalars = 1
480
+ t1Display.InterpolateScalarsBeforeMapping = 1
481
+ t1Display.Opacity = 1.0
482
+ t1Display.PointSize = 2.0
483
+ t1Display.LineWidth = 1.0
484
+ t1Display.Interpolation = 'Gouraud'
485
+ t1Display.Specular = 0.0
486
+ t1Display.SpecularColor = [1.0, 1.0, 1.0]
487
+ t1Display.SpecularPower = 100.0
488
+ t1Display.Ambient = 0.0
489
+ t1Display.Diffuse = 1.0
490
+ t1Display.EdgeColor = [0.0, 0.0, 0.5]
491
+ t1Display.BackfaceRepresentation = 'Follow Frontface'
492
+ t1Display.BackfaceAmbientColor = [1.0, 1.0, 1.0]
493
+ t1Display.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
494
+ t1Display.BackfaceOpacity = 1.0
495
+ t1Display.Position = [0.0, 0.0, 0.0]
496
+ t1Display.Scale = [1.0, 1.0, 1.0]
497
+ t1Display.Orientation = [0.0, 0.0, 0.0]
498
+ t1Display.Origin = [0.0, 0.0, 0.0]
499
+ t1Display.Pickable = 1
500
+ t1Display.Texture = None
501
+ t1Display.Triangulate = 0
502
+ t1Display.NonlinearSubdivisionLevel = 1
503
+ t1Display.OSPRayUseScaleArray = 0
504
+ t1Display.OSPRayScaleArray = ps['domain_label']
505
+ t1Display.OSPRayScaleFunction = 'PiecewiseFunction'
506
+ t1Display.GlyphType = 'Arrow'
507
+ t1Display.SelectionCellLabelBold = 0
508
+ t1Display.SelectionCellLabelColor = [0.0, 1.0, 0.0]
509
+ t1Display.SelectionCellLabelFontFamily = 'Arial'
510
+ t1Display.SelectionCellLabelFontSize = 18
511
+ t1Display.SelectionCellLabelItalic = 0
512
+ t1Display.SelectionCellLabelJustification = 'Left'
513
+ t1Display.SelectionCellLabelOpacity = 1.0
514
+ t1Display.SelectionCellLabelShadow = 0
515
+ t1Display.SelectionPointLabelBold = 0
516
+ t1Display.SelectionPointLabelColor = [1.0, 1.0, 0.0]
517
+ t1Display.SelectionPointLabelFontFamily = 'Arial'
518
+ t1Display.SelectionPointLabelFontSize = 18
519
+ t1Display.SelectionPointLabelItalic = 0
520
+ t1Display.SelectionPointLabelJustification = 'Left'
521
+ t1Display.SelectionPointLabelOpacity = 1.0
522
+ t1Display.SelectionPointLabelShadow = 0
523
+ t1Display.ScalarOpacityUnitDistance = 4.903157073141748
524
+ t1Display.SelectMapper = 'Projected tetra'
525
+ t1Display.GaussianRadius = 0.0
526
+ t1Display.ShaderPreset = 'Sphere'
527
+ t1Display.Emissive = 0
528
+ t1Display.ScaleByArray = 0
529
+ t1Display.SetScaleArray = ['POINTS', ps["quantity"]]
530
+ t1Display.ScaleTransferFunction = 'PiecewiseFunction'
531
+ t1Display.OpacityByArray = 0
532
+ t1Display.OpacityArray = ['POINTS', ps["quantity"]]
533
+ t1Display.OpacityTransferFunction = 'PiecewiseFunction'
534
+
535
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
536
+ t1Display.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
537
+
538
+ # init the 'Arrow' selected for 'GlyphType'
539
+ t1Display.GlyphType.TipResolution = 6
540
+ t1Display.GlyphType.TipRadius = 0.1
541
+ t1Display.GlyphType.TipLength = 0.35
542
+ t1Display.GlyphType.ShaftResolution = 6
543
+ t1Display.GlyphType.ShaftRadius = 0.03
544
+ t1Display.GlyphType.Invert = 0
545
+
546
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
547
+ t1Display.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
548
+
549
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
550
+ t1Display.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
551
+
552
+ # hide data in view
553
+ Hide(p, renderView)
554
+
555
+ # set scalar coloring
556
+ if curve_exists:
557
+ ColorBy(t1Display, (target, curve_label[0]))
558
+ else:
559
+ ColorBy(t1Display, None)
560
+
561
+ # rescale color and/or opacity maps used to include current data range
562
+ t1Display.RescaleTransferFunctionToDataRange(True)
563
+
564
+ # show color bar/color legend
565
+ # t1Display.SetScalarBarVisibility(renderView, False)
566
+
567
+ # get color transfer function/color map for 'curv'
568
+ curvLUT = GetColorTransferFunction(curve_label[0])
569
+ # curvLUT.LockDataRange = 0 # not in v5.8 anymore
570
+ curvLUT.InterpretValuesAsCategories = 0
571
+ curvLUT.ShowCategoricalColorsinDataRangeOnly = 0
572
+ curvLUT.RescaleOnVisibilityChange = 0
573
+ curvLUT.EnableOpacityMapping = 0
574
+ #curvLUT.RGBPoints = [-3.1706008911132812, 1.0, 1.0, 1.0, 1.9234193563461304, 0.0, 0.0, 0.0]
575
+ curvLUT.UseLogScale = 0
576
+ curvLUT.ColorSpace = 'RGB'
577
+ curvLUT.UseBelowRangeColor = 0
578
+ curvLUT.BelowRangeColor = [0.0, 0.0, 0.0]
579
+ curvLUT.UseAboveRangeColor = 0
580
+ curvLUT.AboveRangeColor = [1.0, 1.0, 1.0]
581
+ curvLUT.NanColor = ps['NanColor']
582
+ curvLUT.Discretize = 1
583
+ curvLUT.NumberOfTableValues = 256
584
+ curvLUT.ScalarRangeInitialized = 1.0
585
+ curvLUT.HSVWrap = 0
586
+ curvLUT.VectorComponent = 0
587
+ curvLUT.VectorMode = 'Magnitude'
588
+ curvLUT.AllowDuplicateScalars = 1
589
+ curvLUT.Annotations = []
590
+ curvLUT.ActiveAnnotatedValues = []
591
+ curvLUT.IndexedColors = []
592
+
593
+ # get opacity transfer function/opacity map for 'curv'
594
+ curvPWF = GetOpacityTransferFunction(curve_label[0])
595
+ #curvPWF.Points = [-3.1706008911132812, 0.0, 0.5, 0.0, 1.9234193563461304, 1.0, 0.5, 0.0]
596
+ curvPWF.AllowDuplicateScalars = 1
597
+ curvPWF.ScalarRangeInitialized = 1
598
+
599
+ # Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
600
+ curvLUT.ApplyPreset('Grayscale', True)
601
+
602
+ # =============================================================================
603
+ # threshold data to choose data to plot on surface
604
+ # =============================================================================
605
+
606
+ # create a new 'Threshold'
607
+ t2 = paraview.simple.Threshold(Input=t1)
608
+ t2.Scalars = ['CELLS', quantity]
609
+
610
+ if ps['datarange']:
611
+ t2.ThresholdRange = [float(ps['datarange'][0]), ps['datarange'][1]]
612
+
613
+ t2.AllScalars = 1
614
+ t2.UseContinuousCellRange = 0
615
+
616
+ if ps['interpolate']:
617
+ # create a new 'Cell Data to Point Data'
618
+ t2i = paraview.simple.CellDatatoPointData(Input=t2)
619
+ t2i.PassCellData = 0
620
+ t2i.PieceInvariant = 0
621
+ # show data in view
622
+ t2Display = Show(t2i, renderView)
623
+ else:
624
+ # show data in view
625
+ t2Display = Show(t2, renderView)
626
+
627
+
628
+ # trace defaults for the display properties.
629
+ t2Display.Representation = 'Surface'
630
+ t2Display.AmbientColor = [1.0, 1.0, 1.0]
631
+ t2Display.ColorArrayName = ['POINTS', quantity]
632
+ t2Display.DiffuseColor = [1.0, 1.0, 1.0]
633
+ t2Display.LookupTable = pLUT
634
+ t2Display.MapScalars = 1
635
+ t2Display.InterpolateScalarsBeforeMapping = 1
636
+ t2Display.Opacity = 1.0
637
+ t2Display.PointSize = 2.0
638
+ t2Display.LineWidth = 1.0
639
+ t2Display.Interpolation = 'Gouraud'
640
+ t2Display.Specular = 0.0
641
+ t2Display.SpecularColor = [1.0, 1.0, 1.0]
642
+ t2Display.SpecularPower = 100.0
643
+ t2Display.Ambient = 0.0
644
+ t2Display.Diffuse = 1.0
645
+ t2Display.EdgeColor = [0.0, 0.0, 0.5]
646
+ t2Display.BackfaceRepresentation = 'Follow Frontface'
647
+ t2Display.BackfaceAmbientColor = [1.0, 1.0, 1.0]
648
+ t2Display.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
649
+ t2Display.BackfaceOpacity = 1.0
650
+ t2Display.Position = [0.0, 0.0, 0.0]
651
+ t2Display.Scale = [1.0, 1.0, 1.0]
652
+ t2Display.Orientation = [0.0, 0.0, 0.0]
653
+ t2Display.Origin = [0.0, 0.0, 0.0]
654
+ t2Display.Pickable = 1
655
+ t2Display.Texture = None
656
+ t2Display.Triangulate = 0
657
+ t2Display.NonlinearSubdivisionLevel = 1
658
+ t2Display.OSPRayUseScaleArray = 0
659
+ t2Display.OSPRayScaleArray = quantity
660
+ t2Display.OSPRayScaleFunction = 'PiecewiseFunction'
661
+ t2Display.GlyphType = 'Arrow'
662
+ t2Display.SelectionCellLabelBold = 0
663
+ t2Display.SelectionCellLabelColor = [0.0, 1.0, 0.0]
664
+ t2Display.SelectionCellLabelFontFamily = 'Arial'
665
+ t2Display.SelectionCellLabelFontSize = 18
666
+ t2Display.SelectionCellLabelItalic = 0
667
+ t2Display.SelectionCellLabelJustification = 'Left'
668
+ t2Display.SelectionCellLabelOpacity = 1.0
669
+ t2Display.SelectionCellLabelShadow = 0
670
+ t2Display.SelectionPointLabelBold = 0
671
+ t2Display.SelectionPointLabelColor = [1.0, 1.0, 0.0]
672
+ t2Display.SelectionPointLabelFontFamily = 'Arial'
673
+ t2Display.SelectionPointLabelFontSize = 18
674
+ t2Display.SelectionPointLabelItalic = 0
675
+ t2Display.SelectionPointLabelJustification = 'Left'
676
+ t2Display.SelectionPointLabelOpacity = 1.0
677
+ t2Display.SelectionPointLabelShadow = 0
678
+ t2Display.ScalarOpacityUnitDistance = 3.974831691176322
679
+ t2Display.SelectMapper = 'Projected tetra'
680
+ t2Display.GaussianRadius = 0.0
681
+ t2Display.ShaderPreset = 'Sphere'
682
+ t2Display.Emissive = 0
683
+ t2Display.ScaleByArray = 0
684
+ t2Display.SetScaleArray = ['POINTS', quantity]
685
+ t2Display.ScaleTransferFunction = 'PiecewiseFunction'
686
+ t2Display.OpacityByArray = 0
687
+ t2Display.OpacityArray = ['POINTS', quantity]
688
+ t2Display.OpacityTransferFunction = 'PiecewiseFunction'
689
+
690
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
691
+ t2Display.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
692
+
693
+ # init the 'Arrow' selected for 'GlyphType'
694
+ t2Display.GlyphType.TipResolution = 6
695
+ t2Display.GlyphType.TipRadius = 0.1
696
+ t2Display.GlyphType.TipLength = 0.35
697
+ t2Display.GlyphType.ShaftResolution = 6
698
+ t2Display.GlyphType.ShaftRadius = 0.03
699
+ t2Display.GlyphType.Invert = 0
700
+
701
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
702
+ t2Display.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
703
+
704
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
705
+ t2Display.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
706
+
707
+ # set scalar coloring
708
+ ColorBy(t2Display, (target, quantity))
709
+
710
+ # show color bar/color legend
711
+ t2Display.SetScalarBarVisibility(renderView, True)
712
+
713
+ # get color transfer function/color map for 'mic'
714
+ t2LUT = GetColorTransferFunction(quantity)
715
+ # t2LUT.LockDataRange = 0 # not in v5.8 anymore
716
+ t2LUT.InterpretValuesAsCategories = 0
717
+ t2LUT.ShowCategoricalColorsinDataRangeOnly = 0
718
+ t2LUT.RescaleOnVisibilityChange = 0
719
+ #t2LUT.RGBPoints = [0.0006630485877394676, 0.231373, 0.298039, 0.752941, 0.42029112903401256, 0.865003, 0.865003,
720
+ # 0.865003, 0.8399192094802856, 0.705882, 0.0156863, 0.14902]
721
+ t2LUT.UseLogScale = 0
722
+ t2LUT.ColorSpace = 'Diverging'
723
+ t2LUT.UseBelowRangeColor = 0
724
+ t2LUT.BelowRangeColor = [0.0, 0.0, 0.0]
725
+ t2LUT.UseAboveRangeColor = 0
726
+ t2LUT.AboveRangeColor = [1.0, 1.0, 1.0]
727
+ t2LUT.NanColor = ps['NanColor']
728
+ t2LUT.Discretize = 1
729
+ t2LUT.NumberOfTableValues = 256
730
+ t2LUT.ScalarRangeInitialized = 1.0
731
+ t2LUT.HSVWrap = 0
732
+ t2LUT.VectorComponent = 0
733
+ t2LUT.VectorMode = 'Magnitude'
734
+ t2LUT.AllowDuplicateScalars = 1
735
+ t2LUT.Annotations = []
736
+ t2LUT.ActiveAnnotatedValues = []
737
+ t2LUT.IndexedColors = []
738
+
739
+ t2PWF = GetOpacityTransferFunction(quantity)
740
+ if ps['opacitymap']:
741
+ t2LUT.EnableOpacityMapping = 1
742
+ t2PWF.Points = ps['opacitymap']
743
+
744
+ # get opacity transfer function/opacity map for 'mic'
745
+ t2PWF.AllowDuplicateScalars = 1
746
+ t2PWF.ScalarRangeInitialized = 1
747
+
748
+ # camera placement for renderView
749
+ if len(ps['view']) == 4:
750
+ renderView.CameraPosition = ps['view'][0]
751
+ renderView.CameraFocalPoint = ps['view'][1]
752
+ renderView.CameraViewUp = ps['view'][2]
753
+ renderView.CameraParallelScale = ps['view'][3][0]
754
+ else:
755
+ renderView.ResetCamera()
756
+
757
+ if ps['interpolate']:
758
+ t2LUT.ColorSpace = 'RGB'
759
+ else:
760
+ t2LUT.ColorSpace = 'RGB' #'Diverging'
761
+
762
+ # =============================================================================
763
+ # set colormap for magnitude plot
764
+ # =============================================================================
765
+ if type(ps['colormap']) is str:
766
+ colormap_presets = {'Cool to Warm',
767
+ 'Cool to Warm (Extended)',
768
+ 'Blue to Red Rainbow',
769
+ 'X Ray',
770
+ 'Grayscale',
771
+ 'jet',
772
+ 'hsv',
773
+ 'erdc_iceFire_L',
774
+ 'Plasma (matplotlib)',
775
+ 'Viridis (matplotlib)',
776
+ 'gray_Matlab',
777
+ 'Spectral_lowBlue',
778
+ 'BuRd',
779
+ 'Rainbow Blended White',
780
+ 'b2rcw'}
781
+
782
+ # set colorbar to 'jet' if not specified in presets
783
+ if not (ps['colormap'] in colormap_presets):
784
+ print((
785
+ 'Changing colormap to \'jet\' since user specified colormap \'{}\' is not part of the included presets ...').format(
786
+ ps['colormap']))
787
+ colormap = 'jet'
788
+
789
+ if ps['colormap'] == 'b2rcw':
790
+ rgb_values = b2rcw(ps['datarange'][0], ps['datarange'][1])
791
+ rgb_data = np.linspace(ps['datarange'][0], ps['datarange'][1], rgb_values.shape[0])[:, np.newaxis]
792
+ t2LUT.RGBPoints = np.hstack((rgb_data, rgb_values)).flatten()
793
+ else:
794
+ t2LUT.ApplyPreset(ps['colormap'], True)
795
+ else:
796
+ if ps['colormap_categories']:
797
+
798
+ n_categories = int(len(ps['colormap']) / 4)
799
+
800
+ # Properties modified on hotspotsLUT
801
+ t2LUT.InterpretValuesAsCategories = 1
802
+ t2LUT.AnnotationsInitialized = 1
803
+
804
+ # Properties modified on hotspotsLUT
805
+ t2LUT.Annotations = list(np.array([[str(i), str(i)] for i in range(n_categories)]).flatten())
806
+ t2LUT.IndexedOpacities = [1.0] * n_categories
807
+
808
+ # here now we need only the RGB values
809
+ t2LUT.IndexedColors = np.reshape(ps['colormap'], (n_categories, 4))[:, 1:].flatten()
810
+ else:
811
+
812
+ t2LUT.RGBPoints = ps['colormap']
813
+
814
+ # change representation type
815
+ if ps['edges']:
816
+ t2Display.SetRepresentationType('Surface With Edges')
817
+
818
+ # get color legend/bar for eLUT in view renderView
819
+ t2LUTColorBar = paraview.simple.GetScalarBar(pLUT, renderView)
820
+ t2LUTColorBar.WindowLocation = 'LowerCenter'
821
+ t2LUTColorBar.Orientation = ps['colorbar_orientation']
822
+
823
+ # setting the position does not work anymore for some reason (Paraview 5.8)
824
+ if ps['colorbar_position']:
825
+ t2LUTColorBar.Position = ps['colorbar_position']
826
+ else:
827
+ t2LUTColorBar.Position = [0.847321428571429, 0.292476354256234]
828
+
829
+ t2LUTColorBar.AutoOrient = 1
830
+ t2LUTColorBar.Title = ps['colorbar_label']
831
+ t2LUTColorBar.ComponentTitle = ''
832
+ t2LUTColorBar.TitleJustification = 'Centered'
833
+ t2LUTColorBar.TitleColor = ps['colorbar_labelcolor']
834
+ t2LUTColorBar.TitleOpacity = 1.0
835
+ t2LUTColorBar.TitleFontFamily = ps['colorbar_font']
836
+ t2LUTColorBar.TitleBold = 0
837
+ t2LUTColorBar.TitleItalic = 0
838
+ t2LUTColorBar.TitleShadow = 0
839
+ t2LUTColorBar.TitleFontSize = ps['colorbar_titlefontsize']
840
+ t2LUTColorBar.LabelColor = ps['colorbar_labelcolor']
841
+ t2LUTColorBar.LabelOpacity = 1.0
842
+ t2LUTColorBar.LabelFontFamily = ps['colorbar_font']
843
+ t2LUTColorBar.LabelBold = 0
844
+ t2LUTColorBar.LabelItalic = 0
845
+ t2LUTColorBar.LabelShadow = 0
846
+ t2LUTColorBar.LabelFontSize = ps['colorbar_labelfontsize']
847
+ t2LUTColorBar.AutomaticLabelFormat = 0
848
+ t2LUTColorBar.LabelFormat = ps['colorbar_labelformat']
849
+ # t2LUTColorBar.NumberOfLabels = ps['colorbar_numberoflabels'] # not in v5.8 anymore
850
+ t2LUTColorBar.DrawTickMarks = 1
851
+ # t2LUTColorBar.DrawSubTickMarks = 1 # not in v5.8 anymore
852
+ t2LUTColorBar.DrawTickLabels = 1
853
+ t2LUTColorBar.AddRangeLabels = 1
854
+ t2LUTColorBar.RangeLabelFormat = ps['colorbar_labelformat']
855
+ t2LUTColorBar.DrawAnnotations = 1
856
+ t2LUTColorBar.AddRangeAnnotations = 0
857
+ t2LUTColorBar.AutomaticAnnotations = 0
858
+ t2LUTColorBar.DrawNanAnnotation = 0
859
+ t2LUTColorBar.NanAnnotation = 'NaN'
860
+ t2LUTColorBar.TextPosition = 'Ticks right/top, annotations left/bottom'
861
+ # t2LUTColorBar.AspectRatio = ps['colorbar_aspectratio'] # paraview.NotSupportedException: 'AspectRatio' is obsolete as of ParaView 5.4. Use the 'ScalarBarThickness' property to set the width instead.
862
+
863
+ # Rescale colorbar transfer function
864
+ if ps['datarange']:
865
+ t2LUT.RescaleTransferFunction(float(ps['datarange'][0]), ps['datarange'][1])
866
+ t2PWF.RescaleTransferFunction(float(ps['datarange'][0]), ps['datarange'][1])
867
+ else:
868
+ t2Display.RescaleTransferFunctionToDataRange(False, True)
869
+
870
+ # t2Display.RescaleTransferFunctionToDataRange(True)
871
+
872
+ # turn off orientation axes
873
+ if not(ps['axes']):
874
+ renderView.OrientationAxesVisibility = 0
875
+
876
+ # =============================================================================
877
+ # create and set up vector plots
878
+ # =============================================================================
879
+ if ps['vlabels']:
880
+ vec = [0] * len(ps['vlabels'])
881
+ vecDisplay = [0] * len(ps['vlabels'])
882
+
883
+ if ps['vcolor'].ndim == 1:
884
+ ps['vcolor'] = ps['vcolor'][np.newaxis, :]
885
+
886
+ N_vecs = len(ps['vlabels'])
887
+
888
+ # copy vector colors if only one color is specified
889
+ if len(ps['vlabels']) < ps['vcolor'].shape[0]:
890
+ vcolor = np.tile(ps['vcolor'], (N_vecs, 1))
891
+
892
+ # copy vector scale mode if only one scale mode is specified
893
+ if len(ps['vscale_mode']) < ps['vcolor'].shape[0]:
894
+ vscale_mode = [ps['vscale_mode'] for i in range(N_vecs)]
895
+
896
+ # copy vector scale mode if only one scale mode is specified
897
+ vscales = np.array(ps['vscales'])
898
+
899
+ if ps['vscales'].size < ps['vcolor'].shape[0]:
900
+ vscales = np.tile(ps['vscales'], (N_vecs, 1))
901
+
902
+ # create a new 'Glyph' (vector plot)
903
+ for i in range(N_vecs):
904
+ vec[i] = paraview.simple.Glyph(Input=t2, GlyphType='Arrow')
905
+ vec[i].Scalars = ['POINTS', 'None']
906
+ vec[i].Vectors = ['CELLS', ps['vlabels'][i]]
907
+ vec[i].Orient = 1
908
+ vec[i].ScaleMode = ps['vscale_mode'][i] # 'off', 'vector', 'vector_components'
909
+ vec[i].ScaleFactor = ps['vscales'][i]
910
+ vec[i].GlyphMode = list(ps['vector_mode'].keys())[0]
911
+ if list(ps['vector_mode'].keys())[0] == 'Every Nth Point':
912
+ vec[i].Stride = ps['vector_mode'][list(ps['vector_mode'].keys())[0]]
913
+ vec[i].MaximumNumberOfSamplePoints = 5000
914
+ vec[i].Seed = 10339
915
+ vec[i].GlyphTransform = 'Transform2'
916
+
917
+ # init the 'Arrow' selected for 'GlyphType'
918
+ vec[i].GlyphType.TipResolution = 6
919
+ vec[i].GlyphType.TipRadius = 0.1
920
+ vec[i].GlyphType.TipLength = 0.35
921
+ vec[i].GlyphType.ShaftResolution = 6
922
+ vec[i].GlyphType.ShaftRadius = 0.03
923
+ vec[i].GlyphType.Invert = 0
924
+
925
+ # init the 'Transform2' selected for 'GlyphTransform'
926
+ vec[i].GlyphTransform.Translate = [0.0, 0.0, 0.0]
927
+ vec[i].GlyphTransform.Rotate = [0.0, 0.0, 0.0]
928
+ vec[i].GlyphTransform.Scale = [1.0, 1.0, 1.0]
929
+
930
+ # show data in view
931
+ vecDisplay[i] = paraview.simple.Show(vec[i], renderView)
932
+
933
+ # trace defaults for the display properties.
934
+ vecDisplay[i].Representation = 'Surface'
935
+ vecDisplay[i].AmbientColor = [1.0, 1.0, 1.0]
936
+ vecDisplay[i].ColorArrayName = [None, '']
937
+ vecDisplay[i].DiffuseColor = [1.0, 1.0, 1.0]
938
+ vecDisplay[i].LookupTable = None
939
+ vecDisplay[i].MapScalars = 1
940
+ vecDisplay[i].InterpolateScalarsBeforeMapping = 1
941
+ vecDisplay[i].Opacity = 1.0
942
+ vecDisplay[i].PointSize = 2.0
943
+ vecDisplay[i].LineWidth = 1.0
944
+ vecDisplay[i].Interpolation = 'Gouraud'
945
+ vecDisplay[i].Specular = 0.0
946
+ vecDisplay[i].SpecularColor = [1.0, 1.0, 1.0]
947
+ vecDisplay[i].SpecularPower = 100.0
948
+ vecDisplay[i].Ambient = 0.0
949
+ vecDisplay[i].Diffuse = 1.0
950
+ vecDisplay[i].EdgeColor = [0.0, 0.0, 0.5]
951
+ vecDisplay[i].BackfaceRepresentation = 'Follow Frontface'
952
+ vecDisplay[i].BackfaceAmbientColor = [1.0, 1.0, 1.0]
953
+ vecDisplay[i].BackfaceDiffuseColor = [1.0, 1.0, 1.0]
954
+ vecDisplay[i].BackfaceOpacity = 1.0
955
+ vecDisplay[i].Position = [0.0, 0.0, 0.0]
956
+ vecDisplay[i].Scale = [1.0, 1.0, 1.0]
957
+ vecDisplay[i].Orientation = [0.0, 0.0, 0.0]
958
+ vecDisplay[i].Origin = [0.0, 0.0, 0.0]
959
+ vecDisplay[i].Pickable = 1
960
+ vecDisplay[i].Texture = None
961
+ vecDisplay[i].Triangulate = 0
962
+ vecDisplay[i].NonlinearSubdivisionLevel = 1
963
+ vecDisplay[i].OSPRayUseScaleArray = 0
964
+ vecDisplay[i].OSPRayScaleArray = quantity
965
+ vecDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
966
+ vecDisplay[i].GlyphType = 'Arrow'
967
+ vecDisplay[i].SelectionCellLabelBold = 0
968
+ vecDisplay[i].SelectionCellLabelColor = [0.0, 1.0, 0.0]
969
+ vecDisplay[i].SelectionCellLabelFontFamily = 'Arial'
970
+ vecDisplay[i].SelectionCellLabelFontSize = 18
971
+ vecDisplay[i].SelectionCellLabelItalic = 0
972
+ vecDisplay[i].SelectionCellLabelJustification = 'Left'
973
+ vecDisplay[i].SelectionCellLabelOpacity = 1.0
974
+ vecDisplay[i].SelectionCellLabelShadow = 0
975
+ vecDisplay[i].SelectionPointLabelBold = 0
976
+ vecDisplay[i].SelectionPointLabelColor = [1.0, 1.0, 0.0]
977
+ vecDisplay[i].SelectionPointLabelFontFamily = 'Arial'
978
+ vecDisplay[i].SelectionPointLabelFontSize = 18
979
+ vecDisplay[i].SelectionPointLabelItalic = 0
980
+ vecDisplay[i].SelectionPointLabelJustification = 'Left'
981
+ vecDisplay[i].SelectionPointLabelOpacity = 1.0
982
+ vecDisplay[i].SelectionPointLabelShadow = 0
983
+ vecDisplay[i].GaussianRadius = 0.0
984
+ vecDisplay[i].ShaderPreset = 'Sphere'
985
+ vecDisplay[i].Emissive = 0
986
+ vecDisplay[i].ScaleByArray = 0
987
+ vecDisplay[i].SetScaleArray = [None, '']
988
+ vecDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
989
+ vecDisplay[i].OpacityByArray = 0
990
+ vecDisplay[i].OpacityArray = [None, '']
991
+ vecDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
992
+
993
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
994
+ vecDisplay[i].OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
995
+
996
+ # init the 'Arrow' selected for 'GlyphType'
997
+ vecDisplay[i].GlyphType.TipResolution = 6
998
+ vecDisplay[i].GlyphType.TipRadius = 0.1
999
+ vecDisplay[i].GlyphType.TipLength = 0.35
1000
+ vecDisplay[i].GlyphType.ShaftResolution = 6
1001
+ vecDisplay[i].GlyphType.ShaftRadius = 0.03
1002
+ vecDisplay[i].GlyphType.Invert = 0
1003
+
1004
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
1005
+ vecDisplay[i].ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1006
+
1007
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
1008
+ vecDisplay[i].OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1009
+
1010
+ # change solid color using normalized EGB code (0...1)
1011
+ vecDisplay[i].DiffuseColor = ps['vcolor'][i, :]
1012
+
1013
+ # =============================================================================
1014
+ # coil
1015
+ # =============================================================================
1016
+ source = GetActiveSource()
1017
+ source.UpdatePipeline()
1018
+ cdi = source.GetDataInformation().GetCompositeDataInformation()
1019
+ n_blocks = cdi.GetNumberOfChildren()
1020
+ block_names = [cdi.GetName(i) for i in range(n_blocks)]
1021
+
1022
+ if 'coil' in block_names and ps['show_coil']:
1023
+ plot_coil = True
1024
+ else:
1025
+ plot_coil = False
1026
+
1027
+ if plot_coil:
1028
+
1029
+ # create a new 'Threshold'
1030
+ coilthreshold = paraview.simple.Threshold(Input=p)
1031
+ coilthreshold.Scalars = ['CELLS', 'dipole_mag']
1032
+ # threshold1.ThresholdRange = [1.1648167371749878, 8.777523040771484]
1033
+ coilthreshold.AllScalars = 1
1034
+ coilthreshold.UseContinuousCellRange = 0
1035
+
1036
+ # show data in view
1037
+ coilthresholdDisplay = Show(coilthreshold, renderView)
1038
+ # trace defaults for the display properties.
1039
+ coilthresholdDisplay.Representation = 'Surface'
1040
+ coilthresholdDisplay.AmbientColor = [1.0, 1.0, 1.0]
1041
+ coilthresholdDisplay.ColorArrayName = ['CELLS', 'dipole_mag']
1042
+ coilthresholdDisplay.DiffuseColor = [1.0, 1.0, 1.0]
1043
+ # coilthresholdDisplay.LookupTable = dipolemagLUT
1044
+ coilthresholdDisplay.MapScalars = 1
1045
+ coilthresholdDisplay.InterpolateScalarsBeforeMapping = 1
1046
+ coilthresholdDisplay.Opacity = 1.0
1047
+ coilthresholdDisplay.PointSize = 2.0
1048
+ coilthresholdDisplay.LineWidth = 1.0
1049
+ coilthresholdDisplay.Interpolation = 'Gouraud'
1050
+ coilthresholdDisplay.Specular = 0.0
1051
+ coilthresholdDisplay.SpecularColor = [1.0, 1.0, 1.0]
1052
+ coilthresholdDisplay.SpecularPower = 100.0
1053
+ coilthresholdDisplay.Ambient = 0.0
1054
+ coilthresholdDisplay.Diffuse = 1.0
1055
+ coilthresholdDisplay.EdgeColor = [0.0, 0.0, 0.5]
1056
+ coilthresholdDisplay.BackfaceRepresentation = 'Follow Frontface'
1057
+ coilthresholdDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
1058
+ coilthresholdDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
1059
+ coilthresholdDisplay.BackfaceOpacity = 1.0
1060
+ coilthresholdDisplay.Position = [0.0, 0.0, 0.0]
1061
+ coilthresholdDisplay.Scale = [1.0, 1.0, 1.0]
1062
+ coilthresholdDisplay.Orientation = [0.0, 0.0, 0.0]
1063
+ coilthresholdDisplay.Origin = [0.0, 0.0, 0.0]
1064
+ coilthresholdDisplay.Pickable = 1
1065
+ coilthresholdDisplay.Texture = None
1066
+ coilthresholdDisplay.Triangulate = 0
1067
+ coilthresholdDisplay.NonlinearSubdivisionLevel = 1
1068
+ coilthresholdDisplay.OSPRayUseScaleArray = 0
1069
+ coilthresholdDisplay.OSPRayScaleArray = 'dipole_mag'
1070
+ coilthresholdDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
1071
+ coilthresholdDisplay.GlyphType = 'Arrow'
1072
+ coilthresholdDisplay.SelectionCellLabelBold = 0
1073
+ coilthresholdDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
1074
+ coilthresholdDisplay.SelectionCellLabelFontFamily = 'Arial'
1075
+ coilthresholdDisplay.SelectionCellLabelFontSize = 18
1076
+ coilthresholdDisplay.SelectionCellLabelItalic = 0
1077
+ coilthresholdDisplay.SelectionCellLabelJustification = 'Left'
1078
+ coilthresholdDisplay.SelectionCellLabelOpacity = 1.0
1079
+ coilthresholdDisplay.SelectionCellLabelShadow = 0
1080
+ coilthresholdDisplay.SelectionPointLabelBold = 0
1081
+ coilthresholdDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
1082
+ coilthresholdDisplay.SelectionPointLabelFontFamily = 'Arial'
1083
+ coilthresholdDisplay.SelectionPointLabelFontSize = 18
1084
+ coilthresholdDisplay.SelectionPointLabelItalic = 0
1085
+ coilthresholdDisplay.SelectionPointLabelJustification = 'Left'
1086
+ coilthresholdDisplay.SelectionPointLabelOpacity = 1.0
1087
+ coilthresholdDisplay.SelectionPointLabelShadow = 0
1088
+ coilthresholdDisplay.ScalarOpacityUnitDistance = 10.18430143021554
1089
+ coilthresholdDisplay.SelectMapper = 'Projected tetra'
1090
+ coilthresholdDisplay.GaussianRadius = 0.0
1091
+ coilthresholdDisplay.ShaderPreset = 'Sphere'
1092
+ coilthresholdDisplay.Emissive = 0
1093
+ coilthresholdDisplay.ScaleByArray = 0
1094
+ coilthresholdDisplay.SetScaleArray = [None, '']
1095
+ coilthresholdDisplay.ScaleTransferFunction = 'PiecewiseFunction'
1096
+ coilthresholdDisplay.OpacityByArray = 0
1097
+ coilthresholdDisplay.OpacityArray = [None, '']
1098
+ coilthresholdDisplay.OpacityTransferFunction = 'PiecewiseFunction'
1099
+
1100
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
1101
+ coilthresholdDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1102
+
1103
+ # init the 'Arrow' selected for 'GlyphType'
1104
+ coilthresholdDisplay.GlyphType.TipResolution = 6
1105
+ coilthresholdDisplay.GlyphType.TipRadius = 0.1
1106
+ coilthresholdDisplay.GlyphType.TipLength = 0.35
1107
+ coilthresholdDisplay.GlyphType.ShaftResolution = 6
1108
+ coilthresholdDisplay.GlyphType.ShaftRadius = 0.03
1109
+ coilthresholdDisplay.GlyphType.Invert = 0
1110
+
1111
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
1112
+ coilthresholdDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1113
+
1114
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
1115
+ coilthresholdDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1116
+
1117
+ # show color bar/color legend
1118
+ coilthresholdDisplay.SetScalarBarVisibility(renderView, False)
1119
+
1120
+ # create a new 'Glyph'
1121
+ coilGlyph = paraview.simple.Glyph(Input=coilthreshold, GlyphType='Arrow')
1122
+ coilGlyph.Scalars = ['CELLS', 'dipole_mag']
1123
+ coilGlyph.Vectors = ['POINTS', 'None']
1124
+ coilGlyph.Orient = 1
1125
+ coilGlyph.GlyphMode = 'All Points'
1126
+ coilGlyph.MaximumNumberOfSamplePoints = 5000
1127
+ coilGlyph.Seed = 10339
1128
+ coilGlyph.Stride = 1
1129
+ coilGlyph.GlyphTransform = 'Transform2'
1130
+ coilGlyph.GlyphType = 'Sphere'
1131
+
1132
+ # set dipole scaling and size
1133
+ if ps['coil_dipole_scaling'][0] == 'scaled':
1134
+ coilGlyph.Scalars = ['POINTS', 'magnitude']
1135
+ coilGlyph.ScaleMode = 'scalar'
1136
+ else:
1137
+ coilGlyph.ScaleMode = 'off'
1138
+
1139
+ coilGlyph.ScaleFactor = ps['coil_dipole_scaling'][1]
1140
+
1141
+ # init the 'Transform2' selected for 'GlyphTransform'
1142
+ coilGlyph.GlyphTransform.Translate = [0.0, 0.0, 0.0]
1143
+ coilGlyph.GlyphTransform.Rotate = [0.0, 0.0, 0.0]
1144
+ coilGlyph.GlyphTransform.Scale = [1.0, 1.0, 1.0]
1145
+
1146
+ # get color transfer function/color map for 'dipolemag'
1147
+ dipolemagLUT = GetColorTransferFunction('dipolemag')
1148
+ dipolemagLUT.LockDataRange = 0
1149
+ dipolemagLUT.InterpretValuesAsCategories = 0
1150
+ dipolemagLUT.ShowCategoricalColorsinDataRangeOnly = 0
1151
+ dipolemagLUT.RescaleOnVisibilityChange = 0
1152
+ dipolemagLUT.EnableOpacityMapping = 0
1153
+ dipolemagLUT.UseLogScale = 0
1154
+ dipolemagLUT.ColorSpace = 'Lab'
1155
+ dipolemagLUT.UseBelowRangeColor = 0
1156
+ dipolemagLUT.BelowRangeColor = [0.0, 0.0, 0.0]
1157
+ dipolemagLUT.UseAboveRangeColor = 0
1158
+ dipolemagLUT.AboveRangeColor = [1.0, 1.0, 1.0]
1159
+ dipolemagLUT.NanColor = ps['NanColor']
1160
+ dipolemagLUT.Discretize = 1
1161
+ dipolemagLUT.NumberOfTableValues = 256
1162
+ dipolemagLUT.ScalarRangeInitialized = 1.0
1163
+ dipolemagLUT.HSVWrap = 0
1164
+ dipolemagLUT.VectorComponent = 0
1165
+ dipolemagLUT.VectorMode = 'Magnitude'
1166
+ dipolemagLUT.AllowDuplicateScalars = 1
1167
+ dipolemagLUT.Annotations = []
1168
+ dipolemagLUT.ActiveAnnotatedValues = []
1169
+ dipolemagLUT.IndexedColors = []
1170
+
1171
+ # show data in view
1172
+ coilGlyphDisplay = Show(coilGlyph, renderView)
1173
+
1174
+ # trace defaults for the display properties.
1175
+ coilGlyphDisplay.Representation = 'Surface'
1176
+ coilGlyphDisplay.AmbientColor = [1.0, 1.0, 1.0]
1177
+ coilGlyphDisplay.ColorArrayName = ['POINTS', 'dipole_mag']
1178
+ coilGlyphDisplay.DiffuseColor = [1.0, 1.0, 1.0]
1179
+ coilGlyphDisplay.LookupTable = dipolemagLUT
1180
+ coilGlyphDisplay.MapScalars = 1
1181
+ coilGlyphDisplay.InterpolateScalarsBeforeMapping = 1
1182
+ coilGlyphDisplay.Opacity = 1.0
1183
+ coilGlyphDisplay.PointSize = 2.0
1184
+ coilGlyphDisplay.LineWidth = 1.0
1185
+ coilGlyphDisplay.Interpolation = 'Gouraud'
1186
+ coilGlyphDisplay.Specular = 0.0
1187
+ coilGlyphDisplay.SpecularColor = [1.0, 1.0, 1.0]
1188
+ coilGlyphDisplay.SpecularPower = 100.0
1189
+ coilGlyphDisplay.Ambient = 0.0
1190
+ coilGlyphDisplay.Diffuse = 1.0
1191
+ coilGlyphDisplay.EdgeColor = [0.0, 0.0, 0.5]
1192
+ coilGlyphDisplay.BackfaceRepresentation = 'Follow Frontface'
1193
+ coilGlyphDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
1194
+ coilGlyphDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
1195
+ coilGlyphDisplay.BackfaceOpacity = 1.0
1196
+ coilGlyphDisplay.Position = [0.0, 0.0, 0.0]
1197
+ coilGlyphDisplay.Scale = [1.0, 1.0, 1.0]
1198
+ coilGlyphDisplay.Orientation = [0.0, 0.0, 0.0]
1199
+ coilGlyphDisplay.Origin = [0.0, 0.0, 0.0]
1200
+ coilGlyphDisplay.Pickable = 1
1201
+ coilGlyphDisplay.Texture = None
1202
+ coilGlyphDisplay.Triangulate = 0
1203
+ coilGlyphDisplay.NonlinearSubdivisionLevel = 1
1204
+ coilGlyphDisplay.OSPRayUseScaleArray = 0
1205
+ coilGlyphDisplay.OSPRayScaleArray = 'dipole_mag'
1206
+ coilGlyphDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
1207
+ coilGlyphDisplay.GlyphType = 'Arrow'
1208
+ coilGlyphDisplay.SelectionCellLabelBold = 0
1209
+ coilGlyphDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
1210
+ coilGlyphDisplay.SelectionCellLabelFontFamily = 'Arial'
1211
+ coilGlyphDisplay.SelectionCellLabelFontSize = 18
1212
+ coilGlyphDisplay.SelectionCellLabelItalic = 0
1213
+ coilGlyphDisplay.SelectionCellLabelJustification = 'Left'
1214
+ coilGlyphDisplay.SelectionCellLabelOpacity = 1.0
1215
+ coilGlyphDisplay.SelectionCellLabelShadow = 0
1216
+ coilGlyphDisplay.SelectionPointLabelBold = 0
1217
+ coilGlyphDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
1218
+ coilGlyphDisplay.SelectionPointLabelFontFamily = 'Arial'
1219
+ coilGlyphDisplay.SelectionPointLabelFontSize = 18
1220
+ coilGlyphDisplay.SelectionPointLabelItalic = 0
1221
+ coilGlyphDisplay.SelectionPointLabelJustification = 'Left'
1222
+ coilGlyphDisplay.SelectionPointLabelOpacity = 1.0
1223
+ coilGlyphDisplay.SelectionPointLabelShadow = 0
1224
+ coilGlyphDisplay.GaussianRadius = 0.0
1225
+ coilGlyphDisplay.ShaderPreset = 'Sphere'
1226
+ coilGlyphDisplay.Emissive = 0
1227
+ coilGlyphDisplay.ScaleByArray = 0
1228
+ coilGlyphDisplay.SetScaleArray = ['POINTS', 'dipole_mag']
1229
+ coilGlyphDisplay.ScaleTransferFunction = 'PiecewiseFunction'
1230
+ coilGlyphDisplay.OpacityByArray = 0
1231
+ coilGlyphDisplay.OpacityArray = ['POINTS', 'dipole_mag']
1232
+ coilGlyphDisplay.OpacityTransferFunction = 'PiecewiseFunction'
1233
+
1234
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
1235
+ coilGlyphDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1236
+
1237
+ # init the 'Arrow' selected for 'GlyphType'
1238
+ coilGlyphDisplay.GlyphType.TipResolution = 6
1239
+ coilGlyphDisplay.GlyphType.TipRadius = 0.1
1240
+ coilGlyphDisplay.GlyphType.TipLength = 0.35
1241
+ coilGlyphDisplay.GlyphType.ShaftResolution = 6
1242
+ coilGlyphDisplay.GlyphType.ShaftRadius = 0.03
1243
+ coilGlyphDisplay.GlyphType.Invert = 0
1244
+
1245
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
1246
+ coilGlyphDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1247
+
1248
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
1249
+ coilGlyphDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1250
+
1251
+ # show color bar/color legend
1252
+ coilGlyphDisplay.SetScalarBarVisibility(renderView, False)
1253
+
1254
+ # set dipole color
1255
+ if isinstance(ps['coil_dipole_color'], (str,)):
1256
+ # Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
1257
+ dipolemagLUT.ApplyPreset(ps['coil_dipole_color'], True)
1258
+
1259
+ else:
1260
+ # change solid color
1261
+ coilGlyphDisplay.DiffuseColor = ps['coil_dipole_color']
1262
+
1263
+ # =============================================================
1264
+ # set coil axes direction
1265
+ # =============================================================
1266
+ if ps['coil_axes']:
1267
+ import vtk.numpy_interface.dataset_adapter as dsa
1268
+
1269
+ # read points out of dataset
1270
+ coilthreshold.UpdatePipeline()
1271
+ rawData = servermanager.Fetch(coilthreshold)
1272
+ data = dsa.WrapDataObject(rawData)
1273
+ points = np.array(data.Points.Arrays[2])
1274
+
1275
+ # determine coil center
1276
+ coil_center = np.average(points, axis=0)
1277
+
1278
+ # shift coil to center for SVD
1279
+ points = points - coil_center
1280
+
1281
+ line = [0] * 3
1282
+ lineDisplay = [0] * 3
1283
+ line_color = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
1284
+ U, s, V = np.linalg.svd(points, full_matrices=True)
1285
+ points_transform = np.dot(points, V.transpose())
1286
+ coil_dim = np.max(points_transform, axis=0) - np.min(points_transform, axis=0)
1287
+
1288
+ for i in range(3):
1289
+ # create a new 'Line'
1290
+ line[i] = paraview.simple.Line()
1291
+ # Properties modified on line1
1292
+ line[i].Point1 = coil_center
1293
+ if ((i == 0) or (i == 1)):
1294
+ line[i].Point2 = coil_center + V[i, :] / np.linalg.norm(V[i, :]) * coil_dim[i] / 2
1295
+ if i == 2:
1296
+ line[i].Point2 = coil_center + V[i, :] / np.linalg.norm(V[i, :]) * coil_dim[0] / 2
1297
+ line[i].Resolution = 1000
1298
+ # set active source
1299
+ SetActiveSource(line[i])
1300
+ # show data in view
1301
+ lineDisplay[i] = Show(line[i], renderView)
1302
+ # trace defaults for the display properties.
1303
+ lineDisplay[i].ColorArrayName = [None, '']
1304
+ lineDisplay[i].OSPRayScaleArray = 'Texture Coordinates'
1305
+ lineDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
1306
+ lineDisplay[i].GlyphType = 'Sphere'
1307
+ lineDisplay[i].SetScaleArray = [None, '']
1308
+ lineDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
1309
+ lineDisplay[i].OpacityArray = [None, '']
1310
+ lineDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
1311
+ lineDisplay[i].ShaderPreset = 'Gaussian Blur (Default)'
1312
+ lineDisplay[i].DiffuseColor = line_color[i]
1313
+ lineDisplay[i].SetRepresentationType('3D Glyphs')
1314
+ lineDisplay[i].GlyphType.Radius = 1.0
1315
+
1316
+ # set the background color
1317
+ renderView.Background = ps['background_color']
1318
+
1319
+ # set image size
1320
+ renderView.ViewSize = ps['viewsize'] # [width, height]
1321
+
1322
+ # save scene
1323
+ paraview.simple.SaveScreenshot(ps['fname_png'], magnification=ps['png_resolution'], quality=100, view=renderView)
1324
+
1325
+ # crop surrounding of image
1326
+ crop_image(ps['fname_png'], ps['fname_png'])
1327
+
1328
+ # delete temporary cropped .hdf5 data file and restore original file
1329
+ if data_cropped:
1330
+ shutil.move(os.path.splitext(fn_data_hdf5)[0] + '_backup.hdf5', fn_data_hdf5)
1331
+
1332
+ # Reset Paraview session
1333
+ ResetSession()
1334
+
1335
+
1336
+ def surface_vector_plot_vtu(ps):
1337
+ """ Generate plot with Paraview from data in .vtu file.
1338
+
1339
+ Parameters
1340
+ ----------
1341
+ ps : dict
1342
+ Plot settings dict initialized with create_plot_settings_dict(plotfunction_type='surface_vector_plot_vtu')
1343
+
1344
+ Returns
1345
+ -------
1346
+ <File> : .png file
1347
+ Generated plot
1348
+ """
1349
+
1350
+ if ps['interpolate']:
1351
+ target = 'POINTS'
1352
+ else:
1353
+ target = 'CELLS'
1354
+
1355
+ # add whitespace if colorbar label is not given (empty colorbar labels are plotted wrong)
1356
+ if ps['colorbar_label'] is None or ps['colorbar_label']=='':
1357
+ ps['colorbar_label'] = ' '
1358
+
1359
+ # create a new 'XML Unstructured Grid Reader'
1360
+ p = paraview.simple.XMLUnstructuredGridReader(FileName=[ps['fname_in']])
1361
+
1362
+ label_datasets = p.CellArrayStatus
1363
+ N_datasets = len(label_datasets)
1364
+
1365
+ p.PointArrayStatus = []
1366
+
1367
+ if len(ps['datarange']) == 1 and ps['datarange'][0] == None:
1368
+ datarange = [None, None]
1369
+
1370
+ # get data ranges of included datasets
1371
+ if None in ps['datarange']:
1372
+ datarange_temp = servermanager.Fetch(p).GetCellData().GetArray(ps['quantity']).GetRange()
1373
+ if ps['datarange'][0] == None:
1374
+ ps['datarange'][0] = datarange_temp[0]
1375
+ if ps['datarange'][1] == None:
1376
+ ps['datarange'][1] = datarange_temp[1]
1377
+
1378
+ # get active view
1379
+ renderView = GetActiveViewOrCreate('RenderView')
1380
+
1381
+ # =============================================================================
1382
+ # plot curvature data as 'underlay' (if present)
1383
+ # =============================================================================
1384
+ if 'underlay' in label_datasets:
1385
+ # reload dataset to plot underlay data
1386
+ # create a new 'XML Unstructured Grid Reader'
1387
+ u = paraview.simple.XMLUnstructuredGridReader(FileName=[ps['fname_in']])
1388
+ u.PointArrayStatus = []
1389
+ renderView = GetActiveViewOrCreate('RenderView')
1390
+
1391
+ # show data in view
1392
+ uDisplay = Show(u, renderView)
1393
+ # trace defaults for the display properties.
1394
+ uDisplay.Representation = 'Surface'
1395
+ uDisplay.AmbientColor = [1.0, 1.0, 1.0]
1396
+ uDisplay.ColorArrayName = [None, '']
1397
+ uDisplay.DiffuseColor = [1.0, 1.0, 1.0]
1398
+ uDisplay.LookupTable = None
1399
+ uDisplay.MapScalars = 1
1400
+ uDisplay.InterpolateScalarsBeforeMapping = 1
1401
+ uDisplay.Opacity = 1.0
1402
+ uDisplay.PointSize = 2.0
1403
+ uDisplay.LineWidth = 1.0
1404
+ uDisplay.Interpolation = 'Gouraud'
1405
+ uDisplay.Specular = 0.0
1406
+ uDisplay.SpecularColor = [1.0, 1.0, 1.0]
1407
+ uDisplay.SpecularPower = 100.0
1408
+ uDisplay.Ambient = 0.0
1409
+ uDisplay.Diffuse = 1.0
1410
+ uDisplay.EdgeColor = [0.0, 0.0, 0.5]
1411
+ uDisplay.BackfaceRepresentation = 'Follow Frontface'
1412
+ uDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
1413
+ uDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
1414
+ uDisplay.BackfaceOpacity = 1.0
1415
+ uDisplay.Position = [0.0, 0.0, 0.0]
1416
+ uDisplay.Scale = [1.0, 1.0, 1.0]
1417
+ uDisplay.Orientation = [0.0, 0.0, 0.0]
1418
+ uDisplay.Origin = [0.0, 0.0, 0.0]
1419
+ uDisplay.Pickable = 1
1420
+ uDisplay.Texture = None
1421
+ uDisplay.Triangulate = 0
1422
+ uDisplay.NonlinearSubdivisionLevel = 1
1423
+ uDisplay.OSPRayUseScaleArray = 0
1424
+ uDisplay.OSPRayScaleArray = 'underlay'
1425
+ uDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
1426
+ uDisplay.GlyphType = 'Arrow'
1427
+ uDisplay.SelectionCellLabelBold = 0
1428
+ uDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
1429
+ uDisplay.SelectionCellLabelFontFamily = 'Arial'
1430
+ uDisplay.SelectionCellLabelFontSize = 18
1431
+ uDisplay.SelectionCellLabelItalic = 0
1432
+ uDisplay.SelectionCellLabelJustification = 'Left'
1433
+ uDisplay.SelectionCellLabelOpacity = 1.0
1434
+ uDisplay.SelectionCellLabelShadow = 0
1435
+ uDisplay.SelectionPointLabelBold = 0
1436
+ uDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
1437
+ uDisplay.SelectionPointLabelFontFamily = 'Arial'
1438
+ uDisplay.SelectionPointLabelFontSize = 18
1439
+ uDisplay.SelectionPointLabelItalic = 0
1440
+ uDisplay.SelectionPointLabelJustification = 'Left'
1441
+ uDisplay.SelectionPointLabelOpacity = 1.0
1442
+ uDisplay.SelectionPointLabelShadow = 0
1443
+ uDisplay.ScalarOpacityUnitDistance = 5.089405629151854
1444
+ uDisplay.SelectMapper = 'Projected tetra'
1445
+ uDisplay.GaussianRadius = 0.0
1446
+ uDisplay.ShaderPreset = 'Sphere'
1447
+ uDisplay.Emissive = 0
1448
+ uDisplay.ScaleByArray = 0
1449
+ uDisplay.SetScaleArray = [None, '']
1450
+ uDisplay.ScaleTransferFunction = 'PiecewiseFunction'
1451
+ uDisplay.OpacityByArray = 0
1452
+ uDisplay.OpacityArray = [None, '']
1453
+ uDisplay.OpacityTransferFunction = 'PiecewiseFunction'
1454
+
1455
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
1456
+ uDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1457
+
1458
+ # init the 'Arrow' selected for 'GlyphType'
1459
+ uDisplay.GlyphType.TipResolution = 6
1460
+ uDisplay.GlyphType.TipRadius = 0.1
1461
+ uDisplay.GlyphType.TipLength = 0.35
1462
+ uDisplay.GlyphType.ShaftResolution = 6
1463
+ uDisplay.GlyphType.ShaftRadius = 0.03
1464
+ uDisplay.GlyphType.Invert = 0
1465
+
1466
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
1467
+ uDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1468
+
1469
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
1470
+ uDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1471
+
1472
+ # reset view to fit data
1473
+ renderView.ResetCamera()
1474
+
1475
+ # set scalar coloring
1476
+ ColorBy(uDisplay, ('CELLS', 'underlay'))
1477
+
1478
+ # rescale color and/or opacity maps used to include current data range
1479
+ uDisplay.RescaleTransferFunctionToDataRange(True)
1480
+
1481
+ # show color bar/color legend
1482
+ uDisplay.SetScalarBarVisibility(renderView, True)
1483
+
1484
+ # get color transfer function/color map for 'underlay'
1485
+ uLUT = GetColorTransferFunction('underlay')
1486
+ uLUT.ApplyPreset('X Ray', True)
1487
+ # uLUT.LockDataRange = 0 # not in v5.8 anymore
1488
+ uLUT.InterpretValuesAsCategories = 0
1489
+ uLUT.ShowCategoricalColorsinDataRangeOnly = 0
1490
+ uLUT.RescaleOnVisibilityChange = 0
1491
+ uLUT.EnableOpacityMapping = 0
1492
+ uLUT.UseLogScale = 0
1493
+ uLUT.ColorSpace = 'RGB'
1494
+ uLUT.UseBelowRangeColor = 0
1495
+ uLUT.BelowRangeColor = [0.0, 0.0, 0.0]
1496
+ uLUT.UseAboveRangeColor = 0
1497
+ uLUT.AboveRangeColor = [1.0, 1.0, 1.0]
1498
+ uLUT.NanColor = ps['NanColor']
1499
+ uLUT.Discretize = 1
1500
+ uLUT.NumberOfTableValues = 256
1501
+ uLUT.ScalarRangeInitialized = 1.0
1502
+ uLUT.HSVWrap = 0
1503
+ uLUT.VectorComponent = 0
1504
+ uLUT.VectorMode = 'Magnitude'
1505
+ uLUT.AllowDuplicateScalars = 1
1506
+ uLUT.Annotations = []
1507
+ uLUT.ActiveAnnotatedValues = []
1508
+ uLUT.IndexedColors = []
1509
+
1510
+ # get opacity transfer function/opacity map for 'curv'
1511
+ uPWF = GetOpacityTransferFunction('underlay')
1512
+ uPWF.AllowDuplicateScalars = 1
1513
+ uPWF.ScalarRangeInitialized = 1
1514
+
1515
+ # hide color bar/color legend
1516
+ uDisplay.SetScalarBarVisibility(renderView, False)
1517
+
1518
+ # =============================================================================
1519
+ # plot main results
1520
+ # =============================================================================
1521
+ # create a new 'Cell Data to Point Data' if interpolate is selected or an underlay is present in order to enable
1522
+ # an opacity transfer function of the overlay (main) data
1523
+ if ps['interpolate'] or ('underlay' in label_datasets):
1524
+ Hide(p, renderView)
1525
+ p1 = paraview.simple.CellDatatoPointData(Input=p)
1526
+ p1.PassCellData = 0
1527
+ p1.PieceInvariant = 0
1528
+ pDisplay = Show(p1, renderView)
1529
+ else:
1530
+ pDisplay = Show(p, renderView)
1531
+
1532
+ # trace defaults for the display properties.
1533
+ pDisplay.Representation = 'Surface'
1534
+ pDisplay.AmbientColor = [1.0, 1.0, 1.0]
1535
+ pDisplay.ColorArrayName = [None, '']
1536
+ pDisplay.DiffuseColor = [1.0, 1.0, 1.0]
1537
+ pDisplay.LookupTable = None
1538
+ pDisplay.MapScalars = 1
1539
+ pDisplay.InterpolateScalarsBeforeMapping = 1
1540
+ pDisplay.Opacity = 1.0
1541
+ pDisplay.PointSize = 2.0
1542
+ pDisplay.LineWidth = 1.0
1543
+ pDisplay.Interpolation = 'Gouraud'
1544
+ pDisplay.Specular = 0.0
1545
+ pDisplay.SpecularColor = [1.0, 1.0, 1.0]
1546
+ pDisplay.SpecularPower = 100.0
1547
+ pDisplay.Ambient = 0.0
1548
+ pDisplay.Diffuse = 1.0
1549
+ pDisplay.EdgeColor = [0.0, 0.0, 0.5]
1550
+ pDisplay.BackfaceRepresentation = 'Follow Frontface'
1551
+ pDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
1552
+ pDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
1553
+ pDisplay.BackfaceOpacity = 1.0
1554
+ pDisplay.Position = [0.0, 0.0, 0.0]
1555
+ pDisplay.Scale = [1.0, 1.0, 1.0]
1556
+ pDisplay.Orientation = [0.0, 0.0, 0.0]
1557
+ pDisplay.Origin = [0.0, 0.0, 0.0]
1558
+ pDisplay.Pickable = 1
1559
+ pDisplay.Texture = None
1560
+ pDisplay.Triangulate = 0
1561
+ pDisplay.NonlinearSubdivisionLevel = 1
1562
+ pDisplay.OSPRayUseScaleArray = 0
1563
+ pDisplay.OSPRayScaleArray = ps['quantity']
1564
+ pDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
1565
+ pDisplay.GlyphType = 'Arrow'
1566
+ pDisplay.SelectionCellLabelBold = 0
1567
+ pDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
1568
+ pDisplay.SelectionCellLabelFontFamily = 'Arial'
1569
+ pDisplay.SelectionCellLabelFontSize = 18
1570
+ pDisplay.SelectionCellLabelItalic = 0
1571
+ pDisplay.SelectionCellLabelJustification = 'Left'
1572
+ pDisplay.SelectionCellLabelOpacity = 1.0
1573
+ pDisplay.SelectionCellLabelShadow = 0
1574
+ pDisplay.SelectionPointLabelBold = 0
1575
+ pDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
1576
+ pDisplay.SelectionPointLabelFontFamily = 'Arial'
1577
+ pDisplay.SelectionPointLabelFontSize = 18
1578
+ pDisplay.SelectionPointLabelItalic = 0
1579
+ pDisplay.SelectionPointLabelJustification = 'Left'
1580
+ pDisplay.SelectionPointLabelOpacity = 1.0
1581
+ pDisplay.SelectionPointLabelShadow = 0
1582
+ pDisplay.ScalarOpacityUnitDistance = 1.7832435554535888
1583
+ pDisplay.SelectMapper = 'Projected tetra'
1584
+ pDisplay.GaussianRadius = 0.0
1585
+ pDisplay.ShaderPreset = 'Sphere'
1586
+ pDisplay.Emissive = 0
1587
+ pDisplay.ScaleByArray = 0
1588
+ pDisplay.SetScaleArray = [None, '']
1589
+ pDisplay.ScaleTransferFunction = 'PiecewiseFunction'
1590
+ pDisplay.OpacityByArray = 0
1591
+ pDisplay.OpacityArray = [None, ''] # ???
1592
+ pDisplay.OpacityTransferFunction = 'PiecewiseFunction'
1593
+
1594
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
1595
+ pDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1596
+
1597
+ # init the 'Arrow' selected for 'GlyphType'
1598
+ pDisplay.GlyphType.TipResolution = 6
1599
+ pDisplay.GlyphType.TipRadius = 0.1
1600
+ pDisplay.GlyphType.TipLength = 0.35
1601
+ pDisplay.GlyphType.ShaftResolution = 6
1602
+ pDisplay.GlyphType.ShaftRadius = 0.03
1603
+ pDisplay.GlyphType.Invert = 0
1604
+
1605
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
1606
+ pDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1607
+
1608
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
1609
+ pDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1610
+
1611
+ # reset view to fit data
1612
+ renderView.ResetCamera()
1613
+
1614
+ # camera placement for renderView
1615
+ if len(ps['view']) == 4:
1616
+ renderView.CameraPosition = ps['view'][0]
1617
+ renderView.CameraFocalPoint = ps['view'][1]
1618
+ renderView.CameraViewUp = ps['view'][2]
1619
+ renderView.CameraParallelScale = ps['view'][3][0]
1620
+ else:
1621
+ renderView.ResetCamera()
1622
+
1623
+ # set coloring of surface
1624
+ ColorBy(pDisplay, (target, ps['quantity']))
1625
+
1626
+ # rescale color and/or opacity maps used to include current data range
1627
+ pDisplay.RescaleTransferFunctionToDataRange(False)
1628
+
1629
+ # show color bar/color legend
1630
+ pDisplay.SetScalarBarVisibility(renderView, True)
1631
+
1632
+ # get color transfer function/color map for 'quantity'
1633
+ eLUT = GetColorTransferFunction(ps['quantity'])
1634
+ # eLUT.LockDataRange = 0 # not in v5.8 anymore
1635
+ eLUT.InterpretValuesAsCategories = 0
1636
+ eLUT.ShowCategoricalColorsinDataRangeOnly = 0
1637
+ eLUT.RescaleOnVisibilityChange = 0
1638
+ # if 'underlay' in label_datasets:
1639
+ # eLUT.EnableOpacityMapping = 1
1640
+ # else:
1641
+ # eLUT.EnableOpacityMapping = 0
1642
+ eLUT.UseLogScale = 0
1643
+ if ps['interpolate']:
1644
+ eLUT.ColorSpace = 'RGB'
1645
+ else:
1646
+ eLUT.ColorSpace = 'RGB' #'Diverging'
1647
+ eLUT.UseBelowRangeColor = 0
1648
+ eLUT.BelowRangeColor = [0.0, 0.0, 0.0]
1649
+ eLUT.UseAboveRangeColor = 0
1650
+ eLUT.AboveRangeColor = [1.0, 1.0, 1.0]
1651
+ eLUT.NanColor = ps['NanColor']
1652
+ eLUT.Discretize = 1
1653
+ eLUT.NumberOfTableValues = 256
1654
+ eLUT.ScalarRangeInitialized = 1.0
1655
+ eLUT.HSVWrap = 0
1656
+ eLUT.VectorComponent = 0
1657
+ eLUT.VectorMode = 'Magnitude'
1658
+ eLUT.AllowDuplicateScalars = 1
1659
+ eLUT.Annotations = []
1660
+ eLUT.ActiveAnnotatedValues = []
1661
+ eLUT.IndexedColors = []
1662
+
1663
+ # set opacity transfer function/opacity map 'quantity'
1664
+ ePWF = GetOpacityTransferFunction(ps['quantity'])
1665
+ if not (ps['opacitymap'] == []):
1666
+ eLUT.EnableOpacityMapping = 1
1667
+ ePWF.Points = ps['opacitymap']
1668
+ ePWF.AllowDuplicateScalars = 1
1669
+ ePWF.ScalarRangeInitialized = 1
1670
+
1671
+ # =============================================================================
1672
+ # set colormap for magnitude plot
1673
+ # =============================================================================
1674
+ if type(ps['colormap']) is str:
1675
+ colormap_presets = {'Cool to Warm',
1676
+ 'Cool to Warm (Extended)',
1677
+ 'Blue to Red Rainbow',
1678
+ 'X Ray',
1679
+ 'Grayscale',
1680
+ 'jet',
1681
+ 'hsv',
1682
+ 'erdc_iceFire_L',
1683
+ 'Plasma (matplotlib)',
1684
+ 'Viridis (matplotlib)',
1685
+ 'gray_Matlab',
1686
+ 'Spectral_lowBlue',
1687
+ 'BuRd',
1688
+ 'Rainbow Blended White',
1689
+ 'b2rcw'}
1690
+
1691
+ # set colorbar to 'jet' if not specified in presets
1692
+ if not (ps['colormap'] in colormap_presets):
1693
+ print((
1694
+ 'Changing colormap to \'jet\' since user specified colormap \'{}\' is not part of the included presets ...').format(
1695
+ ps['colormap']))
1696
+ colormap = 'jet'
1697
+
1698
+ if ps['colormap'] == 'b2rcw':
1699
+ rgb_values = b2rcw(ps['datarange'][0],ps['datarange'][1])
1700
+ rgb_data = np.linspace(ps['datarange'][0],ps['datarange'][1], rgb_values.shape[0])[:,np.newaxis]
1701
+ eLUT.RGBPoints = np.hstack((rgb_data,rgb_values)).flatten()
1702
+ else:
1703
+ eLUT.ApplyPreset(ps['colormap'], True)
1704
+ else:
1705
+ eLUT.RGBPoints = ps['colormap']
1706
+
1707
+ # change representation type
1708
+ if ps['edges']:
1709
+ pDisplay.SetRepresentationType('Surface With Edges')
1710
+
1711
+ # get color legend/bar for eLUT in view renderView
1712
+ eLUTColorBar = paraview.simple.GetScalarBar(eLUT, renderView)
1713
+ if ps['colorbar_position']:
1714
+ eLUTColorBar.Position = ps['colorbar_position']
1715
+ else:
1716
+ eLUTColorBar.Position = [0.847321428571429, 0.292476354256234]
1717
+ # eLUTColorBar.Position2 = [0.12, 0.43] #'Position2' is obsolete as of ParaView 5.4. Use the 'ScalarBarLength' property to set the length instead.
1718
+ eLUTColorBar.AutoOrient = 1
1719
+ eLUTColorBar.Orientation = ps['colorbar_orientation']
1720
+ eLUTColorBar.Title = ps['colorbar_label']
1721
+ eLUTColorBar.ComponentTitle = ''
1722
+ eLUTColorBar.TitleJustification = 'Centered'
1723
+ eLUTColorBar.TitleColor = ps['colorbar_labelcolor']
1724
+ eLUTColorBar.TitleOpacity = 1.0
1725
+ eLUTColorBar.TitleFontFamily = ps['colorbar_font']
1726
+ eLUTColorBar.TitleBold = 0
1727
+ eLUTColorBar.TitleItalic = 0
1728
+ eLUTColorBar.TitleShadow = 0
1729
+ eLUTColorBar.TitleFontSize = ps['colorbar_titlefontsize']
1730
+ eLUTColorBar.LabelColor = ps['colorbar_labelcolor']
1731
+ eLUTColorBar.LabelOpacity = 1.0
1732
+ eLUTColorBar.LabelFontFamily = ps['colorbar_font']
1733
+ eLUTColorBar.LabelBold = 0
1734
+ eLUTColorBar.LabelItalic = 0
1735
+ eLUTColorBar.LabelShadow = 0
1736
+ eLUTColorBar.LabelFontSize = ps['colorbar_labelfontsize']
1737
+ eLUTColorBar.AutomaticLabelFormat = 0
1738
+ eLUTColorBar.LabelFormat = ps['colorbar_labelformat']
1739
+ # eLUTColorBar.NumberOfLabels = ps['colorbar_numberoflabels'] # not in v5.8 anymore
1740
+ eLUTColorBar.DrawTickMarks = 1
1741
+ # eLUTColorBar.DrawSubTickMarks = 1 # not in v5.8 anymore
1742
+ eLUTColorBar.DrawTickLabels = 1
1743
+ eLUTColorBar.AddRangeLabels = 1
1744
+ eLUTColorBar.RangeLabelFormat = ps['colorbar_labelformat']
1745
+ eLUTColorBar.DrawAnnotations = 1
1746
+ eLUTColorBar.AddRangeAnnotations = 0
1747
+ eLUTColorBar.AutomaticAnnotations = 0
1748
+ eLUTColorBar.DrawNanAnnotation = 0
1749
+ eLUTColorBar.NanAnnotation = 'NaN'
1750
+ eLUTColorBar.TextPosition = 'Ticks right/top, annotations left/bottom'
1751
+ # eLUTColorBar.AspectRatio = ps['colorbar_aspectratio'] # paraview.NotSupportedException: 'AspectRatio' is obsolete as of ParaView 5.4. Use the 'ScalarBarThickness' property to set the width instead.
1752
+
1753
+ # Rescale colorbar transfer function
1754
+ if ps['datarange']:
1755
+ eLUT.RescaleTransferFunction(ps['datarange'][0], ps['datarange'][1])
1756
+ ePWF.RescaleTransferFunction(ps['datarange'][0], ps['datarange'][1])
1757
+ else:
1758
+ pDisplay.RescaleTransferFunctionToDataRange(False)
1759
+
1760
+ # turn off orientation axes
1761
+ if not (ps['axes']):
1762
+ renderView.OrientationAxesVisibility = 0
1763
+ # =============================================================================
1764
+ # create and set up vector plots
1765
+ # =============================================================================
1766
+ vec = [0] * len(ps['vlabels'])
1767
+ vecDisplay = [0] * len(ps['vlabels'])
1768
+
1769
+ if ps['vcolor'].ndim == 1:
1770
+ ps['vcolor'] = ps['vcolor'][np.newaxis, :]
1771
+
1772
+ N_vecs = len(ps['vlabels'])
1773
+
1774
+ # copy vector colors if only one color is specified
1775
+ if len(ps['vlabels']) < ps['vcolor'].shape[0]:
1776
+ vcolor = np.tile(ps['vcolor'], (N_vecs, 1))
1777
+
1778
+ # copy vector scale mode if only one scale mode is specified
1779
+ if len(ps['vscale_mode']) < ps['vcolor'].shape[0]:
1780
+ vscale_mode = [ps['vscale_mode'] for i in range(N_vecs)]
1781
+
1782
+ # copy vector scale mode if only one scale mode is specified
1783
+ vscales = np.array(ps['vscales'])
1784
+
1785
+ if ps['vscales'].size < ps['vcolor'].shape[0]:
1786
+ vscales = np.tile(ps['vscales'], (N_vecs, 1))
1787
+
1788
+ # create a new 'Glyph' (vector plot)
1789
+ for i in range(N_vecs):
1790
+ vec[i] = paraview.simple.Glyph(Input=p, GlyphType='Arrow')
1791
+ vec[i].Scalars = ['POINTS', 'None']
1792
+ vec[i].Vectors = ['POINTS', 'None']
1793
+ vec[i].Orient = 1
1794
+ vec[i].ScaleMode = ps['vscale_mode'][i] # 'off', 'vector', 'vector_components'
1795
+ vec[i].ScaleFactor = ps['vscales'][i]
1796
+ vec[i].GlyphMode = list(ps['vector_mode'].keys())[0]
1797
+ if list(ps['vector_mode'].keys())[0] == 'Every Nth Point':
1798
+ vec[i].Stride = ps['vector_mode'][list(ps['vector_mode'].keys())[0]]
1799
+ vec[i].MaximumNumberOfSamplePoints = 5000
1800
+ vec[i].Seed = 10339
1801
+ vec[i].GlyphTransform = 'Transform2'
1802
+
1803
+ # init the 'Arrow' selected for 'GlyphType'
1804
+ vec[i].GlyphType.TipResolution = 6
1805
+ vec[i].GlyphType.TipRadius = 0.1
1806
+ vec[i].GlyphType.TipLength = 0.35
1807
+ vec[i].GlyphType.ShaftResolution = 6
1808
+ vec[i].GlyphType.ShaftRadius = 0.03
1809
+ vec[i].GlyphType.Invert = 0
1810
+
1811
+ # init the 'Transform2' selected for 'GlyphTransform'
1812
+ vec[i].GlyphTransform.Translate = [0.0, 0.0, 0.0]
1813
+ vec[i].GlyphTransform.Rotate = [0.0, 0.0, 0.0]
1814
+ vec[i].GlyphTransform.Scale = [1.0, 1.0, 1.0]
1815
+
1816
+ # Properties modified on vec1
1817
+ vec[i].Vectors = ['CELLS', ps['vlabels'][i]]
1818
+
1819
+ # show data in view
1820
+ vecDisplay[i] = paraview.simple.Show(vec[i], renderView)
1821
+
1822
+ # trace defaults for the display properties.
1823
+ vecDisplay[i].Representation = 'Surface'
1824
+ vecDisplay[i].AmbientColor = [1.0, 1.0, 1.0]
1825
+ vecDisplay[i].ColorArrayName = [None, '']
1826
+ vecDisplay[i].DiffuseColor = [1.0, 1.0, 1.0]
1827
+ vecDisplay[i].LookupTable = None
1828
+ vecDisplay[i].MapScalars = 1
1829
+ vecDisplay[i].InterpolateScalarsBeforeMapping = 1
1830
+ vecDisplay[i].Opacity = 1.0
1831
+ vecDisplay[i].PointSize = 2.0
1832
+ vecDisplay[i].LineWidth = 1.0
1833
+ vecDisplay[i].Interpolation = 'Gouraud'
1834
+ vecDisplay[i].Specular = 0.0
1835
+ vecDisplay[i].SpecularColor = [1.0, 1.0, 1.0]
1836
+ vecDisplay[i].SpecularPower = 100.0
1837
+ vecDisplay[i].Ambient = 0.0
1838
+ vecDisplay[i].Diffuse = 1.0
1839
+ vecDisplay[i].EdgeColor = [0.0, 0.0, 0.5]
1840
+ vecDisplay[i].BackfaceRepresentation = 'Follow Frontface'
1841
+ vecDisplay[i].BackfaceAmbientColor = [1.0, 1.0, 1.0]
1842
+ vecDisplay[i].BackfaceDiffuseColor = [1.0, 1.0, 1.0]
1843
+ vecDisplay[i].BackfaceOpacity = 1.0
1844
+ vecDisplay[i].Position = [0.0, 0.0, 0.0]
1845
+ vecDisplay[i].Scale = [1.0, 1.0, 1.0]
1846
+ vecDisplay[i].Orientation = [0.0, 0.0, 0.0]
1847
+ vecDisplay[i].Origin = [0.0, 0.0, 0.0]
1848
+ vecDisplay[i].Pickable = 1
1849
+ vecDisplay[i].Texture = None
1850
+ vecDisplay[i].Triangulate = 0
1851
+ vecDisplay[i].NonlinearSubdivisionLevel = 1
1852
+ vecDisplay[i].OSPRayUseScaleArray = 0
1853
+ vecDisplay[i].OSPRayScaleArray = ps['quantity']
1854
+ vecDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
1855
+ vecDisplay[i].GlyphType = 'Arrow'
1856
+ vecDisplay[i].SelectionCellLabelBold = 0
1857
+ vecDisplay[i].SelectionCellLabelColor = [0.0, 1.0, 0.0]
1858
+ vecDisplay[i].SelectionCellLabelFontFamily = ps['colorbar_font']
1859
+ vecDisplay[i].SelectionCellLabelFontSize = 18
1860
+ vecDisplay[i].SelectionCellLabelItalic = 0
1861
+ vecDisplay[i].SelectionCellLabelJustification = 'Left'
1862
+ vecDisplay[i].SelectionCellLabelOpacity = 1.0
1863
+ vecDisplay[i].SelectionCellLabelShadow = 0
1864
+ vecDisplay[i].SelectionPointLabelBold = 0
1865
+ vecDisplay[i].SelectionPointLabelColor = [1.0, 1.0, 0.0]
1866
+ vecDisplay[i].SelectionPointLabelFontFamily = ps['colorbar_font']
1867
+ vecDisplay[i].SelectionPointLabelFontSize = 18
1868
+ vecDisplay[i].SelectionPointLabelItalic = 0
1869
+ vecDisplay[i].SelectionPointLabelJustification = 'Left'
1870
+ vecDisplay[i].SelectionPointLabelOpacity = 1.0
1871
+ vecDisplay[i].SelectionPointLabelShadow = 0
1872
+ vecDisplay[i].GaussianRadius = 0.0
1873
+ vecDisplay[i].ShaderPreset = 'Sphere'
1874
+ vecDisplay[i].Emissive = 0
1875
+ vecDisplay[i].ScaleByArray = 0
1876
+ vecDisplay[i].SetScaleArray = [None, '']
1877
+ vecDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
1878
+ vecDisplay[i].OpacityByArray = 0
1879
+ vecDisplay[i].OpacityArray = [None, '']
1880
+ vecDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
1881
+
1882
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
1883
+ vecDisplay[i].OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1884
+
1885
+ # init the 'Arrow' selected for 'GlyphType'
1886
+ vecDisplay[i].GlyphType.TipResolution = 6
1887
+ vecDisplay[i].GlyphType.TipRadius = 0.1
1888
+ vecDisplay[i].GlyphType.TipLength = 0.35
1889
+ vecDisplay[i].GlyphType.ShaftResolution = 6
1890
+ vecDisplay[i].GlyphType.ShaftRadius = 0.03
1891
+ vecDisplay[i].GlyphType.Invert = 0
1892
+
1893
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
1894
+ vecDisplay[i].ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1895
+
1896
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
1897
+ vecDisplay[i].OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
1898
+
1899
+ # change solid color using normalized EGB code (0...1)
1900
+ vecDisplay[i].DiffuseColor = ps['vcolor'][i, :]
1901
+
1902
+ # set the background color
1903
+ renderView.Background = ps['background_color']
1904
+
1905
+ # set image size
1906
+ renderView.ViewSize = ps['viewsize'] # [width, height]
1907
+
1908
+ # save scene
1909
+ paraview.simple.SaveScreenshot(ps['fname_png'], magnification=ps['png_resolution'], quality=100, view=renderView,
1910
+ TransparentBackground=True,
1911
+ CompressionLevel=0)
1912
+
1913
+ # crop surrounding of image
1914
+ crop_image(ps['fname_png'], ps['fname_png'])
1915
+
1916
+ # Reset Paraview session
1917
+ ResetSession()
1918
+
1919
+
1920
+ def volume_plot(ps):
1921
+ """
1922
+ Generate plot with Paraview from data in .hdf5 file.
1923
+
1924
+ Parameters
1925
+ ----------
1926
+ ps : dict
1927
+ Plot settings dict initialized with create_plot_settings_dict(plotfunction_type=''volume_plot'')
1928
+
1929
+ Returns
1930
+ -------
1931
+ <File> : .png file
1932
+ Generated plot
1933
+ """
1934
+
1935
+ # add whitespace if colorbar label is not given (empty colorbar labels are plotted wrong)
1936
+ if ps['colorbar_label'] is None or ps['colorbar_label']=='':
1937
+ ps['colorbar_label'] = ' '
1938
+
1939
+ if type(ps['fname_in']) is str:
1940
+ ps['fname_in'] = [ps['fname_in']]
1941
+
1942
+ _, ext = os.path.splitext(ps['fname_in'][0])
1943
+
1944
+ # make .xdmf file if .hdf5 file is provided
1945
+ if ext == '.hdf5':
1946
+ mode = 'hdf5'
1947
+ fname_load = os.path.join(os.path.splitext(ps['fname_in'][0]), '.xdmf')
1948
+
1949
+ if len(ps['fname_in']) == 1:
1950
+ write_xdmf(hdf5_fn = ps['fname_in'][0], hdf5_geo_fn=None, overwrite_xdmf=True)
1951
+ elif len(ps['fname_in']) == 2:
1952
+ write_xdmf(hdf5_fn = ps['fname_in'][0], hdf5_geo_fn = ps['fname_in'][1], overwrite_xdmf=True)
1953
+ else:
1954
+ raise Exception('Please specify either one .hdf5 file containing data and geometry or two .hdf5 files,'
1955
+ 'whereas the first contains the data and the second the geometry!')
1956
+ elif ext == '.xdmf':
1957
+ mode = 'xdmf'
1958
+ fname_load = ps['fname_in']
1959
+
1960
+ else:
1961
+ raise Exception('Please check file type and extension!')
1962
+
1963
+ thresholding = not(ps['domain_IDs'] == [])
1964
+ if ps['interpolate']:
1965
+ target = 'POINTS'
1966
+ else:
1967
+ target = 'CELLS'
1968
+
1969
+ # =============================================================================
1970
+ # Load data
1971
+ # =============================================================================
1972
+
1973
+ # create a new 'Xdmf3ReaderT' for data
1974
+ p = paraview.simple.Xdmf3ReaderT(FileName=[fname_load[0]])
1975
+ p.PointArrays = []
1976
+ p.CellArrays = [ps['quantity'], 'dipole_mag', 'tissue_type']
1977
+ p.Sets = []
1978
+
1979
+ # get active view
1980
+ renderView = GetActiveViewOrCreate('RenderView')
1981
+
1982
+ # show data in view
1983
+ pDisplay = Show(p, renderView)
1984
+ # trace defaults for the display properties.
1985
+ pDisplay.Representation = 'Surface'
1986
+ pDisplay.AmbientColor = [1.0, 1.0, 1.0]
1987
+ pDisplay.ColorArrayName = [None, '']
1988
+ pDisplay.DiffuseColor = [1.0, 1.0, 1.0]
1989
+ pDisplay.LookupTable = None
1990
+ pDisplay.MapScalars = 1
1991
+ pDisplay.InterpolateScalarsBeforeMapping = 1
1992
+ pDisplay.Opacity = 1.0
1993
+ pDisplay.PointSize = 2.0
1994
+ pDisplay.LineWidth = 1.0
1995
+ pDisplay.Interpolation = 'Gouraud'
1996
+ pDisplay.Specular = 0.0
1997
+ pDisplay.SpecularColor = [1.0, 1.0, 1.0]
1998
+ pDisplay.SpecularPower = 100.0
1999
+ pDisplay.Ambient = 0.0
2000
+ pDisplay.Diffuse = 1.0
2001
+ pDisplay.EdgeColor = [0.0, 0.0, 0.5]
2002
+ pDisplay.BackfaceRepresentation = 'Follow Frontface'
2003
+ pDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
2004
+ pDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
2005
+ pDisplay.BackfaceOpacity = 1.0
2006
+ pDisplay.Position = [0.0, 0.0, 0.0]
2007
+ pDisplay.Scale = [1.0, 1.0, 1.0]
2008
+ pDisplay.Orientation = [0.0, 0.0, 0.0]
2009
+ pDisplay.Origin = [0.0, 0.0, 0.0]
2010
+ pDisplay.Pickable = 1
2011
+ pDisplay.Texture = None
2012
+ pDisplay.Triangulate = 0
2013
+ pDisplay.NonlinearSubdivisionLevel = 1
2014
+ pDisplay.OSPRayUseScaleArray = 0
2015
+ pDisplay.OSPRayScaleArray = 'tissue_type'
2016
+ pDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
2017
+ pDisplay.GlyphType = 'Arrow'
2018
+ pDisplay.SelectionCellLabelBold = 0
2019
+ pDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
2020
+ pDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
2021
+ pDisplay.SelectionCellLabelFontSize = 18
2022
+ pDisplay.SelectionCellLabelItalic = 0
2023
+ pDisplay.SelectionCellLabelJustification = 'Left'
2024
+ pDisplay.SelectionCellLabelOpacity = 1.0
2025
+ pDisplay.SelectionCellLabelShadow = 0
2026
+ pDisplay.SelectionPointLabelBold = 0
2027
+ pDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
2028
+ pDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
2029
+ pDisplay.SelectionPointLabelFontSize = 18
2030
+ pDisplay.SelectionPointLabelItalic = 0
2031
+ pDisplay.SelectionPointLabelJustification = 'Left'
2032
+ pDisplay.SelectionPointLabelOpacity = 1.0
2033
+ pDisplay.SelectionPointLabelShadow = 0
2034
+ pDisplay.ScalarOpacityUnitDistance = 1.5164840226522087
2035
+ pDisplay.SelectMapper = 'Projected tetra'
2036
+ pDisplay.GaussianRadius = 0.0
2037
+ pDisplay.ShaderPreset = 'Sphere'
2038
+ pDisplay.Emissive = 0
2039
+ pDisplay.ScaleByArray = 0
2040
+ pDisplay.SetScaleArray = [None, '']
2041
+ pDisplay.ScaleTransferFunction = 'PiecewiseFunction'
2042
+ pDisplay.OpacityByArray = 0
2043
+ pDisplay.OpacityArray = [None, '']
2044
+ pDisplay.OpacityTransferFunction = 'PiecewiseFunction'
2045
+
2046
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
2047
+ pDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2048
+
2049
+ # init the 'Arrow' selected for 'GlyphType'
2050
+ pDisplay.GlyphType.TipResolution = 6
2051
+ pDisplay.GlyphType.TipRadius = 0.1
2052
+ pDisplay.GlyphType.TipLength = 0.35
2053
+ pDisplay.GlyphType.ShaftResolution = 6
2054
+ pDisplay.GlyphType.ShaftRadius = 0.03
2055
+ pDisplay.GlyphType.Invert = 0
2056
+
2057
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
2058
+ pDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2059
+
2060
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
2061
+ pDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2062
+
2063
+ # reset view to fit data
2064
+ renderView.ResetCamera()
2065
+
2066
+ # set scalar coloring
2067
+ ColorBy(pDisplay, ('FIELD', 'vtkBlockColors'))
2068
+
2069
+ # show color bar/color legend
2070
+ pDisplay.SetScalarBarVisibility(renderView, False)
2071
+
2072
+ # get color transfer function/color map for 'vtkBlockColors'
2073
+ vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
2074
+ # vtkBlockColorsLUT.LockDataRange = 0 # not in v5.8 anymore
2075
+ vtkBlockColorsLUT.InterpretValuesAsCategories = 1
2076
+ vtkBlockColorsLUT.ShowCategoricalColorsinDataRangeOnly = 0
2077
+ vtkBlockColorsLUT.RescaleOnVisibilityChange = 0
2078
+ vtkBlockColorsLUT.EnableOpacityMapping = 0
2079
+ vtkBlockColorsLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 0.5, 0.865003, 0.865003, 0.865003, 1.0, 0.705882,
2080
+ 0.0156863, 0.14902]
2081
+ vtkBlockColorsLUT.UseLogScale = 0
2082
+ vtkBlockColorsLUT.ColorSpace = 'Diverging'
2083
+ vtkBlockColorsLUT.UseBelowRangeColor = 0
2084
+ vtkBlockColorsLUT.BelowRangeColor = [0.0, 0.0, 0.0]
2085
+ vtkBlockColorsLUT.UseAboveRangeColor = 0
2086
+ vtkBlockColorsLUT.AboveRangeColor = [1.0, 1.0, 1.0]
2087
+ vtkBlockColorsLUT.NanColor = ps['NanColor']
2088
+ vtkBlockColorsLUT.Discretize = 1
2089
+ vtkBlockColorsLUT.NumberOfTableValues = 256
2090
+ vtkBlockColorsLUT.ScalarRangeInitialized = 0.0
2091
+ vtkBlockColorsLUT.HSVWrap = 0
2092
+ vtkBlockColorsLUT.VectorComponent = 0
2093
+ vtkBlockColorsLUT.VectorMode = 'Magnitude'
2094
+ vtkBlockColorsLUT.AllowDuplicateScalars = 1
2095
+ vtkBlockColorsLUT.Annotations = ['0', '0', '1', '1', '2', '2', '3', '3', '4', '4', '5', '5', '6', '6', '7', '7',
2096
+ '8', '8', '9', '9', '10', '10', '11', '11']
2097
+ vtkBlockColorsLUT.ActiveAnnotatedValues = ['0', '1', '2']
2098
+ vtkBlockColorsLUT.IndexedColors = [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
2099
+ 0.0, 1.0, 0.0, 1.0, 1.0, 0.63, 0.63, 1.0, 0.67, 0.5, 0.33, 1.0, 0.5, 0.75, 0.53,
2100
+ 0.35, 0.7, 1.0, 0.75, 0.5]
2101
+
2102
+ # get opacity transfer function/opacity map for 'vtkBlockColors'
2103
+ vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
2104
+ vtkBlockColorsPWF.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2105
+ vtkBlockColorsPWF.AllowDuplicateScalars = 1
2106
+ vtkBlockColorsPWF.ScalarRangeInitialized = 0
2107
+
2108
+ # hide original dataset
2109
+ Hide(p, renderView)
2110
+
2111
+ # =============================================================================
2112
+ # Process surface data (make threshold w.r.t. tissue_type > 1000)
2113
+ # =============================================================================
2114
+ s = paraview.simple.Threshold(Input=p)
2115
+ s.Scalars = ['CELLS', 'tissue_type']
2116
+ s.ThresholdRange = [np.min(ps['domain_IDs']).astype(float) + 1000, np.max(ps['domain_IDs']).astype(float) + 1000]
2117
+ s.AllScalars = 1
2118
+ s.UseContinuousCellRange = 0
2119
+
2120
+ # get color transfer function/color map for 'tissuetype'
2121
+ tissuetypeLUT = GetColorTransferFunction('tissuetype')
2122
+ # tissuetypeLUT.LockDataRange = 0 # not in v5.8 anymore
2123
+ tissuetypeLUT.InterpretValuesAsCategories = 0
2124
+ tissuetypeLUT.ShowCategoricalColorsinDataRangeOnly = 0
2125
+ tissuetypeLUT.RescaleOnVisibilityChange = 0
2126
+ tissuetypeLUT.EnableOpacityMapping = 0
2127
+ #tissuetypeLUT.RGBPoints = [1002.0, 0.231373, 0.298039, 0.752941, 1002.0050100501, 0.865003, 0.865003, 0.865003,
2128
+ # 1002.0100201002, 0.705882, 0.0156863, 0.14902]
2129
+ tissuetypeLUT.UseLogScale = 0
2130
+ tissuetypeLUT.ColorSpace = 'Diverging'
2131
+ tissuetypeLUT.UseBelowRangeColor = 0
2132
+ tissuetypeLUT.BelowRangeColor = [0.0, 0.0, 0.0]
2133
+ tissuetypeLUT.UseAboveRangeColor = 0
2134
+ tissuetypeLUT.AboveRangeColor = [1.0, 1.0, 1.0]
2135
+ tissuetypeLUT.NanColor = ps['NanColor']
2136
+ tissuetypeLUT.Discretize = 1
2137
+ tissuetypeLUT.NumberOfTableValues = 256
2138
+ tissuetypeLUT.ScalarRangeInitialized = 1.0
2139
+ tissuetypeLUT.HSVWrap = 0
2140
+ tissuetypeLUT.VectorComponent = 0
2141
+ tissuetypeLUT.VectorMode = 'Magnitude'
2142
+ tissuetypeLUT.AllowDuplicateScalars = 1
2143
+ tissuetypeLUT.Annotations = []
2144
+ tissuetypeLUT.ActiveAnnotatedValues = []
2145
+ tissuetypeLUT.IndexedColors = []
2146
+
2147
+ # show data in view
2148
+ sDisplay = Show(s, renderView)
2149
+ # trace defaults for the display properties.
2150
+ sDisplay.Representation = 'Surface'
2151
+ sDisplay.AmbientColor = [1.0, 1.0, 1.0]
2152
+ sDisplay.ColorArrayName = ['CELLS', 'tissue_type']
2153
+ sDisplay.DiffuseColor = [1.0, 1.0, 1.0]
2154
+ sDisplay.LookupTable = tissuetypeLUT
2155
+ sDisplay.MapScalars = 1
2156
+ sDisplay.InterpolateScalarsBeforeMapping = 1
2157
+ sDisplay.Opacity = 1.0
2158
+ sDisplay.PointSize = 2.0
2159
+ sDisplay.LineWidth = 1.0
2160
+ sDisplay.Interpolation = 'Gouraud'
2161
+ sDisplay.Specular = 0.0
2162
+ sDisplay.SpecularColor = [1.0, 1.0, 1.0]
2163
+ sDisplay.SpecularPower = 100.0
2164
+ sDisplay.Ambient = 0.0
2165
+ sDisplay.Diffuse = 1.0
2166
+ sDisplay.EdgeColor = [0.0, 0.0, 0.5]
2167
+ sDisplay.BackfaceRepresentation = 'Follow Frontface'
2168
+ sDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
2169
+ sDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
2170
+ sDisplay.BackfaceOpacity = 1.0
2171
+ sDisplay.Position = [0.0, 0.0, 0.0]
2172
+ sDisplay.Scale = [1.0, 1.0, 1.0]
2173
+ sDisplay.Orientation = [0.0, 0.0, 0.0]
2174
+ sDisplay.Origin = [0.0, 0.0, 0.0]
2175
+ sDisplay.Pickable = 1
2176
+ sDisplay.Texture = None
2177
+ sDisplay.Triangulate = 0
2178
+ sDisplay.NonlinearSubdivisionLevel = 1
2179
+ sDisplay.OSPRayUseScaleArray = 0
2180
+ sDisplay.OSPRayScaleArray = 'tissue_type'
2181
+ sDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
2182
+ sDisplay.GlyphType = 'Arrow'
2183
+ sDisplay.SelectionCellLabelBold = 0
2184
+ sDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
2185
+ sDisplay.SelectionCellLabelFontFamily =ps['colorbar_font']
2186
+ sDisplay.SelectionCellLabelFontSize = 18
2187
+ sDisplay.SelectionCellLabelItalic = 0
2188
+ sDisplay.SelectionCellLabelJustification = 'Left'
2189
+ sDisplay.SelectionCellLabelOpacity = 1.0
2190
+ sDisplay.SelectionCellLabelShadow = 0
2191
+ sDisplay.SelectionPointLabelBold = 0
2192
+ sDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
2193
+ sDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
2194
+ sDisplay.SelectionPointLabelFontSize = 18
2195
+ sDisplay.SelectionPointLabelItalic = 0
2196
+ sDisplay.SelectionPointLabelJustification = 'Left'
2197
+ sDisplay.SelectionPointLabelOpacity = 1.0
2198
+ sDisplay.SelectionPointLabelShadow = 0
2199
+ sDisplay.ScalarOpacityUnitDistance = 3.2593175817027698
2200
+ sDisplay.SelectMapper = 'Projected tetra'
2201
+ sDisplay.GaussianRadius = 0.0
2202
+ sDisplay.ShaderPreset = 'Sphere'
2203
+ sDisplay.Emissive = 0
2204
+ sDisplay.ScaleByArray = 0
2205
+ sDisplay.SetScaleArray = [None, '']
2206
+ sDisplay.ScaleTransferFunction = 'PiecewiseFunction'
2207
+ sDisplay.OpacityByArray = 0
2208
+ sDisplay.OpacityArray = [None, '']
2209
+ sDisplay.OpacityTransferFunction = 'PiecewiseFunction'
2210
+
2211
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
2212
+ sDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2213
+
2214
+ # init the 'Arrow' selected for 'GlyphType'
2215
+ sDisplay.GlyphType.TipResolution = 6
2216
+ sDisplay.GlyphType.TipRadius = 0.1
2217
+ sDisplay.GlyphType.TipLength = 0.35
2218
+ sDisplay.GlyphType.ShaftResolution = 6
2219
+ sDisplay.GlyphType.ShaftRadius = 0.03
2220
+ sDisplay.GlyphType.Invert = 0
2221
+
2222
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
2223
+ sDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2224
+
2225
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
2226
+ sDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2227
+
2228
+ # reset view to fit data
2229
+ renderView.ResetCamera()
2230
+
2231
+ # show color bar/color legend
2232
+ sDisplay.SetScalarBarVisibility(renderView, False)
2233
+
2234
+ # get opacity transfer function/opacity map for 'tissuetype'
2235
+ tissuetypePWF = GetOpacityTransferFunction('tissuetype')
2236
+ #tissuetypePWF.Points = [1002.0, 0.0, 0.5, 0.0, 1002.0100201002, 1.0, 0.5, 0.0]
2237
+ tissuetypePWF.AllowDuplicateScalars = 1
2238
+ tissuetypePWF.ScalarRangeInitialized = 1
2239
+
2240
+ # turn off scalar coloring
2241
+ ColorBy(sDisplay, None)
2242
+
2243
+ # change solid color
2244
+ sDisplay.DiffuseColor = ps['surface_color']
2245
+
2246
+ # =============================================================================
2247
+ # Process volume data
2248
+ # =============================================================================
2249
+ if thresholding:
2250
+
2251
+ #for i in range(len(domain_IDs)):
2252
+
2253
+ # create new threshold
2254
+ #if interpolate:
2255
+ # t[i] = paraview.simple.Threshold(Input=p1)
2256
+ #else:
2257
+ t = paraview.simple.Threshold(Input=p)
2258
+
2259
+ t.Scalars = ['CELLS', ps['domain_label']]
2260
+ t.ThresholdRange = [np.min(ps['domain_IDs']).astype(float), np.max(ps['domain_IDs']).astype(float)]
2261
+ t.AllScalars = 1
2262
+ t.UseContinuousCellRange = 0
2263
+
2264
+ tDisplay = Show(t, renderView)
2265
+
2266
+ ColorBy(tDisplay, (target, ps['quantity']))
2267
+ tDisplay.Representation = 'Surface'
2268
+ tDisplay.AmbientColor = [1.0, 1.0, 1.0]
2269
+ tDisplay.ColorArrayName = [None, '']
2270
+ tDisplay.DiffuseColor = [1.0, 1.0, 1.0]
2271
+ tDisplay.LookupTable = None
2272
+ tDisplay.MapScalars = 1
2273
+ tDisplay.InterpolateScalarsBeforeMapping = 1
2274
+ tDisplay.Opacity = 1.0
2275
+ tDisplay.PointSize = 2.0
2276
+ tDisplay.LineWidth = 1.0
2277
+ tDisplay.Interpolation = 'Gouraud'
2278
+ tDisplay.Specular = 0.0
2279
+ tDisplay.SpecularColor = [1.0, 1.0, 1.0]
2280
+ tDisplay.SpecularPower = 100.0
2281
+ tDisplay.Ambient = 0.0
2282
+ tDisplay.Diffuse = 1.0
2283
+ tDisplay.EdgeColor = [0.0, 0.0, 0.5]
2284
+ tDisplay.BackfaceRepresentation = 'Follow Frontface'
2285
+ tDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
2286
+ tDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
2287
+ tDisplay.BackfaceOpacity = 1.0
2288
+ tDisplay.Position = [0.0, 0.0, 0.0]
2289
+ tDisplay.Scale = [1.0, 1.0, 1.0]
2290
+ tDisplay.Orientation = [0.0, 0.0, 0.0]
2291
+ tDisplay.Origin = [0.0, 0.0, 0.0]
2292
+ tDisplay.Pickable = 1
2293
+ tDisplay.Texture = None
2294
+ tDisplay.Triangulate = 0
2295
+ tDisplay.NonlinearSubdivisionLevel = 1
2296
+ tDisplay.OSPRayUseScaleArray = 0
2297
+ tDisplay.OSPRayScaleArray = ps['quantity']
2298
+ tDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
2299
+ tDisplay.GlyphType = 'Arrow'
2300
+ tDisplay.SelectionCellLabelBold = 0
2301
+ tDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
2302
+ tDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
2303
+ tDisplay.SelectionCellLabelFontSize = 18
2304
+ tDisplay.SelectionCellLabelItalic = 0
2305
+ tDisplay.SelectionCellLabelJustification = 'Left'
2306
+ tDisplay.SelectionCellLabelOpacity = 1.0
2307
+ tDisplay.SelectionCellLabelShadow = 0
2308
+ tDisplay.SelectionPointLabelBold = 0
2309
+ tDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
2310
+ tDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
2311
+ tDisplay.SelectionPointLabelFontSize = 18
2312
+ tDisplay.SelectionPointLabelItalic = 0
2313
+ tDisplay.SelectionPointLabelJustification = 'Left'
2314
+ tDisplay.SelectionPointLabelOpacity = 1.0
2315
+ tDisplay.SelectionPointLabelShadow = 0
2316
+ tDisplay.ScalarOpacityUnitDistance = 1.8692603892074375
2317
+ tDisplay.SelectMapper = 'Projected tetra'
2318
+ tDisplay.GaussianRadius = 0.0
2319
+ tDisplay.ShaderPreset = 'Sphere'
2320
+ tDisplay.Emissive = 0
2321
+ tDisplay.ScaleByArray = 0
2322
+ tDisplay.SetScaleArray = [None, '']
2323
+ tDisplay.ScaleTransferFunction = 'PiecewiseFunction'
2324
+ tDisplay.OpacityByArray = 0
2325
+ tDisplay.OpacityArray = [None, '']
2326
+ tDisplay.OpacityTransferFunction = 'PiecewiseFunction'
2327
+
2328
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
2329
+ tDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2330
+
2331
+ # init the 'Arrow' selected for 'GlyphType'
2332
+ tDisplay.GlyphType.TipResolution = 6
2333
+ tDisplay.GlyphType.TipRadius = 0.1
2334
+ tDisplay.GlyphType.TipLength = 0.35
2335
+ tDisplay.GlyphType.ShaftResolution = 6
2336
+ tDisplay.GlyphType.ShaftRadius = 0.03
2337
+ tDisplay.GlyphType.Invert = 0
2338
+
2339
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
2340
+ tDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2341
+
2342
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
2343
+ tDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2344
+
2345
+ # create a new 'Cell Data to Point Data'
2346
+ # interpolate and no thresholding
2347
+ if ps['interpolate']:
2348
+ if thresholding:
2349
+ p1 = paraview.simple.CellDatatoPointData(Input=t)
2350
+ else:
2351
+ p1 = paraview.simple.CellDatatoPointData(Input=p)
2352
+ p1.PassCellData = 0
2353
+ p1.PieceInvariant = 0
2354
+ pDisplay = Show(p1, renderView)
2355
+ else:
2356
+ if thresholding:
2357
+ pDisplay = Show(t, renderView)
2358
+ else:
2359
+ pDisplay = Show(p, renderView)
2360
+
2361
+ # trace defaults for the display properties.
2362
+ pDisplay.Representation = 'Surface'
2363
+ pDisplay.AmbientColor = [1.0, 1.0, 1.0]
2364
+ pDisplay.ColorArrayName = [None, '']
2365
+ pDisplay.DiffuseColor = [1.0, 1.0, 1.0]
2366
+ pDisplay.LookupTable = None
2367
+ pDisplay.MapScalars = 1
2368
+ pDisplay.InterpolateScalarsBeforeMapping = 1
2369
+ pDisplay.Opacity = 1.0
2370
+ pDisplay.PointSize = 2.0
2371
+ pDisplay.LineWidth = 1.0
2372
+ pDisplay.Interpolation = 'Gouraud'
2373
+ pDisplay.Specular = 0.0
2374
+ pDisplay.SpecularColor = [1.0, 1.0, 1.0]
2375
+ pDisplay.SpecularPower = 100.0
2376
+ pDisplay.Ambient = 0.0
2377
+ pDisplay.Diffuse = 1.0
2378
+ pDisplay.EdgeColor = [0.0, 0.0, 0.5]
2379
+ pDisplay.BackfaceRepresentation = 'Follow Frontface'
2380
+ pDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
2381
+ pDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
2382
+ pDisplay.BackfaceOpacity = 1.0
2383
+ pDisplay.Position = [0.0, 0.0, 0.0]
2384
+ pDisplay.Scale = [1.0, 1.0, 1.0]
2385
+ pDisplay.Orientation = [0.0, 0.0, 0.0]
2386
+ pDisplay.Origin = [0.0, 0.0, 0.0]
2387
+ pDisplay.Pickable = 1
2388
+ pDisplay.Texture = None
2389
+ pDisplay.Triangulate = 0
2390
+ pDisplay.NonlinearSubdivisionLevel = 1
2391
+ pDisplay.OSPRayUseScaleArray = 0
2392
+ pDisplay.OSPRayScaleArray = ''#quantity
2393
+ pDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
2394
+ pDisplay.GlyphType = 'Arrow'
2395
+ pDisplay.SelectionCellLabelBold = 0
2396
+ pDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
2397
+ pDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
2398
+ pDisplay.SelectionCellLabelFontSize = 18
2399
+ pDisplay.SelectionCellLabelItalic = 0
2400
+ pDisplay.SelectionCellLabelJustification = 'Left'
2401
+ pDisplay.SelectionCellLabelOpacity = 1.0
2402
+ pDisplay.SelectionCellLabelShadow = 0
2403
+ pDisplay.SelectionPointLabelBold = 0
2404
+ pDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
2405
+ pDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
2406
+ pDisplay.SelectionPointLabelFontSize = 18
2407
+ pDisplay.SelectionPointLabelItalic = 0
2408
+ pDisplay.SelectionPointLabelJustification = 'Left'
2409
+ pDisplay.SelectionPointLabelOpacity = 1.0
2410
+ pDisplay.SelectionPointLabelShadow = 0
2411
+ pDisplay.ScalarOpacityUnitDistance = 1.6558923367892595
2412
+ pDisplay.SelectMapper = 'Projected tetra'
2413
+ pDisplay.GaussianRadius = 0.0
2414
+ pDisplay.ShaderPreset = 'Sphere'
2415
+ pDisplay.Emissive = 0
2416
+ pDisplay.ScaleByArray = 0
2417
+ pDisplay.SetScaleArray = [target, '']#quantity
2418
+ pDisplay.ScaleTransferFunction = 'PiecewiseFunction'
2419
+ pDisplay.OpacityByArray = 0
2420
+ pDisplay.OpacityArray = [target, '']#quantity
2421
+ pDisplay.OpacityTransferFunction = 'PiecewiseFunction'
2422
+
2423
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
2424
+ pDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2425
+
2426
+ # init the 'Arrow' selected for 'GlyphType'
2427
+ pDisplay.GlyphType.TipResolution = 6
2428
+ pDisplay.GlyphType.TipRadius = 0.1
2429
+ pDisplay.GlyphType.TipLength = 0.35
2430
+ pDisplay.GlyphType.ShaftResolution = 6
2431
+ pDisplay.GlyphType.ShaftRadius = 0.03
2432
+ pDisplay.GlyphType.Invert = 0
2433
+
2434
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
2435
+ pDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2436
+
2437
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
2438
+ pDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2439
+
2440
+ # change representation type
2441
+ if ps['edges']:
2442
+ pDisplay.SetRepresentationType('Surface With Edges')
2443
+
2444
+ # =============================================================================
2445
+ # Make Clip or Slice
2446
+ # =============================================================================
2447
+ # create a new 'Clip'
2448
+ if ps['clip_coords'].any():
2449
+ # hide original surfaces (will be replaced by new slice objects)
2450
+ Hide(s,renderView)
2451
+
2452
+ N_clips = ps['clip_coords'].shape[0]
2453
+ clip_coords_surface = copy.deepcopy(ps['clip_coords'])
2454
+ pcut = [0] * N_clips
2455
+ scut = [0] * N_clips
2456
+ pcutDisplay = [0] * N_clips
2457
+ scutDisplay = [0] * N_clips
2458
+
2459
+ for i in range(N_clips):
2460
+ # shift clip coords of surface a bit to get visability
2461
+ for i_shift in range(3):
2462
+ if ps['clip_normals'][i, i_shift] > 0:
2463
+ if ps['clip_type'][i] == 'clip':
2464
+ clip_coords_surface[i, i_shift] = copy.deepcopy(ps['clip_coords'][i, i_shift]) - 0.1
2465
+ if ps['clip_type'][i] == 'slice':
2466
+ clip_coords_surface[i, i_shift] = copy.deepcopy(ps['clip_coords'][i, i_shift]) + 0.1
2467
+
2468
+ # clip
2469
+ if ps['clip_type'][i] == 'clip':
2470
+
2471
+ # Generate clip
2472
+ if ps['interpolate']:
2473
+ if thresholding:
2474
+ pcut[i] = paraview.simple.Clip(Input=p1)
2475
+ else:
2476
+ if thresholding:
2477
+ pcut[i] = paraview.simple.Clip(Input=t)
2478
+ else:
2479
+ pcut[i] = paraview.simple.Clip(Input=p)
2480
+
2481
+ # init the 'Plane' selected for 'ClipType' (volume)
2482
+ pcut[i].ClipType = 'Plane'
2483
+ pcut[i].Scalars = [target, ps['quantity']]
2484
+ pcut[i].Value = 0.0
2485
+ pcut[i].InsideOut = 0
2486
+ pcut[i].Crinkleclip = 0
2487
+ pcut[i].ClipType.Origin = [ps['clip_coords'][i, 0], ps['clip_coords'][i, 1], ps['clip_coords'][i, 2]]
2488
+ pcut[i].ClipType.Normal = [ps['clip_normals'][i, 0], ps['clip_normals'][i, 1], ps['clip_normals'][i, 2]]
2489
+ pcut[i].ClipType.Offset = 0.0
2490
+
2491
+ # slice
2492
+ elif ps['clip_type'][i] == 'slice':
2493
+
2494
+ # Generate slice
2495
+ if ps['interpolate']:
2496
+ if thresholding:
2497
+ pcut[i] = paraview.simple.Slice(Input=p1)
2498
+ else:
2499
+ if thresholding:
2500
+ pcut[i] = paraview.simple.Slice(Input=t)
2501
+ else:
2502
+ pcut[i] = paraview.simple.Slice(Input=p)
2503
+
2504
+
2505
+
2506
+ # init the 'Plane' selected for 'ClipType' (volume)
2507
+ pcut[i].SliceType = 'Plane'
2508
+ pcut[i].Crinkleslice = 0
2509
+ pcut[i].Triangulatetheslice = 1
2510
+ pcut[i].SliceOffsetValues = [0.0]
2511
+ pcut[i].SliceType.Origin = [ps['clip_coords'][i, 0], ps['clip_coords'][i, 1], ps['clip_coords'][i, 2]]
2512
+ pcut[i].SliceType.Normal = [ps['clip_normals'][i, 0], ps['clip_normals'][i, 1], ps['clip_normals'][i, 2]]
2513
+ pcut[i].SliceType.Offset = 0.0
2514
+
2515
+ # Generate slice (surface)
2516
+ scut[i] = paraview.simple.Slice(Input=s)
2517
+
2518
+ # init the 'Plane' selected for 'ClipType' (surface)
2519
+ scut[i].SliceType = 'Plane'
2520
+ scut[i].Crinkleslice = 0
2521
+ scut[i].Triangulatetheslice = 1
2522
+ scut[i].SliceOffsetValues = [0.0]
2523
+ scut[i].SliceType.Origin = [clip_coords_surface[i, 0], clip_coords_surface[i, 1], clip_coords_surface[i, 2]]
2524
+ scut[i].SliceType.Normal = [ps['clip_normals'][i, 0], ps['clip_normals'][i, 1], ps['clip_normals'][i, 2]]
2525
+ scut[i].SliceType.Offset = 0.0
2526
+
2527
+ # show data in view
2528
+ pcutDisplay[i] = Show(pcut[i], renderView)
2529
+
2530
+ # map results to geometry
2531
+ #pcutDisplay[i].ColorArrayName = [target, quantity]
2532
+ paraview.simple.ColorBy(pcutDisplay[i], (target, ps['quantity']))
2533
+
2534
+ # trace defaults for the display properties.
2535
+ pcutDisplay[i].Representation = 'Surface'
2536
+ pcutDisplay[i].AmbientColor = [1.0, 1.0, 1.0]
2537
+ pcutDisplay[i].ColorArrayName = [None, '']
2538
+ pcutDisplay[i].DiffuseColor = [1.0, 1.0, 1.0]
2539
+ pcutDisplay[i].LookupTable = None
2540
+ pcutDisplay[i].MapScalars = 1
2541
+ pcutDisplay[i].InterpolateScalarsBeforeMapping = 1
2542
+ pcutDisplay[i].Opacity = 1.0
2543
+ pcutDisplay[i].PointSize = 2.0
2544
+ pcutDisplay[i].LineWidth = 1.0
2545
+ pcutDisplay[i].Interpolation = 'Gouraud'
2546
+ pcutDisplay[i].Specular = 0.0
2547
+ pcutDisplay[i].SpecularColor = [1.0, 1.0, 1.0]
2548
+ pcutDisplay[i].SpecularPower = 100.0
2549
+ pcutDisplay[i].Ambient = 0.0
2550
+ pcutDisplay[i].Diffuse = 1.0
2551
+ pcutDisplay[i].EdgeColor = [0.0, 0.0, 0.5]
2552
+ pcutDisplay[i].BackfaceRepresentation = 'Follow Frontface'
2553
+ pcutDisplay[i].BackfaceAmbientColor = [1.0, 1.0, 1.0]
2554
+ pcutDisplay[i].BackfaceDiffuseColor = [1.0, 1.0, 1.0]
2555
+ pcutDisplay[i].BackfaceOpacity = 1.0
2556
+ pcutDisplay[i].Position = [0.0, 0.0, 0.0]
2557
+ pcutDisplay[i].Scale = [1.0, 1.0, 1.0]
2558
+ pcutDisplay[i].Orientation = [0.0, 0.0, 0.0]
2559
+ pcutDisplay[i].Origin = [0.0, 0.0, 0.0]
2560
+ pcutDisplay[i].Pickable = 1
2561
+ pcutDisplay[i].Texture = None
2562
+ pcutDisplay[i].Triangulate = 0
2563
+ pcutDisplay[i].NonlinearSubdivisionLevel = 1
2564
+ pcutDisplay[i].OSPRayUseScaleArray = 0
2565
+ pcutDisplay[i].OSPRayScaleArray = ps['quantity']
2566
+ pcutDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
2567
+ pcutDisplay[i].GlyphType = 'Arrow'
2568
+ pcutDisplay[i].SelectionCellLabelBold = 0
2569
+ pcutDisplay[i].SelectionCellLabelColor = [0.0, 1.0, 0.0]
2570
+ pcutDisplay[i].SelectionCellLabelFontFamily = ps['colorbar_font']
2571
+ pcutDisplay[i].SelectionCellLabelFontSize = 18
2572
+ pcutDisplay[i].SelectionCellLabelItalic = 0
2573
+ pcutDisplay[i].SelectionCellLabelJustification = 'Left'
2574
+ pcutDisplay[i].SelectionCellLabelOpacity = 1.0
2575
+ pcutDisplay[i].SelectionCellLabelShadow = 0
2576
+ pcutDisplay[i].SelectionPointLabelBold = 0
2577
+ pcutDisplay[i].SelectionPointLabelColor = [1.0, 1.0, 0.0]
2578
+ pcutDisplay[i].SelectionPointLabelFontFamily = ps['colorbar_font']
2579
+ pcutDisplay[i].SelectionPointLabelFontSize = 18
2580
+ pcutDisplay[i].SelectionPointLabelItalic = 0
2581
+ pcutDisplay[i].SelectionPointLabelJustification = 'Left'
2582
+ pcutDisplay[i].SelectionPointLabelOpacity = 1.0
2583
+ pcutDisplay[i].SelectionPointLabelShadow = 0
2584
+ if ps['clip_type'][i] == 'clip':
2585
+ pcutDisplay[i].ScalarOpacityUnitDistance = 1.702063581347167
2586
+ pcutDisplay[i].SelectMapper = 'Projected tetra'
2587
+ pcutDisplay[i].GaussianRadius = 0.0
2588
+ pcutDisplay[i].ShaderPreset = 'Sphere'
2589
+ pcutDisplay[i].Emissive = 0
2590
+ pcutDisplay[i].ScaleByArray = 0
2591
+ if ps['interpolate']:
2592
+ pcutDisplay[i].SetScaleArray = [target, ps['quantity']]
2593
+ pcutDisplay[i].OpacityArray = [target, ps['quantity']]
2594
+ else:
2595
+ pcutDisplay[i].SetScaleArray = [None, '']
2596
+ pcutDisplay[i].OpacityArray = [None, '']
2597
+ pcutDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
2598
+ pcutDisplay[i].OpacityByArray = 0
2599
+ pcutDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
2600
+
2601
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
2602
+ pcutDisplay[i].OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2603
+
2604
+ # init the 'Arrow' selected for 'GlyphType'
2605
+ pcutDisplay[i].GlyphType.TipResolution = 6
2606
+ pcutDisplay[i].GlyphType.TipRadius = 0.1
2607
+ pcutDisplay[i].GlyphType.TipLength = 0.35
2608
+ pcutDisplay[i].GlyphType.ShaftResolution = 6
2609
+ pcutDisplay[i].GlyphType.ShaftRadius = 0.03
2610
+ pcutDisplay[i].GlyphType.Invert = 0
2611
+
2612
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
2613
+ pcutDisplay[i].ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2614
+
2615
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
2616
+ pcutDisplay[i].OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2617
+
2618
+ # change representation type
2619
+ if ps['edges']:
2620
+ pcutDisplay[i].SetRepresentationType('Surface With Edges')
2621
+
2622
+ # Apply all settings from volume slices to surface slices
2623
+ #scutDisplay[i] = pcutDisplay[i]
2624
+
2625
+ # set scalar coloring
2626
+ paraview.simple.ColorBy(pcutDisplay[i], (target, ps['quantity']))
2627
+
2628
+ # rescale color and/or opacity maps used to include current data range
2629
+ pcutDisplay[i].RescaleTransferFunctionToDataRange(True)
2630
+
2631
+ # show color bar/color legend
2632
+ pcutDisplay[i].SetScalarBarVisibility(renderView, True)
2633
+
2634
+ # show data in view
2635
+ scutDisplay[i] = Show(scut[i], renderView)
2636
+
2637
+ scutDisplay[i].Representation = 'Surface'
2638
+ scutDisplay[i].AmbientColor = [1.0, 1.0, 1.0]
2639
+ scutDisplay[i].ColorArrayName = ['CELLS', 'tissue_type']
2640
+ scutDisplay[i].DiffuseColor = [1.0, 1.0, 1.0]
2641
+ scutDisplay[i].LookupTable = tissuetypeLUT
2642
+ scutDisplay[i].MapScalars = 1
2643
+ scutDisplay[i].InterpolateScalarsBeforeMapping = 1
2644
+ scutDisplay[i].Opacity = 1.0
2645
+ scutDisplay[i].PointSize = 2.0
2646
+ scutDisplay[i].LineWidth = 1.0
2647
+ scutDisplay[i].Interpolation = 'Gouraud'
2648
+ scutDisplay[i].Specular = 0.0
2649
+ scutDisplay[i].SpecularColor = [1.0, 1.0, 1.0]
2650
+ scutDisplay[i].SpecularPower = 100.0
2651
+ scutDisplay[i].Ambient = 0.0
2652
+ scutDisplay[i].Diffuse = 1.0
2653
+ scutDisplay[i].EdgeColor = [0.0, 0.0, 0.5]
2654
+ scutDisplay[i].BackfaceRepresentation = 'Follow Frontface'
2655
+ scutDisplay[i].BackfaceAmbientColor = [1.0, 1.0, 1.0]
2656
+ scutDisplay[i].BackfaceDiffuseColor = [1.0, 1.0, 1.0]
2657
+ scutDisplay[i].BackfaceOpacity = 1.0
2658
+ scutDisplay[i].Position = [0.0, 0.0, 0.0]
2659
+ scutDisplay[i].Scale = [1.0, 1.0, 1.0]
2660
+ scutDisplay[i].Orientation = [0.0, 0.0, 0.0]
2661
+ scutDisplay[i].Origin = [0.0, 0.0, 0.0]
2662
+ scutDisplay[i].Pickable = 1
2663
+ scutDisplay[i].Texture = None
2664
+ scutDisplay[i].Triangulate = 0
2665
+ scutDisplay[i].NonlinearSubdivisionLevel = 1
2666
+ scutDisplay[i].OSPRayUseScaleArray = 0
2667
+ scutDisplay[i].OSPRayScaleArray = 'tissue_type'
2668
+ scutDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
2669
+ scutDisplay[i].GlyphType = 'Arrow'
2670
+ scutDisplay[i].SelectionCellLabelBold = 0
2671
+ scutDisplay[i].SelectionCellLabelColor = [0.0, 1.0, 0.0]
2672
+ scutDisplay[i].SelectionCellLabelFontFamily = ps['colorbar_font']
2673
+ scutDisplay[i].SelectionCellLabelFontSize = 18
2674
+ scutDisplay[i].SelectionCellLabelItalic = 0
2675
+ scutDisplay[i].SelectionCellLabelJustification = 'Left'
2676
+ scutDisplay[i].SelectionCellLabelOpacity = 1.0
2677
+ scutDisplay[i].SelectionCellLabelShadow = 0
2678
+ scutDisplay[i].SelectionPointLabelBold = 0
2679
+ scutDisplay[i].SelectionPointLabelColor = [1.0, 1.0, 0.0]
2680
+ scutDisplay[i].SelectionPointLabelFontFamily = ps['colorbar_font']
2681
+ scutDisplay[i].SelectionPointLabelFontSize = 18
2682
+ scutDisplay[i].SelectionPointLabelItalic = 0
2683
+ scutDisplay[i].SelectionPointLabelJustification = 'Left'
2684
+ scutDisplay[i].SelectionPointLabelOpacity = 1.0
2685
+ scutDisplay[i].SelectionPointLabelShadow = 0
2686
+ scutDisplay[i].GaussianRadius = 0.0
2687
+ scutDisplay[i].ShaderPreset = 'Sphere'
2688
+ scutDisplay[i].Emissive = 0
2689
+ scutDisplay[i].ScaleByArray = 0
2690
+ if ps['interpolate']:
2691
+ scutDisplay[i].SetScaleArray = [target, 'tissue_type']
2692
+ scutDisplay[i].OpacityArray = [target, 'tissue_type']
2693
+ else:
2694
+ scutDisplay[i].SetScaleArray = [None, '']
2695
+ scutDisplay[i].OpacityArray = [None, '']
2696
+
2697
+ scutDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
2698
+ scutDisplay[i].OpacityByArray = 0
2699
+ scutDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
2700
+
2701
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
2702
+ scutDisplay[i].OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2703
+
2704
+ # init the 'Arrow' selected for 'GlyphType'
2705
+ scutDisplay[i].GlyphType.TipResolution = 6
2706
+ scutDisplay[i].GlyphType.TipRadius = 0.1
2707
+ scutDisplay[i].GlyphType.TipLength = 0.35
2708
+ scutDisplay[i].GlyphType.ShaftResolution = 6
2709
+ scutDisplay[i].GlyphType.ShaftRadius = 0.03
2710
+ scutDisplay[i].GlyphType.Invert = 0
2711
+
2712
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
2713
+ scutDisplay[i].ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2714
+
2715
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
2716
+ scutDisplay[i].OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2717
+
2718
+ # show color bar/color legend
2719
+ scutDisplay[i].SetScalarBarVisibility(renderView, False)
2720
+
2721
+ # turn off scalar coloring
2722
+ ColorBy(scutDisplay[i], None)
2723
+
2724
+ # change solid color
2725
+ scutDisplay[i].DiffuseColor = ps['surface_color']
2726
+
2727
+
2728
+ # =============================================================================
2729
+ # Disable selected elements for final view
2730
+ # =============================================================================
2731
+ if ps['interpolate']:
2732
+ if thresholding:
2733
+ Hide(t, renderView)
2734
+ Hide(p1, renderView)
2735
+ else:
2736
+ Hide(p, renderView)
2737
+ else:
2738
+ if thresholding:
2739
+ Hide(p, renderView)
2740
+
2741
+ # turn off orientation axes
2742
+ if not (ps['axes']):
2743
+ renderView.OrientationAxesVisibility = 0
2744
+
2745
+ # =============================================================================
2746
+ # Setup colormap and colorbar
2747
+ # =============================================================================
2748
+ # get color transfer function/color map for 'quantity'
2749
+ eLUT = GetColorTransferFunction(ps['quantity'])
2750
+ # eLUT.LockDataRange = 0 # not in v5.8 anymore
2751
+ eLUT.InterpretValuesAsCategories = 0
2752
+ eLUT.ShowCategoricalColorsinDataRangeOnly = 0
2753
+ eLUT.RescaleOnVisibilityChange = 0
2754
+ eLUT.EnableOpacityMapping = 0
2755
+ eLUT.UseLogScale = 0
2756
+ if ps['interpolate']:
2757
+ eLUT.ColorSpace = 'RGB'
2758
+ else:
2759
+ eLUT.ColorSpace = 'RGB' #'Diverging'
2760
+ eLUT.ColorSpace = 'Diverging'
2761
+ eLUT.UseBelowRangeColor = 0
2762
+ eLUT.BelowRangeColor = [0.0, 0.0, 0.0]
2763
+ eLUT.UseAboveRangeColor = 0
2764
+ eLUT.AboveRangeColor = [1.0, 1.0, 1.0]
2765
+ eLUT.NanColor = ps['NanColor']
2766
+ eLUT.Discretize = 1
2767
+ eLUT.NumberOfTableValues = 256
2768
+ eLUT.ScalarRangeInitialized = 1.0
2769
+ eLUT.HSVWrap = 0
2770
+ eLUT.VectorComponent = 0
2771
+ eLUT.VectorMode = 'Magnitude'
2772
+ eLUT.AllowDuplicateScalars = 1
2773
+ eLUT.Annotations = []
2774
+ eLUT.ActiveAnnotatedValues = []
2775
+ eLUT.IndexedColors = []
2776
+
2777
+ # set opacity transfer function/opacity map for 'quantity'
2778
+ ePWF = GetOpacityTransferFunction(ps['quantity'])
2779
+ if not(ps['opacitymap']==[]):
2780
+ eLUT.EnableOpacityMapping = 1
2781
+ ePWF.Points = ps['opacitymap']
2782
+ ePWF.AllowDuplicateScalars = 1
2783
+ ePWF.ScalarRangeInitialized = 1
2784
+
2785
+ colormap_presets = {'Cool to Warm',
2786
+ 'Cool to Warm (Extended)',
2787
+ 'Blue to Red Rainbow',
2788
+ 'X Ray',
2789
+ 'Grayscale',
2790
+ 'jet',
2791
+ 'hsv',
2792
+ 'erdc_iceFire_L',
2793
+ 'Plasma (matplotlib)',
2794
+ 'Viridis (matplotlib)',
2795
+ 'gray_Matlab',
2796
+ 'Spectral_lowBlue',
2797
+ 'Rainbow Blended White',
2798
+ 'BuRd'}
2799
+
2800
+ if type(ps['colormap']) is str:
2801
+ # set colorbar to 'jet' if not specified in presets
2802
+ if not (ps['colormap'] in colormap_presets):
2803
+ print((
2804
+ 'Changing colormap to \'jet\' since user specified colormap \'{}\' is not part of the included presets ...').format(
2805
+ ps['colormap']))
2806
+ colormap = 'jet'
2807
+
2808
+ if ps['colormap'] == 'b2rcw':
2809
+ rgb_values = b2rcw(ps['datarange'][0], ps['datarange'][1])
2810
+ rgb_data = np.linspace(ps['datarange'][0], ps['datarange'][1], rgb_values.shape[0])
2811
+ eLUT.RGBPoints = np.hstack((rgb_data,rgb_values))
2812
+ else:
2813
+ # Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
2814
+ eLUT.ApplyPreset(ps['colormap'], True)
2815
+ else:
2816
+ eLUT.RGBPoints = ps['colormap']
2817
+
2818
+ # =============================================================================
2819
+ # colorbar
2820
+ # =============================================================================
2821
+ # get color legend/bar for eLUT in view renderView
2822
+ eLUTColorBar = GetScalarBar(eLUT, renderView)
2823
+ if ps['colorbar_position']:
2824
+ eLUTColorBar.Position = ps['colorbar_position']
2825
+ else:
2826
+ eLUTColorBar.Position = [0.85, 0.05]
2827
+ # eLUTColorBar.Position2 = [0.12, 0.43] # 'Position2' is obsolete as of ParaView 5.4. Use the 'ScalarBarLength' property to set the length instead.
2828
+ eLUTColorBar.AutoOrient = 1
2829
+ eLUTColorBar.Orientation = ps['colorbar_orientation']
2830
+ eLUTColorBar.Title = ps['quantity']
2831
+ eLUTColorBar.ComponentTitle = 'Magnitude'
2832
+ eLUTColorBar.TitleJustification = 'Centered'
2833
+ eLUTColorBar.TitleColor = ps['colorbar_labelcolor']
2834
+ eLUTColorBar.TitleOpacity = 1.0
2835
+ eLUTColorBar.TitleFontFamily = ps['colorbar_font']
2836
+ eLUTColorBar.TitleBold = 0
2837
+ eLUTColorBar.TitleItalic = 0
2838
+ eLUTColorBar.TitleShadow = 0
2839
+ eLUTColorBar.LabelColor = ps['colorbar_labelcolor']
2840
+ eLUTColorBar.LabelOpacity = 1.0
2841
+ eLUTColorBar.LabelFontFamily = ps['colorbar_font']
2842
+ eLUTColorBar.LabelBold = 0
2843
+ eLUTColorBar.LabelItalic = 0
2844
+ eLUTColorBar.LabelShadow = 0
2845
+ eLUTColorBar.AutomaticLabelFormat = 0
2846
+ eLUTColorBar.LabelFormat = ps['colorbar_labelformat']
2847
+ # eLUTColorBar.NumberOfLabels = ps['colorbar_numberoflabels'] # not in v5.8 anymore
2848
+ eLUTColorBar.DrawTickMarks = 1
2849
+ # eLUTColorBar.DrawSubTickMarks = 1 # not in v5.8 anymore
2850
+ eLUTColorBar.DrawTickLabels = 1
2851
+ eLUTColorBar.AddRangeLabels = 1
2852
+ eLUTColorBar.RangeLabelFormat = ps['colorbar_labelformat']
2853
+ eLUTColorBar.DrawAnnotations = 1
2854
+ eLUTColorBar.AddRangeAnnotations = 0
2855
+ eLUTColorBar.AutomaticAnnotations = 0
2856
+ eLUTColorBar.DrawNanAnnotation = 0
2857
+ eLUTColorBar.NanAnnotation = 'NaN'
2858
+ eLUTColorBar.TextPosition = 'Ticks right/top, annotations left/bottom'
2859
+ # eLUTColorBar.AspectRatio = ps['colorbar_aspectratio'] # paraview.NotSupportedException: 'AspectRatio' is obsolete as of ParaView 5.4. Use the 'ScalarBarThickness' property to set the width instead.
2860
+ eLUTColorBar.Title = ps['colorbar_label']
2861
+ eLUTColorBar.ComponentTitle = ''
2862
+ eLUTColorBar.TitleFontSize = ps['colorbar_titlefontsize']
2863
+ eLUTColorBar.LabelFontSize = ps['colorbar_labelfontsize']
2864
+
2865
+ # Rescale transfer function
2866
+ if ps['datarange']:
2867
+ eLUT.RescaleTransferFunction(ps['datarange'][0], ps['datarange'][1])
2868
+ ePWF.RescaleTransferFunction(ps['datarange'][0], ps['datarange'][1])
2869
+
2870
+ # camera placement for renderView
2871
+ if len(ps['view']) == 4:
2872
+ renderView.CameraPosition = ps['view'][0]
2873
+ renderView.CameraFocalPoint = ps['view'][1]
2874
+ renderView.CameraViewUp = ps['view'][2]
2875
+ renderView.CameraParallelScale = ps['view'][3][0]
2876
+ else:
2877
+ renderView.ResetCamera()
2878
+
2879
+ # =============================================================================
2880
+ # coil
2881
+ # =============================================================================
2882
+ source = GetActiveSource()
2883
+ source.UpdatePipeline()
2884
+ cdi = source.GetDataInformation().GetCompositeDataInformation()
2885
+ n_blocks = cdi.GetNumberOfChildren()
2886
+ block_names = [cdi.GetName(i) for i in range(n_blocks)]
2887
+
2888
+ if 'coil' in block_names and ps['show_coil']:
2889
+ plot_coil = True
2890
+ else:
2891
+ plot_coil = False
2892
+
2893
+ if plot_coil:
2894
+
2895
+ # create a new 'Threshold'
2896
+ coilthreshold = paraview.simple.Threshold(Input=p)
2897
+ coilthreshold.Scalars = ['CELLS', 'dipole_mag']
2898
+ #threshold1.ThresholdRange = [1.1648167371749878, 8.777523040771484]
2899
+ coilthreshold.AllScalars = 1
2900
+ coilthreshold.UseContinuousCellRange = 0
2901
+
2902
+ # show data in view
2903
+ coilthresholdDisplay = Show(coilthreshold, renderView)
2904
+ # trace defaults for the display properties.
2905
+ coilthresholdDisplay.Representation = 'Surface'
2906
+ coilthresholdDisplay.AmbientColor = [1.0, 1.0, 1.0]
2907
+ coilthresholdDisplay.ColorArrayName = ['CELLS', 'dipole_mag']
2908
+ coilthresholdDisplay.DiffuseColor = [1.0, 1.0, 1.0]
2909
+ #coilthresholdDisplay.LookupTable = dipolemagLUT
2910
+ coilthresholdDisplay.MapScalars = 1
2911
+ coilthresholdDisplay.InterpolateScalarsBeforeMapping = 1
2912
+ coilthresholdDisplay.Opacity = 1.0
2913
+ coilthresholdDisplay.PointSize = 2.0
2914
+ coilthresholdDisplay.LineWidth = 1.0
2915
+ coilthresholdDisplay.Interpolation = 'Gouraud'
2916
+ coilthresholdDisplay.Specular = 0.0
2917
+ coilthresholdDisplay.SpecularColor = [1.0, 1.0, 1.0]
2918
+ coilthresholdDisplay.SpecularPower = 100.0
2919
+ coilthresholdDisplay.Ambient = 0.0
2920
+ coilthresholdDisplay.Diffuse = 1.0
2921
+ coilthresholdDisplay.EdgeColor = [0.0, 0.0, 0.5]
2922
+ coilthresholdDisplay.BackfaceRepresentation = 'Follow Frontface'
2923
+ coilthresholdDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
2924
+ coilthresholdDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
2925
+ coilthresholdDisplay.BackfaceOpacity = 1.0
2926
+ coilthresholdDisplay.Position = [0.0, 0.0, 0.0]
2927
+ coilthresholdDisplay.Scale = [1.0, 1.0, 1.0]
2928
+ coilthresholdDisplay.Orientation = [0.0, 0.0, 0.0]
2929
+ coilthresholdDisplay.Origin = [0.0, 0.0, 0.0]
2930
+ coilthresholdDisplay.Pickable = 1
2931
+ coilthresholdDisplay.Texture = None
2932
+ coilthresholdDisplay.Triangulate = 0
2933
+ coilthresholdDisplay.NonlinearSubdivisionLevel = 1
2934
+ coilthresholdDisplay.OSPRayUseScaleArray = 0
2935
+ coilthresholdDisplay.OSPRayScaleArray = 'dipole_mag'
2936
+ coilthresholdDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
2937
+ coilthresholdDisplay.GlyphType = 'Arrow'
2938
+ coilthresholdDisplay.SelectionCellLabelBold = 0
2939
+ coilthresholdDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
2940
+ coilthresholdDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
2941
+ coilthresholdDisplay.SelectionCellLabelFontSize = 18
2942
+ coilthresholdDisplay.SelectionCellLabelItalic = 0
2943
+ coilthresholdDisplay.SelectionCellLabelJustification = 'Left'
2944
+ coilthresholdDisplay.SelectionCellLabelOpacity = 1.0
2945
+ coilthresholdDisplay.SelectionCellLabelShadow = 0
2946
+ coilthresholdDisplay.SelectionPointLabelBold = 0
2947
+ coilthresholdDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
2948
+ coilthresholdDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
2949
+ coilthresholdDisplay.SelectionPointLabelFontSize = 18
2950
+ coilthresholdDisplay.SelectionPointLabelItalic = 0
2951
+ coilthresholdDisplay.SelectionPointLabelJustification = 'Left'
2952
+ coilthresholdDisplay.SelectionPointLabelOpacity = 1.0
2953
+ coilthresholdDisplay.SelectionPointLabelShadow = 0
2954
+ coilthresholdDisplay.ScalarOpacityUnitDistance = 10.18430143021554
2955
+ coilthresholdDisplay.SelectMapper = 'Projected tetra'
2956
+ coilthresholdDisplay.GaussianRadius = 0.0
2957
+ coilthresholdDisplay.ShaderPreset = 'Sphere'
2958
+ coilthresholdDisplay.Emissive = 0
2959
+ coilthresholdDisplay.ScaleByArray = 0
2960
+ coilthresholdDisplay.SetScaleArray = [None, '']
2961
+ coilthresholdDisplay.ScaleTransferFunction = 'PiecewiseFunction'
2962
+ coilthresholdDisplay.OpacityByArray = 0
2963
+ coilthresholdDisplay.OpacityArray = [None, '']
2964
+ coilthresholdDisplay.OpacityTransferFunction = 'PiecewiseFunction'
2965
+
2966
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
2967
+ coilthresholdDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2968
+
2969
+ # init the 'Arrow' selected for 'GlyphType'
2970
+ coilthresholdDisplay.GlyphType.TipResolution = 6
2971
+ coilthresholdDisplay.GlyphType.TipRadius = 0.1
2972
+ coilthresholdDisplay.GlyphType.TipLength = 0.35
2973
+ coilthresholdDisplay.GlyphType.ShaftResolution = 6
2974
+ coilthresholdDisplay.GlyphType.ShaftRadius = 0.03
2975
+ coilthresholdDisplay.GlyphType.Invert = 0
2976
+
2977
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
2978
+ coilthresholdDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2979
+
2980
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
2981
+ coilthresholdDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
2982
+
2983
+ # show color bar/color legend
2984
+ coilthresholdDisplay.SetScalarBarVisibility(renderView, False)
2985
+
2986
+ # create a new 'Glyph'
2987
+ coilGlyph = paraview.simple.Glyph(Input=coilthreshold, GlyphType='Arrow')
2988
+ coilGlyph.Scalars = ['CELLS', 'dipole_mag']
2989
+ coilGlyph.Vectors = ['POINTS', 'None']
2990
+ coilGlyph.Orient = 1
2991
+ coilGlyph.GlyphMode = 'All Points'
2992
+ coilGlyph.MaximumNumberOfSamplePoints = 5000
2993
+ coilGlyph.Seed = 10339
2994
+ coilGlyph.Stride = 1
2995
+ coilGlyph.GlyphTransform = 'Transform2'
2996
+ coilGlyph.GlyphType = 'Sphere'
2997
+
2998
+ # set dipole scaling and size
2999
+ if ps['coil_dipole_scaling'][0] == 'scaled':
3000
+ coilGlyph.Scalars = ['POINTS', 'magnitude']
3001
+ coilGlyph.ScaleMode = 'scalar'
3002
+ else:
3003
+ coilGlyph.ScaleMode = 'off'
3004
+
3005
+ coilGlyph.ScaleFactor = ps['coil_dipole_scaling'][1]
3006
+
3007
+ # init the 'Transform2' selected for 'GlyphTransform'
3008
+ coilGlyph.GlyphTransform.Translate = [0.0, 0.0, 0.0]
3009
+ coilGlyph.GlyphTransform.Rotate = [0.0, 0.0, 0.0]
3010
+ coilGlyph.GlyphTransform.Scale = [1.0, 1.0, 1.0]
3011
+
3012
+ # get color transfer function/color map for 'dipolemag'
3013
+ dipolemagLUT = GetColorTransferFunction('dipolemag')
3014
+ # dipolemagLUT.LockDataRange = 0 # not in v5.8 anymore
3015
+ dipolemagLUT.InterpretValuesAsCategories = 0
3016
+ dipolemagLUT.ShowCategoricalColorsinDataRangeOnly = 0
3017
+ dipolemagLUT.RescaleOnVisibilityChange = 0
3018
+ dipolemagLUT.EnableOpacityMapping = 0
3019
+ dipolemagLUT.UseLogScale = 0
3020
+ dipolemagLUT.ColorSpace = 'Lab'
3021
+ dipolemagLUT.UseBelowRangeColor = 0
3022
+ dipolemagLUT.BelowRangeColor = [0.0, 0.0, 0.0]
3023
+ dipolemagLUT.UseAboveRangeColor = 0
3024
+ dipolemagLUT.AboveRangeColor = [1.0, 1.0, 1.0]
3025
+ dipolemagLUT.NanColor = ps['NanColor']
3026
+ dipolemagLUT.Discretize = 1
3027
+ dipolemagLUT.NumberOfTableValues = 256
3028
+ dipolemagLUT.ScalarRangeInitialized = 1.0
3029
+ dipolemagLUT.HSVWrap = 0
3030
+ dipolemagLUT.VectorComponent = 0
3031
+ dipolemagLUT.VectorMode = 'Magnitude'
3032
+ dipolemagLUT.AllowDuplicateScalars = 1
3033
+ dipolemagLUT.Annotations = []
3034
+ dipolemagLUT.ActiveAnnotatedValues = []
3035
+ dipolemagLUT.IndexedColors = []
3036
+
3037
+ # show data in view
3038
+ coilGlyphDisplay = Show(coilGlyph, renderView)
3039
+
3040
+ # trace defaults for the display properties.
3041
+ coilGlyphDisplay.Representation = 'Surface'
3042
+ coilGlyphDisplay.AmbientColor = [1.0, 1.0, 1.0]
3043
+ coilGlyphDisplay.ColorArrayName = ['POINTS', 'dipole_mag']
3044
+ coilGlyphDisplay.DiffuseColor = [1.0, 1.0, 1.0]
3045
+ coilGlyphDisplay.LookupTable = dipolemagLUT
3046
+ coilGlyphDisplay.MapScalars = 1
3047
+ coilGlyphDisplay.InterpolateScalarsBeforeMapping = 1
3048
+ coilGlyphDisplay.Opacity = 1.0
3049
+ coilGlyphDisplay.PointSize = 2.0
3050
+ coilGlyphDisplay.LineWidth = 1.0
3051
+ coilGlyphDisplay.Interpolation = 'Gouraud'
3052
+ coilGlyphDisplay.Specular = 0.0
3053
+ coilGlyphDisplay.SpecularColor = [1.0, 1.0, 1.0]
3054
+ coilGlyphDisplay.SpecularPower = 100.0
3055
+ coilGlyphDisplay.Ambient = 0.0
3056
+ coilGlyphDisplay.Diffuse = 1.0
3057
+ coilGlyphDisplay.EdgeColor = [0.0, 0.0, 0.5]
3058
+ coilGlyphDisplay.BackfaceRepresentation = 'Follow Frontface'
3059
+ coilGlyphDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
3060
+ coilGlyphDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
3061
+ coilGlyphDisplay.BackfaceOpacity = 1.0
3062
+ coilGlyphDisplay.Position = [0.0, 0.0, 0.0]
3063
+ coilGlyphDisplay.Scale = [1.0, 1.0, 1.0]
3064
+ coilGlyphDisplay.Orientation = [0.0, 0.0, 0.0]
3065
+ coilGlyphDisplay.Origin = [0.0, 0.0, 0.0]
3066
+ coilGlyphDisplay.Pickable = 1
3067
+ coilGlyphDisplay.Texture = None
3068
+ coilGlyphDisplay.Triangulate = 0
3069
+ coilGlyphDisplay.NonlinearSubdivisionLevel = 1
3070
+ coilGlyphDisplay.OSPRayUseScaleArray = 0
3071
+ coilGlyphDisplay.OSPRayScaleArray = 'dipole_mag'
3072
+ coilGlyphDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
3073
+ coilGlyphDisplay.GlyphType = 'Arrow'
3074
+ coilGlyphDisplay.SelectionCellLabelBold = 0
3075
+ coilGlyphDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
3076
+ coilGlyphDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
3077
+ coilGlyphDisplay.SelectionCellLabelFontSize = 18
3078
+ coilGlyphDisplay.SelectionCellLabelItalic = 0
3079
+ coilGlyphDisplay.SelectionCellLabelJustification = 'Left'
3080
+ coilGlyphDisplay.SelectionCellLabelOpacity = 1.0
3081
+ coilGlyphDisplay.SelectionCellLabelShadow = 0
3082
+ coilGlyphDisplay.SelectionPointLabelBold = 0
3083
+ coilGlyphDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
3084
+ coilGlyphDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
3085
+ coilGlyphDisplay.SelectionPointLabelFontSize = 18
3086
+ coilGlyphDisplay.SelectionPointLabelItalic = 0
3087
+ coilGlyphDisplay.SelectionPointLabelJustification = 'Left'
3088
+ coilGlyphDisplay.SelectionPointLabelOpacity = 1.0
3089
+ coilGlyphDisplay.SelectionPointLabelShadow = 0
3090
+ coilGlyphDisplay.GaussianRadius = 0.0
3091
+ coilGlyphDisplay.ShaderPreset = 'Sphere'
3092
+ coilGlyphDisplay.Emissive = 0
3093
+ coilGlyphDisplay.ScaleByArray = 0
3094
+ coilGlyphDisplay.SetScaleArray = ['POINTS', 'dipole_mag']
3095
+ coilGlyphDisplay.ScaleTransferFunction = 'PiecewiseFunction'
3096
+ coilGlyphDisplay.OpacityByArray = 0
3097
+ coilGlyphDisplay.OpacityArray = ['POINTS', 'dipole_mag']
3098
+ coilGlyphDisplay.OpacityTransferFunction = 'PiecewiseFunction'
3099
+
3100
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
3101
+ coilGlyphDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3102
+
3103
+ # init the 'Arrow' selected for 'GlyphType'
3104
+ coilGlyphDisplay.GlyphType.TipResolution = 6
3105
+ coilGlyphDisplay.GlyphType.TipRadius = 0.1
3106
+ coilGlyphDisplay.GlyphType.TipLength = 0.35
3107
+ coilGlyphDisplay.GlyphType.ShaftResolution = 6
3108
+ coilGlyphDisplay.GlyphType.ShaftRadius = 0.03
3109
+ coilGlyphDisplay.GlyphType.Invert = 0
3110
+
3111
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
3112
+ coilGlyphDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3113
+
3114
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
3115
+ coilGlyphDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3116
+
3117
+ # show color bar/color legend
3118
+ coilGlyphDisplay.SetScalarBarVisibility(renderView, False)
3119
+
3120
+ # set dipole color
3121
+ if isinstance(ps['coil_dipole_color'], (str,)):
3122
+ # Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
3123
+ dipolemagLUT.ApplyPreset(ps['coil_dipole_color'], True)
3124
+
3125
+ else:
3126
+ # change solid color
3127
+ coilGlyphDisplay.DiffuseColor = ps['coil_dipole_color']
3128
+
3129
+ # =============================================================
3130
+ # set coil axes direction
3131
+ # =============================================================
3132
+ if ps['coil_axes']:
3133
+ import vtk.numpy_interface.dataset_adapter as dsa
3134
+
3135
+ # read points out of dataset
3136
+ coilthreshold.UpdatePipeline()
3137
+ rawData = servermanager.Fetch(coilthreshold)
3138
+ data = dsa.WrapDataObject(rawData)
3139
+ points = np.array(data.Points.Arrays[2])
3140
+
3141
+ # determine coil center
3142
+ coil_center = np.average(points, axis=0)
3143
+
3144
+ # shift coil to center for SVD
3145
+ points = points - coil_center
3146
+
3147
+ line = [0] * 3
3148
+ lineDisplay = [0] * 3
3149
+ line_color = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
3150
+ U, s, V = np.linalg.svd(points, full_matrices=True)
3151
+ points_transform = np.dot(points, V.transpose())
3152
+ coil_dim = np.max(points_transform, axis=0) - np.min(points_transform, axis=0)
3153
+
3154
+ for i in range(3):
3155
+ # create a new 'Line'
3156
+ line[i] = paraview.simple.Line()
3157
+ # Properties modified on line1
3158
+ line[i].Point1 = coil_center
3159
+ if ((i == 0) or (i == 1)):
3160
+ line[i].Point2 = coil_center + V[i, :] / np.linalg.norm(V[i, :]) * coil_dim[i] / 2
3161
+ if i == 2:
3162
+ line[i].Point2 = coil_center + V[i, :] / np.linalg.norm(V[i, :]) * coil_dim[0] / 2
3163
+ line[i].Resolution = 1000
3164
+ # set active source
3165
+ SetActiveSource(line[i])
3166
+ # show data in view
3167
+ lineDisplay[i] = Show(line[i], renderView)
3168
+ # trace defaults for the display properties.
3169
+ lineDisplay[i].ColorArrayName = [None, '']
3170
+ lineDisplay[i].OSPRayScaleArray = 'Texture Coordinates'
3171
+ lineDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
3172
+ lineDisplay[i].GlyphType = 'Sphere'
3173
+ lineDisplay[i].SetScaleArray = [None, '']
3174
+ lineDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
3175
+ lineDisplay[i].OpacityArray = [None, '']
3176
+ lineDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
3177
+ lineDisplay[i].ShaderPreset = 'Gaussian Blur (Default)'
3178
+ lineDisplay[i].DiffuseColor = line_color[i]
3179
+ lineDisplay[i].SetRepresentationType('3D Glyphs')
3180
+ lineDisplay[i].GlyphType.Radius = 1.0
3181
+
3182
+ # =============================================================================
3183
+ # plot parameters
3184
+ # =============================================================================
3185
+
3186
+ # set the background color
3187
+ renderView.Background = ps['background_color']
3188
+
3189
+ # set image size
3190
+ renderView.ViewSize = ps['viewsize'] # [width, height]
3191
+
3192
+ # save scene
3193
+ paraview.simple.SaveScreenshot(ps['fname_png'], magnification=ps['png_resolution'], quality=100, view=renderView)
3194
+
3195
+ # crop surrounding of image
3196
+ crop_image(ps['fname_png'], ps['fname_png'])
3197
+
3198
+ # Reset Paraview session
3199
+ ResetSession()
3200
+
3201
+
3202
+ def volume_plot_vtu(ps):
3203
+ """
3204
+ Generate plot with Paraview from data in .vtu file.
3205
+
3206
+ Parameters
3207
+ ----------
3208
+ ps : dict
3209
+ Plot settings dict initialized with create_plot_settings_dict(plotfunction_type=''volume_plot_vtu'')
3210
+
3211
+ Returns
3212
+ -------
3213
+ <File> : .png file
3214
+ Generated plot
3215
+ """
3216
+
3217
+ # add whitespace if colorbar label is not given (empty colorbar labels are plotted wrong)
3218
+ if ps['colorbar_label'] is None or ps['colorbar_label']=='':
3219
+ ps['colorbar_label'] = ' '
3220
+
3221
+ thresholding = not(ps['domain_IDs'] == [])
3222
+ if ps['interpolate']:
3223
+ target = 'POINTS'
3224
+ else:
3225
+ target = 'CELLS'
3226
+ # =============================================================================
3227
+ # Load and process surface data
3228
+ # =============================================================================
3229
+
3230
+ s = paraview.simple.XMLUnstructuredGridReader(FileName=[ps['fname_vtu_surface']])
3231
+ s.CellArrayStatus = ['quantity']
3232
+ s.PointArrayStatus = []
3233
+
3234
+ # get active view
3235
+ renderView = GetActiveViewOrCreate('RenderView')
3236
+ # uncomment following to set a specific view size
3237
+ # renderView.ViewSize = [1031, 1164]
3238
+
3239
+ # show data in view
3240
+ sDisplay = Show(s, renderView)
3241
+ # trace defaults for the display properties.
3242
+ sDisplay.Representation = 'Surface'
3243
+ sDisplay.AmbientColor = [1.0, 1.0, 1.0]
3244
+ sDisplay.ColorArrayName = [None, '']
3245
+ sDisplay.DiffuseColor = [1.0, 1.0, 1.0]
3246
+ sDisplay.LookupTable = None
3247
+ sDisplay.MapScalars = 1
3248
+ sDisplay.InterpolateScalarsBeforeMapping = 1
3249
+ sDisplay.Opacity = 1.0
3250
+ sDisplay.PointSize = 2.0
3251
+ sDisplay.LineWidth = 1.0
3252
+ sDisplay.Interpolation = 'Gouraud'
3253
+ sDisplay.Specular = 0.0
3254
+ sDisplay.SpecularColor = [1.0, 1.0, 1.0]
3255
+ sDisplay.SpecularPower = 100.0
3256
+ sDisplay.Ambient = 0.0
3257
+ sDisplay.Diffuse = 1.0
3258
+ sDisplay.EdgeColor = [0.0, 0.0, 0.5]
3259
+ sDisplay.BackfaceRepresentation = 'Follow Frontface'
3260
+ sDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
3261
+ sDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
3262
+ sDisplay.BackfaceOpacity = 1.0
3263
+ sDisplay.Position = [0.0, 0.0, 0.0]
3264
+ sDisplay.Scale = [1.0, 1.0, 1.0]
3265
+ sDisplay.Orientation = [0.0, 0.0, 0.0]
3266
+ sDisplay.Origin = [0.0, 0.0, 0.0]
3267
+ sDisplay.Pickable = 1
3268
+ sDisplay.Texture = None
3269
+ sDisplay.Triangulate = 0
3270
+ sDisplay.NonlinearSubdivisionLevel = 1
3271
+ sDisplay.OSPRayUseScaleArray = 0
3272
+ sDisplay.OSPRayScaleArray = ps['quantity']
3273
+ sDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
3274
+ sDisplay.GlyphType = 'Arrow'
3275
+ sDisplay.SelectionCellLabelBold = 0
3276
+ sDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
3277
+ sDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
3278
+ sDisplay.SelectionCellLabelFontSize = 18
3279
+ sDisplay.SelectionCellLabelItalic = 0
3280
+ sDisplay.SelectionCellLabelJustification = 'Left'
3281
+ sDisplay.SelectionCellLabelOpacity = 1.0
3282
+ sDisplay.SelectionCellLabelShadow = 0
3283
+ sDisplay.SelectionPointLabelBold = 0
3284
+ sDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
3285
+ sDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
3286
+ sDisplay.SelectionPointLabelFontSize = 18
3287
+ sDisplay.SelectionPointLabelItalic = 0
3288
+ sDisplay.SelectionPointLabelJustification = 'Left'
3289
+ sDisplay.SelectionPointLabelOpacity = 1.0
3290
+ sDisplay.SelectionPointLabelShadow = 0
3291
+ sDisplay.ScalarOpacityUnitDistance = 2.7853016213990154
3292
+ sDisplay.SelectMapper = 'Projected tetra'
3293
+ sDisplay.GaussianRadius = 0.0
3294
+ sDisplay.ShaderPreset = 'Sphere'
3295
+ sDisplay.Emissive = 0
3296
+ sDisplay.ScaleByArray = 0
3297
+ sDisplay.SetScaleArray = [None, '']
3298
+ sDisplay.ScaleTransferFunction = 'PiecewiseFunction'
3299
+ sDisplay.OpacityByArray = 0
3300
+ sDisplay.OpacityArray = [None, '']
3301
+ sDisplay.OpacityTransferFunction = 'PiecewiseFunction'
3302
+
3303
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
3304
+ sDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3305
+
3306
+ # init the 'Arrow' selected for 'GlyphType'
3307
+ sDisplay.GlyphType.TipResolution = 6
3308
+ sDisplay.GlyphType.TipRadius = 0.1
3309
+ sDisplay.GlyphType.TipLength = 0.35
3310
+ sDisplay.GlyphType.ShaftResolution = 6
3311
+ sDisplay.GlyphType.ShaftRadius = 0.03
3312
+ sDisplay.GlyphType.Invert = 0
3313
+
3314
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
3315
+ sDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3316
+
3317
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
3318
+ sDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3319
+
3320
+ # change solid color
3321
+ sDisplay.DiffuseColor = ps['surface_color']
3322
+
3323
+ # Hide outer surface
3324
+ Hide(s, renderView)
3325
+
3326
+ # =============================================================================
3327
+ # Load and process volume data
3328
+ # =============================================================================
3329
+
3330
+ # create a new 'XML Unstructured Grid Reader' for volume data
3331
+ p = paraview.simple.XMLUnstructuredGridReader(FileName=[ps['fname_vtu_volume']])
3332
+ p.PointArrayStatus = []
3333
+
3334
+ # get data ranges of included datasets
3335
+ # if datarange == []:
3336
+ # sm = servermanager.Fetch(p)
3337
+ # datarange = sm.GetCellData().GetArray(0).GetRange(0)
3338
+
3339
+ # select specific domains
3340
+ # =============================================================================
3341
+
3342
+ # determine IDs of cells in domains of interest
3343
+ # ...
3344
+
3345
+ # select cells/points of domains of interest
3346
+ # selection = paraview.simple.IDSelectionSource(ContainingCells=1, FieldType="CELL", IDs=[0, cellID0, 0, cellID1, 0, cellID2, ...])
3347
+ # selection.GetCellDataInformation()
3348
+
3349
+ # extract selection
3350
+ # extracted = paraview.simple.ExtractSelection(selection)
3351
+
3352
+ # =====================================================
3353
+ # Show only domains of interest (create 'Threshold')
3354
+ # =====================================================
3355
+ #t = [0]*len(domain_IDs)
3356
+ #tDisplay = [0]*len(domain_IDs)
3357
+
3358
+ if thresholding:
3359
+
3360
+ #for i in range(len(domain_IDs)):
3361
+
3362
+ # create new threshold
3363
+ #if interpolate:
3364
+ # t[i] = paraview.simple.Threshold(Input=p1)
3365
+ #else:
3366
+ t = paraview.simple.Threshold(Input=p)
3367
+
3368
+ t.Scalars = ['CELLS', ps['domain_label']]
3369
+ t.ThresholdRange = [np.min(ps['domain_IDs']).astype(float), np.max(ps['domain_IDs']).astype(float)]
3370
+ t.AllScalars = 1
3371
+ t.UseContinuousCellRange = 0
3372
+
3373
+ tDisplay = Show(t, renderView)
3374
+
3375
+ ColorBy(tDisplay, (target, ps['quantity']))
3376
+ tDisplay.Representation = 'Surface'
3377
+ tDisplay.AmbientColor = [1.0, 1.0, 1.0]
3378
+ tDisplay.ColorArrayName = [None, '']
3379
+ tDisplay.DiffuseColor = [1.0, 1.0, 1.0]
3380
+ tDisplay.LookupTable = None
3381
+ tDisplay.MapScalars = 1
3382
+ tDisplay.InterpolateScalarsBeforeMapping = 1
3383
+ tDisplay.Opacity = 1.0
3384
+ tDisplay.PointSize = 2.0
3385
+ tDisplay.LineWidth = 1.0
3386
+ tDisplay.Interpolation = 'Gouraud'
3387
+ tDisplay.Specular = 0.0
3388
+ tDisplay.SpecularColor = [1.0, 1.0, 1.0]
3389
+ tDisplay.SpecularPower = 100.0
3390
+ tDisplay.Ambient = 0.0
3391
+ tDisplay.Diffuse = 1.0
3392
+ tDisplay.EdgeColor = [0.0, 0.0, 0.5]
3393
+ tDisplay.BackfaceRepresentation = 'Follow Frontface'
3394
+ tDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
3395
+ tDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
3396
+ tDisplay.BackfaceOpacity = 1.0
3397
+ tDisplay.Position = [0.0, 0.0, 0.0]
3398
+ tDisplay.Scale = [1.0, 1.0, 1.0]
3399
+ tDisplay.Orientation = [0.0, 0.0, 0.0]
3400
+ tDisplay.Origin = [0.0, 0.0, 0.0]
3401
+ tDisplay.Pickable = 1
3402
+ tDisplay.Texture = None
3403
+ tDisplay.Triangulate = 0
3404
+ tDisplay.NonlinearSubdivisionLevel = 1
3405
+ tDisplay.OSPRayUseScaleArray = 0
3406
+ tDisplay.OSPRayScaleArray = ps['quantity']
3407
+ tDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
3408
+ tDisplay.GlyphType = 'Arrow'
3409
+ tDisplay.SelectionCellLabelBold = 0
3410
+ tDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
3411
+ tDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
3412
+ tDisplay.SelectionCellLabelFontSize = 18
3413
+ tDisplay.SelectionCellLabelItalic = 0
3414
+ tDisplay.SelectionCellLabelJustification = 'Left'
3415
+ tDisplay.SelectionCellLabelOpacity = 1.0
3416
+ tDisplay.SelectionCellLabelShadow = 0
3417
+ tDisplay.SelectionPointLabelBold = 0
3418
+ tDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
3419
+ tDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
3420
+ tDisplay.SelectionPointLabelFontSize = 18
3421
+ tDisplay.SelectionPointLabelItalic = 0
3422
+ tDisplay.SelectionPointLabelJustification = 'Left'
3423
+ tDisplay.SelectionPointLabelOpacity = 1.0
3424
+ tDisplay.SelectionPointLabelShadow = 0
3425
+ tDisplay.ScalarOpacityUnitDistance = 1.8692603892074375
3426
+ tDisplay.SelectMapper = 'Projected tetra'
3427
+ tDisplay.GaussianRadius = 0.0
3428
+ tDisplay.ShaderPreset = 'Sphere'
3429
+ tDisplay.Emissive = 0
3430
+ tDisplay.ScaleByArray = 0
3431
+ tDisplay.SetScaleArray = [None, '']
3432
+ tDisplay.ScaleTransferFunction = 'PiecewiseFunction'
3433
+ tDisplay.OpacityByArray = 0
3434
+ tDisplay.OpacityArray = [None, '']
3435
+ tDisplay.OpacityTransferFunction = 'PiecewiseFunction'
3436
+
3437
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
3438
+ tDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3439
+
3440
+ # init the 'Arrow' selected for 'GlyphType'
3441
+ tDisplay.GlyphType.TipResolution = 6
3442
+ tDisplay.GlyphType.TipRadius = 0.1
3443
+ tDisplay.GlyphType.TipLength = 0.35
3444
+ tDisplay.GlyphType.ShaftResolution = 6
3445
+ tDisplay.GlyphType.ShaftRadius = 0.03
3446
+ tDisplay.GlyphType.Invert = 0
3447
+
3448
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
3449
+ tDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3450
+
3451
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
3452
+ tDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3453
+
3454
+ # create a new 'Cell Data to Point Data'
3455
+ # interpolate and no thresholding
3456
+ if ps['interpolate']:
3457
+ if thresholding:
3458
+ p1 = paraview.simple.CellDatatoPointData(Input=t)
3459
+ else:
3460
+ p1 = paraview.simple.CellDatatoPointData(Input=p)
3461
+ p1.PassCellData = 0
3462
+ p1.PieceInvariant = 0
3463
+ pDisplay = Show(p1, renderView)
3464
+ else:
3465
+ if thresholding:
3466
+ pDisplay = Show(t, renderView)
3467
+ else:
3468
+ pDisplay = Show(p, renderView)
3469
+
3470
+ # trace defaults for the display properties.
3471
+ pDisplay.Representation = 'Surface'
3472
+ pDisplay.AmbientColor = [1.0, 1.0, 1.0]
3473
+ pDisplay.ColorArrayName = [None, '']
3474
+ pDisplay.DiffuseColor = [1.0, 1.0, 1.0]
3475
+ pDisplay.LookupTable = None
3476
+ pDisplay.MapScalars = 1
3477
+ pDisplay.InterpolateScalarsBeforeMapping = 1
3478
+ pDisplay.Opacity = 1.0
3479
+ pDisplay.PointSize = 2.0
3480
+ pDisplay.LineWidth = 1.0
3481
+ pDisplay.Interpolation = 'Gouraud'
3482
+ pDisplay.Specular = 0.0
3483
+ pDisplay.SpecularColor = [1.0, 1.0, 1.0]
3484
+ pDisplay.SpecularPower = 100.0
3485
+ pDisplay.Ambient = 0.0
3486
+ pDisplay.Diffuse = 1.0
3487
+ pDisplay.EdgeColor = [0.0, 0.0, 0.5]
3488
+ pDisplay.BackfaceRepresentation = 'Follow Frontface'
3489
+ pDisplay.BackfaceAmbientColor = [1.0, 1.0, 1.0]
3490
+ pDisplay.BackfaceDiffuseColor = [1.0, 1.0, 1.0]
3491
+ pDisplay.BackfaceOpacity = 1.0
3492
+ pDisplay.Position = [0.0, 0.0, 0.0]
3493
+ pDisplay.Scale = [1.0, 1.0, 1.0]
3494
+ pDisplay.Orientation = [0.0, 0.0, 0.0]
3495
+ pDisplay.Origin = [0.0, 0.0, 0.0]
3496
+ pDisplay.Pickable = 1
3497
+ pDisplay.Texture = None
3498
+ pDisplay.Triangulate = 0
3499
+ pDisplay.NonlinearSubdivisionLevel = 1
3500
+ pDisplay.OSPRayUseScaleArray = 0
3501
+ pDisplay.OSPRayScaleArray = ''#quantity
3502
+ pDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
3503
+ pDisplay.GlyphType = 'Arrow'
3504
+ pDisplay.SelectionCellLabelBold = 0
3505
+ pDisplay.SelectionCellLabelColor = [0.0, 1.0, 0.0]
3506
+ pDisplay.SelectionCellLabelFontFamily = ps['colorbar_font']
3507
+ pDisplay.SelectionCellLabelFontSize = 18
3508
+ pDisplay.SelectionCellLabelItalic = 0
3509
+ pDisplay.SelectionCellLabelJustification = 'Left'
3510
+ pDisplay.SelectionCellLabelOpacity = 1.0
3511
+ pDisplay.SelectionCellLabelShadow = 0
3512
+ pDisplay.SelectionPointLabelBold = 0
3513
+ pDisplay.SelectionPointLabelColor = [1.0, 1.0, 0.0]
3514
+ pDisplay.SelectionPointLabelFontFamily = ps['colorbar_font']
3515
+ pDisplay.SelectionPointLabelFontSize = 18
3516
+ pDisplay.SelectionPointLabelItalic = 0
3517
+ pDisplay.SelectionPointLabelJustification = 'Left'
3518
+ pDisplay.SelectionPointLabelOpacity = 1.0
3519
+ pDisplay.SelectionPointLabelShadow = 0
3520
+ pDisplay.ScalarOpacityUnitDistance = 1.6558923367892595
3521
+ pDisplay.SelectMapper = 'Projected tetra'
3522
+ pDisplay.GaussianRadius = 0.0
3523
+ pDisplay.ShaderPreset = 'Sphere'
3524
+ pDisplay.Emissive = 0
3525
+ pDisplay.ScaleByArray = 0
3526
+ pDisplay.SetScaleArray = [target, '']#quantity
3527
+ pDisplay.ScaleTransferFunction = 'PiecewiseFunction'
3528
+ pDisplay.OpacityByArray = 0
3529
+ pDisplay.OpacityArray = [target, '']#quantity
3530
+ pDisplay.OpacityTransferFunction = 'PiecewiseFunction'
3531
+
3532
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
3533
+ pDisplay.OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3534
+
3535
+ # init the 'Arrow' selected for 'GlyphType'
3536
+ pDisplay.GlyphType.TipResolution = 6
3537
+ pDisplay.GlyphType.TipRadius = 0.1
3538
+ pDisplay.GlyphType.TipLength = 0.35
3539
+ pDisplay.GlyphType.ShaftResolution = 6
3540
+ pDisplay.GlyphType.ShaftRadius = 0.03
3541
+ pDisplay.GlyphType.Invert = 0
3542
+
3543
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
3544
+ pDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3545
+
3546
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
3547
+ pDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3548
+
3549
+ # change representation type
3550
+ if ps['edges']:
3551
+ pDisplay.SetRepresentationType('Surface With Edges')
3552
+
3553
+ # =============================================================================
3554
+ # Make Clip or Slice
3555
+ # =============================================================================
3556
+ # create a new 'Clip'
3557
+ if ps['clip_coords'].any():
3558
+
3559
+ N_clips = ps['clip_coords'].shape[0]
3560
+ clip_coords_surface = copy.deepcopy(ps['clip_coords'])
3561
+ pcut = [0] * N_clips
3562
+ scut = [0] * N_clips
3563
+ pcutDisplay = [0] * N_clips
3564
+ scutDisplay = [0] * N_clips
3565
+
3566
+ for i in range(N_clips):
3567
+ # shift clip coords of surface a bit to get visability
3568
+ for i_shift in range(3):
3569
+ if ps['clip_normals'][i, i_shift] > 0:
3570
+ if ps['clip_type'][i] == 'clip':
3571
+ clip_coords_surface[i, i_shift] = copy.deepcopy(ps['clip_coords'][i, i_shift]) - 0.1
3572
+ if ps['clip_type'][i] == 'slice':
3573
+ clip_coords_surface[i, i_shift] = copy.deepcopy(ps['clip_coords'][i, i_shift]) + 0.1
3574
+
3575
+ # clip
3576
+ if clip_type[i] == 'clip':
3577
+
3578
+ # Generate clip
3579
+ if ps['interpolate']:
3580
+ if thresholding:
3581
+ pcut[i] = paraview.simple.Clip(Input=p1)
3582
+ else:
3583
+ if thresholding:
3584
+ pcut[i] = paraview.simple.Clip(Input=t)
3585
+ else:
3586
+ pcut[i] = paraview.simple.Clip(Input=p)
3587
+
3588
+ # init the 'Plane' selected for 'ClipType' (volume)
3589
+ pcut[i].ClipType = 'Plane'
3590
+ pcut[i].Scalars = [target, ps['quantity']]
3591
+ pcut[i].Value = 0.0
3592
+ pcut[i].InsideOut = 0
3593
+ pcut[i].Crinkleclip = 0
3594
+ pcut[i].ClipType.Origin = [ps['clip_coords'][i, 0], ps['clip_coords'][i, 1], ps['clip_coords'][i, 2]]
3595
+ pcut[i].ClipType.Normal = [ps['clip_normals'][i, 0], ps['clip_normals'][i, 1], ps['clip_normals'][i, 2]]
3596
+ pcut[i].ClipType.Offset = 0.0
3597
+
3598
+ # slice
3599
+ elif ps['clip_type'][i] == 'slice':
3600
+
3601
+ # Generate slice
3602
+ if ps['interpolate']:
3603
+ if thresholding:
3604
+ pcut[i] = paraview.simple.Slice(Input=p1)
3605
+ else:
3606
+ if thresholding:
3607
+ pcut[i] = paraview.simple.Slice(Input=t)
3608
+ else:
3609
+ pcut[i] = paraview.simple.Slice(Input=p)
3610
+
3611
+
3612
+
3613
+ # init the 'Plane' selected for 'ClipType' (volume)
3614
+ pcut[i].SliceType = 'Plane'
3615
+ pcut[i].Crinkleslice = 0
3616
+ pcut[i].Triangulatetheslice = 1
3617
+ pcut[i].SliceOffsetValues = [0.0]
3618
+ pcut[i].SliceType.Origin = [ps['clip_coords'][i, 0], ps['clip_coords'][i, 1], ps['clip_coords'][i, 2]]
3619
+ pcut[i].SliceType.Normal = [ps['clip_normals'][i, 0], ps['clip_normals'][i, 1], ps['clip_normals'][i, 2]]
3620
+ pcut[i].SliceType.Offset = 0.0
3621
+
3622
+ # Generate slice (surface)
3623
+ scut[i] = paraview.simple.Slice(Input=s)
3624
+
3625
+ # init the 'Plane' selected for 'ClipType' (surface)
3626
+ scut[i].SliceType = 'Plane'
3627
+ scut[i].Crinkleslice = 0
3628
+ scut[i].Triangulatetheslice = 1
3629
+ scut[i].SliceOffsetValues = [0.0]
3630
+ scut[i].SliceType.Origin = [clip_coords_surface[i, 0], clip_coords_surface[i, 1], clip_coords_surface[i, 2]]
3631
+ scut[i].SliceType.Normal = [ps['clip_normals'][i, 0], ps['clip_normals'][i, 1], ps['clip_normals'][i, 2]]
3632
+ scut[i].SliceType.Offset = 0.0
3633
+
3634
+ # show data in view
3635
+ pcutDisplay[i] = Show(pcut[i], renderView)
3636
+ scutDisplay[i] = Show(scut[i], renderView)
3637
+
3638
+ # map results to geometry
3639
+ #pcutDisplay[i].ColorArrayName = [target, quantity]
3640
+ paraview.simple.ColorBy(pcutDisplay[i], (target, ps['quantity']))
3641
+
3642
+ # trace defaults for the display properties.
3643
+ pcutDisplay[i].Representation = 'Surface'
3644
+ pcutDisplay[i].AmbientColor = [1.0, 1.0, 1.0]
3645
+ pcutDisplay[i].ColorArrayName = [None, '']
3646
+ pcutDisplay[i].DiffuseColor = [1.0, 1.0, 1.0]
3647
+ pcutDisplay[i].LookupTable = None
3648
+ pcutDisplay[i].MapScalars = 1
3649
+ pcutDisplay[i].InterpolateScalarsBeforeMapping = 1
3650
+ pcutDisplay[i].Opacity = 1.0
3651
+ pcutDisplay[i].PointSize = 2.0
3652
+ pcutDisplay[i].LineWidth = 1.0
3653
+ pcutDisplay[i].Interpolation = 'Gouraud'
3654
+ pcutDisplay[i].Specular = 0.0
3655
+ pcutDisplay[i].SpecularColor = [1.0, 1.0, 1.0]
3656
+ pcutDisplay[i].SpecularPower = 100.0
3657
+ pcutDisplay[i].Ambient = 0.0
3658
+ pcutDisplay[i].Diffuse = 1.0
3659
+ pcutDisplay[i].EdgeColor = [0.0, 0.0, 0.5]
3660
+ pcutDisplay[i].BackfaceRepresentation = 'Follow Frontface'
3661
+ pcutDisplay[i].BackfaceAmbientColor = [1.0, 1.0, 1.0]
3662
+ pcutDisplay[i].BackfaceDiffuseColor = [1.0, 1.0, 1.0]
3663
+ pcutDisplay[i].BackfaceOpacity = 1.0
3664
+ pcutDisplay[i].Position = [0.0, 0.0, 0.0]
3665
+ pcutDisplay[i].Scale = [1.0, 1.0, 1.0]
3666
+ pcutDisplay[i].Orientation = [0.0, 0.0, 0.0]
3667
+ pcutDisplay[i].Origin = [0.0, 0.0, 0.0]
3668
+ pcutDisplay[i].Pickable = 1
3669
+ pcutDisplay[i].Texture = None
3670
+ pcutDisplay[i].Triangulate = 0
3671
+ pcutDisplay[i].NonlinearSubdivisionLevel = 1
3672
+ pcutDisplay[i].OSPRayUseScaleArray = 0
3673
+ pcutDisplay[i].OSPRayScaleArray = ps['quantity']
3674
+ pcutDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
3675
+ pcutDisplay[i].GlyphType = 'Arrow'
3676
+ pcutDisplay[i].SelectionCellLabelBold = 0
3677
+ pcutDisplay[i].SelectionCellLabelColor = [0.0, 1.0, 0.0]
3678
+ pcutDisplay[i].SelectionCellLabelFontFamily = ps['colorbar_font']
3679
+ pcutDisplay[i].SelectionCellLabelFontSize = 18
3680
+ pcutDisplay[i].SelectionCellLabelItalic = 0
3681
+ pcutDisplay[i].SelectionCellLabelJustification = 'Left'
3682
+ pcutDisplay[i].SelectionCellLabelOpacity = 1.0
3683
+ pcutDisplay[i].SelectionCellLabelShadow = 0
3684
+ pcutDisplay[i].SelectionPointLabelBold = 0
3685
+ pcutDisplay[i].SelectionPointLabelColor = [1.0, 1.0, 0.0]
3686
+ pcutDisplay[i].SelectionPointLabelFontFamily = ps['colorbar_font']
3687
+ pcutDisplay[i].SelectionPointLabelFontSize = 18
3688
+ pcutDisplay[i].SelectionPointLabelItalic = 0
3689
+ pcutDisplay[i].SelectionPointLabelJustification = 'Left'
3690
+ pcutDisplay[i].SelectionPointLabelOpacity = 1.0
3691
+ pcutDisplay[i].SelectionPointLabelShadow = 0
3692
+ if ps['clip_type'][i] == 'clip':
3693
+ pcutDisplay[i].ScalarOpacityUnitDistance = 1.702063581347167
3694
+ pcutDisplay[i].SelectMapper = 'Projected tetra'
3695
+ pcutDisplay[i].GaussianRadius = 0.0
3696
+ pcutDisplay[i].ShaderPreset = 'Sphere'
3697
+ pcutDisplay[i].Emissive = 0
3698
+ pcutDisplay[i].ScaleByArray = 0
3699
+ if ps['interpolate']:
3700
+ pcutDisplay[i].SetScaleArray = [target, ps['quantity']]
3701
+ pcutDisplay[i].OpacityArray = [target, ps['quantity']]
3702
+ else:
3703
+ pcutDisplay[i].SetScaleArray = [None, '']
3704
+ pcutDisplay[i].OpacityArray = [None, '']
3705
+ pcutDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
3706
+ pcutDisplay[i].OpacityByArray = 0
3707
+ pcutDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
3708
+
3709
+ # init the 'PiecewiseFunction' selected for 'OSPRayScaleFunction'
3710
+ pcutDisplay[i].OSPRayScaleFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3711
+
3712
+ # init the 'Arrow' selected for 'GlyphType'
3713
+ pcutDisplay[i].GlyphType.TipResolution = 6
3714
+ pcutDisplay[i].GlyphType.TipRadius = 0.1
3715
+ pcutDisplay[i].GlyphType.TipLength = 0.35
3716
+ pcutDisplay[i].GlyphType.ShaftResolution = 6
3717
+ pcutDisplay[i].GlyphType.ShaftRadius = 0.03
3718
+ pcutDisplay[i].GlyphType.Invert = 0
3719
+
3720
+ # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
3721
+ pcutDisplay[i].ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3722
+
3723
+ # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
3724
+ pcutDisplay[i].OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0]
3725
+
3726
+ # change representation type
3727
+ if ps['edges']:
3728
+ pcutDisplay[i].SetRepresentationType('Surface With Edges')
3729
+
3730
+ # Apply all settings from volume slices to surface slices
3731
+ scutDisplay[i] = pcutDisplay[i]
3732
+
3733
+ # set scalar coloring
3734
+ paraview.simple.ColorBy(pcutDisplay[i], (target, ps['quantity']))
3735
+
3736
+ # rescale color and/or opacity maps used to include current data range
3737
+ pcutDisplay[i].RescaleTransferFunctionToDataRange(True)
3738
+
3739
+ # show color bar/color legend
3740
+ pcutDisplay[i].SetScalarBarVisibility(renderView, True)
3741
+
3742
+ # =============================================================================
3743
+ # Disable selected elements for final view
3744
+ # =============================================================================
3745
+ if ps['interpolate']:
3746
+ if thresholding:
3747
+ Hide(t, renderView)
3748
+ Hide(p1, renderView)
3749
+ else:
3750
+ Hide(p, renderView)
3751
+ else:
3752
+ if thresholding:
3753
+ Hide(p, renderView)
3754
+
3755
+ # turn off orientation axes
3756
+ if not (ps['axes']):
3757
+ renderView.OrientationAxesVisibility = 0
3758
+
3759
+ # =============================================================================
3760
+ # Setup colormap and colorbar
3761
+ # =============================================================================
3762
+ # get color transfer function/color map for 'quantity'
3763
+ eLUT = GetColorTransferFunction(ps['quantity'])
3764
+ # eLUT.LockDataRange = 0 # not in v5.8 anymore
3765
+ eLUT.InterpretValuesAsCategories = 0
3766
+ eLUT.ShowCategoricalColorsinDataRangeOnly = 0
3767
+ eLUT.RescaleOnVisibilityChange = 0
3768
+ eLUT.EnableOpacityMapping = 0
3769
+ eLUT.UseLogScale = 0
3770
+ if ps['interpolate']:
3771
+ eLUT.ColorSpace = 'RGB'
3772
+ else:
3773
+ eLUT.ColorSpace = 'RGB' #'Diverging'
3774
+ eLUT.ColorSpace = 'Diverging'
3775
+ eLUT.UseBelowRangeColor = 0
3776
+ eLUT.BelowRangeColor = [0.0, 0.0, 0.0]
3777
+ eLUT.UseAboveRangeColor = 0
3778
+ eLUT.AboveRangeColor = [1.0, 1.0, 1.0]
3779
+ eLUT.NanColor = ps['NanColor']
3780
+ eLUT.Discretize = 1
3781
+ eLUT.NumberOfTableValues = 256
3782
+ eLUT.ScalarRangeInitialized = 1.0
3783
+ eLUT.HSVWrap = 0
3784
+ eLUT.VectorComponent = 0
3785
+ eLUT.VectorMode = 'Magnitude'
3786
+ eLUT.AllowDuplicateScalars = 1
3787
+ eLUT.Annotations = []
3788
+ eLUT.ActiveAnnotatedValues = []
3789
+ eLUT.IndexedColors = []
3790
+
3791
+ # set opacity transfer function/opacity map for 'quantity'
3792
+ ePWF = GetOpacityTransferFunction(ps['quantity'])
3793
+ if not(ps['opacitymap']==[]):
3794
+ eLUT.EnableOpacityMapping = 1
3795
+ ePWF.Points = ps['opacitymap']
3796
+ ePWF.AllowDuplicateScalars = 1
3797
+ ePWF.ScalarRangeInitialized = 1
3798
+
3799
+ colormap_presets = {'Cool to Warm',
3800
+ 'Cool to Warm (Extended)',
3801
+ 'Blue to Red Rainbow',
3802
+ 'X Ray',
3803
+ 'Grayscale',
3804
+ 'jet',
3805
+ 'hsv',
3806
+ 'erdc_iceFire_L',
3807
+ 'Plasma (matplotlib)',
3808
+ 'Viridis (matplotlib)',
3809
+ 'gray_Matlab',
3810
+ 'Spectral_lowBlue',
3811
+ 'Rainbow Blended White'
3812
+ 'BuRd'}
3813
+
3814
+ if type(ps['colormap']) is str:
3815
+ # set colorbar to 'jet' if not specified in presets
3816
+ if not (ps['colormap'] in colormap_presets):
3817
+ print((
3818
+ 'Changing colormap to \'jet\' since user specified colormap \'{}\' is not part of the included presets ...').format(
3819
+ ps['colormap']))
3820
+ colormap = 'jet'
3821
+
3822
+ if ps['colormap'] == 'b2rcw':
3823
+ rgb_values = b2rcw(ps['datarange'][0], ps['datarange'][1])
3824
+ rgb_data = np.linspace(ps['datarange'][0], ps['datarange'][1], rgb_values.shape[0])
3825
+ eLUT.RGBPoints = np.hstack((rgb_data,rgb_values))
3826
+ else:
3827
+ # Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
3828
+ eLUT.ApplyPreset(ps['colormap'], True)
3829
+ else:
3830
+ eLUT.RGBPoints = ps['colormap']
3831
+
3832
+ # =============================================================================
3833
+ # colorbar
3834
+ # =============================================================================
3835
+ # get color legend/bar for eLUT in view renderView
3836
+ eLUTColorBar = GetScalarBar(eLUT, renderView)
3837
+ if ps['colorbar_position']:
3838
+ eLUTColorBar.Position = ps['colorbar_position']
3839
+ else:
3840
+ eLUTColorBar.Position = [0.85, 0.05]
3841
+ # eLUTColorBar.Position2 = [0.12, 0.43] #'Position2' is obsolete as of ParaView 5.4. Use the 'ScalarBarLength' property to set the length instead.
3842
+ eLUTColorBar.AutoOrient = 1
3843
+ eLUTColorBar.Orientation = ps['colorbar_orientation']
3844
+ eLUTColorBar.Title = ps['quantity']
3845
+ eLUTColorBar.ComponentTitle = 'Magnitude'
3846
+ eLUTColorBar.TitleJustification = 'Centered'
3847
+ eLUTColorBar.TitleColor = ps['colorbar_labelcolor']
3848
+ eLUTColorBar.TitleOpacity = 1.0
3849
+ eLUTColorBar.TitleFontFamily = ps['colorbar_font']
3850
+ eLUTColorBar.TitleBold = 0
3851
+ eLUTColorBar.TitleItalic = 0
3852
+ eLUTColorBar.TitleShadow = 0
3853
+ eLUTColorBar.LabelColor = ps['colorbar_labelcolor']
3854
+ eLUTColorBar.LabelOpacity = 1.0
3855
+ eLUTColorBar.LabelFontFamily = ps['colorbar_font']
3856
+ eLUTColorBar.LabelBold = 0
3857
+ eLUTColorBar.LabelItalic = 0
3858
+ eLUTColorBar.LabelShadow = 0
3859
+ eLUTColorBar.AutomaticLabelFormat = 0
3860
+ eLUTColorBar.LabelFormat = ps['colorbar_labelformat']
3861
+ # eLUTColorBar.NumberOfLabels = ps['colorbar_numberoflabels'] # not in v5.8 anymore
3862
+ eLUTColorBar.DrawTickMarks = 1
3863
+ # eLUTColorBar.DrawSubTickMarks = 1 # not in v5.8 anymore
3864
+ eLUTColorBar.DrawTickLabels = 1
3865
+ eLUTColorBar.AddRangeLabels = 1
3866
+ eLUTColorBar.RangeLabelFormat = ps['colorbar_labelformat']
3867
+ eLUTColorBar.DrawAnnotations = 1
3868
+ eLUTColorBar.AddRangeAnnotations = 0
3869
+ eLUTColorBar.AutomaticAnnotations = 0
3870
+ eLUTColorBar.DrawNanAnnotation = 0
3871
+ eLUTColorBar.NanAnnotation = 'NaN'
3872
+ eLUTColorBar.TextPosition = 'Ticks right/top, annotations left/bottom'
3873
+ # eLUTColorBar.AspectRatio = ps['colorbar_aspectratio'] # paraview.NotSupportedException: 'AspectRatio' is obsolete as of ParaView 5.4. Use the 'ScalarBarThickness' property to set the width instead.
3874
+ eLUTColorBar.Title = ps['colorbar_label']
3875
+ eLUTColorBar.ComponentTitle = ''
3876
+ eLUTColorBar.TitleFontSize = ps['colorbar_titlefontsize']
3877
+ eLUTColorBar.LabelFontSize = ps['colorbar_labelfontsize']
3878
+
3879
+
3880
+ # Rescale transfer function
3881
+ if ps['datarange']:
3882
+ eLUT.RescaleTransferFunction(ps['datarange'][0], ps['datarange'][1])
3883
+ ePWF.RescaleTransferFunction(ps['datarange'][0], ps['datarange'][1])
3884
+
3885
+ # camera placement for renderView
3886
+ if len(ps['view']) == 4:
3887
+ renderView.CameraPosition = ps['view'][0]
3888
+ renderView.CameraFocalPoint = ps['view'][1]
3889
+ renderView.CameraViewUp = ps['view'][2]
3890
+ renderView.CameraParallelScale = ps['view'][3][0]
3891
+ else:
3892
+ renderView.ResetCamera()
3893
+
3894
+ # =============================================================================
3895
+ # coil
3896
+ # =============================================================================
3897
+ if ps['fname_vtu_coil'] and ps['show_coil']:
3898
+ # load coil .vtu file and create a new 'XML Unstructured Grid Reader'
3899
+ coil = paraview.simple.XMLUnstructuredGridReader(FileName=[ps['fname_vtu_coil']])
3900
+ coil.PointArrayStatus = ['magnitude']
3901
+
3902
+ # show data in view
3903
+ coilDisplay = paraview.simple.Show(coil, renderView)
3904
+
3905
+ # trace defaults for the display properties.
3906
+ coilDisplay.ColorArrayName = [None, '']
3907
+ coilDisplay.OSPRayScaleArray = 'magnitude'
3908
+ coilDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
3909
+ coilDisplay.ScalarOpacityUnitDistance = 170.51694871976824
3910
+ coilDisplay.SetScaleArray = ['POINTS', 'magnitude']
3911
+ coilDisplay.ScaleTransferFunction = 'PiecewiseFunction'
3912
+ coilDisplay.OpacityArray = ['POINTS', 'magnitude']
3913
+ coilDisplay.OpacityTransferFunction = 'PiecewiseFunction'
3914
+
3915
+ # create a new 'Glyph'
3916
+ coilGlyph = paraview.simple.Glyph(Input=coil, GlyphType='Arrow')
3917
+ coilGlyph.Scalars = ['POINTS', 'None']
3918
+ coilGlyph.Vectors = ['POINTS', 'None']
3919
+ coilGlyph.ScaleFactor = 14.657378544
3920
+ coilGlyph.GlyphTransform = 'Transform2'
3921
+ coilGlyph.GlyphMode = 'All Points'
3922
+
3923
+ # set active source
3924
+ paraview.simple.SetActiveSource(coilGlyph)
3925
+
3926
+ # set dipole scaling and size
3927
+ if ps['coil_dipole_scaling'][0] == 'scaled':
3928
+ coilGlyph.Scalars = ['POINTS', 'magnitude']
3929
+ coilGlyph.ScaleMode = 'scalar'
3930
+ else:
3931
+ coilGlyph.ScaleMode = 'off'
3932
+
3933
+ coilGlyph.ScaleFactor = ps['coil_dipole_scaling'][1]
3934
+
3935
+ # show data in view
3936
+ coilGlyphDisplay = paraview.simple.Show(coilGlyph, renderView)
3937
+
3938
+ # trace defaults for the display properties.
3939
+ coilGlyphDisplay.ColorArrayName = [None, '']
3940
+ coilGlyphDisplay.OSPRayScaleArray = 'magnitude'
3941
+ coilGlyphDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
3942
+ coilGlyphDisplay.GlyphType = 'Sphere'
3943
+ coilGlyphDisplay.SetScaleArray = ['POINTS', 'magnitude']
3944
+ coilGlyphDisplay.ScaleTransferFunction = 'PiecewiseFunction'
3945
+ coilGlyphDisplay.OpacityArray = ['POINTS', 'magnitude']
3946
+ coilGlyphDisplay.OpacityTransferFunction = 'PiecewiseFunction'
3947
+
3948
+ # set dipole color
3949
+ if isinstance(ps['coil_dipole_color'], (str,)):
3950
+ # set scalar coloring
3951
+ paraview.simple.ColorBy(coilGlyphDisplay, ('POINTS', 'magnitude'))
3952
+
3953
+ # rescale color and/or opacity maps used to include current data range
3954
+ coilGlyphDisplay.RescaleTransferFunctionToDataRange(True)
3955
+
3956
+ # show color bar/color legend
3957
+ coilGlyphDisplay.SetScalarBarVisibility(renderView, True)
3958
+
3959
+ # get color transfer function/color map for 'magnitude'
3960
+ magnitudeLUT = paraview.simple.GetColorTransferFunction('magnitude')
3961
+ magnitudeLUT.ColorSpace = 'HSV'
3962
+ magnitudeLUT.ScalarRangeInitialized = 1.0
3963
+ # magnitudeLUT.RGBPoints = [1.16477014, 0.0, 0.0, 1.0, 8.77717169, 1.0, 0.0, 0.0]
3964
+ magnitudeLUT.NanColor = ps['NanColor']
3965
+
3966
+ # get opacity transfer function/opacity map for 'magnitude'
3967
+ magnitudePWF = paraview.simple.GetOpacityTransferFunction('magnitude')
3968
+ magnitudePWF.ScalarRangeInitialized = 1
3969
+ # magnitudePWF.Points = [1.16477014, 0.0, 0.5, 0.0, 8.77717169, 1.0, 0.5, 0.0]
3970
+
3971
+ # Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
3972
+ magnitudeLUT.ApplyPreset(ps['coil_dipole_color'], True)
3973
+ else:
3974
+ coilGlyphDisplay.DiffuseColor = ps['coil_dipole_color']
3975
+
3976
+ # hide data in view
3977
+ paraview.simple.Hide(coil, renderView)
3978
+
3979
+ # show data in view
3980
+ coilGlyphDisplay = paraview.simple.Show(coilGlyph, renderView)
3981
+
3982
+ # hide color bar/color legend
3983
+ coilGlyphDisplay.SetScalarBarVisibility(renderView, False)
3984
+
3985
+ # =============================================================
3986
+ # set coil axes direction
3987
+ # =============================================================
3988
+ if ps['coil_axes']:
3989
+ # Get number of dipoles
3990
+ N_dip = coil.GetClientSideObject().GetOutput().GetNumberOfElements(0)
3991
+
3992
+ # Extract points coordinates
3993
+ points = [coil.GetClientSideObject().GetOutput().GetPoint(i) for i in range(N_dip)]
3994
+ points_array = np.asarray(points)
3995
+
3996
+ # determine coil center
3997
+ coil_center = np.average(points_array, axis=0)
3998
+
3999
+ # shift coil to center for SVD
4000
+ points_array = points_array - coil_center
4001
+
4002
+ line = [0] * 3
4003
+ lineDisplay = [0] * 3
4004
+ line_color = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
4005
+ U, s, V = np.linalg.svd(points_array, full_matrices=True)
4006
+ points_transform = np.dot(points_array, V.transpose())
4007
+ coil_dim = np.max(points_transform, axis=0) - np.min(points_transform, axis=0)
4008
+
4009
+ for i in range(3):
4010
+ # create a new 'Line'
4011
+ line[i] = paraview.simple.Line()
4012
+ # Properties modified on line1
4013
+ line[i].Point1 = coil_center
4014
+ if ((i == 0) or (i == 1)):
4015
+ line[i].Point2 = coil_center + V[i, :] / np.linalg.norm(V[i, :]) * coil_dim[i] / 2
4016
+ if i == 2:
4017
+ line[i].Point2 = coil_center + V[i, :] / np.linalg.norm(V[i, :]) * coil_dim[0] / 2
4018
+ line[i].Resolution = 1000
4019
+ # set active source
4020
+ SetActiveSource(line[i])
4021
+ # show data in view
4022
+ lineDisplay[i] = Show(line[i], renderView)
4023
+ # trace defaults for the display properties.
4024
+ lineDisplay[i].ColorArrayName = [None, '']
4025
+ lineDisplay[i].OSPRayScaleArray = 'Texture Coordinates'
4026
+ lineDisplay[i].OSPRayScaleFunction = 'PiecewiseFunction'
4027
+ lineDisplay[i].GlyphType = 'Sphere'
4028
+ lineDisplay[i].SetScaleArray = [None, '']
4029
+ lineDisplay[i].ScaleTransferFunction = 'PiecewiseFunction'
4030
+ lineDisplay[i].OpacityArray = [None, '']
4031
+ lineDisplay[i].OpacityTransferFunction = 'PiecewiseFunction'
4032
+ lineDisplay[i].ShaderPreset = 'Gaussian Blur (Default)'
4033
+ lineDisplay[i].DiffuseColor = line_color[i]
4034
+ lineDisplay[i].SetRepresentationType('3D Glyphs')
4035
+ lineDisplay[i].GlyphType.Radius = 1.0
4036
+
4037
+ # =============================================================================
4038
+ # plot parameters
4039
+ # =============================================================================
4040
+
4041
+ # set the background color
4042
+ renderView.Background = ps['background_color']
4043
+
4044
+ # set image size
4045
+ renderView.ViewSize = ps['viewsize'] # [width, height]
4046
+
4047
+ # save scene
4048
+ paraview.simple.SaveScreenshot(ps['fname_png'], magnification=ps['png_resolution'], quality=100, view=renderView)
4049
+
4050
+ # crop surrounding of image
4051
+ crop_image(ps['fname_png'], ps['fname_png'])
4052
+
4053
+ # Reset Paraview session
4054
+ ResetSession()
4055
+
4056
+
4057
+ def write_vtu_mult(fname, data_labels, points, triangles, tetrahedras, idx_start, *data):
4058
+ """
4059
+ Writes data in triangles and tetrahedra centers into .vtu file, which can be loaded with Paraview.
4060
+
4061
+ Parameters
4062
+ ----------
4063
+ fname : str
4064
+ Name of .vtu file (incl. path)
4065
+ data_labels : list of str [N_data]
4066
+ Label of each dataset
4067
+ points : nparray of float [N_points x 3]
4068
+ Coordinates of vertices
4069
+ triangles : nparray of int [N_tri x 3]
4070
+ Connectivity of points forming triangles
4071
+ tetrahedras : nparray of int [N_tri x 4]
4072
+ Connectivity of points forming tetrahedra
4073
+ idx_start: int
4074
+ smallest index in connectivity matrix, defines offset w.r.t python
4075
+ indexing, which starts at '0'
4076
+ *data : nparray(s) [N_tet x N_comp(N_data)]
4077
+ Arrays containing data in tetrahedra center
4078
+ multiple components per dataset possible e.g. [Ex, Ey, Ez]
4079
+
4080
+ Returns
4081
+ -------
4082
+ <File> : .vtu file
4083
+ Geometry and data information
4084
+ """
4085
+
4086
+ # this saves triangles and tetrahedras in one vtu file.
4087
+ # data-vectors have to have the same length as len(triangles) + len(tetrahedres)
4088
+ # first: triangles, second: tetrahedras.
4089
+
4090
+ N_points = points.shape[0]
4091
+ N_ele = triangles.shape[0] + tetrahedras.shape[0]
4092
+ triangles_type = 5
4093
+ tetrahedra_type = 10
4094
+
4095
+ # determine number of components in data arguments
4096
+ N_data = len(data)
4097
+ # print(len(data))
4098
+ N_comp = np.zeros(len(data)).astype(int)
4099
+
4100
+ for i in range(len(data)):
4101
+ if hasattr(data[i], 'ndim'):
4102
+ N_comp[i] = data[i].shape[1] if data[i].ndim > 1 else 1
4103
+ else:
4104
+ N_comp[i] = 1
4105
+
4106
+ # open output file
4107
+ f = open(fname, 'w')
4108
+
4109
+ # write .vtu header
4110
+ f.write(
4111
+ '<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">\n')
4112
+
4113
+ # specify grid-type
4114
+ f.write('<UnstructuredGrid>\n')
4115
+ f.write(
4116
+ '<Piece NumberOfPoints="{:d}" NumberOfCells="{:d}">\n'.format(N_points, N_ele))
4117
+
4118
+ # write point data (not used here)
4119
+ f.write('<PointData>\n')
4120
+ f.write('</PointData>\n')
4121
+
4122
+ # write cell data (data)
4123
+ # =============================================================================
4124
+ f.write('<CellData Scalars="scalars">\n')
4125
+ for i_data in range(N_data):
4126
+ f.write('<DataArray type="Float64" Name="{}" NumberOfComponents="{:d}" format="ascii">\n'.format(
4127
+ data_labels[i_data], N_comp[i_data]))
4128
+ np.savetxt(f, data[i_data], '%1.8f') # data
4129
+ f.write('</DataArray>\n')
4130
+ f.write('</CellData>\n')
4131
+
4132
+ # write point coordinates of vertices
4133
+ # =============================================================================
4134
+ f.write('<Points>\n')
4135
+ f.write(
4136
+ '<DataArray type="Float64" Name="Points" NumberOfComponents="3" format="ascii">\n')
4137
+ np.savetxt(f, points, '%1.8f') # points
4138
+ f.write('</DataArray>\n')
4139
+ f.write('</Points>\n')
4140
+
4141
+ # write cell information
4142
+ # =============================================================================
4143
+ f.write('<Cells>\n')
4144
+
4145
+ # tetrahedras and triangles
4146
+ f.write('<DataArray type="Int64" Name="connectivity" format="ascii">\n')
4147
+ # tetrahedra (has to start with 0)
4148
+ np.savetxt(f, triangles - idx_start, '%d')
4149
+ # tetrahedra (has to start with 0)
4150
+ np.savetxt(f, tetrahedras - idx_start, '%d')
4151
+ f.write('</DataArray>\n')
4152
+
4153
+ # offset
4154
+ f.write('<DataArray type="Int64" Name="offsets" format="ascii">\n')
4155
+ # offset (3,6,9,...) for triangles or (4,8,12,...) for tetrahedra
4156
+ np.savetxt(f, triangles.shape[
4157
+ 1] * np.linspace(1, triangles.shape[0], triangles.shape[0]), '%d')
4158
+ np.savetxt(f, triangles.shape[0] * 3 + tetrahedras.shape[1] * np.linspace(
4159
+ 1, tetrahedras.shape[0], tetrahedras.shape[0]), '%d') # add last triangles offset to all tets
4160
+ f.write('</DataArray>\n')
4161
+
4162
+ # type of cells
4163
+ f.write('<DataArray type="UInt8" Name="types" format="ascii">\n')
4164
+ # type 5 (triangles) or 10 (tetrahedra)
4165
+ np.savetxt(f, triangles_type * np.ones((triangles.shape[0], 1)), '%d')
4166
+ # type 5 (triangles) or 10 (tetrahedra)
4167
+ np.savetxt(f, tetrahedra_type * np.ones((tetrahedras.shape[0], 1)), '%d')
4168
+ f.write('</DataArray>\n')
4169
+
4170
+ f.write('</Cells>\n')
4171
+
4172
+ # end of file
4173
+ # =============================================================================
4174
+ f.write('</Piece>\n')
4175
+ f.write('</UnstructuredGrid>\n')
4176
+ f.write('</VTKFile>')
4177
+ f.close()
4178
+
4179
+
4180
+ def write_vtu(fname, data_labels, points, connectivity, idx_start, data):
4181
+ """
4182
+ Writes data in tetrahedra centers into .vtu file, which can be loaded with Paraview.
4183
+
4184
+ Parameters
4185
+ ----------
4186
+ fname : str
4187
+ Name of .vtu file (incl. path)
4188
+ data_labels : list with N_data str
4189
+ Label of each dataset
4190
+ points : array of float [N_points x 3]
4191
+ Coordinates of vertices
4192
+ connectivity : array of int [N_tet x 4]
4193
+ Connectivity of points forming tetrahedra
4194
+ idx_start : int
4195
+ Smallest index in connectivity matrix, defines offset w.r.t Python indexing, which starts at '0'
4196
+ *data : array(s) [N_tet x N_comp(N_data)]
4197
+ Arrays containing data in tetrahedra center multiple components per dataset possible e.g. [Ex, Ey, Ez]
4198
+
4199
+ Returns
4200
+ -------
4201
+ <File> : .vtu file
4202
+ Geometry and data information
4203
+ """
4204
+
4205
+ N_points = points.shape[0]
4206
+ N_ele = connectivity.shape[0]
4207
+ if connectivity.shape[1] == 3:
4208
+ ele_type = 5 # triangles
4209
+ elif connectivity.shape[1] == 4:
4210
+ ele_type = 10 # tetrahedra
4211
+ else:
4212
+ raise RuntimeError('Error in connectivity matrix!')
4213
+
4214
+ # determine number of components in data arguments
4215
+ N_data = len(data)
4216
+ N_comp = np.zeros(len(data)).astype(int)
4217
+
4218
+ for i in range(len(data)):
4219
+ N_comp[i] = data[i].shape[1] if data[i].ndim > 1 else 1
4220
+
4221
+ # open output file
4222
+ f = open(fname, 'w')
4223
+
4224
+ # write .vtu header
4225
+ f.write('<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">\n')
4226
+
4227
+ # specify grid-type
4228
+ f.write('<UnstructuredGrid>\n')
4229
+ f.write('<Piece NumberOfPoints="{:d}" NumberOfCells="{:d}">\n'.format(N_points, N_ele))
4230
+
4231
+ # write point data (not used here)
4232
+ f.write('<PointData>\n')
4233
+ f.write('</PointData>\n')
4234
+
4235
+ # write cell data (data)
4236
+ # =============================================================================
4237
+ f.write('<CellData Scalars="scalars">\n')
4238
+ for i_data in range(N_data):
4239
+ f.write('<DataArray type="Float64" Name="{}" NumberOfComponents="{:d}" format="ascii">\n'.format(
4240
+ data_labels[i_data], N_comp[i_data]))
4241
+ np.savetxt(f, data[i_data], '%1.8f') # data
4242
+ f.write('</DataArray>\n')
4243
+ f.write('</CellData>\n')
4244
+
4245
+ # write point coordinates of vertices
4246
+ # =============================================================================
4247
+ f.write('<Points>\n')
4248
+ f.write(
4249
+ '<DataArray type="Float64" Name="Points" NumberOfComponents="3" format="ascii">\n')
4250
+ np.savetxt(f, points, '%1.8f') # points
4251
+ f.write('</DataArray>\n')
4252
+ f.write('</Points>\n')
4253
+
4254
+ # write cell information
4255
+ # =============================================================================
4256
+ f.write('<Cells>\n')
4257
+
4258
+ # tetrahedra
4259
+ f.write('<DataArray type="Int64" Name="connectivity" format="ascii">\n')
4260
+ # tetrahedra (has to start with 0)
4261
+ np.savetxt(f, connectivity - idx_start, '%d')
4262
+ f.write('</DataArray>\n')
4263
+
4264
+ # offset
4265
+ f.write('<DataArray type="Int64" Name="offsets" format="ascii">\n')
4266
+ # offset (3,6,9,...) for triangles or (4,8,12,...) for tetrahedra
4267
+ np.savetxt(f, connectivity.shape[1] * np.linspace(1, N_ele, N_ele), '%d')
4268
+ f.write('</DataArray>\n')
4269
+
4270
+ # type of cells
4271
+ f.write('<DataArray type="UInt8" Name="types" format="ascii">\n')
4272
+ # type 5 (triangles) or 10 (tetrahedra)
4273
+ np.savetxt(f, ele_type * np.ones((N_ele, 1)), '%d')
4274
+ f.write('</DataArray>\n')
4275
+
4276
+ f.write('</Cells>\n')
4277
+
4278
+ # end of file
4279
+ # =============================================================================
4280
+ f.write('</Piece>\n')
4281
+ f.write('</UnstructuredGrid>\n')
4282
+ f.write('</VTKFile>')
4283
+ f.close()
4284
+
4285
+
4286
+ def write_vtu_coilpos(fname_geo, fname_vtu):
4287
+ """
4288
+ Read dipole data of coil (position and magnitude of each dipole) from geo file and store it as vtu file.
4289
+
4290
+ Parameters
4291
+ ----------
4292
+ fname_geo : str
4293
+ .geo file from SimNIBS.
4294
+ fname_vtu : str
4295
+ .vtu output file. Nodes and nodedata.
4296
+
4297
+ Returns
4298
+ -------
4299
+ <File> : .vtu file
4300
+ Magnetic dipoles of the TMS coil
4301
+ """
4302
+
4303
+ # regex magic: get all floats from line, discard other stuff
4304
+ regexp = '.*?([+-]?\\d*\\.\\d+)(?![-+0-9\\.])'
4305
+ dipoles = np.fromregex(fname_geo,
4306
+ regexp,
4307
+ [('x', np.float_),
4308
+ ('y', np.float_),
4309
+ ('z', np.float_),
4310
+ ('mag', np.float_)])
4311
+ dipoles.astype(np.float_)
4312
+ points = []
4313
+ mag = []
4314
+
4315
+ # this is ugly, but it's monday
4316
+ for i in range(len(dipoles)):
4317
+ points.append([dipoles[i][0], dipoles[i][1], dipoles[i][2]])
4318
+ mag.append(dipoles[i][3])
4319
+
4320
+ # some variables for the vtu file
4321
+ N_points = len(points)
4322
+ N_ele = 1
4323
+ f = open(fname_vtu, 'w')
4324
+
4325
+ f.write(
4326
+ '<VTKFile type="UnstructuredGrid" version="1.0" byte_order="LittleEndian" header_type="UInt64">\n'
4327
+ )
4328
+
4329
+ # specify grid-type
4330
+ f.write('<UnstructuredGrid>\n')
4331
+ f.write(
4332
+ '<Piece NumberOfPoints="{:d}" NumberOfCells="{:d}">\n'.format(N_points, N_ele)
4333
+ )
4334
+
4335
+ # write point data
4336
+ f.write('<PointData>\n')
4337
+ f.write('<DataArray type="Float64" Name="magnitude" NumberOfComponents="1" format="ascii">\n')
4338
+ np.savetxt(f, mag, '%1.8f') # data
4339
+ f.write('</DataArray>\n')
4340
+ f.write('</PointData>\n')
4341
+
4342
+ f.write('<CellData Scalars="scalars">\n')
4343
+ # not used here
4344
+ f.write('</CellData>\n')
4345
+
4346
+ f.write('<Points>\n')
4347
+ f.write(
4348
+ '<DataArray type="Float64" Name="Points" NumberOfComponents="3" format="ascii">\n')
4349
+ np.savetxt(f, points, '%1.8f') # points
4350
+ f.write('</DataArray>\n')
4351
+ f.write('</Points>\n')
4352
+
4353
+ # write cell information
4354
+ # we define one cell which consist of every point, as vtu needs cells to access points.
4355
+ f.write('<Cells>\n')
4356
+ f.write('<DataArray type="Int64" Name="connectivity" format="ascii">')
4357
+ np.savetxt(f, list(range(N_points)), fmt='%d', delimiter=' ') # 1 2 3 4 ... N_Points
4358
+ f.write('</DataArray>\n')
4359
+ f.write('<DataArray type="Int64" Name="offsets" format="ascii">\n')
4360
+ f.write(str(N_points))
4361
+ f.write('</DataArray>\n')
4362
+ f.write('<DataArray type="UInt8" Name="types" format="ascii">\n')
4363
+ f.write('2\n') # element type 2: no lines, just points
4364
+ f.write('</DataArray>\n')
4365
+ f.write('</Cells>\n')
4366
+
4367
+ # end of file
4368
+ #######################################################################
4369
+ f.write('</Piece>\n')
4370
+ f.write('</UnstructuredGrid>\n')
4371
+ f.write('</VTKFile>')
4372
+ f.close()