1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2015-2019 CEA/DEN, EDF R&D
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 paraview.simple import *
27 from MEDLoader import *
29 """ This is a non regression EDF12599"""
30 fname="testMEDReader21.med"
31 imgName="testMEDReader21.png"
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)
46 testTotomed = MEDReader(FileName=fname)
47 testTotomed.AllArrays = ['TS0/%s/ComSup0/%s@@][@@GSSNE'%(meshName,fieldName)]
48 testTotomed.AllTimeSteps = ['0000']
50 if '-D' not in sys.argv:
52 renderView1 = GetActiveViewOrCreate('RenderView')
53 # uncomment following to set a specific view size
54 # renderView1.ViewSize = [739, 503]
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
63 # reset view to fit data
64 renderView1.ResetCamera()
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]
73 ColorBy(testTotomedDisplay, ('FIELD', 'vtkBlockColors'))
75 # hide color bar/color legend
76 testTotomedDisplay.SetScalarBarVisibility(renderView1, False)
78 # get color transfer function/color map for 'vtkBlockColors'
79 vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
81 # get opacity transfer function/opacity map for 'vtkBlockColors'
82 vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
84 # create a new 'ELNO Mesh'
85 eLNOMesh1 = ELNOfieldToSurface(Input=testTotomed)
87 # Properties modified on eLNOMesh1
88 eLNOMesh1.ShrinkFactor = 0.5 # <- test is here !!!!!!!!
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
98 Hide(testTotomed, renderView1)
100 # set scalar coloring
101 ColorBy(eLNOMesh1Display, ('FIELD', 'vtkBlockColors'))
103 # show color bar/color legend
104 eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
106 # set scalar coloring
107 ColorBy(eLNOMesh1Display, ('POINTS', 'MyField'))
109 # rescale color and/or opacity maps used to include current data range
110 eLNOMesh1Display.RescaleTransferFunctionToDataRange(True)
112 # show color bar/color legend
113 eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
115 # get color transfer function/color map for 'MyField'
116 myFieldLUT = GetColorTransferFunction('MyField')
118 # get opacity transfer function/opacity map for 'MyField'
119 myFieldPWF = GetOpacityTransferFunction('MyField')
121 # hide color bar/color legend
122 eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
124 # create a new 'Glyph'
125 glyph1 = Glyph(Input=eLNOMesh1,
127 glyph1.ScaleArray = ['POINTS', 'MyField']
128 glyph1.OrientationArray = ['POINTS', 'No orientation array']
129 glyph1.MaximumGlyphSize = 0.15000000000000002
130 glyph1.GlyphTransform = 'Transform2'
132 # Properties modified on glyph1
133 glyph1.GlyphType = 'Sphere'
134 glyph1.MaximumGlyphSize = 0.15
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'
143 # hide color bar/color legend
144 glyph1Display.SetScalarBarVisibility(renderView1, False)
146 #### saving camera placements for all active views
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]
157 baselineIndex = sys.argv.index('-B')+1
158 baselinePath = sys.argv[baselineIndex]
160 print("Could not get baseline directory. Test failed.")
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()