Salome HOME
Copyright update 2021
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader21.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2015-2021  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 def GenerateCase():
30   """ This is a non regression EDF12599"""
31   fname="testMEDReader21.med"
32   fieldName="MyField"
33   meshName="mesh"
34   m=MEDFileUMesh()
35   m0=MEDCouplingUMesh(meshName,1)
36   m0.setCoords(DataArrayDouble([(0.,0.,0),(1.,0.,0.),(2.,0.,0.)]))
37   m0.allocateCells()
38   m0.insertNextCell(NORM_SEG2,[0,1])
39   m0.insertNextCell(NORM_SEG2,[1,2])
40   m[0]=m0
41   #
42   f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setName(fieldName)
43   f.setMesh(m0) ; f.setArray(DataArrayDouble([1.,7.,3.,2.]))
44   WriteField(fname,f,True)
45   return fname, meshName, fieldName
46
47 @WriteInTmpDir
48 def test(baseline_file):
49   fname, meshName, fieldName = GenerateCase()
50   ########
51   testTotomed = MEDReader(FileName=fname)
52   testTotomed.AllArrays = ['TS0/%s/ComSup0/%s@@][@@GSSNE'%(meshName,fieldName)]
53   testTotomed.AllTimeSteps = ['0000']
54
55   if '-D' not in sys.argv:
56     # get active view
57     renderView1 = GetActiveViewOrCreate('RenderView')
58     # uncomment following to set a specific view size
59     # renderView1.ViewSize = [739, 503]
60
61     # show data in view
62     testTotomedDisplay = Show(testTotomed, renderView1)
63     # trace defaults for the display properties.
64     testTotomedDisplay.ColorArrayName = [None, '']
65     testTotomedDisplay.GlyphType = 'Arrow'
66     testTotomedDisplay.ScalarOpacityUnitDistance = 1.5874010519681994
67
68     # reset view to fit data
69     renderView1.ResetCamera()
70
71     #changing interaction mode based on data extents
72     renderView1.InteractionMode = '2D'
73     renderView1.CameraPosition = [1.0, 10000.0, 10000.0]
74     renderView1.CameraFocalPoint = [1.0, 0.0, 0.0]
75     renderView1.CameraViewUp = [1.0, 1.0, 0.0]
76
77     # set scalar coloring
78     ColorBy(testTotomedDisplay, ('FIELD', 'vtkBlockColors'))
79
80     # hide color bar/color legend
81     testTotomedDisplay.SetScalarBarVisibility(renderView1, False)
82
83     # get color transfer function/color map for 'vtkBlockColors'
84     vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
85
86     # get opacity transfer function/opacity map for 'vtkBlockColors'
87     vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
88
89     # create a new 'ELNO Mesh'
90     eLNOMesh1 = ELNOfieldToSurface(Input=testTotomed)
91
92     # Properties modified on eLNOMesh1
93     eLNOMesh1.ShrinkFactor = 0.5 # <- test is here !!!!!!!!
94
95     # show data in view
96     eLNOMesh1Display = Show(eLNOMesh1, renderView1)
97     # trace defaults for the display properties.
98     eLNOMesh1Display.ColorArrayName = [None, '']
99     eLNOMesh1Display.GlyphType = 'Arrow'
100     eLNOMesh1Display.ScalarOpacityUnitDistance = 1.1905507889761495
101
102     # hide data in view
103     Hide(testTotomed, renderView1)
104
105     # set scalar coloring
106     ColorBy(eLNOMesh1Display, ('FIELD', 'vtkBlockColors'))
107
108     # show color bar/color legend
109     eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
110
111     # set scalar coloring
112     ColorBy(eLNOMesh1Display, ('POINTS', 'MyField'))
113
114     # rescale color and/or opacity maps used to include current data range
115     eLNOMesh1Display.RescaleTransferFunctionToDataRange(True)
116
117     # show color bar/color legend
118     eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
119
120     # get color transfer function/color map for 'MyField'
121     myFieldLUT = GetColorTransferFunction('MyField')
122
123     # get opacity transfer function/opacity map for 'MyField'
124     myFieldPWF = GetOpacityTransferFunction('MyField')
125
126     # hide color bar/color legend
127     eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
128
129     # create a new 'Glyph'
130     glyph1 = Glyph(Input=eLNOMesh1,
131         GlyphType='Arrow')
132     glyph1.ScaleArray = []
133     glyph1.OrientationArray = ['POINTS', 'No orientation array']
134     glyph1.ScaleFactor = 0.15000000000000002
135     glyph1.GlyphTransform = 'Transform2'
136
137     # Properties modified on glyph1
138     glyph1.GlyphType = 'Sphere'
139     glyph1.ScaleFactor = 0.15
140
141     # show data in view
142     glyph1Display = Show(glyph1, renderView1)
143     # trace defaults for the display properties.
144     glyph1Display.ColorArrayName = ['POINTS', 'MyField']
145     glyph1Display.LookupTable = myFieldLUT
146     glyph1Display.GlyphType = 'Arrow'
147
148     # hide color bar/color legend
149     glyph1Display.SetScalarBarVisibility(renderView1, False)
150
151     #### saving camera placements for all active views
152
153     # current camera placement for renderView1
154     renderView1.InteractionMode = '2D'
155     renderView1.CameraPosition = [0.9999999999999908, 9999.999999999995, 9999.999999999993]
156     renderView1.CameraFocalPoint = [1.0, 0.0, 0.0]
157     renderView1.CameraViewUp = [0.6331899945158901, 0.547298104713038, -0.5472981047130381]
158     renderView1.CameraParallelScale = 0.6930835077290218
159     renderView1.ViewSize = [739,503]
160
161     import vtk.test.Testing
162     from vtk.util.misc import vtkGetTempDir
163     vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
164     vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file, threshold=1)
165     vtk.test.Testing.interact()
166
167 if __name__ == "__main__":
168   imgName="testMEDReader21.png"
169   baseline_file = RetriveBaseLine(imgName)
170   test(baseline_file)
171   pass