Salome HOME
Merge from V6_main (04/10/2012)
[modules/med.git] / src / MEDOP / tui / xmedpy / driver_pvis.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2011  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Guillaume Boulant (EDF) 
21
22 import MEDCoupling
23 __mapTypeOfField2ParavisLabel={
24     MEDCoupling.ON_CELLS:"OnCell",
25     MEDCoupling.ON_NODES:"OnPoint",
26     MEDCoupling.ON_GAUSS_PT:"ON_GAUSS_PT",
27     MEDCoupling.ON_GAUSS_NE:"ON_GAUSS_NE"}
28
29 def pvis_typeOfFieldLabel(typeOfField):
30     # A field name could identify several MEDCoupling fields, that
31     # differ by their spatial discretization on the mesh (values on
32     # cells, values on nodes, ...). This spatial discretization is
33     # specified (at least) by the TypeOfField that is an integer value
34     # in this list:
35     # 0 = ON_CELLS = OnCell
36     # 1 = ON_NODES = OnPoint
37     # 2 = ON_GAUSS_PT
38     # 3 = ON_GAUSS_NE
39     try:
40         return __mapTypeOfField2ParavisLabel[typeOfField]
41     except IndexError, e:
42         return "UNCKNOWN"
43
44 def pvis_scalarmap(filename,meshname,fieldname,typeOfField,iteration=-1):
45     """
46     This is the minimalist function to render a scalar map on a field
47     load from a med file using the PARAVIS module.
48     """
49     import pvsimple
50     
51     reader = pvsimple.MEDReader( FileName=filename )
52     # For fiels defined on cells, it seems to be required to specify
53     # the type of fields
54     if typeOfField == MEDCoupling.ON_CELLS:
55         reader.Groups = ["GROUP/%s/%s/No_Group"%(meshname,pvis_typeOfFieldLabel(typeOfField))]
56
57     representation = pvsimple.GetDisplayProperties(reader)
58     representation.ColorArrayName = fieldname
59
60     lookupTable = pvsimple.GetLookupTableForArray(
61         fieldname, 1, NanColor=[0.25, 0.0, 0.0],
62         RGBPoints=[25.0, 0.23, 0.30, 0.754, 245.0, 0.71, 0.016, 0.15],
63         VectorMode='Magnitude', ColorSpace='Diverging', ScalarRangeInitialized=1.0 )
64     representation.LookupTable = lookupTable
65
66     pvsimple.Render()
67
68     return True
69
70
71 def TEST_scalarmap():
72     import os
73     from xmed import properties
74     properties.setup(properties.testdata_02) # test with nodes
75     #properties.setup(properties.testdata_03) # test with cells
76     pvis_scalarmap(properties.testFilePath,
77                    properties.testMeshName,
78                    properties.testFieldName,
79                    properties.testTypeOfField,
80                    properties.testFieldIt)
81     
82 if __name__ == "__main__":
83     TEST_scalarmap()
84
85