Salome HOME
Update copyrights
[modules/paravis.git] / src / Plugins / DevelopedSurface / Test / test_dev_surface2.py
1 # Copyright (C) 2017-2019  EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Author : Anthony Geay (EDF R&D)
20
21 #### import the simple module from the paraview
22 from paraview.simple import *
23 from math import pi
24 TMPFileName="test2.med"
25
26 #### disable automatic camera reset on 'Show'
27 paraview.simple._DisableFirstRenderCameraReset()
28
29 # create a new 'Mandelbrot'
30 mandelbrot1 = Mandelbrot()
31
32 # Properties modified on mandelbrot1
33 mandelbrot1.WholeExtent = [0, 50, 0, 50, 0, 50]
34
35 # get active view
36 renderView1 = GetActiveViewOrCreate('RenderView')
37 # uncomment following to set a specific view size
38 # renderView1.ViewSize = [1017, 317]
39
40 # show data in view
41 mandelbrot1Display = Show(mandelbrot1, renderView1)
42
43 # trace defaults for the display properties.
44 mandelbrot1Display.Representation = 'Outline'
45 mandelbrot1Display.ColorArrayName = ['POINTS', '']
46 mandelbrot1Display.OSPRayScaleArray = 'Iterations'
47 mandelbrot1Display.OSPRayScaleFunction = 'PiecewiseFunction'
48 mandelbrot1Display.SelectOrientationVectors = 'Iterations'
49 mandelbrot1Display.ScaleFactor = 0.25
50 mandelbrot1Display.SelectScaleArray = 'Iterations'
51 mandelbrot1Display.GlyphType = 'Arrow'
52 mandelbrot1Display.GlyphTableIndexArray = 'Iterations'
53 mandelbrot1Display.DataAxesGrid = 'GridAxesRepresentation'
54 mandelbrot1Display.PolarAxes = 'PolarAxesRepresentation'
55 mandelbrot1Display.ScalarOpacityUnitDistance = 0.08124038404635964
56 mandelbrot1Display.Slice = 25
57 mandelbrot1Display.GaussianRadius = 0.125
58 mandelbrot1Display.SetScaleArray = ['POINTS', 'Iterations']
59 mandelbrot1Display.ScaleTransferFunction = 'PiecewiseFunction'
60 mandelbrot1Display.OpacityArray = ['POINTS', 'Iterations']
61 mandelbrot1Display.OpacityTransferFunction = 'PiecewiseFunction'
62 mandelbrot1Display.InputVectors = [None, '']
63 mandelbrot1Display.SelectInputVectors = [None, '']
64 mandelbrot1Display.WriteLog = ''
65
66 # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
67 mandelbrot1Display.ScaleTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 100.0, 1.0, 0.5, 0.0]
68
69 # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
70 mandelbrot1Display.OpacityTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 100.0, 1.0, 0.5, 0.0]
71
72 # reset view to fit data
73 renderView1.ResetCamera()
74
75 # update the view to ensure updated data information
76 renderView1.Update()
77
78 # create a new 'Developed Surface'
79 developedSurface1 = DevelopedSurface(Input=mandelbrot1)
80 developedSurface1.SliceType = 'Cylinder'
81
82 # init the 'Cylinder' selected for 'SliceType'
83 developedSurface1.SliceType.Center = [-0.5, 0.0, 1.0]
84 developedSurface1.SliceType.Radius = 0.5 #1.25
85
86 # show data in view
87 developedSurface1Display = Show(developedSurface1, renderView1)
88
89 # get color transfer function/color map for 'Iterations'
90 iterationsLUT = GetColorTransferFunction('Iterations')
91
92 # trace defaults for the display properties.
93 developedSurface1Display.Representation = 'Surface'
94 developedSurface1Display.ColorArrayName = ['POINTS', 'Iterations']
95 developedSurface1Display.LookupTable = iterationsLUT
96 developedSurface1Display.OSPRayScaleArray = 'Iterations'
97 developedSurface1Display.OSPRayScaleFunction = 'PiecewiseFunction'
98 developedSurface1Display.SelectOrientationVectors = 'Iterations'
99 developedSurface1Display.ScaleFactor = 0.7853981633974483
100 developedSurface1Display.SelectScaleArray = 'Iterations'
101 developedSurface1Display.GlyphType = 'Arrow'
102 developedSurface1Display.GlyphTableIndexArray = 'Iterations'
103 developedSurface1Display.DataAxesGrid = 'GridAxesRepresentation'
104 developedSurface1Display.PolarAxes = 'PolarAxesRepresentation'
105 developedSurface1Display.GaussianRadius = 0.39269908169872414
106 developedSurface1Display.SetScaleArray = ['POINTS', 'Iterations']
107 developedSurface1Display.ScaleTransferFunction = 'PiecewiseFunction'
108 developedSurface1Display.OpacityArray = ['POINTS', 'Iterations']
109 developedSurface1Display.OpacityTransferFunction = 'PiecewiseFunction'
110 developedSurface1Display.InputVectors = [None, '']
111 developedSurface1Display.SelectInputVectors = [None, '']
112 developedSurface1Display.WriteLog = ''
113
114 # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
115 developedSurface1Display.ScaleTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 100.0, 1.0, 0.5, 0.0]
116
117 # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
118 developedSurface1Display.OpacityTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 100.0, 1.0, 0.5, 0.0]
119
120 # hide data in view
121 Hide(mandelbrot1, renderView1)
122
123 # show color bar/color legend
124 developedSurface1Display.SetScalarBarVisibility(renderView1, True)
125
126 # update the view to ensure updated data information
127 renderView1.Update()
128
129 # toggle 3D widget visibility (only when running from the GUI)
130 Hide3DWidgets(proxy=developedSurface1.SliceType)
131
132 #### saving camera placements for all active views
133
134 # current camera placement for renderView1
135 renderView1.CameraPosition = [4.090024784500779, -0.15919161102314858, 7.485304552729019]
136 renderView1.CameraFocalPoint = [4.090024784500779, -0.15919161102314858, 1.0]
137 renderView1.CameraParallelScale = 2.03100960115899
138
139 #### uncomment the following to render all views
140 # RenderAllViews()
141 # alternatively, if you want to write images, you can use SaveScreenshot(...).
142
143 mand=servermanager.Fetch(mandelbrot1)
144 axisId=1
145 high_out=mand.GetSpacing()[axisId]*(mand.GetExtent()[2*axisId+1]-mand.GetExtent()[2*axisId+0])
146
147 vtp=servermanager.Fetch(developedSurface1)
148 arr=vtp.GetPointData().GetArray(0)
149 assert(arr.GetName()=="Iterations")
150 a,b=arr.GetRange()
151 assert(a>=1 and a<=2)
152 assert(b==100.)
153 SaveData(TMPFileName, proxy=developedSurface1)
154 from MEDLoader import *
155
156 mm=MEDFileMesh.New(TMPFileName)
157 m0=mm[0]
158 area=m0.getMeasureField(True).getArray().accumulate()[0]
159
160 zeResu0=area/high_out/developedSurface1.SliceType.Radius
161 assert(abs(zeResu0-2*pi)<1e-5)
162
163 fs=MEDFileFields(TMPFileName)
164 f=fs["Iterations"][0].field(mm)
165 nodeIds=f.getArray().convertToDblArr().findIdsInRange(99.,101.)
166 cellIds=m0.getCellIdsLyingOnNodes(nodeIds,True)
167 zeResu1=m0[cellIds].getMeasureField(True).getArray().accumulate()[0]
168
169 assert(abs(zeResu1-1.1427)<1e-2)
170