/usr/share/rheolef/paraview_rheolef.py is in librheolef1 6.7-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 | 0#
## This file is part of Rheolef.
##
## Copyright (C) 2000-2009 Pierre Saramito
##
## Rheolef is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## Rheolef is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Rheolef; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
# ==========================================================================
# 1. Utilities
# ==========================================================================
# TODO : xmin,xmax, fmin,fmax a partir de data
# TODO : gl2ps : show.InterpolateScalarsBeforeMapping = 0 sinon blanc
# --------------------------------------------------------------------------
# 1.0. queries in the data
# --------------------------------------------------------------------------
def get_approx (data):
if data.GetCellDataInformation().GetNumberOfArrays() > 0:
return "P0"
elif data.GetPointDataInformation().GetNumberOfArrays() > 0:
return "P1"
else:
print "error(paraview_rheolef.py): no data founded"
exit(1)
# --------------------------------------------------------------------------
# 1.1. isovalues
# --------------------------------------------------------------------------
def build_isovalue_list_negative (option):
f_min = option['range'][0]
f_max = option['range'][1]
nn = option['n_isovalue_negative']
np = option['n_isovalue'] - nn
values = [f_min, f_min+1e-15]
for i in range(1, nn):
v = f_min - (1.0*i)/(1.0*nn)*f_min
values = values + [v]
#values = values + [0]
values = values + [-1e-15, 0, 1e-15] # add machine precision zero isolines
for i in range(1, np):
v = (1.0*i)/(1.0*np)*f_max
values = values + [v]
values = values + [f_max-1e-15,f_max]
return values
def build_isovalue_list (option):
if option['n_isovalue_negative'] != 0:
return build_isovalue_list_negative(option)
f_min = option['range'][0]
f_max = option['range'][1]
n_iso = option['n_isovalue']
iso_value = range(0,n_iso+1)
iso_value[0] = f_min
for i in range(1,n_iso):
iso_value[i] = f_min + 1.*i*(f_max-f_min)/n_iso
iso_value[n_iso] = f_max
#print "iso_value=", iso_value
return iso_value
# --------------------------------------------------------------------------
# 1.2. color bars
# --------------------------------------------------------------------------
def make_default_color_bar (option):
# used by geo visu (without fmin,fmax data)
from paraview.simple import GetLookupTableForArray, CreatePiecewiseFunction, CreateScalarBar
color_fct = CreatePiecewiseFunction( Points=[3.05602817274871e-35, 0, 0.5, 0, 105.364967346191, 1, 0.5, 0] )
color_fct.Points = [3.05602817274871e-35, 0, 0.5, 0, 105.364967346191, 1, 0.5, 0, 0, 0, 0.5, 0, 1, 1, 0.5, 0]
color_map = GetLookupTableForArray("mesh", 1, RGBPoints=[0, 0, 0, 1, 0, 1, 0, 0], VectorMode='Magnitude', NanColor=[0.498039215686275, 0.498039215686275, 0.498039215686275], ColorSpace='HSV', ScalarRangeInitialized=1)
color_map.RGBPoints = [0, 0, 0, 0, 0, 0, 0, 1]
try:
color_map.ScalarOpacityFunction = color_fct
except:
# paraview-3 style:
0
try:
color_map.Annotations = ['0', '0']
except:
# paraview-3 style:
0
color_bar = CreateScalarBar(Title='mesh', Enabled=1, LabelFontSize=12, LabelColor=[0, 0, 0], LookupTable=color_map, TitleFontSize=12, TitleColor=[0, 0, 0])
return color_bar
def get_color_fct (color_map, option):
from paraview.simple import CreatePiecewiseFunction
try:
# paraview-4 style:
color_fct = color_map.GetProperty("ScalarOpacityFunction").GetData()
except:
# paraview-3 style:
color_fct = make_color_fct (option)
return color_fct
def make_color_fct (option):
from paraview.simple import CreatePiecewiseFunction
# how to get data range automatically from data ?
f_min = option['range'][0]
f_max = option['range'][1]
color_fct = CreatePiecewiseFunction()
if option['volume'] == 0:
color_fct.Points = [f_min, 0, 0.5, 0, \
f_max, 1, 0.5, 0]
else:
df = f_max-f_min
color_fct.Points = [f_min, 0, 0.5, 0, \
f_min + 0.85*df, 0.2, 0.5, 0,
f_max, 1, 0.5, 0]
return color_fct
def make_color_bar (option):
from paraview.simple import GetLookupTableForArray, CreatePiecewiseFunction, CreateScalarBar
# how to get data range automatically from data ?
f_min = option['range'][0]
f_max = option['range'][1]
if option['name'] != '':
name = option['name']
else:
name = 'scalar'
n_iso = option['n_isovalue']
color_fct = make_color_fct (option)
color_map = GetLookupTableForArray(name, 1)
color_map.NumberOfTableValues = n_iso
color_map.ScalarRangeInitialized=1
color_map.VectorMode='Magnitude'
color_map.ColorSpace='Diverging'
if option['color'] == 'color':
color_map.ColorSpace = 'HSV'
color_map.RGBPoints = [f_min, 0, 0, 1, \
f_max, 1, 0, 0]
color_map.NanColor = [0.5, 0.5, 0.5]
else:
color_map.ColorSpace = 'RGB'
color_map.RGBPoints = [f_min, 0, 0, 0, \
f_max, 1, 1, 1]
color_map.NanColor = [1, 0, 0]
try:
# paraview-4
color_map.ScalarOpacityFunction = color_fct
except:
# paraview-3
0;
color_bar = CreateScalarBar(Title=name, Enabled=1, LabelFontSize=12, LabelColor=[0, 0, 0], LookupTable=color_map, TitleFontSize=12, TitleColor=[0, 0, 0])
return color_bar
# --------------------------------------------------------------------------
# 1.3. final render : graphic window or on file
# --------------------------------------------------------------------------
def do_final_render(paraview,basename,option):
from paraview.simple import GetRenderView, Render, WriteImage, GetActiveView
render = GetRenderView()
render.Background = [1, 1, 1]
if basename == '':
basename = "output"
Render() # the final render is here: do not clean!
file_format = option['format']
if file_format == '':
return
have_recognized_format = 0
import os.path
basename = os.path.basename(basename)
filename = basename+"."+file_format
#print "filename=",filename
from os import remove
from os.path import exists
if exists(filename):
remove(filename)
if file_format == 'pdf' and exists(filename+".gz"):
remove(filename+".gz")
if file_format == 'png' or \
file_format == 'bmp' or \
file_format == 'ppm' or \
file_format == 'tif' or \
file_format == 'jpg':
# png, bmp, ppm, tif, tiff, jpg and jpeg
# doc: http://www.paraview.org/ParaView3/Doc/Nightly/www/py-doc/paraview.simple.html#paraview.simple.WriteAnimation
have_recognized_format = 1
resolution = option.get('resolution')
if resolution == None:
resolution = [1024, 768]
GetRenderView().ViewSize = resolution
Render()
WriteImage(filename, render)
if file_format == 'vrml':
# http://www.paraview.org/pipermail/paraview/2010-June/017989.html
have_recognized_format = 1
exporters = paraview.servermanager.createModule("exporters")
vrml = exporters.VRMLExporter()
vrml.FileName = filename
vrml.SetView(render)
vrml.Write()
if file_format == 'pdf' or \
file_format == 'ps' or \
file_format == 'eps' or \
file_format == 'svg':
# gl2ps: pdf, ps, eps, svg
# http://www.paraview.org/pipermail/paraview/2010-June/017937.html
have_recognized_format = 1
use_tvtk = 0
if not use_tvtk:
# -----------------------
# use raw vtk class
# -----------------------
try:
from vtkRenderingPython import vtkGL2PSExporter # paraview 3
paraview_version="3.x"
except:
try:
from vtk.vtkRenderingPython import vtkGL2PSExporter # paraview 4.0 : segfault sometimes...
paraview_version="4.0"
except:
try:
from vtk.vtkIOExportPython import vtkGL2PSExporter # paraview 4.1
paraview_version="4.1"
except:
paraview_version="x.x"
print "error(paraview_rheolef.py): vector graphic output: module gl2ps not found (HINT: check paraview installation)"
exit(1)
render.CameraViewUp = [0,-1, 0] # view is 180 deg rotated with pvbatch, not with pvpython and paraview...
Render()
view = render.GetRenderWindow()
gl2ps = vtkGL2PSExporter()
#help(gl2ps.__class__)
gl2ps.SetRenderWindow(view)
gl2ps.SetFilePrefix(basename)
file_format2code = {'ps': 0, 'eps': 1, 'pdf': 2, 'tex': 3, 'svg': 4}
if file_format.lower() in file_format2code:
gl2ps.SetFileFormat(file_format2code[file_format.lower()])
else:
print "error(paraview_rheolef.py): invalid file format ",file_format
exit(1)
if file_format.lower() == "pdf":
gl2ps.SetCompress(True) # abble to compress inside pdf
else:
gl2ps.SetCompress(False)
gl2ps.SetLandscape(False);
gl2ps.SetSortToBSP()
gl2ps.DrawBackgroundOn();
gl2ps.SetWrite3DPropsAsRasterImage(False) # rasterize, as png
gl2ps.BestRootOn()
gl2ps.OcclusionCullOn(); # otherwise no fill
gl2ps.PS3ShadingOff();
gl2ps.SilentOff()
gl2ps.SimpleLineOffsetOn();
gl2ps.TextOn()
try:
gl2ps.TextAsPathOn(); # write text as path (paraview-4 style)
except:
0
gl2ps.Write()
else:
# --------------------------------
# use mayavi2/tktk (experimental)
# --------------------------------
print "saving with mayavi/tvtk..."
from tvtk.api import tvtk
gl2ps = tvtk.GL2PSExporter(file_format='eps', sort='bsp', compress=0)
gl2ps.file_prefix = basename
gl2ps.render_window = render.GetRenderWindow()
if file_format.lower() == "pdf":
gl2ps.compress = 1
#open a menu to set options:
#gl2ps.edit_traits(kind='livemodal')
gl2ps.write()
if have_recognized_format == 0:
print "error(paraview_rheolef.py): unrecognized image format %s"%(format)
exit(1)
if format == "pdf" and exists(filename+".gz"):
import os
command="mv %s.gz %s"%(filename,filename)
#print "!", command
os.system (command)
if exists(filename):
print "! output written to \"%s\""%(filename)
else:
print "! failed to create \"%s\""%(filename)
exit(1)
def do_render(paraview, name, option):
from paraview.simple import GetRenderView
x_min = option['bbox'][0][0]
x_max = option['bbox'][1][0]
y_min = option['bbox'][0][1]
y_max = option['bbox'][1][1]
z_min = option['bbox'][0][2]
z_max = option['bbox'][1][2]
if option.get('elevation') != 1:
xg = [(x_max+x_min)/2., (y_max+y_min)/2., (z_max+z_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_max-z_min]
else:
f_min = option['range'][0]
f_max = option['range'][1]
z_scale = max(x_max-x_min,y_max-y_min)/(f_max-f_min)
xg = [(x_max+x_min)/2., (y_max+y_min)/2., z_scale*(f_max+f_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_scale*(f_max-f_min)]
render = GetRenderView()
render.Background = [1, 1, 1]
render.CenterAxesVisibility = 0
render.CenterOfRotation = xg
render.CameraFocalPoint = xg
if option['view_2d'] == 1 and option['elevation'] == 0:
render.InteractionMode = '2D'
render.OrientationAxesVisibility = 0
from math import sqrt
render.CameraParallelScale = max(dx[0],dx[1])/sqrt(2.0)
z_camera = 1+sqrt(3)
render.CameraPosition = [xg[0], xg[1], z_camera]
render.CameraClippingRange = [0.99*z_camera, 1.015*z_camera]
render.CameraViewUp = [0, 1, 0]
render.CameraViewAngle = 30
else:
render.InteractionMode = '3D'
if option['label'] == 0:
render.OrientationAxesVisibility = 0
render.CameraPosition = [xg[0]+3*dx[0], xg[1]+1.2*dx[1], xg[2]+0.4*dx[2]]
render.CameraViewUp = [0, 0, 1]
from os.path import basename
do_final_render(paraview, basename(name), option)
# ==========================================================================
# 2. scalar field
# ==========================================================================
# --------------------------------------------------------------------------
# 2.1. field: 2d scalar color or grayscale
# --------------------------------------------------------------------------
def paraview_field_2d_scalar_color (paraview, basename, option):
from paraview.simple import LegacyVTKReader, GetRenderView, \
GetLookupTableForArray, CreatePiecewiseFunction, Show, \
CreateScalarBar
paraview.simple._DisableFirstRenderCameraReset()
n_iso = option['n_isovalue']
data = LegacyVTKReader(FileNames=[basename+".vtk"] )
color_bar = make_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct (color_map, option)
iso_contour = Show()
if option['format'] != '':
iso_contour.InterpolateScalarsBeforeMapping = 0 # bug gl2ps & paraview
iso_contour.SelectionPointFieldDataArrayName = 'scalar'
iso_contour.ColorArrayName = 'scalar'
if option['fill'] == 1:
iso_contour.Representation = 'Surface'
else:
iso_contour.Representation = 'Wireframe'
iso_contour.ScaleFactor = 1
iso_contour.ScalarOpacityFunction = color_fct
iso_contour.LookupTable = color_map
iso_contour.AmbientColor = [0, 0, 0]
iso_contour.CubeAxesColor = [0, 0, 0]
iso_contour.EdgeColor = [0, 0, 0.5]
iso_contour.BackfaceDiffuseColor = [0.3333333333333333, 0.6666666666666666, 1]
iso_contour.DiffuseColor = [0.3333333333333333, 0.6666666666666666, 1]
iso_contour.ScalarOpacityUnitDistance = 0.09596915518332425
if option['label'] == 1:
render = GetRenderView()
render.Representations.append(color_bar)
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 2.2. field: 2d scalar black-and-white
# --------------------------------------------------------------------------
def paraview_field_2d_scalar_bw (paraview, basename, option):
from paraview.simple import LegacyVTKReader, GetRenderView, \
Show, GetLookupTableForArray, CreatePiecewiseFunction, \
Outline, SetActiveSource, Contour, GetAnimationScene, Render
paraview.simple._DisableFirstRenderCameraReset()
data = LegacyVTKReader( FileNames=[basename+".vtk"] )
if option.get('outline') == None or option.get('outline') == 1:
outline = Outline()
outline_show = Show()
outline_show.ColorArrayName = ''
outline_show.SelectionPointFieldDataArrayName = 'scalar'
outline_show.DiffuseColor = [0, 0, 0]
SetActiveSource(data)
iso_lines = Contour()
iso_lines.PointMergeMethod = "Uniform Binning"
iso_lines.ContourBy = 'scalar'
iso_lines.Isosurfaces = build_isovalue_list(option)
iso_show = Show()
iso_show.SelectionPointFieldDataArrayName = 'scalar'
iso_show.ColorArrayName = ('POINT_DATA', '')
iso_show.DiffuseColor = [0, 0, 0]
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 2.3. field: 2d scalar elevation
# --------------------------------------------------------------------------
def paraview_field_2d_scalar_elevation (paraview, basename, option):
from paraview.simple import LegacyVTKReader, GetRenderView, \
Show, GetLookupTableForArray, CreatePiecewiseFunction, \
Outline, SetActiveSource, Contour, GetAnimationScene, \
WarpByScalar, CreateScalarBar
paraview.simple._DisableFirstRenderCameraReset()
data = LegacyVTKReader( FileNames=[basename+".vtk"] )
# how to get data range automatically ?
x_min = option['bbox'][0][0]
x_max = option['bbox'][1][0]
y_min = option['bbox'][0][1]
y_max = option['bbox'][1][1]
f_min = option['range'][0]
f_max = option['range'][1]
z_scale = max(x_max-x_min,y_max-y_min)/(f_max-f_min)
xg = [(x_max+x_min)/2., (y_max+y_min)/2., z_scale*(f_max+f_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_scale*(f_max-f_min)]
color_bar = make_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct (color_map, option)
warp = WarpByScalar()
warp.Scalars = 'scalar'
warp.ScaleFactor = z_scale
warp_show = Show()
warp_show.InterpolateScalarsBeforeMapping = 1
warp_show.LookupTable = color_map
warp_show.ScalarOpacityFunction = color_fct
if option['fill'] == 1:
warp_show.ColorArrayName = 'scalar'
warp_show.Representation = 'Surface'
else:
warp_show.ColorArrayName = ''
warp_show.Representation = 'Wireframe'
warp_show.SelectionPointFieldDataArrayName = 'scalar'
warp_show.ScaleFactor = 1
warp_show.DiffuseColor = [0, 0, 0]
warp_show.AmbientColor = [0, 0, 0]
warp_show.CubeAxesColor = [0, 0, 0]
warp_show.BackfaceDiffuseColor = [0, 0, 0]
warp_show.EdgeColor = [0, 0, 0.5]
warp_show.ScalarOpacityUnitDistance = 0.15254729527751434
if option['label'] == 1 and option['fill'] == 1:
render = GetRenderView()
render.Representations.append(color_bar)
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 2.4. field: 2d scalar bicolor
# --------------------------------------------------------------------------
def paraview_field_2d_scalar_bicolor (paraview, basename, option):
from paraview.simple import LegacyVTKReader, CreatePiecewiseFunction, GetLookupTableForArray, \
GetLookupTableForArray, CreateScalarBar, Calculator, Contour, IsoVolume, Show, \
SetActiveSource, GetRenderView, Render, Text
f_min = option['range'][0]
f_max = option['range'][1]
eps = 1e-16
if ((f_min*f_max >= 0) or (abs(f_min) < eps) or (abs(f_max) < eps)):
# no change of sign
paraview_field_2d_scalar_color (paraview, basename, option)
return
paraview.simple._DisableFirstRenderCameraReset()
data = LegacyVTKReader( FileNames=[basename+".vtk"] )
# ---------------------------
# two color maps
# ---------------------------
negative_color_fct = CreatePiecewiseFunction()
negative_color_fct.Points = [f_min, 0, 0.5, 0, \
0, 1, 0.5, 0]
negative_color_map = GetLookupTableForArray("scalar", 1)
negative_color_map.RGBPoints = [f_min, 0, 0, 1, \
0, 0, 1, 1]
negative_color_map.VectorMode = 'Magnitude'
negative_color_map.NanColor = [0, 0, 0]
negative_color_map.NumberOfTableValues = option['n_isovalue_negative']
try:
# paraview-4.1:
negative_color_map.ScalarOpacityFunction = negative_color_fct
except:
0
# paraview-4.1:
# negative_color_map.IndexedColors = [1, 0, 0, \
# 1, 0.862745098039215, 0, \
# 0, 0.695201037613489, 0]
negative_color_map.ScalarRangeInitialized = 1
negative_color_map.LockScalarRange = 1
try:
# paraview-4.1:
negative_color_map.Annotations = ["%.15g"%(f_min), "%.7g"%(f_min), \
"0", "0"]
except:
0
positive_color_fct = CreatePiecewiseFunction()
positive_color_fct.Points = [ 0, 0, 0.5, 0, \
0.5, 0.5, 0.5, 0, \
1, 1, 0.5, 0]
positive_color_map = GetLookupTableForArray("Result", 1)
positive_color_map.RGBPoints = [0, 1, 1, 0.5, \
0.1, 1, 1, 0, \
0.5, 0.9, 0.5, 0, \
1, 0.9, 0, 0]
positive_color_map.VectorMode = 'Magnitude'
positive_color_map.NanColor = [0, 0, 0]
positive_color_map.NumberOfTableValues = option['n_isovalue'] - option['n_isovalue_negative']
positive_color_map.ScalarRangeInitialized = 1
positive_color_map.LockScalarRange = 1
#positive_color_map.ScalarOpacityFunction = positive_color_fct
try:
# paraview-4.1:
positive_color_map.Annotations = ["0", "0", \
"1", "%.7g"%(f_max)]
except:
0
negative_color_bar = CreateScalarBar()
negative_color_bar.LookupTable = negative_color_map
negative_color_bar.Title = ' '
negative_color_bar.Position = [0.93, 0.25]
negative_color_bar.Position2 = [0.13, 0.5]
negative_color_bar.Enabled = 1
negative_color_bar.Selectable = 1
negative_color_bar.LabelShadow = 1
negative_color_bar.AutomaticLabelFormat = 0
negative_color_bar.NumberOfLabels = 1
negative_color_bar.TitleFontSize = 10
negative_color_bar.LabelFontSize = 10
negative_color_bar.TitleColor = [0, 0, 0]
negative_color_bar.LabelColor = [0, 0, 0]
positive_color_bar = CreateScalarBar()
positive_color_bar.LookupTable = positive_color_map
positive_color_bar.Title = ' '
positive_color_bar.Position = [0.85, 0.4]
positive_color_bar.Position2 = [0.13, 0.5]
positive_color_bar.Enabled = 1
positive_color_bar.Selectable = 1
positive_color_bar.LabelShadow = 1
positive_color_bar.AutomaticLabelFormat = 0
positive_color_bar.NumberOfLabels = 1
positive_color_bar.TitleFontSize = 10
positive_color_bar.LabelFontSize = 10
positive_color_bar.TitleColor = [0, 0, 0]
positive_color_bar.LabelColor = [0, 0, 0]
# ----------------------------
# title for the two color bars
# ----------------------------
if option['name'] != '' and option['label'] == 1:
title = Text()
title.Text = option['name']
title_show = Show()
title_show.Color = [0,0,0]
title_show.FontFamily = 'Times'
title_show.FontSize = 12
title_show.Justification = 'Center'
title_show.Position = [0.5, 0.95]
# ---------------------------
# negative part, in backgroud
# ---------------------------
SetActiveSource(data)
negative_rescale = Calculator()
#negative_rescale.Function = "scalar/%.16g"%(abs(f_min))
negative_rescale.Function = "scalar"
negative_show = Show()
negative_show.SelectionPointFieldDataArrayName = 'scalar'
negative_show.ColorArrayName = 'scalar'
negative_show.ScalarOpacityFunction = negative_color_fct
negative_show.LookupTable = negative_color_map
negative_show.AmbientColor = [0, 0, 0]
negative_show.CubeAxesColor = [0, 0, 0]
negative_show.EdgeColor = [0, 0, 0.5]
negative_show.ScalarOpacityUnitDistance = 0.4027013671755797
if option['color'] != 'color':
negative_show.Visibility = 0
# ----------------------------------------
# positive part, in foregroud, with a mask
# ----------------------------------------
SetActiveSource(data)
positive_rescale = Calculator()
positive_rescale.Function = "scalar/%.16g"%(f_max)
positive_only = IsoVolume()
positive_only.InputScalars = 'Result'
positive_only.ThresholdRange = [0, 1]
positive_show = Show()
positive_show.SelectionPointFieldDataArrayName = 'Result'
if option['color'] == 'color':
positive_show.ColorArrayName = 'Result'
positive_show.ScalarOpacityFunction = positive_color_fct
positive_show.LookupTable = positive_color_map
else:
positive_show.ColorArrayName = ''
if option['format'] == '':
gray = 75./100.
else:
gray = 95./100.
positive_show.DiffuseColor = [gray, gray, gray]
positive_show.Representation = 'Surface'
positive_show.AmbientColor = [0, 0, 0]
positive_show.CubeAxesColor = [0, 0, 0]
positive_show.ScaleFactor = 1
positive_show.ScalarOpacityUnitDistance = 0.16539091500936676
positive_show.BackfaceDiffuseColor = [1, 1, 1]
positive_show.AmbientColor = [0, 0, 0]
positive_show.CubeAxesColor = [0, 0, 0]
positive_show.EdgeColor = [0, 0, 0]
# ----------------------------------------
# isolines
# ----------------------------------------
if option.get('contours') == None or option.get('contours') == 1:
SetActiveSource(data)
contour = Contour()
contour.Isosurfaces = build_isovalue_list(option)
contour.ContourBy = 'scalar'
contour.PointMergeMethod = "Uniform Binning"
contour_show = Show()
contour_show.SelectionPointFieldDataArrayName = 'scalar'
contour_show.DiffuseColor = [0, 0, 0]
contour_show.AmbientColor = [0, 0, 0]
contour_show.CubeAxesColor = [0, 0, 0]
contour_show.EdgeColor = [0, 0, 0.5]
if option['label'] == 1 and option['color'] == 'color':
render = GetRenderView()
render.Representations.append(negative_color_bar)
render.Representations.append(positive_color_bar)
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 2.5. field: 3d scalar: iso+cut or volume
# --------------------------------------------------------------------------
def paraview_field_3d_scalar (paraview, basename, option):
from paraview.simple import LegacyVTKReader, GetLookupTableForArray, \
CreatePiecewiseFunction, GetRenderView, Show, Contour, \
SetActiveSource, Outline, Slice, active_objects, CreateScalarBar, \
Render, GetDisplayProperties, Clip
paraview.simple._DisableFirstRenderCameraReset()
data = LegacyVTKReader(FileNames=[basename+".vtk"])
x_min = option['bbox'][0][0]
x_max = option['bbox'][1][0]
y_min = option['bbox'][0][1]
y_max = option['bbox'][1][1]
z_min = option['bbox'][0][2]
z_max = option['bbox'][1][2]
f_min = option['range'][0]
f_max = option['range'][1]
xg = [(x_max+x_min)/2., (y_max+y_min)/2., (z_max+z_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_max-z_min]
approx = get_approx (data)
color_bar = make_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct (color_map, option)
#SetActiveSource(data)
outline = Outline()
#SetActiveSource(data)
outline_show = Show()
outline_show.ColorArrayName = ''
#outline_show.SelectionPointFieldDataArrayName = 'scalar'
outline_show.DiffuseColor = [0, 0, 0]
outline_show.AmbientColor = [0, 0, 0]
outline_show.CubeAxesColor = [0, 0, 0]
outline_show.BackfaceDiffuseColor = [0, 0, 0]
outline_show.EdgeColor = [0, 0, 0.5]
# 3d default paraview is a boundary isocontours: hiden
data_show = GetDisplayProperties(data)
data_show.Visibility = 0
SetActiveSource(data)
if option['volume'] == 1:
# -------------------------------
# translucide color volume
# -------------------------------
volume_show = Show()
volume_show.Representation = 'Volume'
volume_show.ColorArrayName = 'scalar'
volume_show.SelectionPointFieldDataArrayName = 'scalar'
volume_show.ScaleFactor = 1
volume_show.LookupTable = color_map
volume_show.ScalarOpacityFunction = color_fct
volume_show.AmbientColor = [0, 0, 0]
volume_show.CubeAxesColor = [0, 0, 0]
volume_show.EdgeColor = [0, 0, 0.5]
volume_show.ScalarOpacityUnitDistance = 0.09531842929969365
else:
if approx == "P0":
# ---------------------------------
# cut with picewise constant colors
# ---------------------------------
clip = Clip()
clip.Scalars = 'scalar'
clip.ClipType = "Plane"
clip.ClipType.Origin = xg
clip.ClipType.Normal = [-0.015940197423022637, -0.9771157601293953, -0.21211011624358989]
clip_show = Show()
clip_show.Representation = 'Surface'
clip_show.SelectionPointFieldDataArrayName = 'scalar'
clip_show.ColorArrayName = 'scalar'
clip_show.ScaleFactor = 1
clip_show.LookupTable = color_map
clip_show.ScalarOpacityFunction = color_fct
clip_show.ScalarOpacityUnitDistance = 0.16539091500936676
clip_show.DiffuseColor = [1, 1, 1]
clip_show.BackfaceDiffuseColor = [1, 1, 1]
clip_show.AmbientColor = [0, 0, 0]
clip_show.CubeAxesColor = [0, 0, 0]
clip_show.EdgeColor = [0, 0, 0]
else: # all except P0: P1, P1d, P2, etc
# -------------------------------
# cut with contours
# -------------------------------
iso_surface = Contour()
iso_surface.ContourBy = 'scalar'
iso_surface.ComputeScalars = 1
iso_surface.Isosurfaces = [(f_max+f_min)/2.]
iso_surface.PointMergeMethod = "Uniform Binning"
iso_show = Show()
iso_show.SelectionPointFieldDataArrayName = 'Normals'
if option['fill'] == 0:
iso_show.Representation = 'Wireframe'
iso_show.ColorArrayName = ''
else:
iso_show.Representation = 'Surface'
iso_show.ColorArrayName = 'scalar'
iso_show.ScaleFactor = 1
iso_show.LookupTable = color_map
iso_show.DiffuseColor = [0, 0, 0]
iso_show.AmbientColor = [0, 0, 0]
iso_show.CubeAxesColor = [0, 0, 0]
iso_show.BackfaceDiffuseColor = [0, 0, 0]
iso_show.EdgeColor = [0, 0, 0.5]
SetActiveSource(data)
cut_plane = Slice()
cut_plane.SliceType = "Plane"
cut_plane.SliceOffsetValues = [0.]
# TODO: check option ?... but this one is not so bad here for the dirichlet.cc and cube.geo demo:
cut_plane.SliceType.Normal = [-0.015940197423022637, -0.9771157601293953, -0.21211011624358989]
if (option['origin'][0] > x_min and option['origin'][0] < x_max):
cut_plane.SliceType.Origin = option['origin']
else:
cut_plane.SliceType.Origin = [(x_max-x_min)/2., (y_max-y_min)/2., (z_max-z_min)/2.]
iso_cut_show = Show()
iso_cut_show.ColorArrayName = 'scalar'
iso_cut_show.SelectionPointFieldDataArrayName = 'scalar'
iso_cut_show.LookupTable = color_map
iso_cut_show.DiffuseColor = [0, 0, 0]
iso_cut_show.AmbientColor = [0, 0, 0]
iso_cut_show.CubeAxesColor = [0, 0, 0]
iso_cut_show.BackfaceDiffuseColor = [0, 0, 0]
iso_cut_show.EdgeColor = [0, 0, 0.5]
if option['label'] == 1:
render = GetRenderView()
render.Representations.append(color_bar)
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 2.6. field: 3d surface scalar: iso contours
# --------------------------------------------------------------------------
def paraview_field_3d_surface_scalar (paraview, basename, option):
from paraview.simple import LegacyVTKReader, GetRenderView, \
GetLookupTableForArray, CreatePiecewiseFunction, Show, \
CreateScalarBar, SetActiveSource, Contour, GetDisplayProperties
paraview.simple._DisableFirstRenderCameraReset()
n_iso = option['n_isovalue']
data = LegacyVTKReader(FileNames=[basename+".vtk"] )
color_bar = make_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct (color_map, option)
if option['color'] == 'black_and_white':
mesh_show = GetDisplayProperties(data)
mesh_show.ColorArrayName = ''
mesh_show.ColorAttributeType = 'CELL_DATA'
mesh_show.Representation = 'Wireframe'
mesh_show.Opacity = 0.25
mesh_show.DiffuseColor = [0, 0, 0]
mesh_show.AmbientColor = [0, 0, 0]
mesh_show.CubeAxesColor = [0, 0, 0]
mesh_show.EdgeColor = [0, 0, 0.5]
#mesh_show.BackfaceDiffuseColor = [0.3333333333333333, 0.6666666666666666, 1]
#mesh_show.DiffuseColor = [0.3333333333333333, 0.6666666666666666, 1]
mesh_show.ScalarOpacityUnitDistance = 0.09596915518332425
else:
iso_contour = Show()
iso_contour.SelectionPointFieldDataArrayName = 'scalar'
iso_contour.ColorArrayName = 'scalar'
if option['fill'] == 1:
iso_contour.Representation = 'Surface'
else:
iso_contour.Representation = 'Wireframe'
if option['stereo'] == 1:
iso_contour.Opacity = 0.65
iso_contour.ScaleFactor = 1
iso_contour.ScalarOpacityFunction = color_fct
iso_contour.LookupTable = color_map
iso_contour.AmbientColor = [0, 0, 0]
iso_contour.CubeAxesColor = [0, 0, 0]
iso_contour.EdgeColor = [0, 0, 0.5]
iso_contour.BackfaceDiffuseColor = [0.3333333333333333, 0.6666666666666666, 1]
iso_contour.DiffuseColor = [0.3333333333333333, 0.6666666666666666, 1]
iso_contour.ScalarOpacityUnitDistance = 0.09596915518332425
SetActiveSource(data)
iso_lines = Contour()
iso_lines.PointMergeMethod = "Uniform Binning"
iso_lines.ContourBy = 'scalar'
iso_lines.Isosurfaces = build_isovalue_list(option)
iso_show = Show()
iso_show.SelectionPointFieldDataArrayName = 'scalar'
iso_show.ColorArrayName = ('POINT_DATA', '')
iso_show.DiffuseColor = [0, 0, 0]
if option['color'] != 'black_and_white' and option['label'] == 1:
render = GetRenderView()
render.Representations.append(color_bar)
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 2.7. scalar field visualization
# --------------------------------------------------------------------------
def paraview_field_scalar (paraview, basename, option):
if option['view_2d'] == 1:
if option['elevation'] == 1:
paraview_field_2d_scalar_elevation (paraview, basename, option)
elif option['color'] == 'black_and_white':
paraview_field_2d_scalar_bw (paraview, basename, option)
elif option['n_isovalue_negative'] != 0:
paraview_field_2d_scalar_bicolor (paraview, basename, option)
else:
paraview_field_2d_scalar_color (paraview, basename, option)
else:
if option['view_map'] == 0:
paraview_field_3d_scalar (paraview, basename, option)
else:
paraview_field_3d_surface_scalar (paraview, basename, option)
# ==========================================================================
# 3. vector field
# ==========================================================================
# 3.1. vector field visualization: deformation
# --------------------------------------------------------------------------
def paraview_field_vector_deformation (paraview, basename, option):
from paraview.simple import LegacyVTKReader, \
Show, WarpByVector, Outline, GetRenderView, SetActiveSource, Outline
paraview.simple._DisableFirstRenderCameraReset()
data = LegacyVTKReader(FileNames=[basename+".vtk"])
x_min = option['bbox'][0][0]
x_max = option['bbox'][1][0]
y_min = option['bbox'][0][1]
y_max = option['bbox'][1][1]
z_min = option['bbox'][0][2]
z_max = option['bbox'][1][2]
f_min = option['range'][0]
f_max = option['range'][1]
xg = [(x_max+x_min)/2., (y_max+y_min)/2., (z_max+z_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_max-z_min]
if option['name'] == '':
option['name'] = '|deformation|'
color_bar = make_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct(color_map, option)
outline = Outline()
outline_show = Show()
outline_show.DiffuseColor = [0, 0, 0]
outline_show.AmbientColor = [0, 0, 0]
outline_show.CubeAxesColor = [0, 0, 0]
outline_show.BackfaceDiffuseColor = [0, 0, 0]
outline_show.EdgeColor = [0, 0, 0.5]
SetActiveSource(data)
deformation = WarpByVector()
deformation.Vectors = 'vector'
if (f_max-f_min != 0):
# adjust the deformation scale to 10% of the domain characteristic length
# can be adjusted by the "-scale" command line option, or interactively
length = max(max(x_max-x_min,y_max-y_min),z_max-z_min)
deformation.ScaleFactor = option['scale']*(0.1*length)/(f_max-f_min)
else:
deformation.ScaleFactor = 1;
deformation_show = Show()
deformation_show.ScaleFactor = 1;
if option['fill'] == 0:
deformation_show.Representation = 'Wireframe'
else:
deformation_show.Representation = 'Surface'
deformation_show.SelectionPointFieldDataArrayName = 'vector_norm'
deformation_show.ColorArrayName = 'vector_norm'
deformation_show.LookupTable = color_map
deformation_show.ScalarOpacityFunction = color_fct
deformation_show.ScalarOpacityUnitDistance = 0.05547965123845249
deformation_show.DiffuseColor = [0, 0, 0]
deformation_show.AmbientColor = [0, 0, 0]
deformation_show.CubeAxesColor = [0, 0, 0]
deformation_show.BackfaceDiffuseColor = [0, 0, 0]
deformation_show.EdgeColor = [0, 0, 0.5]
if option['label'] == 1:
render = GetRenderView()
render.Representations.append(color_bar)
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 3.2. vector field visualization: arrow
# --------------------------------------------------------------------------
def paraview_field_vector_arrow (paraview, basename, option):
from paraview.simple import LegacyVTKReader, \
SetActiveSource, Show, Glyph, Outline, GetRenderView
paraview.simple._DisableFirstRenderCameraReset()
data = LegacyVTKReader(FileNames=[basename+".vtk"])
x_min = option['bbox'][0][0]
x_max = option['bbox'][1][0]
y_min = option['bbox'][0][1]
y_max = option['bbox'][1][1]
z_min = option['bbox'][0][2]
z_max = option['bbox'][1][2]
xg = [(x_max+x_min)/2., (y_max+y_min)/2., (z_max+z_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_max-z_min]
if option['name'] == '':
name = '|vector|'
color_bar = make_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct (color_map, option)
if option['fill'] == 1:
data_show = Show()
data_show.ScaleFactor = 1;
data_show.Representation = 'Surface'
data_show.SelectionPointFieldDataArrayName = 'vector_norm'
data_show.ColorArrayName = 'vector_norm'
data_show.LookupTable = color_map
data_show.ScalarOpacityFunction = color_fct
data_show.ScalarOpacityUnitDistance = 0.05547965123845249
data_show.DiffuseColor = [0, 0, 0]
data_show.AmbientColor = [0, 0, 0]
data_show.CubeAxesColor = [0, 0, 0]
data_show.BackfaceDiffuseColor = [0, 0, 0]
data_show.EdgeColor = [0, 0, 0.5]
arrow = Glyph(GlyphType="Arrow", GlyphTransform="Transform2")
arrow.Scalars = 'vector_norm'
arrow.Vectors = 'vector'
arrow.GlyphType = "Arrow"
arrow.GlyphTransform = "Transform2"
h_average = 0.1; # TODO: compute element average length
arrow.SetScaleFactor = h_average*option['scale'];
arrow.RandomMode = 0
arrow.MaskPoints = 0
arrow_show = Show()
arrow_show.SelectionPointFieldDataArrayName = 'vector_norm'
arrow_show.LookupTable = color_map
if option['fill'] == 1:
arrow_show.ColorArrayName = ''
arrow_show.DiffuseColor = [1, 1, 1]
else:
arrow_show.ColorArrayName = 'vector_norm'
arrow_show.DiffuseColor = [0, 0, 0]
arrow_show.AmbientColor = [0, 0, 0]
arrow_show.CubeAxesColor = [0, 0, 0]
arrow_show.BackfaceDiffuseColor = [0, 0, 0]
arrow_show.EdgeColor = [0, 0, 0.5]
if option['label'] == 1:
render = GetRenderView()
render.Representations.append(color_bar)
do_render(paraview, basename, option)
# --------------------------------------------------------------------------
# 3.3. vector field visualization
# --------------------------------------------------------------------------
def paraview_field_vector (paraview, basename, option):
if option['style'] == 'deformation':
paraview_field_vector_deformation (paraview, basename, option)
else:
paraview_field_vector_arrow (paraview, basename, option)
# ==========================================================================
# 4. tensor field visualization
# ==========================================================================
# warning: requieres the "TensorGlyph" plugin that should be compiled separately
# TODO: distribute it with rheolef, if it can be compiled with paraview-dev ?
def paraview_field_tensor (paraview, basename, option):
from paraview.simple import LegacyVTKReader, \
Show, GetRenderView, SetActiveSource, Outline, \
GetLookupTableForArray, CreatePiecewiseFunction, Render
try:
from paraview.simple import TensorGlyphs
except:
print "error(paraview_rheolef.py): TensorGlyphs paraview pluging not installed (HINT: install it from source code and check PV_PLUGIN_PATH environment variable)"
exit(1)
paraview.simple._DisableFirstRenderCameraReset()
data = LegacyVTKReader(FileNames=[basename+".vtk"])
x_min = option['bbox'][0][0]
x_max = option['bbox'][1][0]
y_min = option['bbox'][0][1]
y_max = option['bbox'][1][1]
z_min = option['bbox'][0][2]
z_max = option['bbox'][1][2]
f_min = option['range'][0]
f_max = option['range'][1]
xg = [(x_max+x_min)/2., (y_max+y_min)/2., (z_max+z_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_max-z_min]
if option['name'] == '':
option['name'] = '|tensor|'
color_bar = make_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct (color_map, option)
SetActiveSource(data)
outline = Outline()
outline_show = Show()
outline_show.ColorArrayName = ''
outline_show.SelectionPointFieldDataArrayName = 'scalar'
outline_show.DiffuseColor = [0, 0, 0]
SetActiveSource(data)
tensor_norm = Show()
tensor_norm.SelectionPointFieldDataArrayName = 'tensor_norm'
tensor_norm.ColorArrayName = 'tensor_norm'
tensor_norm.LookupTable = color_map
tensor_norm.ScalarOpacityFunction = color_fct
tensor_norm.ScalarOpacityUnitDistance = 0.2418271175121958
tensor_norm.ScaleFactor = 1
tensor_norm.AmbientColor = [0, 0, 0]
tensor_norm.CubeAxesColor = [0, 0, 0]
tensor_norm.EdgeColor = [0, 0, 0.5]
if option['view_2d'] != 1:
tensor_norm.Visibility = 0
tensor_glyph = TensorGlyphs()
tensor_glyph.GlyphType = "Sphere"
tensor_glyph.ColorGlyphs = 1
tensor_glyph.ExtractEigenvalues = 1
tensor_glyph.Scalars = 'tensor_norm'
tensor_glyph.Tensors = 'tensor'
h_average = 0.1; # TODO: compute element average length
tensor_glyph.ScaleFactor = 1.5*h_average*option['scale'];
tensor_glyph.LimitScalingByEigenvalues = 0
tensor_glyph_show = Show()
tensor_glyph_show.SelectionPointFieldDataArrayName = 'tensor_norm'
if option['view_2d'] == 1:
tensor_glyph_show.ColorArrayName = ''
else:
tensor_glyph_show.ColorArrayName = 'tensor_norm'
tensor_glyph_show.LookupTable = color_map
tensor_glyph_show.ScaleFactor = 1
gray = 11./12.
tensor_glyph_show.DiffuseColor = [gray, gray, gray]
tensor_glyph_show.BackfaceDiffuseColor = [gray, gray, gray]
tensor_glyph_show.AmbientColor = [0, 0, 0]
tensor_glyph_show.CubeAxesColor = [0, 0, 0]
tensor_glyph_show.EdgeColor = [0, 0, 0.5]
if option['label'] == 1:
render = GetRenderView()
render.Representations.append(color_bar)
do_render(paraview, basename, option)
# ==========================================================================
# 5. geo visualization
# ==========================================================================
# global variables (to all domains):
# ----------------------------------
global_geo_color = [ \
( 0, 0, 0), \
( 0, 1, 0), \
( 0, 0, 1), \
( 1, 1, 0), \
( 1, 0, 1), \
( 0, 1, 1), \
(0.8900, 0.1500, 0.2100 ), \
(0.6400, 0.5800, 0.5000 ), \
(1.0000, 0.3800, 0.0100 ) ]
def geo_n_vertex (data):
n_array = len(data.PointData)
if (n_array < 1):
return 0;
nv = data.PointData.GetFieldData().GetArrayInformation(0).GetNumberOfTuples()
return nv
def paraview_geo_domain (paraview, option, filename, dom_name, idx):
from paraview.simple import LegacyVTKReader, Show, \
ExtractEdges, Shrink, Text, ExtractCellsByRegion, Clip, \
SetActiveSource
data = LegacyVTKReader(FileNames=[filename])
#get bbox of the whole mesh, not only the domain:
x_min = option['bbox'][0][0]
x_max = option['bbox'][1][0]
y_min = option['bbox'][0][1]
y_max = option['bbox'][1][1]
z_min = option['bbox'][0][2]
z_max = option['bbox'][1][2]
xg = [(x_max+x_min)/2., (y_max+y_min)/2., (z_max+z_min)/2.]
dx = [x_max-x_min, y_max-y_min, z_max-z_min]
color_bar = make_default_color_bar (option)
color_map = color_bar.GetProperty("LookupTable").GetData()
color_fct = get_color_fct (color_map, option)
if option['color'] == 'black_and_white':
color = [0, 0, 0]
else:
if option['shrink'] == 0 or idx > 0:
color = global_geo_color[idx % len(global_geo_color)]
else:
gray = 11./12.
color = [gray, gray, gray]
#color = [0, 1, 1]; # petrol blue
if option['label'] == 1 and option['color'] != 'black_and_white' and idx > 0:
text = Text()
text.Text = dom_name
text_show = Show()
text_show.Color = color
text_show.FontFamily = 'Times'
text_show.FontSize = 10
text_show.Justification = 'Center'
text_hight = 0.005*text_show.FontSize; # TODO: how to quantify it clearly ?
y_pos = 0.75 - (idx-1)*text_hight
#print "y_pos(",idx,") = ", y_pos
text_show.Position = [0.02, y_pos]
if option['label'] == 1 and option['color'] != 'black_and_white' and idx == 0:
# TODO: ne = ? how to get it ?
nv = geo_n_vertex(data)
title = Text()
import os.path
title.Text = "%s : %d vertices"%(os.path.basename(dom_name), nv)
title_show = Show()
title_show.Color = [0,0,0]
title_show.FontFamily = 'Times'
title_show.FontSize = 10
title_show.Justification = 'Left'
title_show.Position = [0.05, 0.05]
SetActiveSource(data)
if option['full'] == 0 and option['shrink'] == 0:
mesh_show = Show()
mesh_show.ColorArrayName = ''
mesh_show.SelectionPointFieldDataArrayName = 'mesh'
mesh_show.LookupTable = color_map
mesh_show.ScalarOpacityFunction = color_fct
if ((option['color'] != 'black_and_white' and idx == 0 and option['label'] == 1) or option['fill'] == 0):
mesh_show.Representation = 'Wireframe'
mesh_show.DiffuseColor = [0,0,0]
mesh_show.AmbientColor = color
if (idx != 0):
mesh_show.LineWidth = 2
else:
mesh_show.Representation = 'Surface With Edges'
mesh_show.DiffuseColor = color
mesh_show.AmbientColor = [0, 0, 0]
mesh_show.BackfaceDiffuseColor = [0, 0, 0]
mesh_show.CubeAxesColor = [0, 0, 0]
mesh_show.EdgeColor = [0, 0, 0.5]
if option['cut'] == 1:
mesh_show.Visibility = 0
clip = Clip()
clip.Scalars = 'mesh'
clip.InsideOut = 1; # normal goes out from selected region
try:
clip.Crinkleclip = 1; # paraview-4 style: do not cut inside elements, eliminates them
except:
0; # paraview-3 style: cut inside elements
clip.ClipType = "Plane"
clip.ClipType.Origin = xg
clip.ClipType.Normal = [0.92, -0.25, 0.28]; # TODO: get normal
clip_show = Show()
clip_show.Representation = 'Surface With Edges'
clip_show.SelectionPointFieldDataArrayName = 'mesh'
clip_show.ColorArrayName = ''
clip_show.ScaleFactor = 1
clip_show.LookupTable = color_map
clip_show.ScalarOpacityFunction = []
clip_show.ScalarOpacityUnitDistance = 0.16539091500936676
clip_show.DiffuseColor = [1, 1, 1]
clip_show.BackfaceDiffuseColor = [1, 1, 1]
clip_show.AmbientColor = [0, 0, 0]
clip_show.CubeAxesColor = [0, 0, 0]
clip_show.EdgeColor = [0, 0, 0]
elif option['shrink'] == 1:
shrink = Shrink()
shrink_show = Show()
shrink_show.ScaleFactor = 0.0950000023469329
shrink_show.SelectionPointFieldDataArrayName = 'mesh'
shrink_show.ColorArrayName = ''
shrink_show.LookupTable = color_map
shrink_show.ScalarOpacityFunction = color_fct
shrink_show.DiffuseColor = color
shrink_show.AmbientColor = [0, 0, 0]
shrink_show.BackfaceDiffuseColor = [0, 0, 0]
shrink_show.CubeAxesColor = [0, 0, 0]
shrink_show.EdgeColor = [0, 0, 0.5]
shrink_show.ScalarOpacityUnitDistance = 0.1811050201435371
if option['cut'] == 1:
shrink_show.Visibility = 0
extract = ExtractCellsByRegion(IntersectWith="Plane")
extract.IntersectWith = "Plane"
extract.IntersectWith.Origin = xg
extract.IntersectWith.Normal = [0.92, -0.25, 0.28]; # TODO: get normal
extract_show = Show()
extract_show.ScaleFactor = 0.09669428616762162
extract_show.SelectionPointFieldDataArrayName = 'mesh'
extract_show.ColorArrayName = ''
extract_show.LookupTable = color_map
extract_show.ScalarOpacityFunction = color_fct
extract_show.DiffuseColor = color
extract_show.AmbientColor = [0, 0, 0]
extract_show.CubeAxesColor = [0, 0, 0]
extract_show.EdgeColor = [0, 0, 0.5]
extract_show.ScalarOpacityUnitDistance = 0.1896561226641973
else: # option['full'] == 1:
extract_edges = ExtractEdges()
extract_edges_show = Show()
extract_edges_show.ColorArrayName = ''
extract_edges_show.SelectionPointFieldDataArrayName = 'mesh'
extract_edges_show.LookupTable = color_map
extract_edges_show.DiffuseColor = color
extract_edges_show.AmbientColor = [0, 0, 0]
extract_edges_show.BackfaceDiffuseColor = [0, 0, 0]
extract_edges_show.CubeAxesColor = [0, 0, 0]
extract_edges_show.EdgeColor = [0, 0, 0.5]
if (idx != 0):
extract_edges_show.LineWidth = 2
def paraview_geo (paraview, option, d):
from paraview.simple import GetRenderView
paraview.simple._DisableFirstRenderCameraReset()
if option.get('boundary_only') == None or option.get('boundary_only') != 1:
paraview_geo_domain (paraview, option, d[0]+".vtk", d[0], 0)
if option['cut'] == 1 or option['stereo'] == 1:
option['label'] = 0
if option['label'] == 1 or option['color'] == 'black_and_white':
for i in range(1,len(d)):
paraview_geo_domain (paraview, option, d[0]+"."+d[i]+".vtk", d[i], i)
do_render(paraview, d[0], option)
|