Back to index

salome-paravis  6.5.0
B1.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/B1 case
00021 
00022 import math
00023 import random
00024 from time import sleep
00025 
00026 from paravistest import datadir
00027 from presentations import *
00028 import paravis
00029 import pvsimple
00030 
00031 
00032 DELAY = 0.25
00033 
00034 my_paravis = paravis.myParavis
00035 
00036 # Get view
00037 view = pvsimple.GetRenderView()
00038 sleep(DELAY)
00039 
00040 # Destroy the view
00041 pvsimple.Delete(view)
00042 
00043 
00044 # Create view and set background
00045 view = pvsimple.CreateRenderView()
00046 reset_view(view)
00047 
00048 color = [0, 0.3, 1]
00049 view.Background = color
00050 pvsimple.Render()
00051 
00052 # Import MED file
00053 med_file = datadir + "pointe.med"
00054 field_name = "fieldnodedouble"
00055 entity = EntityType.NODE
00056 timestamp = 1
00057 
00058 my_paravis.ImportFile(med_file)
00059 med_reader = pvsimple.GetActiveSource()
00060 
00061 
00062 # Create scalar map
00063 scalarmap = ScalarMapOnField(med_reader, entity, field_name, timestamp)
00064 print "ScalarMapOnField(...)"
00065 pvsimple.Show(scalarmap.Input)
00066 
00067 # Set view properties
00068 print "view.CameraFocalPoint = [0, 0, 0]"
00069 view.CameraFocalPoint = [0, 0, 0]
00070 print "view.CameraParallelScale = 2"
00071 view.CameraParallelScale = 2
00072 print "pvsimple.ResetCamera(view)"
00073 pvsimple.ResetCamera(view)
00074 
00075 # Play with scalar bar
00076 bar = get_bar()
00077 lt = bar.LookupTable
00078 
00079 range_min = lt.RGBPoints[0]
00080 range_max = lt.RGBPoints[4]
00081 delta = (range_max - range_min) / 2.0
00082 nb_colors = lt.NumberOfTableValues
00083 nb_colors = 64
00084 lt.Discretize = 1
00085 for i in xrange(2, nb_colors):
00086     lt.NumberOfTableValues = nb_colors
00087     x = range_min + delta * i / nb_colors
00088     y = range_max - delta * i / nb_colors
00089     lt.RGBPoints[0] = x
00090     lt.RGBPoints[4] = y
00091     pvsimple.Render(view)
00092     sleep(DELAY / 4.0)
00093 
00094 lt.RGBPoints[0] = range_min
00095 lt.RGBPoints[4] = range_max
00096 
00097 print "pvsimple.ResetCamera(view)"
00098 pvsimple.Render(view)
00099 sleep(DELAY)
00100 
00101 # Destroy the view
00102 print "Destroy the view with Scalar Map"
00103 pvsimple.Delete(view)
00104 
00105 
00106 # Create another view for cut planes
00107 view = pvsimple.CreateRenderView()
00108 reset_view(view)
00109 
00110 color = [0, 0.7, 0]
00111 view.Background = color
00112 pvsimple.Render(view)
00113 
00114 displacement = 0.5
00115 orient = Orientation.YZ
00116 cutplanes = CutPlanesOnField(med_reader, entity, field_name, timestamp,
00117                              orientation=orient,
00118                              displacement=displacement)
00119 print "CutPlanesOnField(...)"
00120 
00121 display_only(cutplanes, view)
00122 print "display_only(cutplanes, view)"
00123 
00124 cam_pos = view.CameraPosition
00125 cam_pos[0] = cam_pos[0] + 10
00126 print "Set view.CameraPosition"
00127 cutplanes.Scale[0] = 3
00128 cutplanes.Scale[1] = 10
00129 pvsimple.Render(view)
00130 sleep(DELAY)
00131 
00132 pvsimple.ResetCamera(view)
00133 
00134 slice_filter = cutplanes.Input
00135 offset_vals = slice_filter.SliceOffsetValues
00136 nb_planes = len(offset_vals)
00137 nb_planes = 30
00138 bounds = get_bounds(med_reader)
00139 for i in xrange(nb_planes, 1, -1):
00140     x = math.pi / 2.0 * (nb_planes - i) / nb_planes
00141     y = math.pi / 2.0 * (nb_planes - i) / nb_planes
00142     normal = get_normal_by_orientation(orient, x, y)
00143     slice_filter.SliceType.Normal = normal
00144     pos = get_positions(i, normal, bounds, displacement)
00145     slice_filter.SliceOffsetValues = pos
00146     pvsimple.Render(view)
00147     sleep(DELAY)
00148 
00149 nb_planes = 10
00150 normal = [0, 1, 0]
00151 slice_filter.SliceType.Normal = normal
00152 for i in xrange(1, nb_planes):
00153     pos = get_positions(i, normal, bounds, displacement)
00154     slice_filter.SliceOffsetValues = pos
00155     pvsimple.Render(view)
00156     sleep(DELAY)
00157 
00158 slice_filter.SliceType.Normal = [0, 0, 1]
00159 slice_filter.UpdatePipeline()
00160 print "pvsimple.ResetCamera(view)"
00161 pvsimple.ResetCamera(view)
00162 sleep(DELAY)
00163 
00164 # Destroy the view
00165 print "Destroy the view with Cut Planes"
00166 pvsimple.Delete(view)
00167 
00168 
00169 # Create one more view for isosurfaces
00170 view = pvsimple.CreateRenderView()
00171 reset_view(view)
00172 
00173 color = [1, 0.7, 0]
00174 view.Background = color
00175 pvsimple.Render(view)
00176 sleep(DELAY)
00177 
00178 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
00179 print "IsoSurfacesOnField(...)"
00180 display_only(isosurf, view)
00181 pvsimple.ResetCamera(view)
00182 print "display_only(isosurf, view)"
00183 sleep(DELAY)
00184 
00185 contour = isosurf.Input
00186 nb_surfaces = len(contour.Isosurfaces)
00187 nb_surfaces = 32
00188 scalar_range = get_data_range(med_reader, entity, field_name, cut_off=True)
00189 for i in xrange(2, nb_surfaces):
00190     contours = get_contours(scalar_range, i)
00191     contour.Isosurfaces = contours
00192     pvsimple.Render(view)
00193     sleep(DELAY)
00194 
00195 contour.Isosurfaces = get_contours(scalar_range, 10)
00196 contour.UpdatePipeline()
00197 print "pvsimple.ResetCamera(view)"
00198 pvsimple.ResetCamera(view)
00199 sleep(DELAY)
00200 
00201 # Destroy the view
00202 print "Destroy the view with Iso Surfaces"
00203 pvsimple.Delete(view)
00204 
00205 
00206 # Create one more view for cut lines
00207 view = pvsimple.CreateRenderView()
00208 reset_view(view)
00209 
00210 color = [0.7, 0.7, 0.7]
00211 view.Background = color
00212 pvsimple.Render(view)
00213 sleep(DELAY)
00214 
00215 cutlines, curves = CutLinesOnField(med_reader, entity, field_name, timestamp,
00216                                    orientation1=Orientation.ZX,
00217                                    orientation2=Orientation.YZ,
00218                                    generate_curves=True)
00219 print "CutLinesOnField(...)"
00220 display_only(cutlines, view)
00221 pvsimple.ResetCamera(view)
00222 print "display_only(cutlines, view)"
00223 sleep(DELAY)
00224 
00225 xy_view = pvsimple.CreateXYPlotView()
00226 print "pvsimple.CreateXYPlotView()"
00227 index = 0
00228 for curve in curves:
00229     xyrep = pvsimple.Show(curve, xy_view)
00230     xyrep.AttributeType = 'Point Data'
00231     xyrep.UseIndexForXAxis = 0
00232     xyrep.XArrayName = 'arc_length'
00233     pvsimple.Render(xy_view)
00234     set_visible_lines(xyrep, [field_name])
00235     xyrep.SeriesLabel = [field_name, 'Y' + str(index)]
00236     r = str(random.random())
00237     g = str(random.random())
00238     b = str(random.random())
00239     xyrep.SeriesColor = [field_name, r, g, b]
00240     index += 1
00241 
00242 pvsimple.Render(xy_view)
00243 sleep(DELAY)
00244 
00245 # Destroy two views
00246 #print "Destroy two views: with Cut Lines and the curves"
00247 #pvsimple.Delete(view)
00248 #pvsimple.Delete(xy_view)
00249 
00250 
00251 # Create one more view for cut segment
00252 view = pvsimple.CreateRenderView()
00253 reset_view(view)
00254 
00255 color = [0.0, 0.7, 0.3]
00256 view.Background = color
00257 pvsimple.Render(view)
00258 sleep(DELAY)
00259 
00260 point1 = [0.0, -1.0, 2.5]
00261 point2 = [0.0, 1.0, 2.5]
00262 cutsegment = CutSegmentOnField(med_reader, entity, field_name, timestamp,
00263                                point1, point2)
00264 
00265 print "CutSegmentOnField(...)"
00266 display_only(cutsegment, view)
00267 pvsimple.ResetCamera(view)
00268 print "display_only(cutsegment, view)"
00269 sleep(DELAY)
00270 
00271 xy_view = pvsimple.CreateXYPlotView()
00272 curve = pvsimple.Show(cutsegment.Input, xy_view)
00273 curve.AttributeType = 'Point Data'
00274 curve.UseIndexForXAxis = 0
00275 curve.XArrayName = 'arc_length'
00276 set_visible_lines(curve, [field_name])
00277 
00278 pvsimple.Render(xy_view)
00279 sleep(DELAY)
00280 
00281 
00282 # Create one more view for animation
00283 view = pvsimple.CreateRenderView()
00284 reset_view(view)
00285 
00286 med_file = datadir + "TimeStamps.med"
00287 field_name = "vitesse"
00288 entity = EntityType.NODE
00289 timestamp = 2
00290 
00291 my_paravis.ImportFile(med_file)
00292 med_reader = pvsimple.GetActiveSource()
00293 
00294 isosurf = IsoSurfacesOnField(med_reader, entity, field_name, timestamp)
00295 print "IsoSurfacesOnField(...)"
00296 pvsimple.ResetCamera(view)
00297 
00298 print "Start Animation"
00299 pvsimple.AnimateReader(med_reader, view)