1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2015-2019 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay
25 from MEDLoader import *
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."""
30 fname="testMEDReader19.med"
31 imgName="testMEDReader19.png"
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)
39 m0.insertNextCell(c[0],c[1:])
41 m1=MEDCouplingUMesh() ; m1.setCoords(coo) ; m1.setMeshDimension(1) ; m1.allocateCells(0)
43 m1.insertNextCell(c[0],c[1:])
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']
60 if '-D' not in sys.argv:
62 renderView1 = GetActiveViewOrCreate('RenderView')
64 # reset view to fit data
65 renderView1.ResetCamera()
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 = []
76 # Properties modified on extractCellType1
77 extractCellType1.AllGeoTypes = ['TRI3']
80 extractCellType1Display = Show(extractCellType1, renderView1)
81 # trace defaults for the display properties.
82 extractCellType1Display.ColorArrayName = [None, '']
83 extractCellType1Display.ScalarOpacityUnitDistance = 0.5
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
90 res=servermanager.Fetch(extractCellType1,0)
91 assert(res.GetBlock(0).GetNumberOfCells()==2) # problem was here in PV4.3.1
93 # compare with baseline image # Waiting KW return to uncomment this part because SIGSEGV in PV5.
95 baselineIndex = sys.argv.index('-B')+1
96 baselinePath = sys.argv[baselineIndex]
98 print("Could not get baseline directory. Test failed.")
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()