1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2015-2023 CEA, EDF
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 medcoupling import *
26 from paraview.simple import *
27 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
30 """ This is a non regression EDF12599"""
31 fname="testMEDReader21.med"
35 m0=MEDCouplingUMesh(meshName,1)
36 m0.setCoords(DataArrayDouble([(0.,0.,0),(1.,0.,0.),(2.,0.,0.)]))
38 m0.insertNextCell(NORM_SEG2,[0,1])
39 m0.insertNextCell(NORM_SEG2,[1,2])
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
48 def test(baseline_file):
49 fname, meshName, fieldName = GenerateCase()
51 testTotomed = MEDReader(FileNames=[fname])
52 testTotomed.FieldsStatus = ['TS0/%s/ComSup0/%s@@][@@GSSNE'%(meshName,fieldName)]
53 testTotomed.TimesFlagsStatus = ['0000']
55 if '-D' not in sys.argv:
57 renderView1 = GetActiveViewOrCreate('RenderView')
58 # uncomment following to set a specific view size
59 # renderView1.ViewSize = [739, 503]
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
68 # reset view to fit data
69 renderView1.ResetCamera()
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]
78 ColorBy(testTotomedDisplay, ('FIELD', 'vtkBlockColors'))
80 # hide color bar/color legend
81 testTotomedDisplay.SetScalarBarVisibility(renderView1, False)
83 # get color transfer function/color map for 'vtkBlockColors'
84 vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
86 # get opacity transfer function/opacity map for 'vtkBlockColors'
87 vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
89 # create a new 'ELNO Mesh'
90 eLNOMesh1 = ELNOfieldToSurface(Input=testTotomed)
92 # Properties modified on eLNOMesh1
93 eLNOMesh1.ShrinkFactor = 0.5 # <- test is here !!!!!!!!
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
103 Hide(testTotomed, renderView1)
105 # set scalar coloring
106 ColorBy(eLNOMesh1Display, ('FIELD', 'vtkBlockColors'))
108 # show color bar/color legend
109 eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
111 # set scalar coloring
112 ColorBy(eLNOMesh1Display, ('POINTS', 'MyField'))
114 # rescale color and/or opacity maps used to include current data range
115 eLNOMesh1Display.RescaleTransferFunctionToDataRange(True)
117 # show color bar/color legend
118 eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
120 # get color transfer function/color map for 'MyField'
121 myFieldLUT = GetColorTransferFunction('MyField')
123 # get opacity transfer function/opacity map for 'MyField'
124 myFieldPWF = GetOpacityTransferFunction('MyField')
126 # hide color bar/color legend
127 eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
129 # create a new 'Glyph'
130 glyph1 = Glyph(Input=eLNOMesh1,
132 glyph1.ScaleArray = []
133 glyph1.OrientationArray = ['POINTS', 'No orientation array']
134 glyph1.ScaleFactor = 0.15000000000000002
135 glyph1.GlyphTransform = 'Transform2'
137 # Properties modified on glyph1
138 glyph1.GlyphType = 'Sphere'
139 glyph1.ScaleFactor = 0.15
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'
148 # hide color bar/color legend
149 glyph1Display.SetScalarBarVisibility(renderView1, False)
151 #### saving camera placements for all active views
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]
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()
167 if __name__ == "__main__":
168 imgName="testMEDReader21.png"
169 baseline_file = RetriveBaseLine(imgName)