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
22 from MEDLoader import *
24 fname="testMEDReader2.med"
25 outImgName="testMEDReader2.png"
27 """ This use case is a mesh containing a large number of orphan cells (cells having no field lying on them)
30 arrX=DataArrayDouble(7) ; arrX.iota()
31 arrY=DataArrayDouble(7) ; arrY.iota()
32 arrZ=DataArrayDouble(7) ; arrZ.iota()
34 m.setCoords(arrX,arrY,arrZ)
35 m=m.buildUnstructured() ; m.setName("mesh")
37 tmp=tmp.buildDescendingConnectivity()[0]
38 nodeIds=tmp.findNodesOnPlane([0.,0.,3.],[0.,0.,1.],1e-12)
39 cellIds=tmp.getCellIdsLyingOnNodes(nodeIds,True)
42 mm.setMeshAtLevel(0,m)
43 mm.setMeshAtLevel(-1,m1)
46 pfl=DataArrayInt([7,8,9,10,13,14,15,16,19,20,21,22,25,26,27,28]) ; pfl.setName("pfl")
47 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("ACellField")
48 arr=DataArrayDouble(16) ; arr.iota()
49 arr2=arr.deepCopy() ; arr2.reverse()
50 arr=DataArrayDouble.Meld(arr,arr2) ; arr.setInfoOnComponents(["aa","bbb"])
52 f1ts=MEDFileField1TS()
53 f1ts.setFieldProfile(f,mm,-1,pfl)
56 ################### MED write is done -> Go to MEDReader
58 from paraview.simple import *
60 testMEDReader1=MEDReader(FileName=fname)
61 testMEDReader1.AllArrays=['TS0/mesh/ComSup0/ACellField@@][@@P0']
62 testMEDReader2=MEDReader(FileName=fname)
63 testMEDReader2.AllArrays=['TS0/mesh/ComSup1/mesh@@][@@P0']
64 GroupDatasets1=GroupDatasets(Input=[testMEDReader1,testMEDReader2])
66 Clip1 = Clip(ClipType="Plane",Input=GroupDatasets1)
67 Clip1.Scalars=['FamilyIdCell']
68 Clip1.ClipType.Origin=[3.0, 3.0, 3.0]
70 Clip1.ClipType.Normal=[0.9255623174457069, 0.0027407477590518157, 0.378585373233375]
71 Clip1.Scalars=['CELLS']
73 DataRepresentation4 = Show()
74 DataRepresentation4.EdgeColor = [0.0, 0.0, 0.5000076295109483]
75 DataRepresentation4.SelectionCellFieldDataArrayName = 'ACellField'
76 DataRepresentation4.ScalarOpacityUnitDistance = 1.61104723630366
77 DataRepresentation4.ExtractedBlockIndex = 2
78 DataRepresentation4.ScaleFactor = 0.6000000000000001
79 DataRepresentation4.Visibility = 1
80 DataRepresentation4.Representation = 'Wireframe'
82 ExtractBlock1 = ExtractBlock(Input=Clip1)
83 ExtractBlock1.BlockIndices=[1, 2]
85 DataRepresentation5 = Show()
86 DataRepresentation5.EdgeColor = [0.0, 0.0, 0.5000076295109483]
87 DataRepresentation5.SelectionCellFieldDataArrayName = 'FamilyIdCell'
88 DataRepresentation5.ScaleFactor = 0.6
89 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 )
90 a2_ACellField_PiecewiseFunction=CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] )
91 a2_ACellField_PVLookupTable.ScalarOpacityFunction = a2_ACellField_PiecewiseFunction
92 DataRepresentation5.ScalarOpacityFunction = a2_ACellField_PiecewiseFunction
93 DataRepresentation5.LookupTable = a2_ACellField_PVLookupTable
94 DataRepresentation5.ColorArrayName = ("CELLS", "ACellField")
96 RenderView1 = GetRenderView()
97 RenderView1.CenterOfRotation = [3.0, 3.0, 3.0]
98 RenderView1.CameraViewUp = [-0.03886073885859842, 0.48373409998193495, 0.8743518533691291]
99 RenderView1.CameraPosition = [7.351939549758929, -5.688193007926853, 8.000155023042788]
100 RenderView1.CameraFocalPoint = [2.9999999999999996, 2.9999999999999987, 2.9999999999999982]
102 RenderView1.ViewSize =[300,300]
105 #WriteImage(outImgName)
107 # compare with baseline image
111 baselineIndex = sys.argv.index('-B')+1
112 baselinePath = sys.argv[baselineIndex]
114 print("Could not get baseline directory. Test failed.")
116 baseline_file = os.path.join(baselinePath, "testMEDReader2.png")
117 import vtk.test.Testing
118 from vtk.util.misc import vtkGetTempDir
119 vtk.test.Testing.VTK_TEMP_DIR = vtk.util.misc.vtkGetTempDir()
120 vtk.test.Testing.compareImage(GetActiveView().GetRenderWindow(), baseline_file,
122 vtk.test.Testing.interact()