Salome HOME
Update baselines for OpenGL2
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader10.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2017  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay
21
22 from MEDLoader import *
23
24 """ This test focuses on GenerateVector part.
25 """
26
27 fname="testMEDReader10.med"
28 outImgName="testMEDReader10.png"
29 ##############
30 coo=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(0.,0.,1.),(1.,0.,1.),(2.,0.,1.),(3.,0.,1.),(0.,1.,1.),(1.,1.,1.),(2.,1.,1.),(3.,1.,1.)])
31 m=MEDCouplingUMesh("myMesh",3) ; m.setCoords(coo)
32 m.allocateCells()
33 m.insertNextCell(NORM_HEXA8,[0,4,5,1,8,12,13,9]) ; m.insertNextCell(NORM_HEXA8,[1,5,6,2,9,13,14,10]) ; m.insertNextCell(NORM_HEXA8,[2,6,7,3,10,14,15,11])
34 f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setName("f0NbComp1") ; f0.setMesh(m) ;
35 arr=DataArrayDouble(8) ; arr.iota() ; arr=DataArrayDouble.Aggregate(arr,arr+8) ; arr.setInfoOnComponents(["1st"])
36 f0.setArray(arr)
37 f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setName("f1NbComp2") ; f1.setMesh(m) ;
38 arr=DataArrayDouble([(-1.,-1.),(0.,0.5),(0.,0.5),(1.,-1.),(-1.,1.),(0.,-0.5),(0.,-0.5),(1.,1.)]) ; arr=DataArrayDouble.Aggregate(arr,arr) ; arr.setInfoOnComponents(["1st","2nd"])
39 f1.setArray(arr)
40 f2=MEDCouplingFieldDouble(ON_NODES) ; f2.setName("f2NbComp3") ; f2.setMesh(m) ;
41 arr=DataArrayDouble([(-1.,-1.,-1.),(0.,0.5,0.),(0.,0.5,0.),(1.,-1.,-1.),(-1.,1.,-1.),(0.,-0.5,0.),(0.,-0.5,0.),(1.,1.,-1)]) ; arr2=arr[:] ; arr2[[0,3,4,7],2]=1.
42 arr=DataArrayDouble.Aggregate(arr,arr2) ; arr.setInfoOnComponents(["1st","2nd","3rd"])
43 f2.setArray(arr)
44 f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setName("f3NbComp4") ; f3.setMesh(m) ;
45 arr=DataArrayDouble([(-1.,-1.,-1.),(0.,0.5,0.),(0.,0.5,0.),(1.,-1.,-1.),(-1.,1.,-1.),(0.,-0.5,0.),(0.,-0.5,0.),(1.,1.,-1)]) ; arr2=arr[:] ; arr2[[0,3,4,7],2]=1.
46 arr=DataArrayDouble.Aggregate(arr,arr2) ; arr3=DataArrayDouble(16) ; arr3.iota() ; arr=DataArrayDouble.Meld([arr,arr3])
47 arr.setInfoOnComponents(["1st","2nd","3rd","4th"])
48 f3.setArray(arr)
49 #
50 WriteMesh(fname,m,True)
51 WriteFieldUsingAlreadyWrittenMesh(fname,f0)
52 WriteFieldUsingAlreadyWrittenMesh(fname,f1)
53 WriteFieldUsingAlreadyWrittenMesh(fname,f2)
54 WriteFieldUsingAlreadyWrittenMesh(fname,f3)
55 ################### MED write is done -> Go to MEDReader
56 from paraview.simple import *
57
58 myMedReader=MEDReader(FileName=fname)
59 keys=myMedReader.GetProperty("FieldsTreeInfo")[::2]
60 # list all the names of arrays that can be seen (including their spatial discretization)
61 arr_name_with_dis=[elt.split("/")[-1] for elt in keys]
62 # list all the names of arrays (Equal to those in the MED File)
63 arr_name=[elt.split(myMedReader.GetProperty("Separator").GetData())[0] for elt in arr_name_with_dis]
64 myMedReader.AllArrays=keys
65 myMedReader.GenerateVectors=1
66
67 RenderView1=GetRenderView()
68 DataRepresentation1 = Show()
69 DataRepresentation1.EdgeColor = [0.0, 0.0, 0.5]
70 DataRepresentation1.SelectionPointFieldDataArrayName='f0NbComp1'
71 DataRepresentation1.ScalarOpacityUnitDistance = 2.299619191183727
72 #DataRepresentation1.ExtractedBlockIndex = 1
73 DataRepresentation1.ScaleFactor = 0.3
74 RenderView1.CenterOfRotation = [1.5, 0.5, 0.5]
75 RenderView1.CameraPosition = [1.5, 0.5, 6.907227082229696]
76 RenderView1.CameraFocalPoint = [1.5, 0.5, 0.5]
77 RenderView1.CameraParallelScale = 1.6583123951777
78 DataRepresentation1.Representation = 'Wireframe'
79 #
80 wbv=WarpByVector(Input=myMedReader)
81 wbv.ScaleFactor=0.1
82 wbv.Vectors=['POINTS','f3NbComp4_Vector']
83 assert(wbv.PointData.keys()==['f0NbComp1','f1NbComp2','f1NbComp2_Vector','f2NbComp3','f3NbComp4','f3NbComp4_Vector'])
84 #
85 DataRepresentation2 = Show()
86 DataRepresentation2.EdgeColor = [0.0, 0.0, 0.5000076295109483]
87 DataRepresentation2.SelectionPointFieldDataArrayName = 'f0NbComp1'
88 DataRepresentation2.SelectionCellFieldDataArrayName = 'FamilyIdCell'
89 DataRepresentation2.ScalarOpacityUnitDistance = 4.546673931685981
90 #DataRepresentation2.ExtractedBlockIndex = 1
91 DataRepresentation2.ScaleFactor = 0.5
92 DataRepresentation1.Visibility = 0
93 DataRepresentation1.ColorArrayName = ('POINT_DATA', '')
94 DataRepresentation1.Visibility = 1
95 a4_f3NbComp4_PVLookupTable = GetLookupTableForArray( "f3NbComp4", 4, RGBPoints=[1.118033988749895, 0.23, 0.299, 0.754, 8.108851429645696, 0.865, 0.865, 0.865, 15.0996688705415, 0.706, 0.016, 0.15], VectorMode='Magnitude', NanColor=[0.25, 0.0, 0.0], ColorSpace='Diverging', ScalarRangeInitialized=1.0 )
96 a4_f3NbComp4_PiecewiseFunction = CreatePiecewiseFunction( Points=[1.118033988749895, 0.0, 0.5, 0.0, 15.0996688705415, 1.0, 0.5, 0.0] )
97 DataRepresentation1.ScalarOpacityFunction = a4_f3NbComp4_PiecewiseFunction
98 DataRepresentation1.LookupTable = a4_f3NbComp4_PVLookupTable
99 a4_f3NbComp4_PVLookupTable.ScalarOpacityFunction = a4_f3NbComp4_PiecewiseFunction
100 DataRepresentation2.ScalarOpacityFunction = a4_f3NbComp4_PiecewiseFunction
101 DataRepresentation2.ColorArrayName = ('POINT_DATA', 'f3NbComp4')
102 DataRepresentation2.LookupTable = a4_f3NbComp4_PVLookupTable
103 RenderView1.CameraViewUp = [0.32310237626907823, -0.28721735329781684, -0.901726702728644]
104 RenderView1.CameraPosition = [0.17151044563787257, 6.31903262423349, -1.8294921560963984]
105 RenderView1.CameraFocalPoint = [1.4999999999999996, 0.49999999999999944, 0.4999999999999996]
106 #
107 RenderView1.ViewSize =[300,300]
108 Render()
109
110 # compare with baseline image
111 import os
112 import sys
113 try:
114   baselineIndex = sys.argv.index('-B')+1
115   baselinePath = sys.argv[baselineIndex]
116 except:
117   print "Could not get baseline directory. Test failed."
118   exit(1)
119 baseline_file = os.path.join(baselinePath, "testMEDReader10.png")
120 import vtk.test.Testing
121 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
122 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
123                                                             threshold=1)
124 vtk.test.Testing.interact()