1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2017 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 fname="testMEDReader2.med"
28 outImgName="testMEDReader2.png"
30 """ This use case is a mesh containing a large number of orphan cells (cells having no field lying on them)
33 arrX=DataArrayDouble(7) ; arrX.iota()
34 arrY=DataArrayDouble(7) ; arrY.iota()
35 arrZ=DataArrayDouble(7) ; arrZ.iota()
37 m.setCoords(arrX,arrY,arrZ)
38 m=m.buildUnstructured() ; m.setName("mesh")
40 tmp=tmp.buildDescendingConnectivity()[0]
41 nodeIds=tmp.findNodesOnPlane([0.,0.,3.],[0.,0.,1.],1e-12)
42 cellIds=tmp.getCellIdsLyingOnNodes(nodeIds,True)
45 mm.setMeshAtLevel(0,m)
46 mm.setMeshAtLevel(-1,m1)
49 pfl=DataArrayInt([7,8,9,10,13,14,15,16,19,20,21,22,25,26,27,28]) ; pfl.setName("pfl")
50 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("ACellField")
51 arr=DataArrayDouble(16) ; arr.iota()
52 arr2=arr.deepCopy() ; arr2.reverse()
53 arr=DataArrayDouble.Meld(arr,arr2) ; arr.setInfoOnComponents(["aa","bbb"])
55 f1ts=MEDFileField1TS()
56 f1ts.setFieldProfile(f,mm,-1,pfl)
59 ################### MED write is done -> Go to MEDReader
61 from paraview.simple import *
63 testMEDReader1=MEDReader(FileName=fname)
64 testMEDReader1.AllArrays=['TS0/mesh/ComSup0/ACellField@@][@@P0']
65 testMEDReader2=MEDReader(FileName=fname)
66 testMEDReader2.AllArrays=['TS0/mesh/ComSup1/mesh@@][@@P0']
67 GroupDatasets1=GroupDatasets(Input=[testMEDReader1,testMEDReader2])
69 Clip1 = Clip(ClipType="Plane",Input=GroupDatasets1)
70 Clip1.Scalars=['FamilyIdCell']
71 Clip1.ClipType.Origin=[3.0, 3.0, 3.0]
73 Clip1.ClipType.Normal=[0.9255623174457069, 0.0027407477590518157, 0.378585373233375]
74 Clip1.Scalars=['CELLS']
76 DataRepresentation4 = Show()
77 DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
78 DataRepresentation4.SelectionCellFieldDataArrayName = 'ACellField'
79 DataRepresentation4.ScalarOpacityUnitDistance = 1.61104723630366
80 DataRepresentation4.ExtractedBlockIndex = 2
81 DataRepresentation4.ScaleFactor = 0.6000000000000001
82 DataRepresentation4.Visibility = 1
83 DataRepresentation4.Representation = 'Wireframe'
85 ExtractBlock1 = ExtractBlock(Input=Clip1)
86 ExtractBlock1.BlockIndices=[1, 2]
88 DataRepresentation5 = Show()
89 DataRepresentation5.EdgeColor = [0.0, 0.0, 0.5000076295109483]
90 DataRepresentation5.SelectionCellFieldDataArrayName = 'FamilyIdCell'
91 DataRepresentation5.ScaleFactor = 0.6
92 a2_ACellField_PVLookupTable=GetLookupTableForArray( "ACellField", 2, RGBPoints=[10.63014581273465, 0.23, 0.299, 0.754, 15.0, 0.706, 0.016, 0.15], VectorMode='Magnitude', NanColor=[0.25, 0.0, 0.0], ColorSpace='Diverging', ScalarRangeInitialized=1.0, AllowDuplicateScalars=1 )
93 a2_ACellField_PiecewiseFunction=CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )
94 a2_ACellField_PVLookupTable.ScalarOpacityFunction = a2_ACellField_PiecewiseFunction
95 DataRepresentation5.ScalarOpacityFunction = a2_ACellField_PiecewiseFunction
96 DataRepresentation5.LookupTable = a2_ACellField_PVLookupTable
97 DataRepresentation5.ColorArrayName = ("CELLS", "ACellField")
99 if '-D' not in sys.argv:
100 RenderView1 = GetRenderView()
101 RenderView1.CenterOfRotation = [3.0, 3.0, 3.0]
102 RenderView1.CameraViewUp = [-0.03886073885859842, 0.48373409998193495, 0.8743518533691291]
103 RenderView1.CameraPosition = [7.351939549758929, -5.688193007926853, 8.000155023042788]
104 RenderView1.CameraFocalPoint = [2.9999999999999996, 2.9999999999999987, 2.9999999999999982]
106 RenderView1.ViewSize =[300,300]
109 #WriteImage(outImgName)
111 # compare with baseline image
113 baselineIndex = sys.argv.index('-B')+1
114 baselinePath = sys.argv[baselineIndex]
116 print("Could not get baseline directory. Test failed.")
118 baseline_file = os.path.join(baselinePath, "testMEDReader2.png")
119 import vtk.test.Testing
120 from vtk.util.misc import vtkGetTempDir
121 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
122 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
124 vtk.test.Testing.interact()