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