Back to index

salome-paravis  6.5.0
B0.py
Go to the documentation of this file.
00001 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 # This case corresponds to: /visu/3D_viewer/B0 case
00021 # Create 3D Viewer and test set view properties for Scalar Map presentation
00022 # Author:       POLYANSKIKH VERA
00023 from paravistest import *
00024 from presentations import *
00025 from pvsimple import *
00026 import sys
00027 import paravis
00028 import time
00029 
00030 # Directory for saving snapshots
00031 picturedir = get_picture_dir(sys.argv[1], "3D_viewer/B0")
00032 
00033 # Add path separator to the end of picture path if necessery
00034 if not picturedir.endswith(os.sep):
00035     picturedir += os.sep
00036 
00037 #import file
00038 myParavis = paravis.myParavis
00039 
00040 # Get view
00041 my_view = GetRenderView()
00042 reset_view(my_view)
00043 Render(my_view)
00044 
00045 theFileName = datadir + "fra.med"
00046 print " --------------------------------- "
00047 print "file ", theFileName
00048 print " --------------------------------- "
00049 
00050 myParavis.ImportFile(theFileName)
00051 proxy = GetActiveSource()
00052 if proxy is None:
00053     raise RuntimeError("Error: can't import file.")
00054 else:
00055     print "OK"
00056 
00057 represents = [RepresentationType.POINTS, RepresentationType.WIREFRAME,\
00058 RepresentationType.SURFACE, RepresentationType.VOLUME]
00059 shrinks = [0, 1]
00060 shadings = [0, 1]
00061 opacities = [1.0, 0.5, 0.0]
00062 linewidths = [1.0, 3.0, 10.0]
00063 compare_prec = 0.00001
00064 shrink_filter = None
00065 shrinked_sm = None
00066 
00067 field_name = 'VITESSE'
00068 
00069 print "\nCreating scalar map.......",
00070 scalar_map = ScalarMapOnField(proxy, EntityType.CELL, field_name, 1)
00071 if scalar_map is None:
00072     raise RuntimeError("Error!!! Presentation wasn't created...")
00073 
00074 display_only(scalar_map, my_view)
00075 reset_view(my_view)
00076 Render(my_view)
00077 
00078 print "\nChange Presentation Parameters..."
00079 
00080 
00081 for reprCode in represents:
00082     repr = RepresentationType.get_name(reprCode)
00083     call_and_check(scalar_map, "Representation", repr, 1)
00084     for shr in shrinks:
00085         if shr > 0 and reprCode != RepresentationType.POINTS:
00086             if shrinked_sm is None:
00087                 scalar_map.Visibility = 1
00088                 shrink_filter = Shrink(scalar_map.Input)
00089                 shrinked_sm = GetRepresentation(shrink_filter)
00090                 shrink_filter.ShrinkFactor = 0.8
00091                 shrink_filter.UpdatePipeline()                
00092                 shrinked_sm.ColorAttributeType = scalar_map.ColorAttributeType
00093                 shrinked_sm.ColorArrayName = scalar_map.ColorArrayName
00094                 lookup_table = scalar_map.LookupTable
00095                 shrinked_sm.LookupTable = lookup_table
00096 
00097             scalar_map.Visibility = 0
00098             shrinked_sm.Representation = scalar_map.Representation
00099             shrinked_sm.Visibility = 1
00100             shape_to_show = shrinked_sm
00101         else:
00102             if shrinked_sm is not None:
00103                 shrinked_sm.Visibility = 0
00104             scalar_map.Visibility = 1
00105             shape_to_show = scalar_map
00106         Render(my_view)
00107 
00108         for sha in shadings:
00109             setShaded(my_view, sha)
00110             call_and_check(shape_to_show, "Shading", sha, 1)
00111             Render(my_view)
00112 
00113             for opa in opacities:
00114                 call_and_check(shape_to_show, "Opacity", opa, 1, compare_prec)
00115 
00116                 for lwi in linewidths:
00117                     call_and_check(shape_to_show, "LineWidth", lwi, 1,
00118                     compare_prec)
00119 
00120                     time.sleep(1)
00121                     # save picture in file
00122                     # Construct image file name
00123                     opa = str(opa).replace('.', '')
00124                     lwi = str(lwi).replace('.', '')
00125                     pic_name = picturedir + "params_" + repr + "_" + str(shr) + "_" + \
00126                         str(sha) + "_" + str(opa) + "_" + str(lwi) + "." + pictureext
00127                     # Show and record the presentation
00128                     WriteImage(pic_name, view=my_view, Magnification=1)
00129                     pass
00130                 pass
00131             pass
00132         pass
00133     pass