Back to index

salome-paravis  6.5.0
demo2.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 
00021 if not ('servermanager' in dir()):
00022   from pvsimple import *
00023 
00024 import os
00025 
00026 def demo2(fname, impth):
00027     """This demo shows the use of readers, data information and display properties."""
00028    
00029  # The view
00030     v = GetRenderView()
00031     if not v:
00032        v = CreateRenderView()
00033     v.CameraPosition = [-20, -9, -45]
00034     v.CameraFocalPoint = [0.7, 0.3, 1.7]
00035     v.CameraViewUp = [-0.75, -0.6, 0.25]
00036     v.CameraViewAngle = [30]
00037     v.StillRender()
00038 
00039     # Create the exodus reader and specify a file name
00040     reader = ExodusIIReader(FileName=fname)
00041 
00042     # Get the list of point arrays.
00043     avail = reader.PointVariables.Available
00044     print avail
00045 
00046     # Select all arrays
00047     reader.PointVariables = avail
00048 
00049     # Turn on the visibility of the reader
00050     Show(reader)
00051 
00052     # Set representation to wireframe
00053     SetDisplayProperties(Representation = "Wireframe")
00054    
00055     # Black background
00056     SetViewProperties(Background = [0., 0., 0.])
00057     Render()
00058 
00059     # Change the elevation of the camera.
00060     GetActiveCamera().Elevation(45)
00061     Render()
00062 
00063     # Now that the reader executed, let's get some information about it's output.
00064     pdi = reader[0].PointData
00065 
00066     # This prints a list of all read point data arrays as well as their value ranges.
00067     print 'Number of point arrays:', len(pdi)
00068     for i in range(len(pdi)):
00069         ai = pdi[i]
00070         print "----------------"
00071         print "Array:", i, " ", ai.Name, ":"
00072         numComps = ai.GetNumberOfComponents()
00073         print "Number of components:", numComps
00074         for j in range(numComps):
00075             print "Range:", ai.GetRange(j)
00076 
00077     # White is boring. Let's color the geometry using a variable. First create a lookup table. This object controls how scalar values are mapped to colors. 
00078     SetDisplayProperties(LookupTable = MakeBlueToRedLT(0.00678, 0.0288))
00079 
00080     # Color by point array called Pres
00081     SetDisplayProperties(ColorAttributeType = "POINT_DATA")
00082     SetDisplayProperties(ColorArrayName = "Pres")
00083 
00084     WriteImage(filename = (impth + "demo2_1.png"), view=v, Magnification=2)
00085 
00086     # Set representation to surface
00087     SetDisplayProperties(Representation = "Surface")
00088 
00089     # Scalar Bar
00090     lt = MakeBlueToRedLT(0.00678, 0.0288)
00091     ScalarBar = CreateScalarBar(LookupTable = lt, Title = "Sample")
00092     GetRenderView().Representations.append(ScalarBar)
00093     WriteImage(filename = (impth + "demo2_2.png"), view=v, Magnification=2)
00094     Render()
00095 
00096 
00097 testdir = os.getenv("TESTDIR")
00098 pvdata = os.getenv("PVDATA")
00099 
00100 if __name__ == "__main__":
00101  demo2(fname=pvdata+"/Data/disk_out_ref.ex2", impth=testdir+"/Pic/")
00102