Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader15.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2022  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 (EDF R&D)
21
22 import os
23 import sys
24
25 from medcoupling import *
26 from paraview.simple import *
27 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
28
29 paraview.simple._DisableFirstRenderCameraReset()
30
31 def GenerateCase():
32   """ This test is a non regression test that checks the behaviour of MEDReader when a mesh has the same name than a field.
33   """
34
35   fname="testMEDReader15.med"
36
37   zeName="zeName"
38   c=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(0.,1.,0.)])
39   m=MEDFileUMesh()
40   m.setCoords(c)
41   m.setName(zeName)
42   m.write(fname,2)
43   f=MEDCouplingFieldDouble(ON_NODES)
44   f.setName(zeName)
45   f.setArray(DataArrayDouble([(-1.,1.,0.),(0.,1.,0.),(1.,1.,0.)]))
46   tmp=MEDCouplingUMesh.Build0DMeshFromCoords(m.getCoords()) ; tmp.setName(zeName)
47   f.setMesh(tmp)
48   WriteFieldUsingAlreadyWrittenMesh(fname,f)
49   return fname
50
51 @WriteInTmpDir
52 def test(baseline_file):
53   fname = GenerateCase()
54   reader=MEDReader(FileName=fname)
55   ExpectedEntries=['TS0/zeName/ComSup0/zeName@@][@@P1','TS0/zeName/ComSup0/MESH@zeName@@][@@P1']
56   assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
57
58   #
59   glyph1=Glyph(Input=reader,GlyphType='Arrow',ScaleArray='FamilyIdNode',OrientationArray='zeName',GlyphMode='All Points',ScaleFactor=0.1,GlyphTransform='Transform2')
60
61   if '-D' not in sys.argv:
62     renderView1=GetActiveViewOrCreate('RenderView')
63     renderView1.InteractionMode='3D'
64     zeNameLUT = GetColorTransferFunction('zeName')
65     zeNameLUT.RGBPoints = [1.0, 0.231373, 0.298039, 0.752941, 1.2071067811865475, 0.865003, 0.865003, 0.865003, 1.4142135623730951, 0.705882, 0.0156863, 0.14902]
66     zeNameLUT.ScalarRangeInitialized = 1.
67     zeNameLUT.VectorMode = 'Component'
68
69     glyph1Display=Show(glyph1,renderView1)
70     glyph1Display.ColorArrayName = ['POINTS', 'FamilyIdNode']
71     glyph1Display.LookupTable = zeNameLUT
72     # set scalar coloring
73     ColorBy(glyph1Display, ('POINTS', 'zeName'))
74     # rescale color and/or opacity maps used to include current data range
75     glyph1Display.RescaleTransferFunctionToDataRange(True)
76     # do not show color bar/color legend
77     glyph1Display.SetScalarBarVisibility(renderView1, False)
78     #
79     renderView1.ViewSize =[300,300]
80     renderView1.GetRenderWindow().DoubleBufferOff()
81     Render()
82
83     # compare with baseline image
84     import vtk.test.Testing
85     from vtk.util.misc import vtkGetTempDir
86     vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
87     vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
88                                                                 threshold=1)
89     vtk.test.Testing.interact()
90
91 if __name__ == "__main__":
92   outImgName="testMEDReader15.png"
93   baseline_file = RetriveBaseLine(outImgName)
94   test(baseline_file)
95   pass