1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay (EDF R&D)
25 from MEDLoader import *
27 """ This test is a non regression test that checks the behaviour of MEDReader when a mesh has the same name than a field.
30 fname="testMEDReader15.med"
31 outImgName="testMEDReader15.png"
34 c=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(0.,1.,0.)])
39 f=MEDCouplingFieldDouble(ON_NODES)
41 f.setArray(DataArrayDouble([(-1.,1.,0.),(0.,1.,0.),(1.,1.,0.)]))
42 tmp=MEDCouplingUMesh.Build0DMeshFromCoords(m.getCoords()) ; tmp.setName(zeName)
44 WriteFieldUsingAlreadyWrittenMesh(fname,f)
47 from paraview.simple import *
49 paraview.simple._DisableFirstRenderCameraReset()
50 reader=MEDReader(FileName=fname)
51 ExpectedEntries=['TS0/zeName/ComSup0/zeName@@][@@P1','TS0/zeName/ComSup0/MESH@zeName@@][@@P1']
52 assert(reader.GetProperty("FieldsTreeInfo")[::2]==ExpectedEntries)
55 glyph1=Glyph(Input=reader,GlyphType='Arrow',ScaleArray='FamilyIdNode',OrientationArray='zeName',GlyphMode='All Points',MaximumGlyphSize=0.1,GlyphTransform='Transform2')
57 if '-D' not in sys.argv:
58 renderView1=GetActiveViewOrCreate('RenderView')
59 renderView1.InteractionMode='3D'
60 zeNameLUT = GetColorTransferFunction('zeName')
61 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]
62 zeNameLUT.ScalarRangeInitialized = 1.
63 zeNameLUT.VectorMode = 'Component'
65 glyph1Display=Show(glyph1,renderView1)
66 glyph1Display.ColorArrayName = ['POINTS', 'FamilyIdNode']
67 glyph1Display.LookupTable = zeNameLUT
69 ColorBy(glyph1Display, ('POINTS', 'zeName'))
70 # rescale color and/or opacity maps used to include current data range
71 glyph1Display.RescaleTransferFunctionToDataRange(True)
72 # do not show color bar/color legend
73 glyph1Display.SetScalarBarVisibility(renderView1, False)
75 renderView1.ViewSize =[300,300]
76 renderView1.GetRenderWindow().DoubleBufferOff()
79 # compare with baseline image
81 baselineIndex = sys.argv.index('-B')+1
82 baselinePath = sys.argv[baselineIndex]
84 print("Could not get baseline directory. Test failed.")
86 baseline_file = os.path.join(baselinePath, "testMEDReader15.png")
87 import vtk.test.Testing
88 from vtk.util.misc import vtkGetTempDir
89 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
90 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
92 vtk.test.Testing.interact()