1 // Copyright (C) 2016 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)
40 MEDPresentationPointSprite::internalGeneratePipeline()
42 MEDPresentation::internalGeneratePipeline();
44 MEDPyLockWrapper lock;
46 setOrCreateRenderView(); // instanciate __viewXXX
49 // Populate internal array of available components:
50 fillAvailableFieldComponents();
51 int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS);
53 // Point sprite needs point data:
54 applyCellToPointIfNeeded();
56 pushAndExecPyLine(_objVar + " = " + _srcObjVar);
58 showObject(); // needs to be done before cell size computation to be sure ParaView has computed bounds, etc ...
60 // Compute cell average size in the mesh to have a nice scaling ratio:
61 std::ostringstream oss;
62 oss << "__avgSize = medcalc.ComputeCellAverageSize(" << _srcObjVar << ");";
63 pushAndExecPyLine(oss.str()); oss.str("");
65 colorBy("POINTS"); // like in Contour
68 oss << _dispVar << ".SetRepresentationType('Point Sprite');";
69 pushAndExecPyLine(oss.str()); oss.str("");
70 oss << _dispVar << ".PointSpriteDefaultsInitialized = 1;";
71 pushAndExecPyLine(oss.str()); oss.str("");
72 oss << _dispVar << ".RadiusArray = ['POINTS', '" << _fieldName << "'];";
73 pushAndExecPyLine(oss.str()); oss.str("");
74 oss << _dispVar << ".RadiusMode = 'Scalar';";
75 pushAndExecPyLine(oss.str()); oss.str("");
77 oss << _dispVar << ".RadiusVectorComponent = " << _selectedComponentIndex << ";";
78 pushAndExecPyLine(oss.str()); oss.str("");
79 oss << _dispVar << ".RadiusIsProportional = 0 ;";
80 pushAndExecPyLine(oss.str()); oss.str("");
81 oss << _dispVar << ".RadiusTransferFunctionEnabled = 1 ;";
82 pushAndExecPyLine(oss.str()); oss.str("");
83 oss << _dispVar << ".MaxPixelSize = 30 ;"; // Avoid too big balls
84 pushAndExecPyLine(oss.str()); oss.str("");
85 oss << _dispVar << ".RadiusRange = [0.0, __avgSize];";
86 pushAndExecPyLine(oss.str()); oss.str("");
90 rescaleTransferFunction();
91 resetCameraAndRender();
95 MEDPresentationPointSprite::updatePipeline(const MEDCALC::PointSpriteParameters& params)
97 if (params.fieldHandlerId != _params.fieldHandlerId)
98 throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!");
100 if (std::string(params.displayedComponent) != std::string(_params.displayedComponent))
101 updateComponent<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(std::string(params.displayedComponent));
102 if (params.scalarBarRange != _params.scalarBarRange)
103 updateScalarBarRange<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.scalarBarRange);
104 if (params.colorMap != _params.colorMap)
105 updateColorMap<MEDPresentationPointSprite, MEDCALC::PointSpriteParameters>(params.colorMap);