1 # Copyright (C) 2010-2014 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # This case corresponds to: /visu/SWIG_scripts/B1 case
24 from time import sleep
26 from paravistest import datadir
27 from presentations import *
34 my_paravis = paravis.myParavis
37 view = pvsimple.GetRenderView()
44 # Create view and set background
45 view = pvsimple.CreateRenderView()
49 view.Background = color
53 med_file = datadir + "pointe.med"
54 field_name = "fieldnodedouble"
55 entity = EntityType.NODE
58 my_paravis.ImportFile(med_file)
59 med_reader = pvsimple.GetActiveSource()
63 scalarmap = ScalarMapOnField(med_reader, entity, field_name, timestamp)
64 print "ScalarMapOnField(...)"
65 pvsimple.Show(scalarmap.Input)
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)
75 # Play with scalar bar
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
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
94 lt.RGBPoints[0] = range_min
95 lt.RGBPoints[4] = range_max
97 print "pvsimple.ResetCamera(view)"
102 print "Destroy the view with Scalar Map"
103 pvsimple.Delete(view)
106 # Create another view for cut planes
107 view = pvsimple.CreateRenderView()
111 view.Background = color
112 pvsimple.Render(view)
115 orient = Orientation.YZ
116 cutplanes = CutPlanesOnField(med_reader, entity, field_name, timestamp,
118 displacement=displacement)
119 print "CutPlanesOnField(...)"
121 display_only(cutplanes, view)
122 print "display_only(cutplanes, view)"
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)
132 pvsimple.ResetCamera(view)
134 slice_filter = cutplanes.Input
135 offset_vals = slice_filter.SliceOffsetValues
136 nb_planes = len(offset_vals)
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)
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)
158 slice_filter.SliceType.Normal = [0, 0, 1]
159 slice_filter.UpdatePipeline()
160 print "pvsimple.ResetCamera(view)"
161 pvsimple.ResetCamera(view)
165 print "Destroy the view with Cut Planes"
166 pvsimple.Delete(view)
169 # Create one more view for isosurfaces
170 view = pvsimple.CreateRenderView()
174 view.Background = color
175 pvsimple.Render(view)
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)"
185 contour = isosurf.Input
186 nb_surfaces = len(contour.Isosurfaces)
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)
195 contour.Isosurfaces = get_contours(scalar_range, 10)
196 contour.UpdatePipeline()
197 print "pvsimple.ResetCamera(view)"
198 pvsimple.ResetCamera(view)
202 print "Destroy the view with Iso Surfaces"
203 pvsimple.Delete(view)
206 # Create one more view for cut lines
207 view = pvsimple.CreateRenderView()
210 color = [0.7, 0.7, 0.7]
211 view.Background = color
212 pvsimple.Render(view)
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)"
225 xy_view = pvsimple.CreateXYPlotView()
226 print "pvsimple.CreateXYPlotView()"
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]
242 pvsimple.Render(xy_view)
246 #print "Destroy two views: with Cut Lines and the curves"
247 #pvsimple.Delete(view)
248 #pvsimple.Delete(xy_view)
251 # Create one more view for cut segment
252 view = pvsimple.CreateRenderView()
255 color = [0.0, 0.7, 0.3]
256 view.Background = color
257 pvsimple.Render(view)
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,
265 print "CutSegmentOnField(...)"
266 display_only(cutsegment, view)
267 pvsimple.ResetCamera(view)
268 print "display_only(cutsegment, view)"
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])
278 pvsimple.Render(xy_view)
282 # Create one more view for animation
283 view = pvsimple.CreateRenderView()
286 med_file = datadir + "TimeStamps.med"
287 field_name = "vitesse"
288 entity = EntityType.NODE
291 my_paravis.ImportFile(med_file)
292 med_reader = pvsimple.GetActiveSource()
294 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
295 print "IsoSurfacesOnField(...)"
296 pvsimple.ResetCamera(view)
298 print "Start Animation"
299 pvsimple.AnimateReader(med_reader, view)