Salome HOME
Merge 'abn/V8_1_fix' branch into V8_1_BR.
[modules/med.git] / src / MEDCalc / cmp / MEDPresentationPointSprite.cxx
1 // Copyright (C) 2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "MEDPyLockWrapper.hxx"
21
22 #include "MEDPresentationPointSprite.hxx"
23 #include "MEDPresentationException.hxx"
24
25 #include <SALOME_KernelServices.hxx>
26 #undef LOG  // should be fixed in KERNEL - double definition
27 #include <Basics_Utils.hxx>
28
29 #include <sstream>
30
31 const std::string MEDPresentationPointSprite::TYPE_NAME = "MEDPresentationPointSprite";
32
33 MEDPresentationPointSprite::MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params,
34                                                    const MEDCALC::ViewModeType viewMode) :
35     MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params)
36 {
37 }
38
39 void
40 MEDPresentationPointSprite::initFieldMeshInfos()
41 {
42   MEDPresentation::initFieldMeshInfos();
43   _colorByType = "POINTS";
44 }
45
46 void
47 MEDPresentationPointSprite::scaleBallRadius()
48 {
49   std::ostringstream oss;
50   oss << _dispVar << ".RadiusVectorComponent = " << _selectedComponentIndex << ";";
51   pushAndExecPyLine(oss.str()); oss.str("");
52 }
53
54
55 void
56 MEDPresentationPointSprite::internalGeneratePipeline()
57 {
58   MEDPresentation::internalGeneratePipeline();
59
60   MEDPyLockWrapper lock;
61
62   setOrCreateRenderView(); // instanciate __viewXXX
63   createSource();
64
65   // Populate internal array of available components:
66   fillAvailableFieldComponents();
67   int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
68
69   // Point sprite needs point data:
70   applyCellToPointIfNeeded();
71
72   pushAndExecPyLine(_objVar + " = " + _srcObjVar);
73
74   showObject(); // needs to be done before cell size computation to be sure ParaView has computed bounds, etc ...
75
76   // Compute cell average size in the mesh to have a nice scaling ratio:
77   std::ostringstream oss;
78   oss << "__avgSize = medcalc.ComputeCellAverageSize(" << _srcObjVar << ");";
79   pushAndExecPyLine(oss.str()); oss.str("");
80
81   colorBy();    // see initFieldInfo() - necessarily POINTS like in Contour
82
83   // Set point sprite:
84   oss << _dispVar << ".SetRepresentationType('Point Sprite');";
85   pushAndExecPyLine(oss.str()); oss.str("");
86   oss << _dispVar << ".PointSpriteDefaultsInitialized = 1;";
87   pushAndExecPyLine(oss.str()); oss.str("");
88   oss << _dispVar << ".RadiusArray = ['POINTS', '" << _fieldName << "'];";
89   pushAndExecPyLine(oss.str()); oss.str("");
90   oss << _dispVar << ".RadiusMode = 'Scalar';";
91   pushAndExecPyLine(oss.str()); oss.str("");
92
93   scaleBallRadius();
94   oss << _dispVar << ".RadiusIsProportional = 0 ;";
95   pushAndExecPyLine(oss.str()); oss.str("");
96   oss << _dispVar << ".RadiusTransferFunctionEnabled = 1 ;";
97   pushAndExecPyLine(oss.str()); oss.str("");
98   oss << _dispVar << ".MaxPixelSize = 30 ;";   // Avoid too big balls
99   pushAndExecPyLine(oss.str()); oss.str("");
100   oss << _dispVar << ".RadiusRange = [0.0, __avgSize];";
101   pushAndExecPyLine(oss.str()); oss.str("");
102
103   showScalarBar();
104   selectColorMap();
105   rescaleTransferFunction();
106   resetCameraAndRender();
107 }
108
109 void
110 MEDPresentationPointSprite::updatePipeline(const MEDCALC::PointSpriteParameters& params)
111 {
112   if (params.fieldHandlerId != _params.fieldHandlerId)
113     throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
114
115   if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
116     {
117       updateComponent<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(std::string(params.displayedComponent));
118       scaleBallRadius();
119       pushAndExecPyLine("pvs.Render();");
120     }
121   if (params.scalarBarRange != _params.scalarBarRange)
122     updateScalarBarRange<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.scalarBarRange);
123   if (params.colorMap != _params.colorMap)
124     updateColorMap<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.colorMap);
125 }