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