Back to index

salome-paravis  6.5.0
A8.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/A8 case
00021 # Create table
00022 
00023 import paraview.simple as pv
00024 import paraview.servermanager as sm
00025 
00026 
00027 # Define script for table creation
00028 script = """
00029 import math
00030 
00031 
00032 # Get table output
00033 table = self.GetTableOutput()
00034 
00035 nb_rows = 10
00036 nb_cols = 200
00037 
00038 # Create first column
00039 col1 = vtk.vtkDoubleArray()
00040 col1.SetName('Frequency')
00041 for i in xrange(0, nb_rows):
00042     col1.InsertNextValue(i * 10 + 1)
00043 table.AddColumn(col1)
00044 
00045 # Create the rest columns
00046 for i in xrange(1, nb_cols + 1):
00047    col = vtk.vtkDoubleArray()
00048    col.SetName('Power ' + str(i))
00049 
00050    # Fill the next column
00051    for j in xrange(0, nb_rows):
00052       if j % 2 == 1:
00053          col.InsertNextValue(math.log10(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
00054       else:
00055          col.InsertNextValue(math.sin(j * 30 * math.pi / 180) * 20 + i * 15 + j * 5)
00056 
00057    table.AddColumn(col)
00058 """
00059 
00060 # Creating programmable source (table)
00061 ps = pv.ProgrammableSource()
00062 ps.OutputDataSetType = 'vtkTable'
00063 ps.Script = script
00064 pv.RenameSource("Very useful data", ps)
00065 ps.UpdatePipeline()