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.
27 from time import sleep
29 from presentations import *
35 # MED files and table directories
36 samples_dir = os.getenv("DATA_DIR")
39 if samples_dir is not None:
40 samples_dir = os.path.normpath(samples_dir)
41 datadir = samples_dir + "/MedFiles/"
42 tablesdir = samples_dir + "/Tables/"
45 view = pvs.GetRenderView()
49 delete_pv_object(view)
52 # Create view and set background
53 view = pvs.CreateRenderView()
57 view.Background = color
60 # Load MED reader plugin
61 pv_root_dir = os.getenv("PARAVIS_ROOT_DIR")
62 if sys.platform == "win32":
63 pvs.LoadPlugin(pv_root_dir + "/lib/paraview/MEDReaderPlugin.dll")
64 elif sys.platform == "darwin":
65 pvs.LoadPlugin(pv_root_dir + "/lib/paraview/libMEDReaderPlugin.dylib")
67 pvs.LoadPlugin(pv_root_dir + "/lib/paraview/libMEDReaderPlugin.so")
70 med_file = datadir + "pointe.med"
71 field_name = "fieldnodedouble"
72 entity = EntityType.NODE
75 med_reader = pvs.MEDReader(FileName=med_file)
76 med_reader.UpdatePipeline()
79 scalarmap = ScalarMapOnField(med_reader, entity, field_name, timestamp)
80 pvs.Show(scalarmap.Input)
83 print("view.CameraFocalPoint = [0, 0, 0]")
84 view.CameraFocalPoint = [0, 0, 0]
85 print("view.CameraParallelScale = 2")
86 view.CameraParallelScale = 2
87 print("pvs.ResetCamera(view)")
90 # Play with scalar bar
94 range_min = lt.RGBPoints[0]
95 range_max = lt.RGBPoints[4]
96 delta = (range_max - range_min) / 2.0
97 nb_colors = lt.NumberOfTableValues
100 for i in range(2, nb_colors):
101 lt.NumberOfTableValues = nb_colors
102 x = range_min + delta * i / nb_colors
103 y = range_max - delta * i / nb_colors
109 lt.RGBPoints[0] = range_min
110 lt.RGBPoints[4] = range_max
112 print("pvs.ResetCamera(view)")
113 pvs.ResetCamera(view)
115 # Create another view for cut planes
116 view = pvs.CreateRenderView()
120 view.Background = color
124 orient = Orientation.YZ
125 cutplanes = CutPlanesOnField(med_reader, entity, field_name, timestamp,
127 displacement=displacement)
128 print("CutPlanesOnField(...)")
130 display_only(cutplanes, view)
131 print("display_only(cutplanes, view)")
133 cam_pos = view.CameraPosition
134 cam_pos[0] = cam_pos[0] + 10
135 print("Set view.CameraPosition")
136 cutplanes.Scale[0] = 3
137 cutplanes.Scale[1] = 10
141 pvs.ResetCamera(view)
143 slice_filter = cutplanes.Input
144 offset_vals = slice_filter.SliceOffsetValues
145 nb_planes = len(offset_vals)
147 bounds = get_bounds(med_reader)
148 for i in range(nb_planes, 1, -1):
149 x = math.pi / 2.0 * (nb_planes - i) / nb_planes
150 y = math.pi / 2.0 * (nb_planes - i) / nb_planes
151 normal = get_normal_by_orientation(orient, x, y)
152 slice_filter.SliceType.Normal = normal
153 pos = get_positions(i, normal, bounds, displacement)
154 slice_filter.SliceOffsetValues = pos
160 slice_filter.SliceType.Normal = normal
161 for i in range(1, nb_planes):
162 pos = get_positions(i, normal, bounds, displacement)
163 slice_filter.SliceOffsetValues = pos
167 slice_filter.SliceType.Normal = [0, 0, 1]
168 slice_filter.UpdatePipeline()
169 print("pvs.ResetCamera(view)")
170 pvs.ResetCamera(view)
172 # Create one more view for iso surfaces
173 view = pvs.CreateRenderView()
177 view.Background = color
181 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
182 display_only(isosurf, view)
183 pvs.ResetCamera(view)
184 print("display_only(isosurf, view)")
187 contour = isosurf.Input
188 nb_surfaces = len(contour.Isosurfaces)
190 scalar_range = get_data_range(med_reader, entity, field_name, cut_off=True)
191 for i in range(2, nb_surfaces):
192 contours = get_contours(scalar_range, i)
193 contour.Isosurfaces = contours
197 contour.Isosurfaces = get_contours(scalar_range, 10)
198 contour.UpdatePipeline()
199 print("pvs.ResetCamera(view)")
200 pvs.ResetCamera(view)
202 # Create one more view for cut lines
203 view = pvs.CreateRenderView()
206 color = [0.7, 0.7, 0.7]
207 view.Background = color
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 pvs.ResetCamera(view)
218 print("display_only(cutlines, view)")
221 xy_view = pvs.CreateXYPlotView()
222 print("pvs.CreateXYPlotView()")
225 xyrep = pvs.Show(curve, xy_view)
226 xyrep.AttributeType = 'Point Data'
227 xyrep.UseIndexForXAxis = 0
228 xyrep.XArrayName = 'arc_length'
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]
241 # Create one more view for cut segment
242 view = pvs.CreateRenderView()
245 color = [0.0, 0.7, 0.3]
246 view.Background = color
250 point1 = [0.0, -1.0, 2.5]
251 point2 = [0.0, 1.0, 2.5]
252 cutsegment = CutSegmentOnField(med_reader, entity, field_name, timestamp,
254 print("CutSegmentOnField(...)")
255 display_only(cutsegment, view)
256 pvs.ResetCamera(view)
257 print("display_only(cutsegment, view)")
260 xy_view = pvs.CreateXYPlotView()
261 curve = pvs.Show(cutsegment.Input, xy_view)
262 curve.AttributeType = 'Point Data'
263 curve.UseIndexForXAxis = 0
264 curve.XArrayName = 'arc_length'
265 set_visible_lines(xyrep, [field_name])
271 # Create one more view for animation
272 view = pvs.CreateRenderView()
275 med_file = datadir + "TimeStamps.med"
276 field_name = "vitesse"
277 entity = EntityType.NODE
280 med_reader = pvs.MEDReader(FileName=med_file)
282 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
283 pvs.ResetCamera(view)
285 print("Start Animation")
286 pvs.AnimateReader(med_reader, view)