Salome HOME
a69af55ed53a28cdbcf74af453c2ae6a22c143c6
[modules/paravis.git] / src / Plugins / MEDReader / Test / testMEDReader19.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2015-2017  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay
21
22 import os
23 import sys
24
25 from MEDLoader import *
26
27 """ 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)
28 There is still a problem when both image comparison and Fetch are enable together."""
29
30 fname="testMEDReader19.med"
31 imgName="testMEDReader19.png"
32 meshName="mesh"
33 mm=MEDFileUMesh()
34 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)])
35 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]]
36 conn1=[[NORM_SEG2,4,5],[NORM_SEG2,5,2],[NORM_SEG2,1,0],[NORM_SEG2,6,7]]
37 m0=MEDCouplingUMesh() ; m0.setCoords(coo) ; m0.setMeshDimension(2) ; m0.allocateCells(0)
38 for c in conn0:
39     m0.insertNextCell(c[0],c[1:])
40 mm[0]=m0
41 m1=MEDCouplingUMesh() ; m1.setCoords(coo) ; m1.setMeshDimension(1) ; m1.allocateCells(0)
42 for c in conn1:
43     m1.insertNextCell(c[0],c[1:])
44 mm[-1]=m1
45 mm.setName(meshName)
46 mm.write(fname,2)
47 #
48 #### import the simple module from the paraview
49 from paraview.simple import *
50 import vtk.test.Testing # this line must be here. If not SIGSEGV ! KW10658
51 #### disable automatic camera reset on 'Show'
52 paraview.simple._DisableFirstRenderCameraReset()
53 # create a new 'MED Reader'
54 testMEDReader19med = MEDReader(FileName=fname)
55 testMEDReader19med.AllArrays = ['TS0/mesh/ComSup0/mesh@@][@@P0']
56 testMEDReader19med.AllTimeSteps = ['0000']
57 # Properties modified on testMEDReader19med
58 testMEDReader19med.AllArrays = ['TS0/mesh/ComSup0/mesh@@][@@P0']
59
60 if '-D' not in sys.argv:
61     # get active view
62     renderView1 = GetActiveViewOrCreate('RenderView')
63
64     # reset view to fit data
65     renderView1.ResetCamera()
66
67     #changing interaction mode based on data extents
68     renderView1.InteractionMode = '2D'
69     renderView1.CameraPosition = [0.2, 0.2, 10000.0]
70     renderView1.CameraFocalPoint = [0.2, 0.2, 0.0]
71     testMEDReader19med.UpdatePipeline()
72     # create a new 'Extract Cell Type'
73     extractCellType1 = ExtractCellType(Input=testMEDReader19med)
74     extractCellType1.AllGeoTypes = []
75
76     # Properties modified on extractCellType1
77     extractCellType1.AllGeoTypes = ['TRI3']
78
79     # show data in view
80     extractCellType1Display = Show(extractCellType1, renderView1)
81     # trace defaults for the display properties.
82     extractCellType1Display.ColorArrayName = [None, '']
83     extractCellType1Display.ScalarOpacityUnitDistance = 0.5
84
85     renderView1.InteractionMode = '2D'
86     renderView1.CameraPosition = [0.2, 0.2, 10000.0]
87     renderView1.CameraFocalPoint = [0.2, 0.2, 0.0]
88     renderView1.CameraParallelScale = 0.7071067811865476
89
90     res=servermanager.Fetch(extractCellType1,0)
91     assert(res.GetBlock(0).GetNumberOfCells()==2) # problem was here in PV4.3.1
92
93     # compare with baseline image # Waiting KW return to uncomment this part because SIGSEGV in PV5.
94     try:
95       baselineIndex = sys.argv.index('-B')+1
96       baselinePath = sys.argv[baselineIndex]
97     except:
98       print("Could not get baseline directory. Test failed.")
99       exit(1)
100     baseline_file = os.path.join(baselinePath, imgName)
101     import vtk.test.Testing
102     from vtk.util.misc import vtkGetTempDir
103     vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
104     vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file, threshold=1)
105     vtk.test.Testing.interact()