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