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