Salome HOME
Update copyrights
[modules/paravis.git] / src / Plugins / DevelopedSurface / Test / test_dev_surface3.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="test3.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 developedSurface1.SliceType.Axis = [-0.5065630563269753, -0.6288876685363318, -0.5898255422814533]
86
87 # show data in view
88 developedSurface1Display = Show(developedSurface1, renderView1)
89
90 # get color transfer function/color map for 'Iterations'
91 iterationsLUT = GetColorTransferFunction('Iterations')
92
93 # trace defaults for the display properties.
94 developedSurface1Display.Representation = 'Surface'
95 developedSurface1Display.ColorArrayName = ['POINTS', 'Iterations']
96 developedSurface1Display.LookupTable = iterationsLUT
97 developedSurface1Display.OSPRayScaleArray = 'Iterations'
98 developedSurface1Display.OSPRayScaleFunction = 'PiecewiseFunction'
99 developedSurface1Display.SelectOrientationVectors = 'Iterations'
100 developedSurface1Display.ScaleFactor = 0.7853981633974483
101 developedSurface1Display.SelectScaleArray = 'Iterations'
102 developedSurface1Display.GlyphType = 'Arrow'
103 developedSurface1Display.GlyphTableIndexArray = 'Iterations'
104 developedSurface1Display.DataAxesGrid = 'GridAxesRepresentation'
105 developedSurface1Display.PolarAxes = 'PolarAxesRepresentation'
106 developedSurface1Display.GaussianRadius = 0.39269908169872414
107 developedSurface1Display.SetScaleArray = ['POINTS', 'Iterations']
108 developedSurface1Display.ScaleTransferFunction = 'PiecewiseFunction'
109 developedSurface1Display.OpacityArray = ['POINTS', 'Iterations']
110 developedSurface1Display.OpacityTransferFunction = 'PiecewiseFunction'
111 developedSurface1Display.InputVectors = [None, '']
112 developedSurface1Display.SelectInputVectors = [None, '']
113 developedSurface1Display.WriteLog = ''
114
115 # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
116 developedSurface1Display.ScaleTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 100.0, 1.0, 0.5, 0.0]
117
118 # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
119 developedSurface1Display.OpacityTransferFunction.Points = [1.0, 0.0, 0.5, 0.0, 100.0, 1.0, 0.5, 0.0]
120
121 # hide data in view
122 Hide(mandelbrot1, renderView1)
123
124 # show color bar/color legend
125 developedSurface1Display.SetScalarBarVisibility(renderView1, True)
126
127 # update the view to ensure updated data information
128 renderView1.Update()
129
130 # toggle 3D widget visibility (only when running from the GUI)
131 Hide3DWidgets(proxy=developedSurface1.SliceType)
132
133 #### saving camera placements for all active views
134
135 # current camera placement for renderView1
136 renderView1.CameraPosition = [4.090024784500779, -0.15919161102314858, 7.485304552729019]
137 renderView1.CameraFocalPoint = [4.090024784500779, -0.15919161102314858, 1.0]
138 renderView1.CameraParallelScale = 2.03100960115899
139
140 #### uncomment the following to render all views
141 # RenderAllViews()
142 # alternatively, if you want to write images, you can use SaveScreenshot(...).
143
144
145 vtp=servermanager.Fetch(developedSurface1)
146 arr=vtp.GetPointData().GetArray(0)
147 assert(arr.GetName()=="Iterations")
148 a,b=arr.GetRange()
149 assert(a>=1 and a<=2)
150 assert(b==100.)
151 SaveData(TMPFileName, proxy=developedSurface1)
152 from MEDLoader import *
153
154 mm=MEDFileMesh.New(TMPFileName)
155 m0=mm[0]
156 area=m0.getMeasureField(True).getArray().accumulate()[0]
157
158
159 fs=MEDFileFields(TMPFileName)
160 f=fs["Iterations"][0].field(mm)
161 nodeIds=f.getArray().convertToDblArr().findIdsInRange(99.,101.)
162 cellIds=m0.getCellIdsLyingOnNodes(nodeIds,True)
163 zeResu1=m0[cellIds].getMeasureField(True).getArray().accumulate()[0]
164
165 assert(abs(zeResu1-1.3564)<1e-2)
166