From: akl Date: Tue, 25 Mar 2014 10:33:21 +0000 (+0400) Subject: Building of MESH presentation X-Git-Tag: V7_4_0rc1~4^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b77d5cf05fb847d6d8e46f2beeba461f431ef62;p=modules%2Fparavis.git Building of MESH presentation --- diff --git a/src/PV_SWIG/VTKWrapping/presentations.py b/src/PV_SWIG/VTKWrapping/presentations.py index 5894aabc..360b5434 100644 --- a/src/PV_SWIG/VTKWrapping/presentations.py +++ b/src/PV_SWIG/VTKWrapping/presentations.py @@ -199,6 +199,15 @@ def get_field_short_name(full_field_name): return short_name +def find_mesh_full_name(proxy, short_mesh_name): + """Return full mesh path by short mesh name, if found""" + proxy.UpdatePipeline() + all_mesh_names = get_mesh_full_names(proxy) + for name in all_mesh_names: + if short_mesh_name == get_field_short_name(name): + return name + + def process_prs_for_test(prs, view, picture_name, show_bar=True): """Show presentation and record snapshot image. @@ -360,6 +369,7 @@ def get_data_range(proxy, entity, field_name, vector_mode='Magnitude', Data range as [min, max] """ + proxy.UpdatePipeline() entity_data_info = None field_data = proxy.GetFieldDataInformation() @@ -392,6 +402,7 @@ def get_data_range(proxy, entity, field_name, vector_mode='Magnitude', def get_bounds(proxy): """Get bounds of the proxy in 3D.""" + proxy.UpdatePipeline() dataInfo = proxy.GetDataInformation() bounds_info = dataInfo.GetBounds() return bounds_info @@ -399,24 +410,28 @@ def get_bounds(proxy): def get_x_range(proxy): """Get X range of the proxy bounds in 3D.""" + proxy.UpdatePipeline() bounds_info = get_bounds(proxy) return bounds_info[0:2] def get_y_range(proxy): """Get Y range of the proxy bounds in 3D.""" + proxy.UpdatePipeline() bounds_info = get_bounds(proxy) return bounds_info[2:4] def get_z_range(proxy): """Get Z range of the proxy bounds in 3D.""" + proxy.UpdatePipeline() bounds_info = get_bounds(proxy) return bounds_info[4:6] def is_planar_input(proxy): """Check if the given input is planar.""" + proxy.UpdatePipeline() bounds_info = get_bounds(proxy) if (abs(bounds_info[0] - bounds_info[1]) <= FLT_MIN or @@ -429,6 +444,7 @@ def is_planar_input(proxy): def is_data_on_cells(proxy, field_name): """Check the existence of a field on cells with the given name.""" + proxy.UpdatePipeline() cell_data_info = proxy.GetCellDataInformation() return (field_name in cell_data_info.keys()) @@ -441,6 +457,7 @@ def is_empty(proxy): False: otherwise """ + proxy.UpdatePipeline() data_info = proxy.GetDataInformation() nb_cells = data_info.GetNumberOfCells() @@ -451,6 +468,7 @@ def is_empty(proxy): def get_orientation(proxy): """Get the optimum cutting plane orientation for Plot 3D.""" + proxy.UpdatePipeline() orientation = Orientation.XY bounds = get_bounds(proxy) @@ -622,6 +640,7 @@ def get_contours(scalar_range, nb_contours): def get_nb_components(proxy, entity, field_name): """Return number of components for the field.""" + proxy.UpdatePipeline() entity_data_info = None field_data = proxy.GetFieldDataInformation() @@ -675,6 +694,7 @@ def get_scale_factor(proxy): def get_default_scale(prs_type, proxy, entity, field_name): """Get default scale factor.""" + proxy.UpdatePipeline() data_range = get_data_range(proxy, entity, field_name) if prs_type == PrsTypeEnum.DEFORMEDSHAPE: @@ -702,6 +722,7 @@ def get_calc_magnitude(proxy, array_entity, array_name): the calculator object. """ + proxy.UpdatePipeline() calculator = None # Transform vector array to scalar array if possible @@ -736,6 +757,7 @@ def get_add_component_calc(proxy, array_entity, array_name): the calculator object. """ + proxy.UpdatePipeline() calculator = None nb_components = get_nb_components(proxy, array_entity, array_name) @@ -759,8 +781,10 @@ def select_all_cells(proxy): Used in creation of mesh/submesh presentation. """ + proxy.UpdatePipeline() extractCT = pvs.ExtractCellType() extractCT.AllGeoTypes = extractCT.GetProperty("GeoTypesInfo")[::2] + extractCT.UpdatePipelineInformation() def select_cells_with_data(proxy, on_points=[], on_cells=[], on_gauss=[]): @@ -771,6 +795,7 @@ def select_cells_with_data(proxy, on_points=[], on_cells=[], on_gauss=[]): types with data for even one field (from available) will be selected. """ + proxy.UpdatePipeline() if not hasattr(proxy, 'Entity'): separator = proxy.GetProperty("Separator").GetData() @@ -840,8 +865,9 @@ def select_cells_with_data(proxy, on_points=[], on_cells=[], on_gauss=[]): proxy.Entity = cell_types_on proxy.UpdatePipeline() -def if_possible(proxy, field_name, entity, prs_type): +def if_possible(proxy, field_name, entity, prs_type, extrGrps=None): """Check if the presentation creation is possible on the given field.""" + proxy.UpdatePipeline() result = True if (prs_type == PrsTypeEnum.DEFORMEDSHAPE or prs_type == PrsTypeEnum.DEFORMEDSHAPESCALARMAP or @@ -853,7 +879,7 @@ def if_possible(proxy, field_name, entity, prs_type): result = (entity == EntityType.CELL or field_name in proxy.QuadraturePointArrays.Available) elif (prs_type == PrsTypeEnum.MESH): - result = len(get_group_names(proxy, field_name, entity)) > 0 + result = len(get_group_names(extrGrps)) > 0 return result @@ -951,39 +977,28 @@ def get_group_entity(full_group_name): def get_group_short_name(full_group_name): """Return short name of the group by its full name.""" - aList = full_group_name.split('/') - if len(aList) >= 4 : - short_name = full_group_name.split('/')[3] - return short_name + short_name = re.sub('^GRP_', '', full_group_name) + return short_name -def get_mesh_names(proxy): +def get_mesh_full_names(proxy): """Return all mesh names in the given proxy as a set.""" + proxy.UpdatePipeline() fields = proxy.GetProperty("FieldsTreeInfo")[::2] - mesh_names = set([get_field_mesh_name(item) for item in fields]) - return mesh_names + mesh_full_names = set([item for item in fields if get_field_mesh_name(item) == get_field_short_name(item)]) + return mesh_full_names -def get_group_names(proxy, mesh_name, entity, wo_nogroups=False): - """Return full names of all groups of the given entity type - from the mesh with the given name as a list. +def get_group_names(extrGrps): + """Return full names of all groups of the given 'ExtractGroup' filter object. """ - groups = proxy.Groups.Available - - condition = lambda item: (get_group_mesh_name(item) == mesh_name and - get_group_entity(item) == entity) - group_names = [item for item in groups if condition(item)] - - if wo_nogroups: - # Remove "No_Group" group - not_no_group = lambda item: get_group_short_name(item) != "No_Group" - group_names = filter(not_no_group, group_names) - + group_names = filter(lambda x:x[:4]=="GRP_",list(extrGrps.GetProperty("GroupsFlagsInfo")[::2])) return group_names def get_time(proxy, timestamp_nb): """Get time value by timestamp number.""" + proxy.UpdatePipeline() # Check timestamp number timestamps = [] @@ -1010,6 +1025,7 @@ def create_prs(prs_type, proxy, field_entity, field_name, timestamp_nb): Set the presentation properties like visu.CreatePrsForResult() do. """ + proxy.UpdatePipeline() prs = None if prs_type == PrsTypeEnum.SCALARMAP: @@ -1061,6 +1077,7 @@ def ScalarMapOnField(proxy, entity, field_name, timestamp_nb, Scalar Map as representation object. """ + proxy.UpdatePipeline() # We don't need mesh parts with no data on them if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) @@ -1131,6 +1148,7 @@ def CutPlanesOnField(proxy, entity, field_name, timestamp_nb, Cut Planes as representation object. """ + proxy.UpdatePipeline() if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) else: @@ -1226,6 +1244,7 @@ def CutLinesOnField(proxy, entity, field_name, timestamp_nb, (Cut Lines as representation object, list of 'PlotOverLine') otherwise """ + proxy.UpdatePipeline() if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) else: @@ -1353,6 +1372,7 @@ def CutSegmentOnField(proxy, entity, field_name, timestamp_nb, Cut Segment as 3D representation object. """ + proxy.UpdatePipeline() if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) else: @@ -1426,6 +1446,7 @@ def VectorsOnField(proxy, entity, field_name, timestamp_nb, Vectors as representation object. """ + proxy.UpdatePipeline() if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) else: @@ -1544,6 +1565,7 @@ def DeformedShapeOnField(proxy, entity, field_name, Defromed Shape as representation object. """ + proxy.UpdatePipeline() # We don't need mesh parts with no data on them if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) @@ -1641,6 +1663,7 @@ def DeformedShapeAndScalarMapOnField(proxy, entity, field_name, Defromed Shape And Scalar Map as representation object. """ + proxy.UpdatePipeline() # We don't need mesh parts with no data on them on_points = [] on_cells = [] @@ -1763,6 +1786,7 @@ def Plot3DOnField(proxy, entity, field_name, timestamp_nb, Plot 3D as representation object. """ + proxy.UpdatePipeline() # We don't need mesh parts with no data on them if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) @@ -1920,6 +1944,7 @@ def IsoSurfacesOnField(proxy, entity, field_name, timestamp_nb, Iso Surfaces as representation object. """ + proxy.UpdatePipeline() # We don't need mesh parts with no data on them if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) @@ -2039,6 +2064,7 @@ def GaussPointsOnField(proxy, entity, field_name, Gauss Points as representation object. """ + proxy.UpdatePipeline() # We don't need mesh parts with no data on them on_gauss = select_cells_with_data(proxy, on_gauss=[field_name]) if not on_gauss: @@ -2211,6 +2237,7 @@ def GaussPointsOnField1(proxy, entity, field_name, Gauss Points as representation object. """ + proxy.UpdatePipeline() select_cells_with_data(proxy, on_gauss=[field_name]) nb_components = get_nb_components(proxy, entity, field_name) @@ -2332,6 +2359,7 @@ def StreamLinesOnField(proxy, entity, field_name, timestamp_nb, Stream Lines as representation object. """ + proxy.UpdatePipeline() # We don't need mesh parts with no data on them if entity == EntityType.NODE: select_cells_with_data(proxy, on_points=[field_name]) @@ -2413,21 +2441,25 @@ def MeshOnEntity(proxy, mesh_name, entity): Arguments: proxy -- the pipeline object, containig data - mesh_name -- the mesh name - entity -- the entity type + mesh_name -- the full or short name of mesh field Returns: Submesh as representation object of the given source. """ - # Select all cell types - select_all_cells(proxy) - - # Get subset of groups on the given entity - subset = get_group_names(proxy, mesh_name, entity) - - # Select only groups of the given entity type - proxy.Groups = subset + proxy.UpdatePipeline() + mesh_full_name = None + aList = mesh_name.split('/') + if len(aList) >= 2: + mesh_full_name = mesh_name + else: + mesh_full_name = find_mesh_full_name(proxy, mesh_name) + if not mesh_full_name: + raise RuntimeError, "The given mesh name was not found" + # Select only the given mesh + proxy.AllArrays = [] + proxy.UpdatePipeline() + proxy.AllArrays = [mesh_full_name] proxy.UpdatePipeline() # Get representation object if the submesh is not empty @@ -2440,42 +2472,42 @@ def MeshOnEntity(proxy, mesh_name, entity): return prs -def MeshOnGroup(proxy, group_name): +def MeshOnGroup(proxy, extrGroups, group_name): """Creates submesh on the group. Arguments: proxy -- the pipeline object, containig data group_name -- the full group name + extrGroups -- all extracted groups object Returns: Representation object of the given source with single group selected. """ - # Select all cell types - select_all_cells(proxy) - - # Select only the group with the given name - one_group = [group_name] - proxy.Groups = one_group proxy.UpdatePipeline() + # Deselect all groups + extrGroups.AllGroups = [] + extrGroups.UpdatePipelineInformation() + # Select only the group with the given name + extrGroups.AllGroups = [group_name] + extrGroups.UpdatePipelineInformation() # Get representation object if the submesh is not empty prs = None # Check if the group was set - if proxy.Groups.GetData() == one_group: - group_entity = get_group_entity(group_name) + if len(extrGroups.AllGroups) == 1 and \ + extrGroups.AllGroups[0] == group_name: # Check if the submesh is not empty - nb_items = 0 - if group_entity == EntityType.NODE: - nb_items = proxy.GetDataInformation().GetNumberOfPoints() - elif group_entity == EntityType.CELL: - nb_items = proxy.GetDataInformation().GetNumberOfCells() - - if nb_items: - prs = pvs.GetRepresentation(proxy) + nb_points = proxy.GetDataInformation().GetNumberOfPoints() + nb_cells = proxy.GetDataInformation().GetNumberOfCells() + + if nb_points or nb_cells: +# prs = pvs.GetRepresentation(proxy) + prs = pvs.Show() prs.ColorArrayName = '' + display_only(prs) return prs @@ -2529,6 +2561,7 @@ def CreatePrsForProxy(proxy, view, prs_types, picture_dir, picture_ext): picture_ext: graphics files extension (determines file type) """ + proxy.UpdatePipeline() # List of the field names fields_info = proxy.GetProperty("FieldsTreeInfo")[::2] print fields_info @@ -2539,53 +2572,40 @@ def CreatePrsForProxy(proxy, view, prs_types, picture_dir, picture_ext): # Mesh Presentation if PrsTypeEnum.MESH in prs_types: - # Create Mesh presentation. Build all possible submeshes. - - extGrp=pvs.ExtractGroup() - - # Remember the current state - groups = filter(lambda x:x[:4]=="GRP_",list(extGrp.GetProperty("GroupsFlagsInfo")[::2])) - # Iterate on meshes - mesh_names = get_mesh_names(proxy) + mesh_names = get_mesh_full_names(proxy) for mesh_name in mesh_names: - # Build mesh on nodes and cells - for entity in (EntityType.NODE, EntityType.CELL): - entity_name = EntityType.get_name(entity) - if if_possible(proxy, mesh_name, entity, PrsTypeEnum.MESH): - print "Creating submesh on " + entity_name + " for '" + mesh_name + "' mesh... " - prs = MeshOnEntity(proxy, mesh_name, entity) - if prs is None: - print "FAILED" - continue - else: - print "OK" - # Construct image file name - pic_name = picture_dir + mesh_name + "_" + entity_name + "." + picture_ext - - # Show and dump the presentation into a graphics file - process_prs_for_test(prs, view, pic_name, False) - - # Build submesh on all groups of the mesh - mesh_groups = get_group_names(proxy, mesh_name, - entity, wo_nogroups=True) - for group in mesh_groups: - print "Creating submesh on group " + group + "... " - prs = MeshOnGroup(proxy, group) - if prs is None: - print "FAILED" - continue - else: - print "OK" - # Construct image file name - pic_name = picture_dir + group.replace('/', '_') + "." + picture_ext - - # Show and dump the presentation into a graphics file - process_prs_for_test(prs, view, pic_name, False) - - # Restore the state - extGrp.AllGroups = groups + # Build mesh field presentation + print "Creating submesh for '" + get_field_short_name(mesh_name) + "' mesh... " + prs = MeshOnEntity(proxy, mesh_name, None) + if prs is None: + print "FAILED" + continue + else: + print "OK" + # Construct image file name + pic_name = picture_dir + get_field_short_name(mesh_name) + "." + picture_ext + + # Show and dump the presentation into a graphics file + process_prs_for_test(prs, view, pic_name, False) + + # Create Mesh presentation. Build all groups. + extGrp = pvs.ExtractGroup() extGrp.UpdatePipelineInformation() + if if_possible(proxy, None, None, PrsTypeEnum.MESH, extGrp): + for group in get_group_names(extGrp): + print "Creating submesh on group " + get_group_short_name(group) + "... " + prs = MeshOnGroup(proxy, extGrp, group) + if prs is None: + print "FAILED" + continue + else: + print "OK" + # Construct image file name + pic_name = picture_dir + get_group_short_name(group) + "." + picture_ext + + # Show and dump the presentation into a graphics file + process_prs_for_test(prs, view, pic_name, False) # Presentations on fields for field in fields_info: