Salome HOME
Merge branch 'abn/port_pv42' into abn/rearch
[modules/paravis.git] / test / demo2.py
1 # Copyright (C) 2010-2014  CEA/DEN, EDF R&D
2 #
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, or (at your option) any later version.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20
21 if not ('servermanager' in dir()):
22   from pvsimple import *
23
24 import os, inspect
25
26 def demo2(fname, impth):
27     """This demo shows the use of readers, data information and display properties."""
28    
29  # The view
30     v = GetRenderView()
31     if not v:
32        v = CreateRenderView()
33     v.CameraPosition = [-20, -9, -45]
34     v.CameraFocalPoint = [0.7, 0.3, 1.7]
35     v.CameraViewUp = [-0.75, -0.6, 0.25]
36     v.CameraViewAngle = [30]
37     v.StillRender()
38
39     # Create the exodus reader and specify a file name
40     reader = ExodusIIReader(FileName=fname)
41
42     # Get the list of point arrays.
43     avail = reader.PointVariables.Available
44     print avail
45
46     # Select all arrays
47     reader.PointVariables = avail
48
49     # Turn on the visibility of the reader
50     Show(reader)
51
52     # Set representation to wireframe
53     SetDisplayProperties(Representation = "Wireframe")
54    
55     # Black background
56     SetViewProperties(Background = [0., 0., 0.])
57     Render()
58
59     # Change the elevation of the camera.
60     GetActiveCamera().Elevation(45)
61     Render()
62
63     # Now that the reader executed, let's get some information about it's output.
64     pdi = reader[0].PointData
65
66     # This prints a list of all read point data arrays as well as their value ranges.
67     print 'Number of point arrays:', len(pdi)
68     for i in range(len(pdi)):
69         ai = pdi[i]
70         print "----------------"
71         print "Array:", i, " ", ai.Name, ":"
72         numComps = ai.GetNumberOfComponents()
73         print "Number of components:", numComps
74         for j in range(numComps):
75             print "Range:", ai.GetRange(j)
76
77     # 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. 
78     SetDisplayProperties(LookupTable = MakeBlueToRedLT(0.00678, 0.0288))
79
80     # Color by point array called Pres
81     SetDisplayProperties(ColorAttributeType = "POINT_DATA")
82     SetDisplayProperties(ColorArrayName = "Pres")
83
84     WriteImage(filename = (impth + "demo2_1.png"), view=v, Magnification=2)
85
86     # Set representation to surface
87     SetDisplayProperties(Representation = "Surface")
88
89     # Scalar Bar
90     lt = MakeBlueToRedLT(0.00678, 0.0288)
91     ScalarBar = CreateScalarBar(LookupTable = lt, Title = "Sample")
92     GetRenderView().Representations.append(ScalarBar)
93     WriteImage(filename = (impth + "demo2_2.png"), view=v, Magnification=2)
94     Render()
95
96
97 scriptdir = inspect.getframeinfo(inspect.currentframe())[0]
98 testdir = os.path.dirname( os.path.abspath(scriptdir) )
99 pvdata = os.getenv("SAMPLES_SRC_DIR")
100
101 if __name__ == "__main__":
102     demo2(fname=pvdata+"/Data/disk_out_ref.ex2", impth=testdir+"/Pic/")