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