1 # Copyright (C) 2010-2013 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 This module is intended to provide Python API for building presentations
22 typical for Post-Pro module (Scalar Map, Deformed Shape, Vectors, etc.)
26 from __future__ import division
27 ##from __future__ import print_function
32 from math import sqrt, sin, cos, radians
33 from string import upper
35 # Do not use pv as a short name.
36 # It is a name of function from numpy and may be redefined implicitly by 'from numpy import *' call.
37 # import pvsimple as pv
38 import pvsimple as pvs
40 # # TODO(MZN): to be removed (issue with Point Sprite texture)
41 # #import paravisSM as sm
43 # import paraview.simple as pvs
44 # import paraview.servermanager as sm
50 VTK_LARGE_FLOAT = 1E+38
51 GAP_COEFFICIENT = 0.0001
56 _med_field_sep = '@@][@@'
62 Post-Pro presentation types.
70 DEFORMEDSHAPESCALARMAP = 6
76 _type2name = {MESH: 'Mesh',
77 SCALARMAP: 'Scalar Map',
78 ISOSURFACES: 'Iso Surfaces',
79 CUTPLANES: 'Cut Planes',
80 CUTLINES: 'Cut Lines',
81 DEFORMEDSHAPE: 'Deformed Shape',
82 DEFORMEDSHAPESCALARMAP: 'Deformed Shape And Scalar Map',
85 STREAMLINES: 'Stream Lines',
86 GAUSSPOINTS: 'Gauss Points'}
89 def get_name(cls, type):
90 """Return presentaion name by its type."""
91 return cls._type2name[type]
101 _type2name = {NODE: 'P1',
104 _name2type = {'P1': NODE,
107 _type2pvtype = {NODE: 'POINT_DATA',
111 def get_name(cls, type):
112 """Return entity name (used in full group names) by its type."""
113 return cls._type2name[type]
116 def get_type(cls, name):
117 """Return entity type by its name (used in full group names)."""
118 return cls._name2type[name]
121 def get_pvtype(cls, type):
122 """Return entity type from ['CELL_DATA', 'POINT_DATA']"""
123 return cls._type2pvtype[type]
127 """Orientation types.
129 Defines a set of plane orientation possibilities:
130 AUTO: plane orientation should be calculated.
131 XY: plane formed by X and Y axis.
132 YZ: plane formed by Y and Z axis.
133 ZX: plane formed by Z and X axis
145 Set of elements defining the position of the vector head:
146 CENTER: in the center of the vector
147 TAIL: in the tail of the vector
148 HEAD: in the head of the vector
158 Gauss Points primitive types.
164 _type2mode = {SPRITE: 'Texture',
165 POINT: 'SimplePoint',
166 SPHERE: 'Sphere (Texture)'}
169 def get_mode(cls, type):
170 """Return paraview point sprite mode by the primitive type."""
171 return cls._type2mode[type]
174 # Auxiliary functions
176 def get_field_mesh_name(full_field_name):
177 """Return mesh name of the field by its full name."""
178 aList = full_field_name.split('/')
180 field_name = full_field_name.split('/')[1]
184 def get_field_entity(full_field_name):
185 """Return entity type of the field by its full name."""
186 aList = full_field_name.split(_med_field_sep)
188 entity_name = full_field_name.split(_med_field_sep)[-1]
189 entity = EntityType.get_type(entity_name)
193 def get_field_short_name(full_field_name):
194 """Return short name of the field by its full name."""
195 aList = full_field_name.split('/')
197 short_name_with_type = full_field_name.split('/')[-1]
198 short_name = short_name_with_type.split(_med_field_sep)[0]
202 def process_prs_for_test(prs, view, picture_name, show_bar=True):
203 """Show presentation and record snapshot image.
206 prs: the presentation to show
207 view: the render view
208 picture_name: the full name of the graphics file to save
209 show_bar: to show scalar bar or not
212 # Show the presentation only
213 display_only(prs, view)
216 if show_bar and _current_bar:
217 _current_bar.Visibility = 1
222 # Create a directory for screenshot if necessary
223 file_name = re.sub("\s+", "_", picture_name)
224 pic_dir = os.path.dirname(picture_name)
225 if not os.path.exists(pic_dir):
229 pvs.WriteImage(file_name, view=view, Magnification=1)
232 def reset_view(view=None):
235 Set predefined (taken from Post-Pro) camera settings.
236 If the view is not passed, the active view is used.
240 view = pvs.GetRenderView()
243 view.CameraFocalPoint = [0.0, 0.0, 0.0]
244 view.CameraViewUp = [0.0, 0.0, 1.0]
245 view.CameraPosition = [738.946, -738.946, 738.946]
247 # Turn on the headligth
249 view.LightIntensity = 0.5
251 # Use parallel projection
252 view.CameraParallelProjection = 1
255 pvs.Render(view=view)
258 def hide_all(view, to_remove=False):
259 """Hide all representations in the view."""
261 view = pvs.GetRenderView()
263 rep_list = view.Representations
265 if hasattr(rep, 'Visibility') and rep.Visibility != 0:
268 view.Representations.remove(rep)
269 pvs.Render(view=view)
272 def display_only(prs, view=None):
273 """Display only the given presentation in the view."""
275 view = pvs.GetRenderView()
277 rep_list = view.Representations
279 if hasattr(rep, 'Visibility'):
280 rep.Visibility = (rep == prs)
281 pvs.Render(view=view)
284 def set_visible_lines(xy_prs, lines):
285 """Set visible only the given lines for XYChartRepresentation."""
286 sv = xy_prs.GetProperty("SeriesVisibilityInfo").GetData()
289 for i in xrange(0, len(sv)):
292 if line_name in lines:
299 xy_prs.SeriesVisibility = sv
302 def check_vector_mode(vector_mode, nb_components):
303 """Check vector mode.
305 Check if vector mode is correct for the data array with the
306 given number of components.
309 vector_mode: 'Magnitude', 'X', 'Y' or 'Z'
310 nb_components: number of component in the data array
313 ValueError: in case of the vector mode is unexistent
317 if vector_mode not in ('Magnitude', 'X', 'Y', 'Z'):
318 raise ValueError("Unexistent vector mode: " + vector_mode)
320 if ((nb_components == 1 and (vector_mode == 'Y' or vector_mode == 'Z')) or
321 (nb_components == 2 and vector_mode == 'Z')):
322 raise ValueError("Incorrect vector mode " + vector_mode + " for " +
323 nb_components + "-component field")
326 def get_vector_component(vector_mode):
327 """Get vector component as ineger.
329 Translate vector component notation from string
339 if vector_mode == 'X':
341 elif vector_mode == 'Y':
343 elif vector_mode == 'Z':
349 def get_data_range(proxy, entity, field_name, vector_mode='Magnitude',
351 """Get data range for the field.
354 proxy: the pipeline object, containig data array for the field
355 entity: the field entity
356 field_name: the field name
357 vector_mode: the vector mode ('Magnitude', 'X', 'Y' or 'Z')
360 Data range as [min, max]
363 entity_data_info = None
364 field_data = proxy.GetFieldDataInformation()
366 if field_name in field_data.keys():
367 entity_data_info = field_data
368 elif entity == EntityType.CELL:
369 entity_data_info = proxy.GetCellDataInformation()
370 elif entity == EntityType.NODE:
371 entity_data_info = proxy.GetPointDataInformation()
375 if field_name in entity_data_info.keys():
376 vcomp = get_vector_component(vector_mode)
377 data_range = entity_data_info[field_name].GetComponentRange(vcomp)
379 pv_entity = EntityType.get_pvtype(entity)
380 warnings.warn("Field " + field_name +
381 " is unknown for " + pv_entity + "!")
384 if cut_off and (data_range[0] <= data_range[1]):
385 data_range = list(data_range)
386 delta = abs(data_range[1] - data_range[0]) * GAP_COEFFICIENT
387 data_range[0] += delta
388 data_range[1] -= delta
393 def get_bounds(proxy):
394 """Get bounds of the proxy in 3D."""
395 dataInfo = proxy.GetDataInformation()
396 bounds_info = dataInfo.GetBounds()
400 def get_x_range(proxy):
401 """Get X range of the proxy bounds in 3D."""
402 bounds_info = get_bounds(proxy)
403 return bounds_info[0:2]
406 def get_y_range(proxy):
407 """Get Y range of the proxy bounds in 3D."""
408 bounds_info = get_bounds(proxy)
409 return bounds_info[2:4]
412 def get_z_range(proxy):
413 """Get Z range of the proxy bounds in 3D."""
414 bounds_info = get_bounds(proxy)
415 return bounds_info[4:6]
418 def is_planar_input(proxy):
419 """Check if the given input is planar."""
420 bounds_info = get_bounds(proxy)
422 if (abs(bounds_info[0] - bounds_info[1]) <= FLT_MIN or
423 abs(bounds_info[2] - bounds_info[3]) <= FLT_MIN or
424 abs(bounds_info[4] - bounds_info[5]) <= FLT_MIN):
430 def is_data_on_cells(proxy, field_name):
431 """Check the existence of a field on cells with the given name."""
432 cell_data_info = proxy.GetCellDataInformation()
433 return (field_name in cell_data_info.keys())
437 """Check if the object contains any points or cells.
440 True: if the given proxy doesn't contain any points or cells
444 data_info = proxy.GetDataInformation()
446 nb_cells = data_info.GetNumberOfCells()
447 nb_points = data_info.GetNumberOfPoints()
449 return not(nb_cells + nb_points)
452 def get_orientation(proxy):
453 """Get the optimum cutting plane orientation for Plot 3D."""
454 orientation = Orientation.XY
456 bounds = get_bounds(proxy)
457 delta = [bounds[1] - bounds[0],
458 bounds[3] - bounds[2],
459 bounds[5] - bounds[4]]
461 if (delta[0] >= delta[1] and delta[0] >= delta[2]):
462 if (delta[1] >= delta[2]):
463 orientation = Orientation.XY
465 orientation = Orientation.ZX
466 elif (delta[1] >= delta[0] and delta[1] >= delta[2]):
467 if (delta[0] >= delta[2]):
468 orientation = Orientation.XY
470 orientation = Orientation.YZ
471 elif (delta[2] >= delta[0] and delta[2] >= delta[1]):
472 if (delta[0] >= delta[1]):
473 orientation = Orientation.ZX
475 orientation = Orientation.YZ
480 def dot_product(a, b):
481 """Dot product of two 3-vectors."""
482 dot = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
486 def multiply3x3(a, b):
487 """Mutltiply one 3x3 matrix by another."""
493 c[0][i] = a[0][0] * b[0][i] + a[0][1] * b[1][i] + a[0][2] * b[2][i]
494 c[1][i] = a[1][0] * b[0][i] + a[1][1] * b[1][i] + a[1][2] * b[2][i]
495 c[2][i] = a[2][0] * b[0][i] + a[2][1] * b[1][i] + a[2][2] * b[2][i]
501 """Get X rotation matrix by angle."""
502 rx = [[1.0, 0.0, 0.0],
503 [0.0, cos(ang), -sin(ang)],
504 [0.0, sin(ang), cos(ang)]]
510 """Get Y rotation matrix by angle."""
511 ry = [[cos(ang), 0.0, sin(ang)],
513 [-sin(ang), 0.0, cos(ang)]]
519 """Get Z rotation matrix by angle."""
520 rz = [[cos(ang), -sin(ang), 0.0],
521 [sin(ang), cos(ang), 0.0],
527 def get_normal_by_orientation(orientation, ang1=0, ang2=0):
528 """Get normal for the plane by its orientation."""
530 rotation = [[], [], []]
531 rx = ry = rz = [[1.0, 0.0, 0.0],
535 normal = [0.0, 0.0, 0.0]
536 if orientation == Orientation.XY:
541 rotation = multiply3x3(rx, ry)
543 elif orientation == Orientation.ZX:
548 rotation = multiply3x3(rz, rx)
550 elif orientation == Orientation.YZ:
555 rotation = multiply3x3(ry, rz)
558 for i in xrange(0, 3):
559 normal[i] = rotation[i][i_plane]
564 def get_bound_project(bound_box, dir):
565 """Get bounds projection"""
566 bound_points = [[bound_box[0], bound_box[2], bound_box[4]],
567 [bound_box[1], bound_box[2], bound_box[4]],
568 [bound_box[0], bound_box[3], bound_box[4]],
569 [bound_box[1], bound_box[3], bound_box[4]],
570 [bound_box[0], bound_box[2], bound_box[5]],
571 [bound_box[1], bound_box[2], bound_box[5]],
572 [bound_box[0], bound_box[3], bound_box[5]],
573 [bound_box[1], bound_box[3], bound_box[5]]]
575 bound_prj = [0, 0, 0]
576 bound_prj[0] = dot_product(dir, bound_points[0])
577 bound_prj[1] = bound_prj[0]
579 for i in xrange(1, 8):
580 tmp = dot_product(dir, bound_points[i])
581 if bound_prj[1] < tmp:
583 if bound_prj[0] > tmp:
586 bound_prj[2] = bound_prj[1] - bound_prj[0]
587 bound_prj[1] = bound_prj[0] + (1.0 - EPS) * bound_prj[2]
588 bound_prj[0] = bound_prj[0] + EPS * bound_prj[2]
589 bound_prj[2] = bound_prj[1] - bound_prj[0]
594 def get_positions(nb_planes, dir, bounds, displacement):
595 """Compute plane positions."""
597 bound_prj = get_bound_project(bounds, dir)
599 step = bound_prj[2] / (nb_planes - 1)
600 abs_displacement = step * displacement
601 start_pos = bound_prj[0] - 0.5 * step + abs_displacement
602 for i in xrange(nb_planes):
603 pos = start_pos + i * step
604 positions.append(pos)
606 pos = bound_prj[0] + bound_prj[2] * displacement
607 positions.append(pos)
612 def get_contours(scalar_range, nb_contours):
613 """Generate contour values."""
615 for i in xrange(nb_contours):
616 pos = scalar_range[0] + i * (
617 scalar_range[1] - scalar_range[0]) / (nb_contours - 1)
623 def get_nb_components(proxy, entity, field_name):
624 """Return number of components for the field."""
625 entity_data_info = None
626 field_data = proxy.GetFieldDataInformation()
628 if field_name in field_data.keys():
629 entity_data_info = field_data
630 elif entity == EntityType.CELL:
631 entity_data_info = proxy.GetCellDataInformation()
632 elif entity == EntityType.NODE:
633 entity_data_info = proxy.GetPointDataInformation()
636 if field_name in entity_data_info.keys():
637 nb_comp = entity_data_info[field_name].GetNumberOfComponents()
639 pv_entity = EntityType.get_pvtype(entity)
640 raise ValueError("Field " + field_name +
641 " is unknown for " + pv_entity + "!")
646 def get_scale_factor(proxy):
647 """Compute scale factor."""
651 proxy.UpdatePipeline()
652 data_info = proxy.GetDataInformation()
654 nb_cells = data_info.GetNumberOfCells()
655 nb_points = data_info.GetNumberOfPoints()
656 nb_elements = nb_cells if nb_cells > 0 else nb_points
657 bounds = get_bounds(proxy)
662 for i in xrange(0, 6, 2):
663 vol = abs(bounds[i + 1] - bounds[i])
668 if nb_elements == 0 or dim < 1 / VTK_LARGE_FLOAT:
671 volume /= nb_elements
673 return pow(volume, 1 / dim)
676 def get_default_scale(prs_type, proxy, entity, field_name):
677 """Get default scale factor."""
678 data_range = get_data_range(proxy, entity, field_name)
680 if prs_type == PrsTypeEnum.DEFORMEDSHAPE:
681 EPS = 1.0 / VTK_LARGE_FLOAT
682 if abs(data_range[1]) > EPS:
683 scale_factor = get_scale_factor(proxy)
684 return scale_factor / data_range[1]
685 elif prs_type == PrsTypeEnum.PLOT3D:
686 bounds = get_bounds(proxy)
687 length = sqrt((bounds[1] - bounds[0]) ** 2 +
688 (bounds[3] - bounds[2]) ** 2 +
689 (bounds[5] - bounds[4]) ** 2)
692 if data_range[1] > 0:
693 return length / data_range[1] * EPS
698 def get_calc_magnitude(proxy, array_entity, array_name):
699 """Compute magnitude for the given vector array via Calculator.
702 the calculator object.
707 # Transform vector array to scalar array if possible
708 nb_components = get_nb_components(proxy, array_entity, array_name)
709 if (nb_components > 1):
710 calculator = pvs.Calculator(proxy)
711 attribute_mode = "Point Data"
712 if array_entity != EntityType.NODE:
713 attribute_mode = "Cell Data"
714 calculator.AttributeMode = attribute_mode
715 if (nb_components == 2):
716 # Workaroud: calculator unable to compute magnitude
717 # if number of components equal to 2
718 func = "sqrt(" + array_name + "_X^2+" + array_name + "_Y^2)"
719 calculator.Function = func
721 calculator.Function = "mag(" + array_name + ")"
722 calculator.ResultArrayName = array_name + "_magnitude"
723 calculator.UpdatePipeline()
728 def get_add_component_calc(proxy, array_entity, array_name):
729 """Creates 3-component array from 2-component.
731 The first two components is from the original array. The 3rd component
733 If the number of components is not equal to 2 - return original array name.
736 the calculator object.
741 nb_components = get_nb_components(proxy, array_entity, array_name)
742 if nb_components == 2:
743 calculator = pvs.Calculator(proxy)
744 attribute_mode = "Point Data"
745 if array_entity != EntityType.NODE:
746 attribute_mode = "Cell Data"
747 calculator.AttributeMode = attribute_mode
748 expression = "iHat * " + array_name + "_X + jHat * " + array_name + "_Y + kHat * 0"
749 calculator.Function = expression
750 calculator.ResultArrayName = array_name + "_3c"
751 calculator.UpdatePipeline()
756 def select_all_cells(proxy):
757 """Select all cell types.
759 Used in creation of mesh/submesh presentation.
762 extractCT = pvs.ExtractCellType()
763 extractCT.AllGeoTypes = extractCT.GetProperty("GeoTypesInfo")[::2]
766 def select_cells_with_data(proxy, on_points=None, on_cells=None):
767 """Select cell types with data.
769 Only cell types with data for the given fields will be selected.
770 If no fields defined (neither on points nor on cells) only cell
771 types with data for even one field (from available) will be selected.
774 if not hasattr(proxy, 'Entity'):
777 #all_cell_types = proxy.CellTypes.Available
778 all_cell_types = proxy.Entity.Available
779 all_arrays = list(proxy.CellArrays.GetData())
780 all_arrays.extend(proxy.PointArrays.GetData())
783 file_name = proxy.FileName.split(os.sep)[-1]
784 print "Warning: " + file_name + " doesn't contain any data array."
786 # List of cell types to be selected
789 for cell_type in all_cell_types:
790 #proxy.CellTypes = [cell_type]
791 proxy.Entity = [cell_type]
792 proxy.UpdatePipeline()
794 cell_arrays = proxy.GetCellDataInformation().keys()
795 point_arrays = proxy.GetPointDataInformation().keys()
797 if on_points or on_cells:
798 if on_points is None:
803 if (all(array in cell_arrays for array in on_cells) and
804 all(array in point_arrays for array in on_points)):
805 # Add cell type to the list
806 cell_types_on.append(cell_type)
808 in_arrays = lambda array: ((array in cell_arrays) or
809 (array in point_arrays))
810 if any(in_arrays(array) for array in all_arrays):
811 cell_types_on.append(cell_type)
814 #proxy.CellTypes = cell_types_on
815 proxy.Entity = cell_types_on
816 proxy.UpdatePipeline()
818 def if_possible(proxy, field_name, entity, prs_type):
819 """Check if the presentation creation is possible on the given field."""
821 if (prs_type == PrsTypeEnum.DEFORMEDSHAPE or
822 prs_type == PrsTypeEnum.DEFORMEDSHAPESCALARMAP or
823 prs_type == PrsTypeEnum.VECTORS or
824 prs_type == PrsTypeEnum.STREAMLINES):
825 nb_comp = get_nb_components(proxy, entity, field_name)
826 result = (nb_comp > 1)
827 elif (prs_type == PrsTypeEnum.GAUSSPOINTS):
828 result = (entity == EntityType.CELL or
829 field_name in proxy.QuadraturePointArrays.Available)
830 elif (prs_type == PrsTypeEnum.MESH):
831 result = len(get_group_names(proxy, field_name, entity)) > 0
836 def add_scalar_bar(field_name, nb_components,
837 vector_mode, lookup_table, time_value):
838 """Add scalar bar with predefined properties."""
841 # Construct bar title
842 title = "\n".join([field_name, str(time_value)])
843 if nb_components > 1:
844 title = "\n".join([title, vector_mode])
847 scalar_bar = pvs.CreateScalarBar(Enabled=1)
848 scalar_bar.Orientation = 'Vertical'
849 scalar_bar.Title = title
850 scalar_bar.LookupTable = lookup_table
852 # Set default properties same as in Post-Pro
853 scalar_bar.NumberOfLabels = 5
854 scalar_bar.AutomaticLabelFormat = 0
855 scalar_bar.LabelFormat = '%-#6.6g'
857 scalar_bar.TitleFontFamily = 'Arial'
858 scalar_bar.TitleFontSize = 8
859 scalar_bar.TitleBold = 1
860 scalar_bar.TitleItalic = 1
861 scalar_bar.TitleShadow = 1
863 scalar_bar.LabelFontFamily = 'Arial'
864 scalar_bar.LabelFontSize = 8
865 scalar_bar.LabelBold = 1
866 scalar_bar.LabelItalic = 1
867 scalar_bar.LabelShadow = 1
869 # Add the scalar bar to the view
870 pvs.GetRenderView().Representations.append(scalar_bar)
872 # Reassign the current bar
873 _current_bar = scalar_bar
879 """Get current scalar bar."""
885 def get_lookup_table(field_name, nb_components, vector_mode='Magnitude'):
886 """Get lookup table for the given field."""
887 lookup_table = pvs.GetLookupTableForArray(field_name, nb_components)
889 if vector_mode == 'Magnitude':
890 lookup_table.VectorMode = vector_mode
891 elif vector_mode == 'X':
892 lookup_table.VectorMode = 'Component'
893 lookup_table.VectorComponent = 0
894 elif vector_mode == 'Y':
895 lookup_table.VectorMode = 'Component'
896 lookup_table.VectorComponent = 1
897 elif vector_mode == 'Z':
898 lookup_table.VectorMode = 'Component'
899 lookup_table.VectorComponent = 2
901 raise ValueError("Incorrect vector mode: " + vector_mode)
903 lookup_table.Discretize = 0
904 lookup_table.ColorSpace = 'HSV'
905 lookup_table.LockScalarRange = 0
910 def get_group_mesh_name(full_group_name):
911 """Return mesh name of the group by its full name."""
912 aList = full_group_name.split('/')
914 group_name = full_group_name.split('/')[1]
918 def get_group_entity(full_group_name):
919 """Return entity type of the group by its full name."""
920 aList = full_group_name.split('/')
922 entity_name = full_group_name.split('/')[2]
923 entity = EntityType.get_type(entity_name)
927 def get_group_short_name(full_group_name):
928 """Return short name of the group by its full name."""
929 aList = full_group_name.split('/')
931 short_name = full_group_name.split('/')[3]
935 def get_mesh_names(proxy):
936 """Return all mesh names in the given proxy as a set."""
937 fields = proxy.GetProperty("FieldsTreeInfo")[::2]
938 mesh_names = set([get_field_mesh_name(item) for item in fields])
942 def get_group_names(proxy, mesh_name, entity, wo_nogroups=False):
943 """Return full names of all groups of the given entity type
944 from the mesh with the given name as a list.
946 groups = proxy.Groups.Available
948 condition = lambda item: (get_group_mesh_name(item) == mesh_name and
949 get_group_entity(item) == entity)
950 group_names = [item for item in groups if condition(item)]
953 # Remove "No_Group" group
954 not_no_group = lambda item: get_group_short_name(item) != "No_Group"
955 group_names = filter(not_no_group, group_names)
960 def get_time(proxy, timestamp_nb):
961 """Get time value by timestamp number."""
962 # Check timestamp number
965 if (hasattr(proxy, 'TimestepValues')):
966 timestamps = proxy.TimestepValues.GetData()
967 elif (hasattr(proxy.Input, 'TimestepValues')):
968 timestamps = proxy.Input.TimestepValues.GetData()
970 length = len(timestamps)
971 if (timestamp_nb > 0 and (timestamp_nb - 1) not in xrange(length) ) or (timestamp_nb < 0 and -timestamp_nb > length):
972 raise ValueError("Timestamp number is out of range: " + str(timestamp_nb))
976 return timestamps[timestamp_nb - 1]
978 return timestamps[timestamp_nb]
980 def create_prs(prs_type, proxy, field_entity, field_name, timestamp_nb):
981 """Auxiliary function.
983 Build presentation of the given type on the given field and
985 Set the presentation properties like visu.CreatePrsForResult() do.
990 if prs_type == PrsTypeEnum.SCALARMAP:
991 prs = ScalarMapOnField(proxy, field_entity, field_name, timestamp_nb)
992 elif prs_type == PrsTypeEnum.CUTPLANES:
993 prs = CutPlanesOnField(proxy, field_entity, field_name, timestamp_nb,
994 orientation=Orientation.ZX)
995 elif prs_type == PrsTypeEnum.CUTLINES:
996 prs = CutLinesOnField(proxy, field_entity, field_name, timestamp_nb,
997 orientation1=Orientation.XY,
998 orientation2=Orientation.ZX)
999 elif prs_type == PrsTypeEnum.DEFORMEDSHAPE:
1000 prs = DeformedShapeOnField(proxy, field_entity,
1001 field_name, timestamp_nb)
1002 elif prs_type == PrsTypeEnum.DEFORMEDSHAPESCALARMAP:
1003 prs = DeformedShapeAndScalarMapOnField(proxy, field_entity,
1004 field_name, timestamp_nb)
1005 elif prs_type == PrsTypeEnum.VECTORS:
1006 prs = VectorsOnField(proxy, field_entity, field_name, timestamp_nb)
1007 elif prs_type == PrsTypeEnum.PLOT3D:
1008 prs = Plot3DOnField(proxy, field_entity, field_name, timestamp_nb)
1009 elif prs_type == PrsTypeEnum.ISOSURFACES:
1010 prs = IsoSurfacesOnField(proxy, field_entity, field_name, timestamp_nb)
1011 elif prs_type == PrsTypeEnum.GAUSSPOINTS:
1012 prs = GaussPointsOnField(proxy, field_entity, field_name, timestamp_nb)
1013 elif prs_type == PrsTypeEnum.STREAMLINES:
1014 prs = StreamLinesOnField(proxy, field_entity, field_name, timestamp_nb)
1016 raise ValueError("Unexistent presentation type.")
1021 # Functions for building Post-Pro presentations
1022 def ScalarMapOnField(proxy, entity, field_name, timestamp_nb,
1023 vector_mode='Magnitude'):
1024 """Creates Scalar Map presentation on the given field.
1027 proxy: the pipeline object, containig data
1028 entity: the entity type from PrsTypeEnum
1029 field_name: the field name
1030 timestamp_nb: the number of time step (1, 2, ...)
1031 vector_mode: the mode of transformation of vector values
1032 into scalar values, applicable only if the field contains vector values.
1033 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1036 Scalar Map as representation object.
1039 # We don't need mesh parts with no data on them
1040 if entity == EntityType.NODE:
1041 select_cells_with_data(proxy, on_points=[field_name])
1043 select_cells_with_data(proxy, on_cells=[field_name])
1046 nb_components = get_nb_components(proxy, entity, field_name)
1047 check_vector_mode(vector_mode, nb_components)
1050 time_value = get_time(proxy, timestamp_nb)
1053 pvs.GetRenderView().ViewTime = time_value
1054 pvs.UpdatePipeline(time_value, proxy)
1056 # Get Scalar Map representation object
1057 scalarmap = pvs.GetRepresentation(proxy)
1060 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1062 # Set field range if necessary
1063 data_range = get_data_range(proxy, entity,
1064 field_name, vector_mode)
1065 lookup_table.LockScalarRange = 1
1066 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1068 scalarmap.ColorAttributeType = EntityType.get_pvtype(entity)
1069 scalarmap.ColorArrayName = field_name
1070 scalarmap.LookupTable = lookup_table
1073 bar_title = field_name + ", " + str(time_value)
1074 if (nb_components > 1):
1075 bar_title += "\n" + vector_mode
1076 add_scalar_bar(field_name, nb_components, vector_mode,
1077 lookup_table, time_value)
1082 def CutPlanesOnField(proxy, entity, field_name, timestamp_nb,
1083 nb_planes=10, orientation=Orientation.YZ,
1085 displacement=0.5, vector_mode='Magnitude'):
1086 """Creates Cut Planes presentation on the given field.
1089 proxy: the pipeline object, containig data
1090 entity: the entity type from PrsTypeEnum
1091 field_name: the field name
1092 timestamp_nb: the number of time step (1, 2, ...)
1093 nb_planes: number of cutting planes
1094 orientation: cutting planes orientation in 3D space
1095 angle1: rotation of the planes in 3d space around the first axis of the
1096 selected orientation (X axis for XY, Y axis for YZ, Z axis for ZX).
1097 The angle of rotation is set in degrees. Acceptable range: [-45, 45].
1098 angle2: rotation of the planes in 3d space around the second axis of the
1099 selected orientation. Acceptable range: [-45, 45].
1100 displacement: the displacement of the planes into one or another side
1101 vector_mode: the mode of transformation of vector values
1102 into scalar values, applicable only if the field contains vector values.
1103 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1106 Cut Planes as representation object.
1110 nb_components = get_nb_components(proxy, entity, field_name)
1111 check_vector_mode(vector_mode, nb_components)
1114 time_value = get_time(proxy, timestamp_nb)
1117 pvs.GetRenderView().ViewTime = time_value
1118 pvs.UpdatePipeline(time_value, proxy)
1120 # Create slice filter
1121 slice_filter = pvs.Slice(proxy)
1122 slice_filter.SliceType = "Plane"
1124 # Set cut planes normal
1125 normal = get_normal_by_orientation(orientation,
1126 radians(angle1), radians(angle2))
1127 slice_filter.SliceType.Normal = normal
1129 # Set cut planes positions
1130 positions = get_positions(nb_planes, normal,
1131 get_bounds(proxy), displacement)
1132 slice_filter.SliceOffsetValues = positions
1134 # Get Cut Planes representation object
1135 cut_planes = pvs.GetRepresentation(slice_filter)
1138 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1140 # Set field range if necessary
1141 data_range = get_data_range(proxy, entity,
1142 field_name, vector_mode)
1143 lookup_table.LockScalarRange = 1
1144 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1147 cut_planes.ColorAttributeType = EntityType.get_pvtype(entity)
1148 cut_planes.ColorArrayName = field_name
1149 cut_planes.LookupTable = lookup_table
1152 add_scalar_bar(field_name, nb_components,
1153 vector_mode, lookup_table, time_value)
1158 def CutLinesOnField(proxy, entity, field_name, timestamp_nb,
1160 orientation1=Orientation.XY,
1161 base_angle1=0, base_angle2=0,
1162 orientation2=Orientation.YZ,
1163 cut_angle1=0, cut_angle2=0,
1164 displacement1=0.5, displacement2=0.5,
1165 generate_curves=False,
1166 vector_mode='Magnitude'):
1167 """Creates Cut Lines presentation on the given field.
1170 proxy: the pipeline object, containig data
1171 entity: the entity type from PrsTypeEnum
1172 field_name: the field name
1173 timestamp_nb: the number of time step (1, 2, ...)
1174 nb_lines: number of lines
1175 orientation1: base plane orientation in 3D space
1176 base_angle1: rotation of the base plane in 3d space around the first
1177 axis of the orientation1 (X axis for XY, Y axis for YZ, Z axis for ZX).
1178 The angle of rotation is set in degrees. Acceptable range: [-45, 45].
1179 base_angle2: rotation of the base plane in 3d space around the second
1180 axis of the orientation1. Acceptable range: [-45, 45].
1181 orientation2: cutting planes orientation in 3D space
1182 cut_angle1: rotation of the cut planes in 3d space around the first
1183 axis of the orientation2. Acceptable range: [-45, 45].
1184 cut_angle2: rotation of the cuting planes in 3d space around the second
1185 axis of the orientation2. Acceptable range: [-45, 45].
1186 displacement1: base plane displacement
1187 displacement2: cutting planes displacement
1188 generate_curves: if true, 'PlotOverLine' filter will be created
1190 vector_mode: the mode of transformation of vector values
1191 into scalar values, applicable only if the field contains vector values.
1192 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1195 Cut Lines as representation object if generate_curves == False,
1196 (Cut Lines as representation object, list of 'PlotOverLine') otherwise
1200 nb_components = get_nb_components(proxy, entity, field_name)
1201 check_vector_mode(vector_mode, nb_components)
1204 time_value = get_time(proxy, timestamp_nb)
1207 pvs.GetRenderView().ViewTime = time_value
1208 pvs.UpdatePipeline(time_value, proxy)
1211 base_plane = pvs.Slice(proxy)
1212 base_plane.SliceType = "Plane"
1214 # Set base plane normal
1215 base_normal = get_normal_by_orientation(orientation1,
1216 radians(base_angle1),
1217 radians(base_angle2))
1218 base_plane.SliceType.Normal = base_normal
1220 # Set base plane position
1221 base_position = get_positions(1, base_normal,
1222 get_bounds(proxy), displacement1)
1223 base_plane.SliceOffsetValues = base_position
1226 base_plane.UpdatePipeline()
1227 if (base_plane.GetDataInformation().GetNumberOfCells() == 0):
1230 # Create cutting planes
1231 cut_planes = pvs.Slice(base_plane)
1232 cut_planes.SliceType = "Plane"
1234 # Set cutting planes normal and get positions
1235 cut_normal = get_normal_by_orientation(orientation2,
1236 radians(cut_angle1),
1237 radians(cut_angle2))
1238 cut_planes.SliceType.Normal = cut_normal
1240 # Set cutting planes position
1241 cut_positions = get_positions(nb_lines, cut_normal,
1242 get_bounds(base_plane), displacement2)
1248 for pos in cut_positions:
1249 # Get points for plot over line objects
1250 cut_planes.SliceOffsetValues = pos
1251 cut_planes.UpdatePipeline()
1252 bounds = get_bounds(cut_planes)
1253 point1 = [bounds[0], bounds[2], bounds[4]]
1254 point2 = [bounds[1], bounds[3], bounds[5]]
1256 # Create plot over line filter
1257 pol = pvs.PlotOverLine(cut_planes,
1258 Source="High Resolution Line Source")
1259 pvs.RenameSource('Y' + str(index), pol)
1260 pol.Source.Point1 = point1
1261 pol.Source.Point2 = point2
1262 pol.UpdatePipeline()
1267 cut_planes.SliceOffsetValues = cut_positions
1268 cut_planes.UpdatePipeline()
1270 # Get Cut Lines representation object
1271 cut_lines = pvs.GetRepresentation(cut_planes)
1274 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1276 # Set field range if necessary
1277 data_range = get_data_range(proxy, entity,
1278 field_name, vector_mode)
1279 lookup_table.LockScalarRange = 1
1280 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1283 cut_lines.ColorAttributeType = EntityType.get_pvtype(entity)
1284 cut_lines.ColorArrayName = field_name
1285 cut_lines.LookupTable = lookup_table
1287 # Set wireframe represenatation mode
1288 cut_lines.Representation = 'Wireframe'
1291 add_scalar_bar(field_name, nb_components,
1292 vector_mode, lookup_table, time_value)
1295 # If curves were generated return tuple (cut lines, list of curves)
1297 result = cut_lines, curves
1302 def CutSegmentOnField(proxy, entity, field_name, timestamp_nb,
1303 point1, point2, vector_mode='Magnitude'):
1304 """Creates Cut Segment presentation on the given field.
1307 proxy: the pipeline object, containig data
1308 entity: the entity type from PrsTypeEnum
1309 field_name: the field name
1310 timestamp_nb: the number of time step (1, 2, ...)
1311 point1: set the first point of the segment (as [x, y, z])
1312 point1: set the second point of the segment (as [x, y, z])
1313 vector_mode: the mode of transformation of vector values
1314 into scalar values, applicable only if the field contains vector values.
1315 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1318 Cut Segment as 3D representation object.
1322 nb_components = get_nb_components(proxy, entity, field_name)
1323 check_vector_mode(vector_mode, nb_components)
1326 time_value = get_time(proxy, timestamp_nb)
1329 pvs.GetRenderView().ViewTime = time_value
1330 pvs.UpdatePipeline(time_value, proxy)
1332 # Create plot over line filter
1333 pol = pvs.PlotOverLine(proxy, Source="High Resolution Line Source")
1334 pol.Source.Point1 = point1
1335 pol.Source.Point2 = point2
1336 pol.UpdatePipeline()
1338 # Get Cut Segment representation object
1339 cut_segment = pvs.GetRepresentation(pol)
1342 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1344 # Set field range if necessary
1345 data_range = get_data_range(proxy, entity,
1346 field_name, vector_mode)
1347 lookup_table.LockScalarRange = 1
1348 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1351 cut_segment.ColorAttributeType = EntityType.get_pvtype(entity)
1352 cut_segment.ColorArrayName = field_name
1353 cut_segment.LookupTable = lookup_table
1355 # Set wireframe represenatation mode
1356 cut_segment.Representation = 'Wireframe'
1359 add_scalar_bar(field_name, nb_components,
1360 vector_mode, lookup_table, time_value)
1365 def VectorsOnField(proxy, entity, field_name, timestamp_nb,
1367 glyph_pos=GlyphPos.TAIL, glyph_type='2D Glyph',
1368 is_colored=False, vector_mode='Magnitude'):
1369 """Creates Vectors presentation on the given field.
1372 proxy: the pipeline object, containig data
1373 entity: the entity type from PrsTypeEnum
1374 field_name: the field name
1375 timestamp_nb: the number of time step (1, 2, ...)
1376 scale_factor: scale factor
1377 glyph_pos: the position of glyphs
1378 glyph_type: the type of glyphs
1379 is_colored: this option allows to color the presentation according to
1380 the corresponding data array values
1381 vector_mode: the mode of transformation of vector values
1382 into scalar values, applicable only if the field contains vector values.
1383 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1386 Vectors as representation object.
1390 nb_components = get_nb_components(proxy, entity, field_name)
1391 check_vector_mode(vector_mode, nb_components)
1394 time_value = get_time(proxy, timestamp_nb)
1397 pvs.GetRenderView().ViewTime = time_value
1398 pvs.UpdatePipeline(time_value, proxy)
1400 # Extract only groups with data for the field
1404 if is_data_on_cells(proxy, field_name):
1405 cell_centers = pvs.CellCenters(source)
1406 cell_centers.VertexCells = 1
1407 source = cell_centers
1409 vector_array = field_name
1410 # If the given vector array has only 2 components, add the third one
1411 if nb_components == 2:
1412 calc = get_add_component_calc(source, EntityType.NODE, field_name)
1413 vector_array = calc.ResultArrayName
1417 glyph = pvs.Glyph(source)
1418 glyph.Vectors = vector_array
1419 glyph.ScaleMode = 'vector'
1420 glyph.MaskPoints = 0
1423 glyph.GlyphType = glyph_type
1424 if glyph_type == '2D Glyph':
1425 glyph.GlyphType.GlyphType = 'Arrow'
1426 elif glyph_type == 'Cone':
1427 glyph.GlyphType.Resolution = 7
1428 glyph.GlyphType.Height = 2
1429 glyph.GlyphType.Radius = 0.2
1431 # Set glyph position if possible
1432 if glyph.GlyphType.GetProperty("Center"):
1433 if (glyph_pos == GlyphPos.TAIL):
1434 glyph.GlyphType.Center = [0.5, 0.0, 0.0]
1435 elif (glyph_pos == GlyphPos.HEAD):
1436 glyph.GlyphType.Center = [-0.5, 0.0, 0.0]
1437 elif (glyph_pos == GlyphPos.CENTER):
1438 glyph.GlyphType.Center = [0.0, 0.0, 0.0]
1440 if scale_factor is not None:
1441 glyph.SetScaleFactor = scale_factor
1443 def_scale = get_default_scale(PrsTypeEnum.DEFORMEDSHAPE,
1444 proxy, entity, field_name)
1445 glyph.SetScaleFactor = def_scale
1447 glyph.UpdatePipeline()
1449 # Get Vectors representation object
1450 vectors = pvs.GetRepresentation(glyph)
1453 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1455 # Set field range if necessary
1456 data_range = get_data_range(proxy, entity,
1457 field_name, vector_mode)
1458 lookup_table.LockScalarRange = 1
1459 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1463 vectors.ColorArrayName = 'GlyphVector'
1465 vectors.ColorArrayName = ''
1466 vectors.LookupTable = lookup_table
1468 vectors.LineWidth = 1.0
1470 # Set wireframe represenatation mode
1471 vectors.Representation = 'Wireframe'
1474 add_scalar_bar(field_name, nb_components,
1475 vector_mode, lookup_table, time_value)
1480 def DeformedShapeOnField(proxy, entity, field_name,
1482 scale_factor=None, is_colored=False,
1483 vector_mode='Magnitude'):
1484 """Creates Defromed Shape presentation on the given field.
1487 proxy: the pipeline object, containig data
1488 entity: the entity type from PrsTypeEnum
1489 field_name: the field name
1490 timestamp_nb: the number of time step (1, 2, ...)
1491 scale_factor: scale factor of the deformation
1492 is_colored: this option allows to color the presentation according to
1493 the corresponding data array values
1494 vector_mode: the mode of transformation of vector values
1495 into scalar values, applicable only if the field contains vector values.
1496 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1499 Defromed Shape as representation object.
1502 # We don't need mesh parts with no data on them
1503 if entity == EntityType.NODE:
1504 select_cells_with_data(proxy, on_points=[field_name])
1506 select_cells_with_data(proxy, on_cells=[field_name])
1509 nb_components = get_nb_components(proxy, entity, field_name)
1510 check_vector_mode(vector_mode, nb_components)
1513 time_value = get_time(proxy, timestamp_nb)
1516 pvs.GetRenderView().ViewTime = time_value
1517 pvs.UpdatePipeline(time_value, proxy)
1520 source = pvs.MergeBlocks(proxy)
1522 # Cell data to point data
1523 if is_data_on_cells(proxy, field_name):
1524 cell_to_point = pvs.CellDatatoPointData()
1525 cell_to_point.PassCellData = 1
1526 source = cell_to_point
1528 vector_array = field_name
1529 # If the given vector array has only 2 components, add the third one
1530 if nb_components == 2:
1531 calc = get_add_component_calc(source, EntityType.NODE, field_name)
1532 vector_array = calc.ResultArrayName
1536 warp_vector = pvs.WarpByVector(source)
1537 warp_vector.Vectors = [vector_array]
1538 if scale_factor is not None:
1539 warp_vector.ScaleFactor = scale_factor
1541 def_scale = get_default_scale(PrsTypeEnum.DEFORMEDSHAPE,
1542 proxy, entity, field_name)
1543 warp_vector.ScaleFactor = def_scale
1545 # Get Deformed Shape representation object
1546 defshape = pvs.GetRepresentation(warp_vector)
1549 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1551 # Set field range if necessary
1552 data_range = get_data_range(proxy, entity,
1553 field_name, vector_mode)
1554 lookup_table.LockScalarRange = 1
1555 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1559 defshape.ColorAttributeType = EntityType.get_pvtype(entity)
1560 defshape.ColorArrayName = field_name
1562 defshape.ColorArrayName = ''
1563 defshape.LookupTable = lookup_table
1565 # Set wireframe represenatation mode
1566 defshape.Representation = 'Wireframe'
1569 add_scalar_bar(field_name, nb_components,
1570 vector_mode, lookup_table, time_value)
1575 def DeformedShapeAndScalarMapOnField(proxy, entity, field_name,
1579 scalar_field_name=None,
1580 vector_mode='Magnitude'):
1581 """Creates Defromed Shape And Scalar Map presentation on the given field.
1584 proxy: the pipeline object, containig data
1585 entity: the entity type from PrsTypeEnum
1586 field_name: the field name
1587 timestamp_nb: the number of time step (1, 2, ...)
1588 scale_factor: scale factor of the deformation
1589 scalar_entity: scalar field entity
1590 scalar_field_name: scalar field, i.e. the field for coloring
1591 vector_mode: the mode of transformation of vector values
1592 into scalar values, applicable only if the field contains vector values.
1593 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1596 Defromed Shape And Scalar Map as representation object.
1599 # We don't need mesh parts with no data on them
1603 if entity == EntityType.NODE:
1604 on_points.append(field_name)
1606 on_cells.append(field_name)
1608 if scalar_entity and scalar_field_name:
1609 if scalar_entity == EntityType.NODE:
1610 on_points.append(scalar_field_name)
1612 on_cells.append(scalar_field_name)
1614 select_cells_with_data(proxy, on_points, on_cells)
1617 nb_components = get_nb_components(proxy, entity, field_name)
1618 check_vector_mode(vector_mode, nb_components)
1621 time_value = get_time(proxy, timestamp_nb)
1624 pvs.GetRenderView().ViewTime = time_value
1625 pvs.UpdatePipeline(time_value, proxy)
1627 # Set scalar field by default
1628 scalar_field_entity = scalar_entity
1629 scalar_field = scalar_field_name
1630 if (scalar_field_entity is None) or (scalar_field is None):
1631 scalar_field_entity = entity
1632 scalar_field = field_name
1635 source = pvs.MergeBlocks(proxy)
1637 # Cell data to point data
1638 if is_data_on_cells(proxy, field_name):
1639 cell_to_point = pvs.CellDatatoPointData(source)
1640 cell_to_point.PassCellData = 1
1641 source = cell_to_point
1643 vector_array = field_name
1644 # If the given vector array has only 2 components, add the third one
1645 if nb_components == 2:
1646 calc = get_add_component_calc(source, EntityType.NODE, field_name)
1647 vector_array = calc.ResultArrayName
1651 warp_vector = pvs.WarpByVector(source)
1652 warp_vector.Vectors = [vector_array]
1653 if scale_factor is not None:
1654 warp_vector.ScaleFactor = scale_factor
1656 def_scale = get_default_scale(PrsTypeEnum.DEFORMEDSHAPE,
1657 proxy, entity, field_name)
1658 warp_vector.ScaleFactor = def_scale
1660 # Get Defromed Shape And Scalar Map representation object
1661 defshapemap = pvs.GetRepresentation(warp_vector)
1664 lookup_table = get_lookup_table(scalar_field, nb_components, vector_mode)
1666 # Set field range if necessary
1667 data_range = get_data_range(proxy, scalar_field_entity,
1668 scalar_field, vector_mode)
1669 lookup_table.LockScalarRange = 1
1670 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1673 defshapemap.ColorArrayName = scalar_field
1674 defshapemap.LookupTable = lookup_table
1675 defshapemap.ColorAttributeType = EntityType.get_pvtype(scalar_field_entity)
1678 add_scalar_bar(field_name, nb_components,
1679 vector_mode, lookup_table, time_value)
1684 def Plot3DOnField(proxy, entity, field_name, timestamp_nb,
1685 orientation=Orientation.AUTO,
1687 position=0.5, is_relative=True,
1689 is_contour=False, nb_contours=32,
1690 vector_mode='Magnitude'):
1691 """Creates Plot 3D presentation on the given field.
1694 proxy: the pipeline object, containig data
1695 entity: the entity type from PrsTypeEnum
1696 field_name: the field name
1697 timestamp_nb: the number of time step (1, 2, ...)
1698 orientation: the cut plane plane orientation in 3D space, if
1699 the input is planar - will not be taken into account
1700 angle1: rotation of the cut plane in 3d space around the first axis
1701 of the selected orientation (X axis for XY, Y axis for YZ,
1703 The angle of rotation is set in degrees. Acceptable range: [-45, 45].
1704 angle2: rotation of the cut plane in 3d space around the second axis
1705 of the selected orientation. Acceptable range: [-45, 45].
1706 position: position of the cut plane in the object (ranging from 0 to 1).
1707 The value 0.5 corresponds to cutting by halves.
1708 is_relative: defines if the cut plane position is relative or absolute
1709 scale_factor: deformation scale factor
1710 is_contour: if True - Plot 3D will be represented with a set of contours,
1711 otherwise - Plot 3D will be represented with a smooth surface
1712 nb_contours: number of contours, applied if is_contour is True
1713 vector_mode: the mode of transformation of vector values
1714 into scalar values, applicable only if the field contains vector values.
1715 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1718 Plot 3D as representation object.
1721 # We don't need mesh parts with no data on them
1722 if entity == EntityType.NODE:
1723 select_cells_with_data(proxy, on_points=[field_name])
1725 select_cells_with_data(proxy, on_cells=[field_name])
1728 nb_components = get_nb_components(proxy, entity, field_name)
1729 check_vector_mode(vector_mode, nb_components)
1732 time_value = get_time(proxy, timestamp_nb)
1735 pvs.GetRenderView().ViewTime = time_value
1736 pvs.UpdatePipeline(time_value, proxy)
1739 merge_blocks = pvs.MergeBlocks(proxy)
1740 merge_blocks.UpdatePipeline()
1746 # Define orientation if necessary (auto mode)
1747 plane_orientation = orientation
1748 if (orientation == Orientation.AUTO):
1749 plane_orientation = get_orientation(proxy)
1751 # Get cutting plane normal
1754 if (not is_planar_input(proxy)):
1755 normal = get_normal_by_orientation(plane_orientation,
1756 radians(angle1), radians(angle2))
1758 # Create slice filter
1759 slice_filter = pvs.Slice(merge_blocks)
1760 slice_filter.SliceType = "Plane"
1762 # Set cutting plane normal
1763 slice_filter.SliceType.Normal = normal
1765 # Set cutting plane position
1767 base_position = get_positions(1, normal,
1768 get_bounds(proxy), position)
1769 slice_filter.SliceOffsetValues = base_position
1771 slice_filter.SliceOffsetValues = position
1773 slice_filter.UpdatePipeline()
1774 poly_data = slice_filter
1776 normal = get_normal_by_orientation(plane_orientation, 0, 0)
1780 if not poly_data or poly_data.GetDataInformation().GetNumberOfCells() == 0:
1781 geometry_filter = pvs.GeometryFilter(merge_blocks)
1782 poly_data = geometry_filter
1783 use_normal = 1 # TODO(MZN): workaround
1789 if is_data_on_cells(poly_data, field_name):
1790 # Cell data to point data
1791 cell_to_point = pvs.CellDatatoPointData(poly_data)
1792 cell_to_point.PassCellData = 1
1793 source = cell_to_point
1795 scalars = ['POINTS', field_name]
1797 # Transform vector array to scalar array if necessary
1798 if (nb_components > 1):
1799 calc = get_calc_magnitude(source, EntityType.NODE, field_name)
1800 scalars = ['POINTS', calc.ResultArrayName]
1804 warp_scalar = pvs.WarpByScalar(source)
1805 warp_scalar.Scalars = scalars
1806 warp_scalar.Normal = normal
1807 warp_scalar.UseNormal = use_normal
1808 if scale_factor is not None:
1809 warp_scalar.ScaleFactor = scale_factor
1811 def_scale = get_default_scale(PrsTypeEnum.PLOT3D,
1812 proxy, entity, field_name)
1813 warp_scalar.ScaleFactor = def_scale
1815 warp_scalar.UpdatePipeline()
1816 source = warp_scalar
1820 contour = pvs.Contour(warp_scalar)
1821 contour.PointMergeMethod = "Uniform Binning"
1822 contour.ContourBy = ['POINTS', field_name]
1823 scalar_range = get_data_range(proxy, entity,
1824 field_name, vector_mode)
1825 contour.Isosurfaces = get_contours(scalar_range, nb_contours)
1826 contour.UpdatePipeline()
1829 # Get Plot 3D representation object
1830 plot3d = pvs.GetRepresentation(source)
1833 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1835 # Set field range if necessary
1836 data_range = get_data_range(proxy, entity,
1837 field_name, vector_mode)
1838 lookup_table.LockScalarRange = 1
1839 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1842 plot3d.ColorAttributeType = EntityType.get_pvtype(entity)
1843 plot3d.ColorArrayName = field_name
1844 plot3d.LookupTable = lookup_table
1847 add_scalar_bar(field_name, nb_components,
1848 vector_mode, lookup_table, time_value)
1853 def IsoSurfacesOnField(proxy, entity, field_name, timestamp_nb,
1854 custom_range=None, nb_surfaces=10,
1855 is_colored=True, color=None, vector_mode='Magnitude'):
1856 """Creates Iso Surfaces presentation on the given field.
1859 proxy: the pipeline object, containig data
1860 entity: the entity type from PrsTypeEnum
1861 field_name: the field name
1862 timestamp_nb: the number of time step (1, 2, ...)
1863 custom_range: scalar range, if undefined the source range will be applied
1864 nb_surfaces: number of surfaces, which will be generated
1865 is_colored: this option allows to color the presentation according to
1866 the corresponding data array values. If False - the presentation will
1868 color: defines the presentation color as [R, G, B] triple. Taken into
1869 account only if is_colored is False.
1870 vector_mode: the mode of transformation of vector values
1871 into scalar values, applicable only if the field contains vector values.
1872 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
1875 Iso Surfaces as representation object.
1878 # We don't need mesh parts with no data on them
1879 if entity == EntityType.NODE:
1880 select_cells_with_data(proxy, on_points=[field_name])
1882 select_cells_with_data(proxy, on_cells=[field_name])
1885 nb_components = get_nb_components(proxy, entity, field_name)
1886 check_vector_mode(vector_mode, nb_components)
1889 time_value = get_time(proxy, timestamp_nb)
1892 pvs.GetRenderView().ViewTime = time_value
1893 pvs.UpdatePipeline(time_value, proxy)
1896 source = pvs.MergeBlocks(proxy)
1898 # Transform cell data into point data if necessary
1899 if is_data_on_cells(proxy, field_name):
1900 cell_to_point = pvs.CellDatatoPointData(source)
1901 cell_to_point.PassCellData = 1
1902 source = cell_to_point
1904 contour_by = ['POINTS', field_name]
1906 # Transform vector array to scalar array if necessary
1907 if (nb_components > 1):
1908 calc = get_calc_magnitude(source, EntityType.NODE, field_name)
1909 contour_by = ['POINTS', calc.ResultArrayName]
1912 # Contour filter settings
1913 contour = pvs.Contour(source)
1914 contour.ComputeScalars = 1
1915 contour.ContourBy = contour_by
1918 scalar_range = custom_range
1919 if (scalar_range is None):
1920 scalar_range = get_data_range(proxy, entity,
1921 field_name, cut_off=True)
1923 # Get contour values for the range
1924 surfaces = get_contours(scalar_range, nb_surfaces)
1926 # Set contour values
1927 contour.Isosurfaces = surfaces
1929 # Get Iso Surfaces representation object
1930 isosurfaces = pvs.GetRepresentation(contour)
1933 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
1935 # Set field range if necessary
1936 data_range = get_data_range(proxy, entity,
1937 field_name, vector_mode)
1938 lookup_table.LockScalarRange = 1
1939 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
1941 # Set display properties
1943 isosurfaces.ColorAttributeType = EntityType.get_pvtype(entity)
1944 isosurfaces.ColorArrayName = field_name
1946 isosurfaces.ColorArrayName = ''
1948 isosurfaces.DiffuseColor = color
1949 isosurfaces.LookupTable = lookup_table
1952 add_scalar_bar(field_name, nb_components,
1953 vector_mode, lookup_table, time_value)
1958 def GaussPointsOnField(proxy, entity, field_name,
1960 is_deformed=True, scale_factor=None,
1961 is_colored=True, color=None,
1962 primitive=GaussType.SPRITE,
1963 is_proportional=True,
1965 multiplier=None, vector_mode='Magnitude'):
1966 """Creates Gauss Points on the given field.
1970 proxy: the pipeline object, containig data
1971 entity: the field entity type from PrsTypeEnum
1972 field_name: the field name
1973 timestamp_nb: the number of time step (1, 2, ...)
1974 is_deformed: defines whether the Gauss Points will be deformed or not
1975 scale_factor -- the scale factor for deformation. Will be taken into
1976 account only if is_deformed is True.
1977 If not passed by user, default scale will be computed.
1978 is_colored -- defines whether the Gauss Points will be multicolored,
1979 using the corresponding data values
1980 color: defines the presentation color as [R, G, B] triple. Taken into
1981 account only if is_colored is False.
1982 primitive: primitive type from GaussType
1983 is_proportional: if True, the size of primitives will depends on
1984 the gauss point value
1985 max_pixel_size: the maximum sizr of the Gauss Points primitive in pixels
1986 multiplier: coefficient between data values and the size of primitives
1987 If not passed by user, default scale will be computed.
1988 vector_mode: the mode of transformation of vector values into
1989 scalar values, applicable only if the field contains vector values.
1990 Possible modes: 'Magnitude' - vector module;
1991 'X', 'Y', 'Z' - vector components.
1994 Gauss Points as representation object.
1997 # We don't need mesh parts with no data on them
1998 if entity == EntityType.NODE:
1999 select_cells_with_data(proxy, on_points=[field_name])
2001 select_cells_with_data(proxy, on_cells=[field_name])
2004 nb_components = get_nb_components(proxy, entity, field_name)
2005 check_vector_mode(vector_mode, nb_components)
2008 time_value = get_time(proxy, timestamp_nb)
2011 pvs.GetRenderView().ViewTime = time_value
2012 proxy.UpdatePipeline(time=time_value)
2016 fields_info = proxy.GetProperty("FieldsTreeInfo")[::2]
2017 arr_name_with_dis=[elt.split("/")[-1] for elt in fields_info]
2018 gauss_name=field_name+proxy.GetProperty("Separator").GetData()+'GAUSS'
2020 # If no quadrature point array is passed, use cell centers
2021 if arr_name_with_dis.count(gauss_name) > 0:
2022 index = arr_name_with_dis.index(gauss_name)
2023 field = fields_info[index]
2024 source.AllArrays = [field]
2025 generate_qp = pvs.GenerateQuadraturePoints(source)
2026 generate_qp.SelectSourceArray = ['CELLS', 'ELGA_Offset']
2027 source = generate_qp
2030 cell_centers = pvs.CellCenters(source)
2031 cell_centers.VertexCells = 1
2032 source = cell_centers
2034 source.UpdatePipeline()
2036 # Check if deformation enabled
2037 if is_deformed and nb_components > 1:
2038 vector_array = field_name
2039 # If the given vector array has only 2 components, add the third one
2040 if nb_components == 2:
2041 calc = get_add_component_calc(source,
2042 EntityType.NODE, field_name)
2043 vector_array = calc.ResultArrayName
2047 warp_vector = pvs.WarpByVector(source)
2048 warp_vector.Vectors = [vector_array]
2049 if scale_factor is not None:
2050 warp_vector.ScaleFactor = scale_factor
2052 def_scale = get_default_scale(PrsTypeEnum.DEFORMEDSHAPE, proxy,
2054 warp_vector.ScaleFactor = def_scale
2055 warp_vector.UpdatePipeline()
2056 source = warp_vector
2058 # Get Gauss Points representation object
2059 gausspnt = pvs.GetRepresentation(source)
2062 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
2064 # Set field range if necessary
2065 data_range = get_data_range(proxy, entity,
2066 field_name, vector_mode)
2067 lookup_table.LockScalarRange = 1
2068 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
2070 # Set display properties
2072 gausspnt.ColorAttributeType = EntityType.get_pvtype(entity)
2073 gausspnt.ColorArrayName = field_name
2075 gausspnt.ColorArrayName = ''
2077 gausspnt.DiffuseColor = color
2079 gausspnt.LookupTable = lookup_table
2082 add_scalar_bar(field_name, nb_components,
2083 vector_mode, lookup_table, time_value)
2085 # Set point sprite representation
2086 gausspnt.Representation = 'Point Sprite'
2088 # Point sprite settings
2089 gausspnt.InterpolateScalarsBeforeMapping = 0
2090 gausspnt.MaxPixelSize = max_pixel_size
2093 gausspnt.RenderMode = GaussType.get_mode(primitive)
2095 #if primitive == GaussType.SPRITE:
2097 # TODO(MZN): replace with pvsimple high-level interface
2098 # texture = sm.CreateProxy("textures", "SpriteTexture")
2099 # alphamprop = texture.GetProperty("AlphaMethod")
2100 # alphamprop.SetElement(0, 2) # Clamp
2101 # alphatprop = texture.GetProperty("AlphaThreshold")
2102 # alphatprop.SetElement(0, 63)
2103 # maxprop = texture.GetProperty("Maximum")
2104 # maxprop.SetElement(0, 255)
2105 # texture.UpdateVTKObjects()
2107 # gausspnt.Texture = texture
2108 #gausspnt.Texture.AlphaMethod = 'Clamp'
2109 #gausspnt.Texture.AlphaThreshold = 63
2110 #gausspnt.Texture.Maximum= 255
2112 # Proportional radius
2113 gausspnt.RadiusUseScalarRange = 0
2114 gausspnt.RadiusIsProportional = 0
2119 mult = abs(0.1 / data_range[1])
2121 gausspnt.RadiusScalarRange = data_range
2122 gausspnt.RadiusTransferFunctionEnabled = 1
2123 gausspnt.RadiusMode = 'Scalar'
2124 gausspnt.RadiusArray = ['POINTS', field_name]
2125 if nb_components > 1:
2126 v_comp = get_vector_component(vector_mode)
2127 gausspnt.RadiusVectorComponent = v_comp
2128 gausspnt.RadiusTransferFunctionMode = 'Table'
2129 gausspnt.RadiusScalarRange = data_range
2130 gausspnt.RadiusUseScalarRange = 1
2131 gausspnt.RadiusIsProportional = 1
2132 gausspnt.RadiusProportionalFactor = mult
2134 gausspnt.RadiusTransferFunctionEnabled = 0
2135 gausspnt.RadiusMode = 'Constant'
2136 gausspnt.RadiusArray = ['POINTS', 'Constant Radius']
2140 def GaussPointsOnField1(proxy, entity, field_name,
2142 is_colored=True, color=None,
2143 primitive=GaussType.SPHERE,
2144 is_proportional=True,
2147 vector_mode='Magnitude'):
2148 """Creates Gauss Points on the given field. Use GaussPoints() Paraview interface.
2151 proxy: the pipeline object, containig data
2152 entity: the field entity type from PrsTypeEnum
2153 field_name: the field name
2154 timestamp_nb: the number of time step (1, 2, ...)
2155 is_colored -- defines whether the Gauss Points will be multicolored,
2156 using the corresponding data values
2157 color: defines the presentation color as [R, G, B] triple. Taken into
2158 account only if is_colored is False.
2159 primitive: primitive type from GaussType
2160 is_proportional: if True, the size of primitives will depends on
2161 the gauss point value
2162 max_pixel_size: the maximum sizr of the Gauss Points primitive in pixels
2163 multiplier: coefficient between data values and the size of primitives
2164 If not passed by user, default scale will be computed.
2165 vector_mode: the mode of transformation of vector values into
2166 scalar values, applicable only if the field contains vector values.
2167 Possible modes: 'Magnitude' - vector module;
2168 'X', 'Y', 'Z' - vector components.
2171 Gauss Points as representation object.
2175 time_value = get_time(proxy, timestamp_nb)
2178 pvs.GetRenderView().ViewTime = time_value
2179 proxy.UpdatePipeline(time=time_value)
2181 # Create Gauss Points object
2182 source = pvs.GaussPoints(proxy)
2183 source.UpdatePipeline()
2185 # Get Gauss Points representation object
2186 gausspnt = pvs.GetRepresentation(source)
2189 entity_data_info = None
2190 point_data_info = source.GetPointDataInformation()
2191 if field_name in point_data_info.keys():
2192 entity_data_info = point_data_info
2194 entity_data_info = source.GetCellDataInformation()
2195 nb_components = entity_data_info[field_name].GetNumberOfComponents()
2197 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
2199 # Set field range if necessary
2200 data_range = get_data_range(proxy, entity,
2201 field_name, vector_mode)
2202 lookup_table.LockScalarRange = 1
2203 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
2205 # Set display properties
2207 gausspnt.ColorAttributeType = EntityType.get_pvtype(entity)
2208 gausspnt.ColorArrayName = field_name
2210 gausspnt.ColorArrayName = ''
2212 gausspnt.DiffuseColor = color
2214 gausspnt.LookupTable = lookup_table
2217 add_scalar_bar(field_name, nb_components,
2218 vector_mode, lookup_table, time_value)
2220 # Set point sprite representation
2221 gausspnt.Representation = 'Point Sprite'
2223 # Point sprite settings
2224 gausspnt.InterpolateScalarsBeforeMapping = 0
2225 gausspnt.MaxPixelSize = max_pixel_size
2228 gausspnt.RenderMode = GaussType.get_mode(primitive)
2230 #if primitive == GaussType.SPRITE:
2232 # TODO(MZN): replace with pvsimple high-level interface
2233 # texture = sm.CreateProxy("textures", "SpriteTexture")
2234 # alphamprop = texture.GetProperty("AlphaMethod")
2235 # alphamprop.SetElement(0, 2) # Clamp
2236 # alphatprop = texture.GetProperty("AlphaThreshold")
2237 # alphatprop.SetElement(0, 63)
2238 # maxprop = texture.GetProperty("Maximum")
2239 # maxprop.SetElement(0, 255)
2240 # texture.UpdateVTKObjects()
2242 # gausspnt.Texture = texture
2243 #gausspnt.Texture.AlphaMethod = 'Clamp'
2244 #gausspnt.Texture.AlphaThreshold = 63
2245 #gausspnt.Texture.Maximum= 255
2247 # Proportional radius
2248 gausspnt.RadiusUseScalarRange = 0
2249 gausspnt.RadiusIsProportional = 0
2254 mult = abs(0.1 / data_range[1])
2256 gausspnt.RadiusScalarRange = data_range
2257 gausspnt.RadiusTransferFunctionEnabled = 1
2258 gausspnt.RadiusMode = 'Scalar'
2259 gausspnt.RadiusArray = ['POINTS', field_name]
2260 if nb_components > 1:
2261 v_comp = get_vector_component(vector_mode)
2262 gausspnt.RadiusVectorComponent = v_comp
2263 gausspnt.RadiusTransferFunctionMode = 'Table'
2264 gausspnt.RadiusScalarRange = data_range
2265 gausspnt.RadiusUseScalarRange = 1
2266 gausspnt.RadiusIsProportional = 1
2267 gausspnt.RadiusProportionalFactor = mult
2269 gausspnt.RadiusTransferFunctionEnabled = 0
2270 gausspnt.RadiusMode = 'Constant'
2271 gausspnt.RadiusArray = ['POINTS', 'Constant Radius']
2275 def StreamLinesOnField(proxy, entity, field_name, timestamp_nb,
2276 direction='BOTH', is_colored=False, color=None,
2277 vector_mode='Magnitude'):
2278 """Creates Stream Lines presentation on the given field.
2281 proxy: the pipeline object, containig data
2282 entity: the entity type from PrsTypeEnum
2283 field_name: the field name
2284 timestamp_nb: the number of time step (1, 2, ...)
2285 direction: the stream lines direction ('FORWARD', 'BACKWARD' or 'BOTH')
2286 is_colored: this option allows to color the presentation according to
2287 the corresponding data values. If False - the presentation will
2289 color: defines the presentation color as [R, G, B] triple. Taken into
2290 account only if is_colored is False.
2291 vector_mode: the mode of transformation of vector values
2292 into scalar values, applicable only if the field contains vector values.
2293 Possible modes: 'Magnitude', 'X', 'Y' or 'Z'.
2296 Stream Lines as representation object.
2299 # We don't need mesh parts with no data on them
2300 if entity == EntityType.NODE:
2301 select_cells_with_data(proxy, on_points=[field_name])
2303 select_cells_with_data(proxy, on_cells=[field_name])
2306 nb_components = get_nb_components(proxy, entity, field_name)
2307 check_vector_mode(vector_mode, nb_components)
2310 time_value = get_time(proxy, timestamp_nb)
2313 pvs.GetRenderView().ViewTime = time_value
2314 pvs.UpdatePipeline(time_value, proxy)
2317 source = pvs.MergeBlocks(proxy)
2319 # Cell data to point data
2320 if is_data_on_cells(proxy, field_name):
2321 cell_to_point = pvs.CellDatatoPointData(source)
2322 cell_to_point.PassCellData = 1
2323 cell_to_point.UpdatePipeline()
2324 source = cell_to_point
2326 vector_array = field_name
2327 # If the given vector array has only 2 components, add the third one
2328 if nb_components == 2:
2329 calc = get_add_component_calc(source, EntityType.NODE, field_name)
2330 vector_array = calc.ResultArrayName
2331 calc.UpdatePipeline()
2335 stream = pvs.StreamTracer(source)
2336 stream.SeedType = "Point Source"
2337 stream.Vectors = ['POINTS', vector_array]
2338 stream.SeedType = "Point Source"
2339 stream.IntegrationDirection = direction
2340 stream.IntegratorType = 'Runge-Kutta 2'
2341 stream.UpdatePipeline()
2343 # Get Stream Lines representation object
2344 if is_empty(stream):
2346 streamlines = pvs.GetRepresentation(stream)
2349 lookup_table = get_lookup_table(field_name, nb_components, vector_mode)
2351 # Set field range if necessary
2352 data_range = get_data_range(proxy, entity,
2353 field_name, vector_mode)
2354 lookup_table.LockScalarRange = 1
2355 lookup_table.RGBPoints = [data_range[0], 0, 0, 1, data_range[1], 1, 0, 0]
2359 streamlines.ColorAttributeType = EntityType.get_pvtype(entity)
2360 streamlines.ColorArrayName = field_name
2362 streamlines.ColorArrayName = ''
2364 streamlines.DiffuseColor = color
2366 streamlines.LookupTable = lookup_table
2369 add_scalar_bar(field_name, nb_components,
2370 vector_mode, lookup_table, time_value)
2375 def MeshOnEntity(proxy, mesh_name, entity):
2376 """Creates submesh of the entity type for the mesh.
2379 proxy -- the pipeline object, containig data
2380 mesh_name -- the mesh name
2381 entity -- the entity type
2384 Submesh as representation object of the given source.
2387 # Select all cell types
2388 select_all_cells(proxy)
2390 # Get subset of groups on the given entity
2391 subset = get_group_names(proxy, mesh_name, entity)
2393 # Select only groups of the given entity type
2394 proxy.Groups = subset
2395 proxy.UpdatePipeline()
2397 # Get representation object if the submesh is not empty
2399 if (proxy.GetDataInformation().GetNumberOfPoints() or
2400 proxy.GetDataInformation().GetNumberOfCells()):
2401 prs = pvs.GetRepresentation(proxy)
2402 prs.ColorArrayName = ''
2407 def MeshOnGroup(proxy, group_name):
2408 """Creates submesh on the group.
2411 proxy -- the pipeline object, containig data
2412 group_name -- the full group name
2415 Representation object of the given source with single group
2419 # Select all cell types
2420 select_all_cells(proxy)
2422 # Select only the group with the given name
2423 one_group = [group_name]
2424 proxy.Groups = one_group
2425 proxy.UpdatePipeline()
2427 # Get representation object if the submesh is not empty
2430 # Check if the group was set
2431 if proxy.Groups.GetData() == one_group:
2432 group_entity = get_group_entity(group_name)
2433 # Check if the submesh is not empty
2435 if group_entity == EntityType.NODE:
2436 nb_items = proxy.GetDataInformation().GetNumberOfPoints()
2437 elif group_entity == EntityType.CELL:
2438 nb_items = proxy.GetDataInformation().GetNumberOfCells()
2441 prs = pvs.GetRepresentation(proxy)
2442 prs.ColorArrayName = ''
2447 def CreatePrsForFile(paravis_instance, file_name, prs_types,
2448 picture_dir, picture_ext):
2449 """Build presentations of the given types for the file.
2451 Build presentations for all fields on all timestamps.
2454 paravis_instance: ParaVis module instance object
2455 file_name: full path to the MED file
2456 prs_types: the list of presentation types to build
2457 picture_dir: the directory path for saving snapshots
2458 picture_ext: graphics files extension (determines file type)
2462 print "Import " + file_name.split(os.sep)[-1] + "..."
2465 proxy = pvs.MEDReader(FileName=file_name)
2469 proxy.UpdatePipeline()
2470 _med_field_sep = proxy.GetProperty("Separator")
2476 view = pvs.GetRenderView()
2478 # Create required presentations for the proxy
2479 CreatePrsForProxy(proxy, view, prs_types,
2480 picture_dir, picture_ext)
2482 def CreatePrsForProxy(proxy, view, prs_types, picture_dir, picture_ext):
2483 """Build presentations of the given types for all fields of the proxy.
2485 Save snapshots in graphics files (type depends on the given extension).
2486 Stores the files in the given directory.
2489 proxy: the pipeline object, containig data
2490 view: the render view
2491 prs_types: the list of presentation types to build
2492 picture_dir: the directory path for saving snapshots
2493 picture_ext: graphics files extension (determines file type)
2496 # List of the field names
2497 fields_info = proxy.GetProperty("FieldsTreeInfo")[::2]
2500 # Add path separator to the end of picture path if necessery
2501 if not picture_dir.endswith(os.sep):
2502 picture_dir += os.sep
2505 if PrsTypeEnum.MESH in prs_types:
2506 # Create Mesh presentation. Build all possible submeshes.
2508 extGrp=pvs.ExtractGroup()
2510 # Remember the current state
2511 groups = filter(lambda x:x[:4]=="GRP_",list(extGrp.GetProperty("GroupsFlagsInfo")[::2]))
2514 mesh_names = get_mesh_names(proxy)
2515 for mesh_name in mesh_names:
2516 # Build mesh on nodes and cells
2517 for entity in (EntityType.NODE, EntityType.CELL):
2518 entity_name = EntityType.get_name(entity)
2519 if if_possible(proxy, mesh_name, entity, PrsTypeEnum.MESH):
2520 print "Creating submesh on " + entity_name + " for '" + mesh_name + "' mesh... "
2521 prs = MeshOnEntity(proxy, mesh_name, entity)
2527 # Construct image file name
2528 pic_name = picture_dir + mesh_name + "_" + entity_name + "." + picture_ext
2530 # Show and dump the presentation into a graphics file
2531 process_prs_for_test(prs, view, pic_name, False)
2533 # Build submesh on all groups of the mesh
2534 mesh_groups = get_group_names(proxy, mesh_name,
2535 entity, wo_nogroups=True)
2536 for group in mesh_groups:
2537 print "Creating submesh on group " + group + "... "
2538 prs = MeshOnGroup(proxy, group)
2544 # Construct image file name
2545 pic_name = picture_dir + group.replace('/', '_') + "." + picture_ext
2547 # Show and dump the presentation into a graphics file
2548 process_prs_for_test(prs, view, pic_name, False)
2551 extGrp.AllGroups = groups
2552 extGrp.UpdatePipelineInformation()
2554 # Presentations on fields
2555 for field in fields_info:
2556 # Restore fields selection state
2557 proxy.AllArrays = []
2558 proxy.UpdatePipelineInformation()
2559 # Select only the current field:
2560 # necessary for getting the right timestamps
2561 field_name = get_field_short_name(field)
2562 field_entity = get_field_entity(field)
2563 proxy.AllArrays = field
2564 proxy.UpdatePipelineInformation()
2567 entity_data_info = proxy.GetCellDataInformation()
2568 timestamps = proxy.TimestepValues.GetData()
2570 for prs_type in prs_types:
2571 # Ignore mesh presentation
2572 if prs_type == PrsTypeEnum.MESH:
2575 # Get name of presentation type
2576 prs_name = PrsTypeEnum.get_name(prs_type)
2578 # Build the presentation if possible
2579 possible = if_possible(proxy, field_name,
2580 field_entity, prs_type)
2582 # Presentation type for graphics file name
2583 f_prs_type = prs_name.replace(' ', '').upper()
2585 for timestamp_nb in xrange(1, len(timestamps) + 1):
2586 time = timestamps[timestamp_nb - 1]
2587 print "Creating " + prs_name + " on " + field_name + ", time = " + str(time) + "... "
2588 prs = create_prs(prs_type, proxy,
2589 field_entity, field_name, timestamp_nb)
2596 # Construct image file name
2597 pic_name = picture_dir + field_name + "_" + str(time) + "_" + f_prs_type + "." + picture_ext
2599 # Show and dump the presentation into a graphics file
2600 process_prs_for_test(prs, view, pic_name)