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/A9 case
21 # Import MED file; create Scalar Map, Cut Planes, Cut Lines,
22 # Cut Segment, Iso Surfaces, Animation; display curves.
26 from time import sleep
28 from presentations import *
34 # MED files and table directories
35 samples_dir = os.getenv("DATA_DIR")
38 if samples_dir is not None:
39 samples_dir = os.path.normpath(samples_dir)
40 datadir = samples_dir + "/MedFiles/"
41 tablesdir = samples_dir + "/Tables/"
44 view = pvs.GetRenderView()
51 # Create view and set background
52 view = pvs.CreateRenderView()
56 view.Background = color
59 # Load MED reader plugin
60 pv_root_dir = os.getenv("PARAVIS_ROOT_DIR")
61 pvs.LoadPlugin(pv_root_dir + "/lib/paraview/libMEDReaderPlugin.so")
64 med_file = datadir + "pointe.med"
65 field_name = "fieldnodedouble"
66 entity = EntityType.NODE
69 med_reader = pvs.MEDReader(FileName=med_file)
70 med_reader.UpdatePipeline()
73 scalarmap = ScalarMapOnField(med_reader, entity, field_name, timestamp)
74 pvs.Show(scalarmap.Input)
77 print "view.CameraFocalPoint = [0, 0, 0]"
78 view.CameraFocalPoint = [0, 0, 0]
79 print "view.CameraParallelScale = 2"
80 view.CameraParallelScale = 2
81 print "pvs.ResetCamera(view)"
84 # Play with scalar bar
88 range_min = lt.RGBPoints[0]
89 range_max = lt.RGBPoints[4]
90 delta = (range_max - range_min) / 2.0
91 nb_colors = lt.NumberOfTableValues
94 for i in xrange(2, nb_colors):
95 lt.NumberOfTableValues = nb_colors
96 x = range_min + delta * i / nb_colors
97 y = range_max - delta * i / nb_colors
103 lt.RGBPoints[0] = range_min
104 lt.RGBPoints[4] = range_max
106 print "pvs.ResetCamera(view)"
107 pvs.ResetCamera(view)
109 # Create another view for cut planes
110 view = pvs.CreateRenderView()
114 view.Background = color
118 orient = Orientation.YZ
119 cutplanes = CutPlanesOnField(med_reader, entity, field_name, timestamp,
121 displacement=displacement)
122 print "CutPlanesOnField(...)"
124 display_only(cutplanes, view)
125 print "display_only(cutplanes, view)"
127 cam_pos = view.CameraPosition
128 cam_pos[0] = cam_pos[0] + 10
129 print "Set view.CameraPosition"
130 cutplanes.Scale[0] = 3
131 cutplanes.Scale[1] = 10
135 pvs.ResetCamera(view)
137 slice_filter = cutplanes.Input
138 offset_vals = slice_filter.SliceOffsetValues
139 nb_planes = len(offset_vals)
141 bounds = get_bounds(med_reader)
142 for i in xrange(nb_planes, 1, -1):
143 x = math.pi / 2.0 * (nb_planes - i) / nb_planes
144 y = math.pi / 2.0 * (nb_planes - i) / nb_planes
145 normal = get_normal_by_orientation(orient, x, y)
146 slice_filter.SliceType.Normal = normal
147 pos = get_positions(i, normal, bounds, displacement)
148 slice_filter.SliceOffsetValues = pos
154 slice_filter.SliceType.Normal = normal
155 for i in xrange(1, nb_planes):
156 pos = get_positions(i, normal, bounds, displacement)
157 slice_filter.SliceOffsetValues = pos
161 slice_filter.SliceType.Normal = [0, 0, 1]
162 slice_filter.UpdatePipeline()
163 print "pvs.ResetCamera(view)"
164 pvs.ResetCamera(view)
166 # Create one more view for iso surfaces
167 view = pvs.CreateRenderView()
171 view.Background = color
175 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
176 display_only(isosurf, view)
177 pvs.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
191 contour.Isosurfaces = get_contours(scalar_range, 10)
192 contour.UpdatePipeline()
193 print "pvs.ResetCamera(view)"
194 pvs.ResetCamera(view)
196 # Create one more view for cut lines
197 view = pvs.CreateRenderView()
200 color = [0.7, 0.7, 0.7]
201 view.Background = color
205 cutlines, curves = CutLinesOnField(med_reader, entity, field_name, timestamp,
206 orientation1=Orientation.ZX,
207 orientation2=Orientation.YZ,
208 generate_curves=True)
209 print "CutLinesOnField(...)"
210 display_only(cutlines, view)
211 pvs.ResetCamera(view)
212 print "display_only(cutlines, view)"
215 xy_view = pvs.CreateXYPlotView()
216 print "pvs.CreateXYPlotView()"
219 xyrep = pvs.Show(curve, xy_view)
220 xyrep.AttributeType = 'Point Data'
221 xyrep.UseIndexForXAxis = 0
222 xyrep.XArrayName = 'arc_length'
224 set_visible_lines(xyrep, [field_name])
225 xyrep.SeriesLabel = [field_name, 'Y' + str(index)]
226 r = str(random.random())
227 g = str(random.random())
228 b = str(random.random())
229 xyrep.SeriesColor = [field_name, r, g, b]
235 # Create one more view for cut segment
236 view = pvs.CreateRenderView()
239 color = [0.0, 0.7, 0.3]
240 view.Background = color
244 point1 = [0.0, -1.0, 2.5]
245 point2 = [0.0, 1.0, 2.5]
246 cutsegment = CutSegmentOnField(med_reader, entity, field_name, timestamp,
248 print "CutSegmentOnField(...)"
249 display_only(cutsegment, view)
250 pvs.ResetCamera(view)
251 print "display_only(cutsegment, view)"
254 xy_view = pvs.CreateXYPlotView()
255 curve = pvs.Show(cutsegment.Input, xy_view)
256 curve.AttributeType = 'Point Data'
257 curve.UseIndexForXAxis = 0
258 curve.XArrayName = 'arc_length'
259 set_visible_lines(xyrep, [field_name])
265 # Create one more view for animation
266 view = pvs.CreateRenderView()
269 med_file = datadir + "TimeStamps.med"
270 field_name = "vitesse"
271 entity = EntityType.NODE
274 med_reader = pvs.MEDReader(FileName=med_file)
276 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
277 pvs.ResetCamera(view)
279 print "Start Animation"
280 pvs.AnimateReader(med_reader, view)