Salome HOME
Merge Python 3 porting.
[modules/paravis.git] / test / VisuPrs / SWIG_scripts / B1.py
1 # Copyright (C) 2010-2016  CEA/DEN, 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
20 # This case corresponds to: /visu/SWIG_scripts/B1 case
21
22 import math
23 import random
24 from time import sleep
25
26 from paravistest import datadir
27 from presentations import *
28 import pvsimple
29
30 DELAY = 0.25
31
32 # Get view
33 view = pvsimple.GetRenderView()
34 sleep(DELAY)
35
36 # Destroy the view
37 delete_pv_object(view)
38
39
40 # Create view and set background
41 view = pvsimple.CreateRenderView()
42 reset_view(view)
43
44 color = [0, 0.3, 1]
45 view.Background = color
46 pvsimple.Render()
47
48 # Import MED file
49 med_file = datadir + "pointe.med"
50 field_name = "fieldnodedouble"
51 entity = EntityType.NODE
52 timestamp = 1
53
54 pvsimple.OpenDataFile(med_file)
55 med_reader = pvsimple.GetActiveSource()
56
57
58 # Create scalar map
59 scalarmap = ScalarMapOnField(med_reader, entity, field_name, timestamp)
60 print("ScalarMapOnField(...)")
61 pvsimple.Show(scalarmap.Input)
62
63 # Set view properties
64 print("view.CameraFocalPoint = [0, 0, 0]")
65 view.CameraFocalPoint = [0, 0, 0]
66 print("view.CameraParallelScale = 2")
67 view.CameraParallelScale = 2
68 print("pvsimple.ResetCamera(view)")
69 pvsimple.ResetCamera(view)
70
71 # Play with scalar bar
72 bar = get_bar()
73 lt = bar.LookupTable
74
75 range_min = lt.RGBPoints[0]
76 range_max = lt.RGBPoints[4]
77 delta = (range_max - range_min) / 2.0
78 nb_colors = lt.NumberOfTableValues
79 nb_colors = 64
80 lt.Discretize = 1
81 for i in range(2, nb_colors):
82     lt.NumberOfTableValues = nb_colors
83     x = range_min + delta * i / nb_colors
84     y = range_max - delta * i / nb_colors
85     lt.RGBPoints[0] = x
86     lt.RGBPoints[4] = y
87     pvsimple.Render(view)
88     sleep(DELAY / 4.0)
89
90 lt.RGBPoints[0] = range_min
91 lt.RGBPoints[4] = range_max
92
93 print("pvsimple.ResetCamera(view)")
94 pvsimple.Render(view)
95 sleep(DELAY)
96
97 # Destroy the view
98 print("Destroy the view with Scalar Map")
99 delete_pv_object(view)
100
101
102 # Create another view for cut planes
103 view = pvsimple.CreateRenderView()
104 reset_view(view)
105
106 color = [0, 0.7, 0]
107 view.Background = color
108 pvsimple.Render(view)
109
110 displacement = 0.5
111 orient = Orientation.YZ
112 cutplanes = CutPlanesOnField(med_reader, entity, field_name, timestamp,
113                              orientation=orient,
114                              displacement=displacement)
115 print("CutPlanesOnField(...)")
116
117 display_only(cutplanes, view)
118 print("display_only(cutplanes, view)")
119
120 cam_pos = view.CameraPosition
121 cam_pos[0] = cam_pos[0] + 10
122 print("Set view.CameraPosition")
123 cutplanes.Scale[0] = 3
124 cutplanes.Scale[1] = 10
125 pvsimple.Render(view)
126 sleep(DELAY)
127
128 pvsimple.ResetCamera(view)
129
130 slice_filter = cutplanes.Input
131 offset_vals = slice_filter.SliceOffsetValues
132 nb_planes = len(offset_vals)
133 nb_planes = 30
134 bounds = get_bounds(med_reader)
135 for i in range(nb_planes, 1, -1):
136     x = math.pi / 2.0 * (nb_planes - i) / nb_planes
137     y = math.pi / 2.0 * (nb_planes - i) / nb_planes
138     normal = get_normal_by_orientation(orient, x, y)
139     slice_filter.SliceType.Normal = normal
140     pos = get_positions(i, normal, bounds, displacement)
141     slice_filter.SliceOffsetValues = pos
142     pvsimple.Render(view)
143     sleep(DELAY)
144
145 nb_planes = 10
146 normal = [0, 1, 0]
147 slice_filter.SliceType.Normal = normal
148 for i in range(1, nb_planes):
149     pos = get_positions(i, normal, bounds, displacement)
150     slice_filter.SliceOffsetValues = pos
151     pvsimple.Render(view)
152     sleep(DELAY)
153
154 slice_filter.SliceType.Normal = [0, 0, 1]
155 slice_filter.UpdatePipeline()
156 print("pvsimple.ResetCamera(view)")
157 pvsimple.ResetCamera(view)
158 sleep(DELAY)
159
160 # Destroy the view
161 print("Destroy the view with Cut Planes")
162 delete_pv_object(view)
163
164
165 # Create one more view for isosurfaces
166 view = pvsimple.CreateRenderView()
167 reset_view(view)
168
169 color = [1, 0.7, 0]
170 view.Background = color
171 pvsimple.Render(view)
172 sleep(DELAY)
173
174 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
175 print("IsoSurfacesOnField(...)")
176 display_only(isosurf, view)
177 pvsimple.ResetCamera(view)
178 print("display_only(isosurf, view)")
179 sleep(DELAY)
180
181 contour = isosurf.Input
182 nb_surfaces = len(contour.Isosurfaces)
183 nb_surfaces = 32
184 scalar_range = get_data_range(med_reader, entity, field_name, cut_off=True)
185 for i in range(2, nb_surfaces):
186     contours = get_contours(scalar_range, i)
187     contour.Isosurfaces = contours
188     pvsimple.Render(view)
189     sleep(DELAY)
190
191 contour.Isosurfaces = get_contours(scalar_range, 10)
192 contour.UpdatePipeline()
193 print("pvsimple.ResetCamera(view)")
194 pvsimple.ResetCamera(view)
195 sleep(DELAY)
196
197 # Destroy the view
198 print("Destroy the view with Iso Surfaces")
199 delete_pv_object(view)
200
201
202 # Create one more view for cut lines
203 view = pvsimple.CreateRenderView()
204 reset_view(view)
205
206 color = [0.7, 0.7, 0.7]
207 view.Background = color
208 pvsimple.Render(view)
209 sleep(DELAY)
210
211 cutlines, curves = CutLinesOnField(med_reader, entity, field_name, timestamp,
212                                    orientation1=Orientation.ZX,
213                                    orientation2=Orientation.YZ,
214                                    generate_curves=True)
215 print("CutLinesOnField(...)")
216 display_only(cutlines, view)
217 pvsimple.ResetCamera(view)
218 print("display_only(cutlines, view)")
219 sleep(DELAY)
220
221 xy_view = pvsimple.CreateXYPlotView()
222 print("pvsimple.CreateXYPlotView()")
223 index = 0
224 for curve in curves:
225     xyrep = pvsimple.Show(curve, xy_view)
226     xyrep.AttributeType = 'Point Data'
227     xyrep.UseIndexForXAxis = 0
228     xyrep.XArrayName = 'arc_length'
229     pvsimple.Render(xy_view)
230     set_visible_lines(xyrep, [field_name])
231     xyrep.SeriesLabel = [field_name, 'Y' + str(index)]
232     r = str(random.random())
233     g = str(random.random())
234     b = str(random.random())
235     xyrep.SeriesColor = [field_name, r, g, b]
236     index += 1
237
238 pvsimple.Render(xy_view)
239 sleep(DELAY)
240
241 # Destroy two views
242 #print "Destroy two views: with Cut Lines and the curves"
243 #delete_pv_object(view)
244 #delete_pv_object(xy_view)
245
246
247 # Create one more view for cut segment
248 view = pvsimple.CreateRenderView()
249 reset_view(view)
250
251 color = [0.0, 0.7, 0.3]
252 view.Background = color
253 pvsimple.Render(view)
254 sleep(DELAY)
255
256 point1 = [0.0, -1.0, 2.5]
257 point2 = [0.0, 1.0, 2.5]
258 cutsegment = CutSegmentOnField(med_reader, entity, field_name, timestamp,
259                                point1, point2)
260
261 print("CutSegmentOnField(...)")
262 display_only(cutsegment, view)
263 pvsimple.ResetCamera(view)
264 print("display_only(cutsegment, view)")
265 sleep(DELAY)
266
267 xy_view = pvsimple.CreateXYPlotView()
268 curve = pvsimple.Show(cutsegment.Input, xy_view)
269 curve.AttributeType = 'Point Data'
270 curve.UseIndexForXAxis = 0
271 curve.XArrayName = 'arc_length'
272 set_visible_lines(curve, [field_name])
273
274 pvsimple.Render(xy_view)
275 sleep(DELAY)
276
277
278 # Create one more view for animation
279 view = pvsimple.CreateRenderView()
280 reset_view(view)
281
282 med_file = datadir + "TimeStamps.med"
283 field_name = "vitesse"
284 entity = EntityType.NODE
285 timestamp = 2
286
287 pvsimple.OpenDataFile(med_file)
288 med_reader = pvsimple.GetActiveSource()
289
290 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
291 print("IsoSurfacesOnField(...)")
292 pvsimple.ResetCamera(view)
293
294 print("Start Animation")
295 pvsimple.AnimateReader(med_reader, view)