1 # Copyright (C) 2010-2016 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/A4 case
24 from time import sleep
26 from paravistest import datadir
27 from presentations import *
33 view = pvsimple.GetRenderView()
37 delete_pv_object(view)
40 # Create view and set background
41 view = pvsimple.CreateRenderView()
45 view.Background = color
49 med_file = datadir + "pointe.med"
50 field_name = "fieldnodedouble"
51 entity = EntityType.NODE
54 pvsimple.OpenDataFile(med_file)
55 med_reader = pvsimple.GetActiveSource()
59 scalarmap = ScalarMapOnField(med_reader, entity, field_name, timestamp)
60 print "ScalarMapOnField(...)"
61 pvsimple.Show(scalarmap.Input)
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)
71 # Play with scalar bar
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
81 for i in xrange(2, nb_colors):
82 lt.NumberOfTableValues = nb_colors
83 x = range_min + delta * i / nb_colors
84 y = range_max - delta * i / nb_colors
90 lt.RGBPoints[0] = range_min
91 lt.RGBPoints[4] = range_max
93 print "pvsimple.ResetCamera(view)"
98 print "Destroy the view with Scalar Map"
99 delete_pv_object(view)
102 # Create another view for cut planes
103 view = pvsimple.CreateRenderView()
107 view.Background = color
108 pvsimple.Render(view)
111 orient = Orientation.YZ
112 cutplanes = CutPlanesOnField(med_reader, entity, field_name, timestamp,
114 displacement=displacement)
115 print "CutPlanesOnField(...)"
117 display_only(cutplanes, view)
118 print "display_only(cutplanes, view)"
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)
128 pvsimple.ResetCamera(view)
130 slice_filter = cutplanes.Input
131 offset_vals = slice_filter.SliceOffsetValues
132 nb_planes = len(offset_vals)
134 bounds = get_bounds(med_reader)
135 for i in xrange(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)
147 slice_filter.SliceType.Normal = normal
148 for i in xrange(1, nb_planes):
149 pos = get_positions(i, normal, bounds, displacement)
150 slice_filter.SliceOffsetValues = pos
151 pvsimple.Render(view)
154 slice_filter.SliceType.Normal = [0, 0, 1]
155 slice_filter.UpdatePipeline()
156 print "pvsimple.ResetCamera(view)"
157 pvsimple.ResetCamera(view)
161 print "Destroy the view with Cut Planes"
162 delete_pv_object(view)
165 # Create one more view for isosurfaces
166 view = pvsimple.CreateRenderView()
170 view.Background = color
171 pvsimple.Render(view)
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)"
181 contour = isosurf.Input
182 nb_surfaces = len(contour.Isosurfaces)
184 scalar_range = get_data_range(med_reader, entity, field_name, cut_off=True)
185 for i in xrange(2, nb_surfaces):
186 contours = get_contours(scalar_range, i)
187 contour.Isosurfaces = contours
188 pvsimple.Render(view)
191 contour.Isosurfaces = get_contours(scalar_range, 10)
192 contour.UpdatePipeline()
193 print "pvsimple.ResetCamera(view)"
194 pvsimple.ResetCamera(view)
198 print "Destroy the view with Iso Surfaces"
199 delete_pv_object(view)
202 # Create one more view for cut lines
203 view = pvsimple.CreateRenderView()
206 color = [0.7, 0.7, 0.7]
207 view.Background = color
208 pvsimple.Render(view)
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)"
221 xy_view = pvsimple.CreateXYPlotView()
222 print "pvsimple.CreateXYPlotView()"
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]
238 pvsimple.Render(xy_view)
242 #print "Destroy two views: with Cut Lines and the curves"
243 #delete_pv_object(view)
244 #delete_pv_object(xy_view)
246 # Create one more view for animation
247 view = pvsimple.CreateRenderView()
250 med_file = datadir + "TimeStamps.med"
251 field_name = "vitesse"
252 entity = EntityType.NODE
255 pvsimple.OpenDataFile(med_file)
256 med_reader = pvsimple.GetActiveSource()
258 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
259 print "IsoSurfacesOnField(...)"
260 pvsimple.ResetCamera(view)
262 print "Start Animation"
263 pvsimple.AnimateReader(med_reader, view)