Salome HOME
Merge branch 'V8_0_BR'
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader19.py
1 from MEDLoader import *
2
3 """ This is a non regression bug revealed during training session. The bug is linked to the native Threshold VTK filter. Corrected with PV version >= 4.4. (KW10658)
4 There is still a problem when both image comparison and Fetch are enable together."""
5
6 fname="testMEDReader19.med"
7 imgName="testMEDReader19.png"
8 meshName="mesh"
9 mm=MEDFileUMesh()
10 coo=DataArrayDouble([(-0.3,-0.3),(0.2,-0.3),(0.7,-0.3),(-0.3,0.2),(0.2,0.2),(0.7,0.2),(-0.3,0.7),(0.2,0.7),(0.7,0.7)])
11 conn0=[[NORM_TRI3,1,4,2],[NORM_TRI3,4,5,2],[NORM_QUAD4,0,3,4,1],[NORM_QUAD4,6,7,4,3],[NORM_QUAD4,7,8,5,4]]
12 conn1=[[NORM_SEG2,4,5],[NORM_SEG2,5,2],[NORM_SEG2,1,0],[NORM_SEG2,6,7]]
13 m0=MEDCouplingUMesh() ; m0.setCoords(coo) ; m0.setMeshDimension(2) ; m0.allocateCells(0)
14 for c in conn0:
15     m0.insertNextCell(c[0],c[1:])
16 mm[0]=m0
17 m1=MEDCouplingUMesh() ; m1.setCoords(coo) ; m1.setMeshDimension(1) ; m1.allocateCells(0)
18 for c in conn1:
19     m1.insertNextCell(c[0],c[1:])
20 mm[-1]=m1
21 mm.setName(meshName)
22 mm.write(fname,2)
23 #
24 #### import the simple module from the paraview
25 from paraview.simple import *
26 import vtk.test.Testing # this line must be here. If not SIGSEGV ! KW10658
27 #### disable automatic camera reset on 'Show'
28 paraview.simple._DisableFirstRenderCameraReset()
29 # create a new 'MED Reader'
30 testMEDReader19med = MEDReader(FileName=fname)
31 testMEDReader19med.AllArrays = ['TS0/mesh/ComSup0/mesh@@][@@P0']
32 testMEDReader19med.AllTimeSteps = ['0000']
33 # Properties modified on testMEDReader19med
34 testMEDReader19med.AllArrays = ['TS0/mesh/ComSup0/mesh@@][@@P0']
35
36 # get active view
37 renderView1 = GetActiveViewOrCreate('RenderView')
38
39 # reset view to fit data
40 renderView1.ResetCamera()
41
42 #changing interaction mode based on data extents
43 renderView1.InteractionMode = '2D'
44 renderView1.CameraPosition = [0.2, 0.2, 10000.0]
45 renderView1.CameraFocalPoint = [0.2, 0.2, 0.0]
46 testMEDReader19med.UpdatePipeline()
47 # create a new 'Extract Cell Type'
48 extractCellType1 = ExtractCellType(Input=testMEDReader19med)
49 extractCellType1.AllGeoTypes = []
50
51 # Properties modified on extractCellType1
52 extractCellType1.AllGeoTypes = ['TRI3']
53
54 # show data in view
55 extractCellType1Display = Show(extractCellType1, renderView1)
56 # trace defaults for the display properties.
57 extractCellType1Display.ColorArrayName = [None, '']
58 extractCellType1Display.ScalarOpacityUnitDistance = 0.5
59 extractCellType1Display.OpacityArray = [None, '']
60 extractCellType1Display.RadiusArray = [None, '']
61 extractCellType1Display.RadiusRange = [0.2, 0.7]
62 extractCellType1Display.ConstantRadius = 0.7
63 extractCellType1Display.PointSpriteDefaultsInitialized = 1
64 extractCellType1Display.SelectInputVectors = [None, '']
65 extractCellType1Display.WriteLog = ''
66
67
68 renderView1.InteractionMode = '2D'
69 renderView1.CameraPosition = [0.2, 0.2, 10000.0]
70 renderView1.CameraFocalPoint = [0.2, 0.2, 0.0]
71 renderView1.CameraParallelScale = 0.7071067811865476
72
73 res=servermanager.Fetch(extractCellType1,0)
74 assert(res.GetBlock(0).GetNumberOfCells()==2) # problem was here in PV4.3.1
75
76 # compare with baseline image # Waiting KW return to uncomment this part because SIGSEGV in PV5.
77 import os
78 import sys
79 try:
80   baselineIndex = sys.argv.index('-B')+1
81   baselinePath = sys.argv[baselineIndex]
82 except:
83   print "Could not get baseline directory. Test failed."
84   exit(1)
85 baseline_file = os.path.join(baselinePath, imgName)
86 import vtk.test.Testing
87 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
88 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file, threshold=25)
89 vtk.test.Testing.interact()
90