1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2016 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)
22 # non regression test that emulates https://ageay@git.salome-platform.org/gitpub/samples/datafiles.git Med/ResOK_0000.med
23 # This test point error during commit efd9331a9455785d0f04b75 in PARAVIS
24 # Commit of the correction : a4e89b15c2faff6341ab9c3d78abc in PARAVIS
25 # Due to mistake in MEDReader, the family field array on nodes was deleted twice when changing time step
27 from MEDLoader import *
28 fname="testMEDReader20.med"
29 png="testMEDReader20.png"
31 arrX=DataArrayDouble(nb+1) ; arrX.iota()
32 arrY=DataArrayDouble([0.,1.])
33 m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m=m.buildUnstructured(); m.setName("mesh") ; m.simplexize(0)
34 mm=MEDFileUMesh() ; mm[0]=m
35 m1=m.computeSkin() ; mm[-1]=m1
37 f0=DataArrayInt(m1.getNumberOfCells()) ; f0.iota() ; mm.setFamilyFieldArr(-1,f0)
38 f1=DataArrayInt(m1.getNumberOfNodes()) ; f1.iota() ; mm.setFamilyFieldArr(1,f1) # <- very important the bug can be shown here
40 nbCells=m1.getNumberOfCells() ; nbNodes=m.getNumberOfNodes()
43 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m)
45 arr=DataArrayInt(2*nb) ; arr.iota(i) ; arr%=nb ; arr=arr.convertToDblArr()
46 f.setArray(arr) ; f.setTime(float(i),i,0)
47 WriteFieldUsingAlreadyWrittenMesh(fname,f)
49 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m1)
51 arr=DataArrayInt(nbCells) ; arr.iota(i) ; arr%=nbCells ; arr=arr.convertToDblArr()
52 f.setArray(arr) ; f.setTime(float(i),i,0)
53 WriteFieldUsingAlreadyWrittenMesh(fname,f)
55 f=MEDCouplingFieldDouble(ON_NODES) ; f.setMesh(m)
56 f.setName("FieldNode")
57 arr=DataArrayDouble(nbNodes) ; arr[:]=float(i)
58 f.setArray(arr) ; f.setTime(float(i),i,0)
59 WriteFieldUsingAlreadyWrittenMesh(fname,f)
62 from paraview.simple import *
63 #### disable automatic camera reset on 'Show'
64 paraview.simple._DisableFirstRenderCameraReset()
66 # create a new 'MED Reader'
67 testMEDReader20med = MEDReader(FileName=fname)
68 testMEDReader20med.AllArrays = ['TS0/mesh/ComSup0/Field@@][@@P0']
69 testMEDReader20med.AllTimeSteps = ['0000', '0001', '0002', '0003', '0004']
72 animationScene1 = GetAnimationScene()
74 # update animation scene based on data timesteps
75 animationScene1.UpdateAnimationUsingDataTimeSteps()
78 renderView1 = GetActiveViewOrCreate('RenderView')
79 # uncomment following to set a specific view size
80 # renderView1.ViewSize = [610, 477]
83 testMEDReader20medDisplay = Show(testMEDReader20med, renderView1)
84 # trace defaults for the display properties.
85 testMEDReader20medDisplay.ColorArrayName = [None, '']
86 testMEDReader20medDisplay.GlyphType = 'Arrow'
87 testMEDReader20medDisplay.ScalarOpacityUnitDistance = 4.664739046219201
89 # reset view to fit data
90 renderView1.ResetCamera()
92 #changing interaction mode based on data extents
93 renderView1.InteractionMode = '2D'
94 renderView1.CameraPosition = [5.0, 0.5, 10000.0]
95 renderView1.CameraFocalPoint = [5.0, 0.5, 0.0]
98 ColorBy(testMEDReader20medDisplay, ('FIELD', 'vtkBlockColors'))
100 # show color bar/color legend
101 testMEDReader20medDisplay.SetScalarBarVisibility(renderView1, True)
103 # get color transfer function/color map for 'vtkBlockColors'
104 vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
106 # get opacity transfer function/opacity map for 'vtkBlockColors'
107 vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
109 # set scalar coloring
110 ColorBy(testMEDReader20medDisplay, ('CELLS', 'Field'))
112 # rescale color and/or opacity maps used to include current data range
113 testMEDReader20medDisplay.RescaleTransferFunctionToDataRange(True)
115 # show color bar/color legend
116 testMEDReader20medDisplay.SetScalarBarVisibility(renderView1, True)
118 # get color transfer function/color map for 'Field'
119 fieldLUT = GetColorTransferFunction('Field')
121 # get opacity transfer function/opacity map for 'Field'
122 fieldPWF = GetOpacityTransferFunction('Field')
124 animationScene1.GoToNext() # <- very important to see the bug play with time steps...
125 animationScene1.GoToNext()
126 animationScene1.GoToNext()
127 animationScene1.GoToNext()
128 animationScene1.GoToPrevious()
129 animationScene1.GoToPrevious()
131 # current camera placement for renderView1
132 renderView1.InteractionMode = '2D'
133 renderView1.CameraPosition = [5.0, 0.5, 10000.0]
134 renderView1.CameraFocalPoint = [5.0, 0.5, 0.0]
135 renderView1.CameraParallelScale = 5.024937810560445
139 renderView1.ViewSize =[300,300]
143 #### saving camera placements for all active views
145 # current camera placement for renderView1
146 renderView1.InteractionMode = '2D'
147 renderView1.CameraPosition = [5.0, 0.5, 10000.0]
148 renderView1.CameraFocalPoint = [5.0, 0.5, 0.0]
149 renderView1.CameraParallelScale = 5.024937810560445
150 # compare with baseline image
154 baselineIndex = sys.argv.index('-B')+1
155 baselinePath = sys.argv[baselineIndex]
157 print "Could not get baseline directory. Test failed."
159 baseline_file = os.path.join(baselinePath,png)
160 import vtk.test.Testing
161 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
162 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file, threshold=25)
163 vtk.test.Testing.interact()