Salome HOME
e3b89762456d6732889f1d5c9c513ea956c25b49
[modules/paravis.git] / src / Plugins / MEDReader / plugin / Test / testMEDReader19.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2015-2023  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 medcoupling import *
26 from paraview.simple import *
27 from MEDReaderHelper import WriteInTmpDir,RetriveBaseLine
28 #### import the simple module from the paraview
29 #### disable automatic camera reset on 'Show'
30 paraview.simple._DisableFirstRenderCameraReset()
31 import vtk.test.Testing # this line must be here. If not SIGSEGV ! KW10658
32
33 def GenerateCase():
34     """ 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)
35     There is still a problem when both image comparison and Fetch are enable together."""
36     fname="testMEDReader19.med"
37     meshName="mesh"
38     mm=MEDFileUMesh()
39     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)])
40     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]]
41     conn1=[[NORM_SEG2,4,5],[NORM_SEG2,5,2],[NORM_SEG2,1,0],[NORM_SEG2,6,7]]
42     m0=MEDCouplingUMesh() ; m0.setCoords(coo) ; m0.setMeshDimension(2) ; m0.allocateCells(0)
43     for c in conn0:
44         m0.insertNextCell(c[0],c[1:])
45     mm[0]=m0
46     m1=MEDCouplingUMesh() ; m1.setCoords(coo) ; m1.setMeshDimension(1) ; m1.allocateCells(0)
47     for c in conn1:
48         m1.insertNextCell(c[0],c[1:])
49     mm[-1]=m1
50     mm.setName(meshName)
51     mm.write(fname,2)
52     return fname
53
54 @WriteInTmpDir
55 def test(baseline_file):
56     fname = GenerateCase()
57     # create a new 'MED Reader'
58     testMEDReader19med = MEDReader(FileNames=[fname])
59     testMEDReader19med.FieldsStatus = ['TS0/mesh/ComSup0/mesh@@][@@P0']
60     testMEDReader19med.TimesFlagsStatus = ['0000']
61     # Properties modified on testMEDReader19med
62     testMEDReader19med.FieldsStatus = ['TS0/mesh/ComSup0/mesh@@][@@P0']
63
64     if '-D' not in sys.argv:
65         # get active view
66         renderView1 = GetActiveViewOrCreate('RenderView')
67
68         # reset view to fit data
69         renderView1.ResetCamera()
70
71         #changing interaction mode based on data extents
72         renderView1.InteractionMode = '2D'
73         renderView1.CameraPosition = [0.2, 0.2, 10000.0]
74         renderView1.CameraFocalPoint = [0.2, 0.2, 0.0]
75         testMEDReader19med.UpdatePipeline()
76         # create a new 'Extract Cell Type'
77         extractCellType1 = ExtractCellType(Input=testMEDReader19med)
78         extractCellType1.AllGeoTypes = []
79
80         # Properties modified on extractCellType1
81         extractCellType1.AllGeoTypes = ['Triangle']
82
83         # show data in view
84         extractCellType1Display = Show(extractCellType1, renderView1)
85         # trace defaults for the display properties.
86         extractCellType1Display.ColorArrayName = [None, '']
87         extractCellType1Display.ScalarOpacityUnitDistance = 0.5
88
89         renderView1.InteractionMode = '2D'
90         renderView1.CameraPosition = [0.2, 0.2, 10000.0]
91         renderView1.CameraFocalPoint = [0.2, 0.2, 0.0]
92         renderView1.CameraParallelScale = 0.7071067811865476
93
94         res=servermanager.Fetch(extractCellType1,0)
95         assert(res.GetBlock(0).GetNumberOfCells()==2) # problem was here in PV4.3.1
96
97         # compare with baseline image # Waiting KW return to uncomment this part because SIGSEGV in PV5.
98         import vtk.test.Testing
99         from vtk.util.misc import vtkGetTempDir
100         vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
101         vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file, threshold=1)
102         vtk.test.Testing.interact()
103
104 if __name__ == "__main__":
105     imgName="testMEDReader19.png"
106     baseline_file = RetriveBaseLine(imgName)
107     test(baseline_file)