# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2015-2016 CEA/DEN, EDF R&D
+# Copyright (C) 2016, 2017 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
#
# Author : Anthony Geay (EDF R&D)
-from paraview.simple import *
+# non regression test that emulates https://ageay@git.salome-platform.org/gitpub/samples/datafiles.git Med/ResOK_0000.med
+# This test point error during commit efd9331a9455785d0f04b75 in PARAVIS
+# Commit of the correction : a4e89b15c2faff6341ab9c3d78abc in PARAVIS
+# Due to mistake in MEDReader, the family field array on nodes was deleted twice when changing time step
from MEDLoader import *
-
-""" This is a non regression EDF12599"""
fname="testMEDReader20.med"
-imgName="testMEDReader20.png"
-fieldName="MyField"
-meshName="mesh"
-m=MEDFileUMesh()
-m0=MEDCouplingUMesh(meshName,1)
-m0.setCoords(DataArrayDouble([(0.,0.,0),(1.,0.,0.),(2.,0.,0.)]))
-m0.allocateCells()
-m0.insertNextCell(NORM_SEG2,[0,1])
-m0.insertNextCell(NORM_SEG2,[1,2])
-m[0]=m0
+png="testMEDReader20.png"
+nb=10
+arrX=DataArrayDouble(nb+1) ; arrX.iota()
+arrY=DataArrayDouble([0.,1.])
+m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m=m.buildUnstructured(); m.setName("mesh") ; m.simplexize(0)
+mm=MEDFileUMesh() ; mm[0]=m
+m1=m.computeSkin() ; mm[-1]=m1
#
-f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setName(fieldName)
-f.setMesh(m0) ; f.setArray(DataArrayDouble([1.,7.,3.,2.]))
-MEDLoader.WriteField(fname,f,True)
-########
-testTotomed = MEDReader(FileName=fname)
-testTotomed.AllArrays = ['TS0/%s/ComSup0/%s@@][@@GSSNE'%(meshName,fieldName)]
-testTotomed.AllTimeSteps = ['0000']
+f0=DataArrayInt(m1.getNumberOfCells()) ; f0.iota() ; mm.setFamilyFieldArr(-1,f0)
+f1=DataArrayInt(m1.getNumberOfNodes()) ; f1.iota() ; mm.setFamilyFieldArr(1,f1) # <- very important the bug can be shown here
+#
+nbCells=m1.getNumberOfCells() ; nbNodes=m.getNumberOfNodes()
+mm.write(fname,2)
+for i in range(5):
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m)
+ f.setName("Field")
+ arr=DataArrayInt(2*nb) ; arr.iota(i) ; arr%=nb ; arr=arr.convertToDblArr()
+ f.setArray(arr) ; f.setTime(float(i),i,0)
+ WriteFieldUsingAlreadyWrittenMesh(fname,f)
+ #
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m1)
+ f.setName("Field")
+ arr=DataArrayInt(nbCells) ; arr.iota(i) ; arr%=nbCells ; arr=arr.convertToDblArr()
+ f.setArray(arr) ; f.setTime(float(i),i,0)
+ WriteFieldUsingAlreadyWrittenMesh(fname,f)
+ #
+ f=MEDCouplingFieldDouble(ON_NODES) ; f.setMesh(m)
+ f.setName("FieldNode")
+ arr=DataArrayDouble(nbNodes) ; arr[:]=float(i)
+ f.setArray(arr) ; f.setTime(float(i),i,0)
+ WriteFieldUsingAlreadyWrittenMesh(fname,f)
+ pass
+#####################
+from paraview.simple import *
+#### disable automatic camera reset on 'Show'
+paraview.simple._DisableFirstRenderCameraReset()
+
+# create a new 'MED Reader'
+testMEDReader20med = MEDReader(FileName=fname)
+testMEDReader20med.AllArrays = ['TS0/mesh/ComSup0/Field@@][@@P0']
+testMEDReader20med.AllTimeSteps = ['0000', '0001', '0002', '0003', '0004']
+
+# get animation scene
+animationScene1 = GetAnimationScene()
+
+# update animation scene based on data timesteps
+animationScene1.UpdateAnimationUsingDataTimeSteps()
+
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# uncomment following to set a specific view size
-# renderView1.ViewSize = [739, 503]
+# renderView1.ViewSize = [610, 477]
# show data in view
-testTotomedDisplay = Show(testTotomed, renderView1)
+testMEDReader20medDisplay = Show(testMEDReader20med, renderView1)
# trace defaults for the display properties.
-testTotomedDisplay.ColorArrayName = [None, '']
-testTotomedDisplay.GlyphType = 'Arrow'
-testTotomedDisplay.ScalarOpacityUnitDistance = 1.5874010519681994
-testTotomedDisplay.SelectUncertaintyArray = [None, '']
-testTotomedDisplay.UncertaintyTransferFunction = 'PiecewiseFunction'
-testTotomedDisplay.OpacityArray = [None, '']
-testTotomedDisplay.RadiusArray = [None, '']
-testTotomedDisplay.RadiusRange = [0.0, 2.0]
-testTotomedDisplay.ConstantRadius = 2.0
-testTotomedDisplay.PointSpriteDefaultsInitialized = 1
-testTotomedDisplay.SelectInputVectors = [None, '']
-testTotomedDisplay.WriteLog = ''
+testMEDReader20medDisplay.ColorArrayName = [None, '']
+testMEDReader20medDisplay.GlyphType = 'Arrow'
+testMEDReader20medDisplay.ScalarOpacityUnitDistance = 4.664739046219201
# reset view to fit data
renderView1.ResetCamera()
#changing interaction mode based on data extents
renderView1.InteractionMode = '2D'
-renderView1.CameraPosition = [1.0, 10000.0, 10000.0]
-renderView1.CameraFocalPoint = [1.0, 0.0, 0.0]
-renderView1.CameraViewUp = [1.0, 1.0, 0.0]
-
-# set scalar coloring
-ColorBy(testTotomedDisplay, ('FIELD', 'vtkBlockColors'))
-
-# show color bar/color legend
-testTotomedDisplay.SetScalarBarVisibility(renderView1, True)
-
-# get color transfer function/color map for 'vtkBlockColors'
-vtkBlockColorsLUT = GetColorTransferFunction('vtkBlockColors')
-
-# get opacity transfer function/opacity map for 'vtkBlockColors'
-vtkBlockColorsPWF = GetOpacityTransferFunction('vtkBlockColors')
-
-# create a new 'ELNO Mesh'
-eLNOMesh1 = ELNOMesh(Input=testTotomed)
-
-# Properties modified on eLNOMesh1
-eLNOMesh1.ShrinkFactor = 0.5 # <- test is here !!!!!!!!
-
-# show data in view
-eLNOMesh1Display = Show(eLNOMesh1, renderView1)
-# trace defaults for the display properties.
-eLNOMesh1Display.ColorArrayName = [None, '']
-eLNOMesh1Display.GlyphType = 'Arrow'
-eLNOMesh1Display.ScalarOpacityUnitDistance = 1.1905507889761495
-eLNOMesh1Display.SelectUncertaintyArray = ['POINTS', 'MyField']
-eLNOMesh1Display.UncertaintyTransferFunction = 'PiecewiseFunction'
-eLNOMesh1Display.OpacityArray = [None, '']
-eLNOMesh1Display.RadiusArray = [None, '']
-eLNOMesh1Display.RadiusRange = [0.25, 1.75]
-eLNOMesh1Display.ConstantRadius = 1.75
-eLNOMesh1Display.PointSpriteDefaultsInitialized = 1
-eLNOMesh1Display.SelectInputVectors = [None, '']
-eLNOMesh1Display.WriteLog = ''
-
-# hide data in view
-Hide(testTotomed, renderView1)
-
-# set scalar coloring
-ColorBy(eLNOMesh1Display, ('FIELD', 'vtkBlockColors'))
-
-# show color bar/color legend
-eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
+renderView1.CameraPosition = [5.0, 0.5, 10000.0]
+renderView1.CameraFocalPoint = [5.0, 0.5, 0.0]
# set scalar coloring
-ColorBy(eLNOMesh1Display, ('POINTS', 'MyField'))
+ColorBy(testMEDReader20medDisplay, ('CELLS', 'Field'))
# rescale color and/or opacity maps used to include current data range
-eLNOMesh1Display.RescaleTransferFunctionToDataRange(True)
+testMEDReader20medDisplay.RescaleTransferFunctionToDataRange(True)
-# show color bar/color legend
-eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
+# do not show color bar/color legend
+testMEDReader20medDisplay.SetScalarBarVisibility(renderView1, False)
-# get color transfer function/color map for 'MyField'
-myFieldLUT = GetColorTransferFunction('MyField')
+# get color transfer function/color map for 'Field'
+fieldLUT = GetColorTransferFunction('Field')
-# get opacity transfer function/opacity map for 'MyField'
-myFieldPWF = GetOpacityTransferFunction('MyField')
+# get opacity transfer function/opacity map for 'Field'
+fieldPWF = GetOpacityTransferFunction('Field')
-# hide color bar/color legend
-eLNOMesh1Display.SetScalarBarVisibility(renderView1, False)
+animationScene1.GoToNext() # <- very important to see the bug play with time steps...
+animationScene1.GoToNext()
+animationScene1.GoToNext()
+animationScene1.GoToNext()
+animationScene1.GoToPrevious()
+animationScene1.GoToPrevious()
-# create a new 'Glyph'
-glyph1 = Glyph(Input=eLNOMesh1,
- GlyphType='Arrow')
-glyph1.Scalars = ['POINTS', 'MyField']
-glyph1.Vectors = ['POINTS', 'None']
-glyph1.ScaleFactor = 0.15000000000000002
-glyph1.GlyphTransform = 'Transform2'
+# current camera placement for renderView1
+renderView1.InteractionMode = '2D'
+renderView1.CameraPosition = [5.0, 0.5, 10000.0]
+renderView1.CameraFocalPoint = [5.0, 0.5, 0.0]
+renderView1.CameraParallelScale = 5.024937810560445
-# Properties modified on glyph1
-glyph1.GlyphType = 'Sphere'
-glyph1.ScaleFactor = 0.15
+#
-# show data in view
-glyph1Display = Show(glyph1, renderView1)
-# trace defaults for the display properties.
-glyph1Display.ColorArrayName = ['POINTS', 'MyField']
-glyph1Display.LookupTable = myFieldLUT
-glyph1Display.GlyphType = 'Arrow'
-glyph1Display.SelectUncertaintyArray = ['POINTS', 'MyField']
-glyph1Display.UncertaintyTransferFunction = 'PiecewiseFunction'
-glyph1Display.OpacityArray = [None, '']
-glyph1Display.RadiusArray = [None, '']
-glyph1Display.RadiusRange = [0.17688040435314178, 1.8231196403503418]
-glyph1Display.ConstantRadius = 1.8231196403503418
-glyph1Display.PointSpriteDefaultsInitialized = 1
-glyph1Display.SelectInputVectors = ['POINTS', 'Normals']
-glyph1Display.WriteLog = ''
-
-# show color bar/color legend
-glyph1Display.SetScalarBarVisibility(renderView1, True)
+renderView1.ViewSize =[300,300]
+Render()
+#WriteImage(png)
#### saving camera placements for all active views
# current camera placement for renderView1
renderView1.InteractionMode = '2D'
-renderView1.CameraPosition = [0.9999999999999908, 9999.999999999995, 9999.999999999993]
-renderView1.CameraFocalPoint = [1.0, 0.0, 0.0]
-renderView1.CameraViewUp = [0.6331899945158901, 0.547298104713038, -0.5472981047130381]
-renderView1.CameraParallelScale = 0.6930835077290218
-renderView1.ViewSize = [739,503]
-
+renderView1.CameraPosition = [5.0, 0.5, 10000.0]
+renderView1.CameraFocalPoint = [5.0, 0.5, 0.0]
+renderView1.CameraParallelScale = 5.024937810560445
+# compare with baseline image
import os
import sys
try:
except:
print "Could not get baseline directory. Test failed."
exit(1)
-baseline_file = os.path.join(baselinePath, imgName)
+baseline_file = os.path.join(baselinePath,png)
import vtk.test.Testing
vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
-vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file, threshold=25)
+vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file, threshold=1)
vtk.test.Testing.interact()
-