Back to index

salome-paravis  6.5.0
A9.py
Go to the documentation of this file.
00001 # Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 # This case corresponds to: /visu/SWIG_scripts/A9 case
00021 # Import MED file; create Scalar Map, Cut Planes, Cut Lines,
00022 # Cut Segment, Iso Surfaces, Animation; display curves.
00023  
00024 import math
00025 import random
00026 from time import sleep
00027 
00028 from presentations import *
00029 
00030 
00031 # Delay
00032 DELAY = 0.25
00033 
00034 # MED files and table directories
00035 samples_dir = os.getenv("DATA_DIR")
00036 datadir = None
00037 tablesdir = None
00038 if samples_dir is not None:
00039     samples_dir = os.path.normpath(samples_dir)
00040     datadir = samples_dir + "/MedFiles/"
00041     tablesdir = samples_dir + "/Tables/"
00042 
00043 # Get view
00044 view = pv.GetRenderView()
00045 sleep(DELAY)
00046 
00047 # Destroy the view
00048 pv.Delete(view)
00049 
00050 
00051 # Create view and set background
00052 view = pv.CreateRenderView()
00053 reset_view(view)
00054 
00055 color = [0, 0.3, 1]
00056 view.Background = color
00057 pv.Render()
00058 
00059 # Load MED reader plugin
00060 pv_root_dir = os.getenv("PARAVIS_ROOT_DIR")
00061 pv.LoadPlugin(pv_root_dir + "/lib/paraview/libMedReaderPlugin.so")
00062 
00063 # Import MED file
00064 med_file = datadir + "pointe.med"
00065 field_name = "fieldnodedouble"
00066 entity = EntityType.NODE
00067 timestamp = 1
00068 
00069 med_reader = pv.MEDReader(FileName=med_file)
00070 med_reader.UpdatePipeline()
00071 
00072 # Create scalar map
00073 scalarmap = ScalarMapOnField(med_reader, entity, field_name, timestamp)
00074 pv.Show(scalarmap.Input)
00075 
00076 # Set view properties
00077 print "view.CameraFocalPoint = [0, 0, 0]"
00078 view.CameraFocalPoint = [0, 0, 0]
00079 print "view.CameraParallelScale = 2"
00080 view.CameraParallelScale = 2
00081 print "pv.ResetCamera(view)"
00082 pv.ResetCamera(view)
00083 
00084 # Play with scalar bar
00085 bar = get_bar()
00086 lt = bar.LookupTable
00087 
00088 range_min = lt.RGBPoints[0]
00089 range_max = lt.RGBPoints[4]
00090 delta = (range_max - range_min) / 2.0
00091 nb_colors = lt.NumberOfTableValues
00092 nb_colors = 64
00093 lt.Discretize = 1
00094 for i in xrange(2, nb_colors):
00095     lt.NumberOfTableValues = nb_colors
00096     x = range_min + delta * i / nb_colors
00097     y = range_max - delta * i / nb_colors
00098     lt.RGBPoints[0] = x
00099     lt.RGBPoints[4] = y
00100     pv.Render(view)
00101     sleep(DELAY / 4.0)
00102 
00103 lt.RGBPoints[0] = range_min
00104 lt.RGBPoints[4] = range_max
00105 
00106 print "pv.ResetCamera(view)"
00107 pv.ResetCamera(view)
00108 
00109 # Create another view for cut planes
00110 view = pv.CreateRenderView()
00111 reset_view(view)
00112 
00113 color = [0, 0.7, 0]
00114 view.Background = color
00115 pv.Render(view)
00116 
00117 displacement = 0.5
00118 orient = Orientation.YZ
00119 cutplanes = CutPlanesOnField(med_reader, entity, field_name, timestamp,
00120                              orientation=orient,
00121                              displacement=displacement)
00122 print "CutPlanesOnField(...)"
00123 
00124 display_only(cutplanes, view)
00125 print "display_only(cutplanes, view)"
00126 
00127 cam_pos = view.CameraPosition
00128 cam_pos[0] = cam_pos[0] + 10
00129 print "Set view.CameraPosition"
00130 cutplanes.Scale[0] = 3
00131 cutplanes.Scale[1] = 10
00132 pv.Render(view)
00133 sleep(DELAY)
00134 
00135 pv.ResetCamera(view)
00136 
00137 slice_filter = cutplanes.Input
00138 offset_vals = slice_filter.SliceOffsetValues
00139 nb_planes = len(offset_vals)
00140 nb_planes = 30
00141 bounds = get_bounds(med_reader)
00142 for i in xrange(nb_planes, 1, -1):
00143     x = math.pi / 2.0 * (nb_planes - i) / nb_planes
00144     y = math.pi / 2.0 * (nb_planes - i) / nb_planes
00145     normal = get_normal_by_orientation(orient, x, y)
00146     slice_filter.SliceType.Normal = normal
00147     pos = get_positions(i, normal, bounds, displacement)
00148     slice_filter.SliceOffsetValues = pos
00149     pv.Render(view)
00150     sleep(DELAY)
00151 
00152 nb_planes = 10
00153 normal = [0, 1, 0]
00154 slice_filter.SliceType.Normal = normal
00155 for i in xrange(1, nb_planes):
00156     pos = get_positions(i, normal, bounds, displacement)
00157     slice_filter.SliceOffsetValues = pos
00158     pv.Render(view)
00159     sleep(DELAY)
00160 
00161 slice_filter.SliceType.Normal = [0, 0, 1]
00162 slice_filter.UpdatePipeline()
00163 print "pv.ResetCamera(view)"
00164 pv.ResetCamera(view)
00165 
00166 # Create one more view for iso surfaces
00167 view = pv.CreateRenderView()
00168 reset_view(view)
00169 
00170 color = [1, 0.7, 0]
00171 view.Background = color
00172 pv.Render(view)
00173 sleep(DELAY)
00174 
00175 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
00176 display_only(isosurf, view)
00177 pv.ResetCamera(view)
00178 print "display_only(isosurf, view)"
00179 sleep(DELAY)
00180 
00181 contour = isosurf.Input
00182 nb_surfaces = len(contour.Isosurfaces)
00183 nb_surfaces = 32
00184 scalar_range = get_data_range(med_reader, entity, field_name, cut_off=True)
00185 for i in xrange(2, nb_surfaces):
00186     contours = get_contours(scalar_range, i)
00187     contour.Isosurfaces = contours
00188     pv.Render(view)
00189     sleep(DELAY)
00190 
00191 contour.Isosurfaces = get_contours(scalar_range, 10)
00192 contour.UpdatePipeline()
00193 print "pv.ResetCamera(view)"
00194 pv.ResetCamera(view)
00195 
00196 # Create one more view for cut lines
00197 view = pv.CreateRenderView()
00198 reset_view(view)
00199 
00200 color = [0.7, 0.7, 0.7]
00201 view.Background = color
00202 pv.Render(view)
00203 sleep(DELAY)
00204 
00205 cutlines, curves = CutLinesOnField(med_reader, entity, field_name, timestamp,
00206                                    orientation1=Orientation.ZX,
00207                                    orientation2=Orientation.YZ,
00208                                    generate_curves=True)
00209 print "CutLinesOnField(...)"
00210 display_only(cutlines, view)
00211 pv.ResetCamera(view)
00212 print "display_only(cutlines, view)"
00213 sleep(DELAY)
00214 
00215 xy_view = pv.CreateXYPlotView()
00216 print "pv.CreateXYPlotView()"
00217 index = 0
00218 for curve in curves:
00219     xyrep = pv.Show(curve, xy_view)
00220     xyrep.AttributeType = 'Point Data'
00221     xyrep.UseIndexForXAxis = 0
00222     xyrep.XArrayName = 'arc_length'
00223     pv.Render(xy_view)
00224     set_visible_lines(xyrep, [field_name])
00225     xyrep.SeriesLabel = [field_name, 'Y' + str(index)]
00226     r = str(random.random())
00227     g = str(random.random())
00228     b = str(random.random())
00229     xyrep.SeriesColor = [field_name, r, g, b]
00230     index += 1
00231 
00232 pv.Render(xy_view)
00233 sleep(DELAY)
00234 
00235 # Create one more view for cut segment
00236 view = pv.CreateRenderView()
00237 reset_view(view)
00238 
00239 color = [0.0, 0.7, 0.3]
00240 view.Background = color
00241 pv.Render(view)
00242 sleep(DELAY)
00243 
00244 point1 = [0.0, -1.0, 2.5]
00245 point2 = [0.0, 1.0, 2.5]
00246 cutsegment = CutSegmentOnField(med_reader, entity, field_name, timestamp,
00247                                point1, point2)
00248 print "CutSegmentOnField(...)"
00249 display_only(cutsegment, view)
00250 pv.ResetCamera(view)
00251 print "display_only(cutsegment, view)"
00252 sleep(DELAY)
00253 
00254 xy_view = pv.CreateXYPlotView()
00255 curve = pv.Show(cutsegment.Input, xy_view)
00256 curve.AttributeType = 'Point Data'
00257 curve.UseIndexForXAxis = 0
00258 curve.XArrayName = 'arc_length'
00259 set_visible_lines(xyrep, [field_name])
00260 
00261 pv.Render(xy_view)
00262 sleep(DELAY)
00263 
00264 
00265 # Create one more view for animation
00266 view = pv.CreateRenderView()
00267 reset_view(view)
00268 
00269 med_file = datadir + "TimeStamps.med"
00270 field_name = "vitesse"
00271 entity = EntityType.NODE
00272 timestamp = 2
00273 
00274 med_reader = pv.MEDReader(FileName=med_file)
00275 
00276 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
00277 pv.ResetCamera(view)
00278 
00279 print "Start Animation"
00280 pv.AnimateReader(med_reader, view)