1 // Copyright (C) 2016-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDPyLockWrapper.hxx"
22 #include "MEDPresentationPointSprite.hxx"
23 #include "MEDPresentationException.hxx"
25 #include <SALOME_KernelServices.hxx>
26 #undef LOG // should be fixed in KERNEL - double definition
27 #include <Basics_Utils.hxx>
31 const std::string MEDPresentationPointSprite::TYPE_NAME = "MEDPresentationPointSprite";
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),
41 MEDPresentationPointSprite::initFieldMeshInfos()
43 MEDPresentation::initFieldMeshInfos();
44 _colorByType = "POINTS";
48 MEDPresentationPointSprite::scaleBallRadius()
50 std::ostringstream oss;
51 int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
53 // set component or euclidean norm as the array to scale the ball radius
54 if (!_hideDataOutsideCustomRange) {
57 if (_selectedComponentIndex == -1)
58 oss << _dispVar << ".ScaleArrayComponent = 'Magnitude';";
60 oss << _dispVar << ".ScaleArrayComponent = " << _selectedComponentIndex << ";";
61 pushAndExecPyLine(oss.str()); oss.str("");
65 oss << getDispVar() << ".SetScaleArray = ['POINTS', '" << getThresholdFieldName() << "'];";
66 oss << getDispVar() << ".ScaleArrayComponent = " << 0 << ";";
69 // rescale transfer function to update scalar bar and get min-max range
70 rescaleTransferFunction();
72 // _rangeVar (to get min and max of the fields) is updated in rescaleTransferFunction
73 oss << getDispVar() << ".ScaleTransferFunction.RescaleTransferFunction(" << _rangeVar << "[0], " << _rangeVar << "[1]);";
74 pushAndExecPyLine(oss.str());
79 MEDPresentationPointSprite::internalGeneratePipeline()
81 MEDPresentation::internalGeneratePipeline();
83 MEDPyLockWrapper lock;
85 setOrCreateRenderView(); // instantiate __viewXXX
89 // Populate internal array of available components:
90 fillAvailableFieldComponents();
91 //int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS); // todo: unused
93 // Point sprite needs point data:
94 applyCellToPointIfNeeded();
96 pushAndExecPyLine(_objVar + " = " + _srcObjVar);
98 showObject(); // needs to be done before cell size computation to be sure ParaView has computed bounds, etc ...
100 colorBy(); // see initFieldInfo() - necessarily POINTS like in Contour
102 std::ostringstream oss;
105 oss << _dispVar << ".SetRepresentationType('Point Gaussian');";
106 pushAndExecPyLine(oss.str()); oss.str("");
107 oss << _dispVar << ".ScaleByArray = 1;";
108 pushAndExecPyLine(oss.str()); oss.str("");
109 oss << _dispVar << ".SetScaleArray = ['POINTS', '" << _fieldName << "'];";
110 pushAndExecPyLine(oss.str()); oss.str("");
112 // Compute the best radius again (like reset using current data value in GUI)
113 oss << "pvs.ResetProperty('GaussianRadius');";
114 pushAndExecPyLine(oss.str()); oss.str("");
116 // Make the radius twice the default radius
117 oss << _dispVar << ".GaussianRadius = 2*" << _dispVar << ".GaussianRadius" << ";";
118 oss <<"__gr = "<< _dispVar << ".GaussianRadius";
119 pushAndExecPyLine(oss.str()); oss.str("");
121 PyObject * obj = getPythonObjectFromMain("__gr");
122 if (obj && PyFloat_Check(obj)) {
123 _gaussianRadius = PyFloat_AsDouble(obj);
129 // Scale the radius array with the component and the scalar map
132 resetCameraAndRender();
136 MEDPresentationPointSprite::updatePipeline(const MEDCALC::PointSpriteParameters& params)
138 if (params.fieldHandlerId != _params.fieldHandlerId)
139 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
141 if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
143 updateComponent<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(std::string(params.displayedComponent));
145 pushAndExecPyLine("pvs.Render();");
147 if (params.scalarBarRange != _params.scalarBarRange ||
148 params.hideDataOutsideCustomRange != _params.hideDataOutsideCustomRange ||
149 params.scalarBarRangeArray[0] != _params.scalarBarRangeArray[0] ||
150 params.scalarBarRangeArray[1] != _params.scalarBarRangeArray[1])
151 updateScalarBarRange<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.scalarBarRange,
152 params.hideDataOutsideCustomRange,
153 params.scalarBarRangeArray[0],
154 params.scalarBarRangeArray[1]);
155 if (params.colorMap != _params.colorMap)
156 updateColorMap<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.colorMap);
157 if (params.visibility != _params.visibility)
158 updateVisibility<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.visibility);
159 if (params.scalarBarVisibility != _params.scalarBarVisibility)
160 updateScalarBarVisibility<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.scalarBarVisibility);
164 MEDPresentationPointSprite::additionalThresholdVisualizationActions() {
165 if (_hideDataOutsideCustomRange) {
167 std::ostringstream oss;
168 std::string aDispVar = getDispVar();
169 oss << aDispVar << ".SetRepresentationType('Point Gaussian');";
170 oss << aDispVar << ".ScaleByArray = 1;";
171 oss << aDispVar << ".SetScaleArray = ['POINTS', '" << getThresholdFieldName() << "'];";
172 oss << aDispVar << ".GaussianRadius = " << _gaussianRadius << ";";
173 oss << aDispVar << ".ScaleTransferFunction.RescaleTransferFunction(" << _rangeVar << "[0], " << _rangeVar << "[1]);";
179 MEDPresentationPointSprite::additionalThresholdActions() {
184 MEDPresentationPointSprite::additionalUnThresholdActions() {