From: abn Date: Wed, 3 Aug 2016 15:05:00 +0000 (+0200) Subject: [MEDCalcl] PointSprite and VectorField presentations. X-Git-Tag: V8_1_0b1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fmed.git;a=commitdiff_plain;h=7d544dd8676fb5c514b5bc2c175967b45d10cc67 [MEDCalcl] PointSprite and VectorField presentations. + also some refactoring to group common pipelines commands + still some work to be done on the scaling factor for VectorField --- diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index 09689a92d..c045eec36 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -111,13 +111,13 @@ module MEDCALC long nbContours; }; -// struct VectorFieldParameters { -// long fieldHandlerId; -// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name -// ScalarBarRangeType scalarBarRange; -// ColorMapType colorMap; -// }; -// + struct VectorFieldParameters { + long fieldHandlerId; + string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name - only used to color the glyphs + ScalarBarRangeType scalarBarRange; + ColorMapType colorMap; + }; + struct SlicesParameters { long fieldHandlerId; string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name @@ -131,12 +131,12 @@ module MEDCALC // long fieldHandlerId; // }; // -// struct PointSpriteParameters { -// long fieldHandlerId; -// string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name -// ScalarBarRangeType scalarBarRange; -// ColorMapType colorMap; -// }; + struct PointSpriteParameters { + long fieldHandlerId; + string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name + ScalarBarRangeType scalarBarRange; + ColorMapType colorMap; + }; typedef sequence PresentationsList; @@ -144,14 +144,13 @@ module MEDCALC interface MEDPresentationManager : SALOME::GenericObj { - long makeMeshView(in MeshViewParameters params, in ViewModeType viewMode); - long makeScalarMap(in ScalarMapParameters params, in ViewModeType viewMode); - long makeContour(in ContourParameters params, in ViewModeType viewMode) - raises (SALOME::SALOME_Exception); -// long makeVectorField(in VectorFieldParameters params, in ViewModeType viewMode); - long makeSlices(in SlicesParameters params, in ViewModeType viewMode); + long makeMeshView(in MeshViewParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); + long makeScalarMap(in ScalarMapParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); + long makeContour(in ContourParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); + long makeVectorField(in VectorFieldParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); + long makeSlices(in SlicesParameters params, in ViewModeType viewMode) raises (SALOME::SALOME_Exception); // long makeDeflectionShape(in DeflectionShapeParameters params, in ViewModeType viewMode); -// long makePointSprite(in PointSpriteParameters params, in ViewModeType viewMode); + long makePointSprite(in PointSpriteParameters params, in ViewModeType viewMode); void setPresentationStringProperty(in long presId, in string propName, in string propValue); string getPresentationStringProperty(in long presId, in string propName); @@ -162,14 +161,16 @@ module MEDCALC ScalarMapParameters getScalarMapParameters(in long presId); ContourParameters getContourParameters(in long presId); SlicesParameters getSlicesParameters(in long presId); + VectorFieldParameters getVectorFieldParameters(in long presId); + PointSpriteParameters getPointSpriteParameters(in long presId); void updateMeshView(in long presId, in MeshViewParameters params); void updateScalarMap(in long presId, in ScalarMapParameters params); void updateContour(in long presId, in ContourParameters params); -// void updateVectorField(in long presId, in VectorFieldParameters params); + void updateVectorField(in long presId, in VectorFieldParameters params); void updateSlices(in long presId, in SlicesParameters params); // void updateDeflectionShape(in long presId, in DeflectionShapeParameters params); -// void updatePointSprite(in long presId, in PointSpriteParameters params); + void updatePointSprite(in long presId, in PointSpriteParameters params); boolean removePresentation(in long presId); diff --git a/src/MEDCalc/cmp/CMakeLists.txt b/src/MEDCalc/cmp/CMakeLists.txt index 3a443934c..c735141c4 100644 --- a/src/MEDCalc/cmp/CMakeLists.txt +++ b/src/MEDCalc/cmp/CMakeLists.txt @@ -42,10 +42,10 @@ SET(COMMON_SOURCES MEDPresentationMeshView.cxx MEDPresentationScalarMap.cxx MEDPresentationContour.cxx -# MEDPresentationVectorField.cxx + MEDPresentationVectorField.cxx MEDPresentationSlices.cxx -# MEDPresentationDeflectionShape.cxx -# MEDPresentationPointSprite.cxx + MEDPresentationPointSprite.cxx +# MEDPresentationDeflectionShape.cxx ) SET(MEDFactoryEngine_SOURCES diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index c82f30765..a11077b64 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -57,6 +57,7 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s _fileName = dataSHandler->uri; _fieldName = fieldHandler->fieldname; _fieldType = getFieldTypeString((MEDCoupling::TypeOfField) fieldHandler->type); + _meshName = meshHandler->name; if (_fileName.substr(0, 7) != std::string("file://")) { const char* msg = "MEDPresentation(): Data source is not a file! Can not proceed."; @@ -209,6 +210,9 @@ MEDPresentation::getIntProperty(const std::string& propName) const } +/** +* @return a borrowed reference. Do not DECRREF! +*/ PyObject* MEDPresentation::getPythonObjectFromMain(const char* python_var) const { @@ -244,74 +248,123 @@ MEDPresentation::getRenderViewVar() const return oss.str(); } -std::string -MEDPresentation::getRenderViewCommand() const +void +MEDPresentation::createSource() { - std::ostringstream oss, oss2; + std::ostringstream oss; + oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _srcObjVar << ".GenerateVectors = 1;"; + pushAndExecPyLine(oss.str()); oss.str(""); +} + +void +MEDPresentation::setOrCreateRenderView() +{ + std::ostringstream oss2; std::string view(getRenderViewVar()); - oss2 << "pvs._DisableFirstRenderCameraReset();" << std::endl; + oss2 << "pvs._DisableFirstRenderCameraReset();"; + pushAndExecPyLine(oss2.str()); oss2.str(""); if (_viewMode == MEDCALC::VIEW_MODE_OVERLAP) { // this might potentially re-assign to an existing view variable, but this is OK, we // normally reassign exaclty the same RenderView object. - oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl; + oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');"; + pushAndExecPyLine(oss2.str()); oss2.str(""); } else if (_viewMode == MEDCALC::VIEW_MODE_REPLACE) { // same as above - oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');" << std::endl; - oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");" << std::endl; - oss2 << "pvs.Render();" << std::endl; + oss2 << view << " = pvs.GetActiveViewOrCreate('RenderView');"; + pushAndExecPyLine(oss2.str()); oss2.str(""); + oss2 << "pvs.active_objects.source and pvs.Hide(view=" << view << ");"; + pushAndExecPyLine(oss2.str()); oss2.str(""); + oss2 << "pvs.Render();"; + pushAndExecPyLine(oss2.str()); oss2.str(""); } else if (_viewMode == MEDCALC::VIEW_MODE_NEW_LAYOUT) { - oss2 << "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');" << std::endl; - oss2 << view << " = pvs.CreateView('RenderView');" << std::endl; + oss2 << "__layout1 = pvs.servermanager.misc.ViewLayout(registrationGroup='layouts');"; + pushAndExecPyLine(oss2.str()); oss2.str(""); + oss2 << view << " = pvs.CreateView('RenderView');"; + pushAndExecPyLine(oss2.str()); oss2.str(""); } else if (_viewMode == MEDCALC::VIEW_MODE_SPLIT_VIEW) { - oss2 << view << " = pvs.CreateView('RenderView');" << std::endl; + oss2 << view << " = pvs.CreateView('RenderView');"; + pushAndExecPyLine(oss2.str()); oss2.str(""); } - return oss2.str(); } -std::string -MEDPresentation::getResetCameraCommand() const +void +MEDPresentation::resetCameraAndRender() { - return getRenderViewVar() + ".ResetCamera();"; + pushAndExecPyLine(getRenderViewVar() + ".ResetCamera();"); + pushAndExecPyLine("pvs.Render();"); } -std::string -MEDPresentation::getComponentSelectionCommand() const +void +MEDPresentation::selectFieldComponent() { std::ostringstream oss, oss_l; std::string ret; if (_selectedComponentIndex != -1) { - oss << _lutVar << ".VectorMode = 'Component';\n"; + oss << _lutVar << ".VectorMode = 'Component';"; + pushAndExecPyLine(oss.str()); oss.str(""); oss << _lutVar << ".VectorComponent = " << _selectedComponentIndex << ";"; + pushAndExecPyLine(oss.str()); oss.str(""); } else // Euclidean norm { oss << _lutVar << ".VectorMode = 'Magnitude';"; + pushAndExecPyLine(oss.str()); oss.str(""); } - return oss.str(); } -std::string -MEDPresentation::getColorMapCommand() const +void +MEDPresentation::selectColorMap() { - std::string ret; + std::ostringstream oss, oss2; + + oss2 << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; + pushAndExecPyLine(oss2.str()); + switch (_colorMap) { case MEDCALC::COLOR_MAP_BLUE_TO_RED_RAINBOW: - ret = _lutVar + ".ApplyPreset('Blue to Red Rainbow',True);"; + oss << _lutVar << ".ApplyPreset('Blue to Red Rainbow',True);"; break; case MEDCALC::COLOR_MAP_COOL_TO_WARM: - ret = _lutVar + ".ApplyPreset('Cool to Warm',True);"; + oss << _lutVar << ".ApplyPreset('Cool to Warm',True);"; break; default: STDLOG("MEDPresentation::getColorMapCommand(): invalid colormap!"); throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!"); } - return ret; + pushAndExecPyLine(oss.str()); } -std::string -MEDPresentation::getRescaleCommand() const + +void +MEDPresentation::showObject() +{ + std::ostringstream oss; + oss << _dispVar << " = pvs.Show(" << _objVar << ", " << getRenderViewVar() << ");"; + pushAndExecPyLine(oss.str()); +} + +void +MEDPresentation::showScalarBar() +{ + std::ostringstream oss; + oss << _dispVar << ".SetScalarBarVisibility(" << getRenderViewVar() << ", True);"; + pushAndExecPyLine(oss.str()); +} + +void +MEDPresentation::colorBy(const std::string & fieldType) +{ + std::ostringstream oss; + oss << "pvs.ColorBy(" << _dispVar << ", ('" << fieldType << "', '" << _fieldName << "'));"; + pushAndExecPyLine(oss.str()); +} + +void +MEDPresentation::rescaleTransferFunction() { std::string ret; switch(_sbRange) @@ -326,7 +379,7 @@ MEDPresentation::getRescaleCommand() const STDLOG("MEDPresentation::getRescaleCommand(): invalid range!"); throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!"); } - return ret; + pushAndExecPyLine(ret); } int @@ -416,3 +469,97 @@ MEDPresentation::fillAvailableFieldComponents() } } +/** + * In case where a CELLS field needs to be converted to POINT field. + * This updates the source object to become the result of the CellDatatoPointData filter. + */ +void +MEDPresentation::applyCellToPointIfNeeded() +{ + std::ostringstream oss, oss2; + // Apply Cell data to point data: + oss2 << "__srcObj" << GeneratePythonId(); + oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + // Now the source becomes the result of the CellDatatoPointData: + _srcObjVar = oss2.str(); +} + +/** + * Convert a vector field into a 3D vector field: + * - if the vector field is already 3D, nothing to do + * - if it is 2D, then add a null component + * - otherwise (tensor field, scalar field) throw + */ +void +MEDPresentation::convertTo3DVectorField() +{ + std::ostringstream oss, oss1, oss2, oss3; + + int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS); + if (nbCompo < 2 || nbCompo > 3) + { + oss << "The field '" << _fieldName << "' must have 2 or 3 components for this presentation!"; + STDLOG(oss.str()); + throw KERNEL::createSalomeException(oss.str().c_str()); + } + if (nbCompo == 3) + return; + + // Apply calculator: + oss2 << "__srcObj" << GeneratePythonId(); + oss << oss2.str() << " = pvs.Calculator(Input=" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + // Now the source becomes the result of the CellDatatoPointData: + _srcObjVar = oss2.str(); + std::string typ; + if(_fieldType == "CELLS") + typ = "Cell Data"; + else if(_fieldType == "POINTS") + typ = "Point Data"; + else + { + oss3 << "Field '" << _fieldName << "' has invalid field type"; + STDLOG(oss3.str()); + throw KERNEL::createSalomeException(oss3.str().c_str()); + } + oss << _srcObjVar << ".AttributeMode = '" << typ << "';"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _srcObjVar << ".ResultArrayName = '" << _fieldName << "_CALC';"; // will never be needed I think + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _srcObjVar << ".Function = '" << _fieldName << "_0*iHat + " << _fieldName << "_1*jHat + 0.0*zHat';"; + pushAndExecPyLine(oss.str()); oss.str(""); +} + +//double +//MEDPresentation::computeCellAverageSize() +//{ +// std::ostringstream oss; +// oss << "import MEDLoader;"; +// pushAndExecPyLine(oss.str()); oss.str(""); +// oss << "__mesh = MEDLoader.ReadMeshFromFile('" << _fileName << "', '" << _meshName << "');"; +// pushAndExecPyLine(oss.str()); oss.str(""); +// +// oss << "__bb = __mesh.getBoundingBox()"; +// pushAndExecPyLine(oss.str()); oss.str(""); +// oss << "__deltas = [x[1]-x[0] for x in __bb];"; +// pushAndExecPyLine(oss.str()); oss.str(""); +// oss << "__vol = reduce(lambda x,y:x*y, __deltas, 1.0);"; +// pushAndExecPyLine(oss.str()); oss.str(""); +// // Average cell size is the the n-th root of average volume of a cell, with n being the space dimension +// oss << "__cellSize = (__vol/__mesh.getNumberOfCells())**(1.0/len(__bb));"; +// pushAndExecPyLine(oss.str()); oss.str(""); +// +// PyObject * pyObj = getPythonObjectFromMain("__cellSize"); +// bool err = false; +// if (!pyObj || !PyFloat_Check(pyObj)) { /* nothing to do, err handler below */} +// else { +// double ret= PyFloat_AsDouble(pyObj); +// if(!PyErr_Occurred()) +// return ret; +// } +// // From here, an error for sure. +// const char * msg = "MEDPresentation::computeCellAverageSize(): Python error."; +// STDLOG(msg); +// throw KERNEL::createSalomeException(msg); +//} diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index bfcdd2fcc..55999b0e1 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -73,13 +73,18 @@ protected: const MEDCALC::ViewModeType viewMode, const MEDCALC::ColorMapType colorMap, const MEDCALC::ScalarBarRangeType sbRange); - std::string getRenderViewCommand() const; std::string getRenderViewVar() const; - std::string getResetCameraCommand() const; - std::string getComponentSelectionCommand() const; - std::string getColorMapCommand() const; - std::string getRescaleCommand() const; + // The most common elements of the ParaView pipeline: + void setOrCreateRenderView(); + void createSource(); + void selectFieldComponent(); + void showObject(); + void colorBy(const std::string & fieldType); + void showScalarBar(); + void rescaleTransferFunction(); + void selectColorMap(); + void resetCameraAndRender(); virtual void internalGeneratePipeline(); PyObject* getPythonObjectFromMain(const char* var) const; @@ -90,6 +95,10 @@ protected: MEDPresentation::TypeID getID() const { return _fieldHandlerId; } void fillAvailableFieldComponents(); + void applyCellToPointIfNeeded(); + void convertTo3DVectorField(); +// double computeCellAverageSize(); + //void computeFieldRange // virtual MEDCALC::ViewModeType getViewMode() = 0; @@ -118,6 +127,7 @@ private: void updatePipeline(const PresentationParameters& params); protected: + std::string _meshName; std::string _fileName; std::string _fieldName; std::string _fieldType; diff --git a/src/MEDCalc/cmp/MEDPresentation.txx b/src/MEDCalc/cmp/MEDPresentation.txx index dc99dcdc5..59b09181c 100644 --- a/src/MEDCalc/cmp/MEDPresentation.txx +++ b/src/MEDCalc/cmp/MEDPresentation.txx @@ -89,8 +89,7 @@ MEDPresentation::updateComponent(const std::string& newCompo) MEDPyLockWrapper lock; std::ostringstream oss; - std::string cmd = getComponentSelectionCommand(); - pushAndExecPyLine(cmd); + selectFieldComponent(); pushAndExecPyLine("pvs.Render();"); } @@ -115,8 +114,7 @@ MEDPresentation::updateColorMap(MEDCALC::ColorMapType colorMap) // Update the pipeline: { MEDPyLockWrapper lock; - std::string cmd = getColorMapCommand(); - pushAndExecPyLine(cmd); + selectColorMap(); pushAndExecPyLine("pvs.Render();"); } } @@ -140,8 +138,7 @@ MEDPresentation::updateScalarBarRange(MEDCALC::ScalarBarRangeType sbRange) // Update the pipeline: { MEDPyLockWrapper lock; - std::string cmd = getRescaleCommand(); - pushAndExecPyLine(cmd); + rescaleTransferFunction(); pushAndExecPyLine("pvs.Render();"); } } diff --git a/src/MEDCalc/cmp/MEDPresentationContour.cxx b/src/MEDCalc/cmp/MEDPresentationContour.cxx index fee4659e5..f08493b30 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.cxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.cxx @@ -36,15 +36,17 @@ MEDPresentationContour::MEDPresentationContour(const MEDCALC::ContourParameters& setIntProperty(MEDPresentationContour::PROP_NB_CONTOUR, params.nbContours); } -std::string -MEDPresentationContour::getContourCommand() const +void +MEDPresentationContour::setNumberContours() { - std::ostringstream oss1; + std::ostringstream oss; - oss1 << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();\n"; - oss1 << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");\n"; - oss1 << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];\n"; - return oss1.str(); + oss << "min_max = " << _srcObjVar << ".PointData.GetArray('" << _fieldName << "').GetRange();"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << "delta = (min_max[1]-min_max[0])/float(" << _params.nbContours << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".Isosurfaces = [min_max[0]+0.5*delta+i*delta for i in range(" << _params.nbContours << ")];"; + pushAndExecPyLine(oss.str()); oss.str(""); } void @@ -54,11 +56,7 @@ MEDPresentationContour::internalGeneratePipeline() MEDPyLockWrapper lock; - std::ostringstream oss_o, oss; - std::string view(getRenderViewVar()); - - oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');"; - pushAndExecPyLine(oss.str()); oss.str(""); + createSource(); // Populate internal array of available components: fillAvailableFieldComponents(); @@ -69,41 +67,27 @@ MEDPresentationContour::internalGeneratePipeline() throw KERNEL::createSalomeException(msg); } - pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX + setOrCreateRenderView(); // instanciate __viewXXX - if(_fieldType == "CELLS") - { - // In case of a CELLS field need to convert to POINT field, and update source - STDLOG("Applying CellDatatoPointData filter"); - std::ostringstream oss2, oss4; - // Apply Cell data to point data: - oss2 << "__obj" << GeneratePythonId(); - oss << oss2.str() << " = pvs.CellDatatoPointData(Input=" << _srcObjVar << ");"; - pushAndExecPyLine(oss.str()); oss.str(""); - // Now the source becomes the result of the CellDatatoPointData: - _srcObjVar = oss2.str(); - } + // Contour needs point data: + applyCellToPointIfNeeded(); + + std::ostringstream oss; oss << _objVar << " = pvs.Contour(Input=" << _srcObjVar << ");"; pushAndExecPyLine(oss.str()); oss.str(""); + + showObject(); + oss << _objVar << ".ContourBy = ['POINTS', '" << _fieldName << "'];"; pushAndExecPyLine(oss.str()); oss.str(""); // Set number of contours - pushAndExecPyLine(getContourCommand()); - - oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << "pvs.ColorBy(" << _dispVar << ", ('POINTS', '" << _fieldName << "'));"; // necessarily POINTS - pushAndExecPyLine(oss.str()); oss.str(""); - oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << getRescaleCommand(); - pushAndExecPyLine(oss.str()); oss.str(""); - oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; - pushAndExecPyLine(oss.str()); oss.str(""); - pushAndExecPyLine(getColorMapCommand()); oss.str(""); - pushAndExecPyLine(getResetCameraCommand()); - pushAndExecPyLine("pvs.Render();"); + setNumberContours(); + colorBy("POINTS"); // necessarily POINTS because of the conversion above + showScalarBar(); + rescaleTransferFunction(); + selectColorMap(); + resetCameraAndRender(); } void @@ -132,8 +116,7 @@ MEDPresentationContour::updateNbContours(const int nbContours) // Update the pipeline: { MEDPyLockWrapper lock; - std::string cmd = getContourCommand(); - pushAndExecPyLine(cmd); + setNumberContours(); pushAndExecPyLine("pvs.Render();"); } } diff --git a/src/MEDCalc/cmp/MEDPresentationContour.hxx b/src/MEDCalc/cmp/MEDPresentationContour.hxx index bf36fee8c..d7fbc19de 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.hxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.hxx @@ -41,7 +41,7 @@ protected: void updateNbContours(const int nbContours); virtual void internalGeneratePipeline(); - std::string getContourCommand() const; + void setNumberContours(); private: MEDCALC::ContourParameters _params; diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index 09b2f5726..876b3ec1c 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -26,9 +26,9 @@ #include "MEDPresentationScalarMap.hxx" #include "MEDPresentationContour.hxx" #include "MEDPresentationSlices.hxx" -//#include "MEDPresentationVectorField.hxx" +#include "MEDPresentationVectorField.hxx" //#include "MEDPresentationDeflectionShape.hxx" -//#include "MEDPresentationPointSprite.hxx" +#include "MEDPresentationPointSprite.hxx" #include @@ -141,12 +141,12 @@ MEDPresentationManager_i::makeContour(const MEDCALC::ContourParameters& params, return _makePresentation(params, viewMode); } -//MEDPresentation::TypeID -//MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params) -//{ -// return _makePresentation(params); -//} -// +MEDPresentation::TypeID +MEDPresentationManager_i::makeVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode) +{ + return _makePresentation(params, viewMode); +} + MEDPresentation::TypeID MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, const MEDCALC::ViewModeType viewMode) { @@ -158,12 +158,12 @@ MEDPresentationManager_i::makeSlices(const MEDCALC::SlicesParameters& params, co //{ // return _makePresentation(params); //} -// -//MEDPresentation::TypeID -//MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params) -//{ -// return _makePresentation(params); -//} + +MEDPresentation::TypeID +MEDPresentationManager_i::makePointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode) +{ + return _makePresentation(params, viewMode); +} MEDCALC::MeshViewParameters MEDPresentationManager_i::getMeshViewParameters(MEDPresentation::TypeID presentationID) @@ -200,6 +200,23 @@ MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentati return tmp._retn(); } +MEDCALC::VectorFieldParameters* +MEDPresentationManager_i::getVectorFieldParameters(MEDPresentation::TypeID presentationID) +{ + MEDCALC::VectorFieldParameters* p = new MEDCALC::VectorFieldParameters(); + _getParameters(presentationID, *p); + MEDCALC::VectorFieldParameters_var tmp(p); + return tmp._retn(); +} + +MEDCALC::PointSpriteParameters* +MEDPresentationManager_i::getPointSpriteParameters(MEDPresentation::TypeID presentationID) +{ + MEDCALC::PointSpriteParameters* p = new MEDCALC::PointSpriteParameters(); + _getParameters(presentationID, *p); + MEDCALC::PointSpriteParameters_var tmp(p); + return tmp._retn(); +} void MEDPresentationManager_i::updateMeshView(MEDPresentation::TypeID presentationID, const MEDCALC::MeshViewParameters& params) @@ -219,12 +236,12 @@ MEDPresentationManager_i::updateContour(MEDPresentation::TypeID presentationID, return _updatePresentation(presentationID, params); } -//void -//MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params) -//{ -// return _updatePresentation(presentationID, params); -//} -// +void +MEDPresentationManager_i::updateVectorField(MEDPresentation::TypeID presentationID, const MEDCALC::VectorFieldParameters& params) +{ + return _updatePresentation(presentationID, params); +} + void MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, const MEDCALC::SlicesParameters& params) { @@ -236,12 +253,12 @@ MEDPresentationManager_i::updateSlices(MEDPresentation::TypeID presentationID, c //{ // return _updatePresentation(presentationID, params); //} -// -//void -//MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params) -//{ -// return _updatePresentation(presentationID, params); -//} + +void +MEDPresentationManager_i::updatePointSprite(MEDPresentation::TypeID presentationID, const MEDCALC::PointSpriteParameters& params) +{ + return _updatePresentation(presentationID, params); +} CORBA::Boolean MEDPresentationManager_i::removePresentation(MEDPresentation::TypeID presentationID) diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index c2c17873a..9f89afcc1 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -42,10 +42,10 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT MEDPresentation::TypeID makeMeshView(const MEDCALC::MeshViewParameters&, const MEDCALC::ViewModeType); MEDCALC_EXPORT MEDPresentation::TypeID makeScalarMap(const MEDCALC::ScalarMapParameters&, const MEDCALC::ViewModeType); MEDCALC_EXPORT MEDPresentation::TypeID makeContour(const MEDCALC::ContourParameters&, const MEDCALC::ViewModeType); -// MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&, const MEDCALC::ViewModeType); + MEDCALC_EXPORT MEDPresentation::TypeID makeVectorField(const MEDCALC::VectorFieldParameters&, const MEDCALC::ViewModeType); MEDCALC_EXPORT MEDPresentation::TypeID makeSlices(const MEDCALC::SlicesParameters&, const MEDCALC::ViewModeType); // MEDCALC_EXPORT MEDPresentation::TypeID makeDeflectionShape(const MEDCALC::DeflectionShapeParameters&, const MEDCALC::ViewModeType); -// MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&, const MEDCALC::ViewModeType); + MEDCALC_EXPORT MEDPresentation::TypeID makePointSprite(const MEDCALC::PointSpriteParameters&, const MEDCALC::ViewModeType); MEDCALC_EXPORT void setPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName, const char* propValue); MEDCALC_EXPORT char* getPresentationStringProperty(MEDPresentation::TypeID presentationID, const char* propName); @@ -57,14 +57,16 @@ class MEDPresentationManager_i: public POA_MEDCALC::MEDPresentationManager, MEDCALC_EXPORT MEDCALC::ScalarMapParameters* getScalarMapParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT MEDCALC::ContourParameters getContourParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT MEDCALC::SlicesParameters* getSlicesParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::VectorFieldParameters* getVectorFieldParameters(MEDPresentation::TypeID presentationID); + MEDCALC_EXPORT MEDCALC::PointSpriteParameters* getPointSpriteParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT void updateMeshView(MEDPresentation::TypeID, const MEDCALC::MeshViewParameters&); MEDCALC_EXPORT void updateScalarMap(MEDPresentation::TypeID, const MEDCALC::ScalarMapParameters&); MEDCALC_EXPORT void updateContour(MEDPresentation::TypeID, const MEDCALC::ContourParameters&); -// MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&); + MEDCALC_EXPORT void updateVectorField(MEDPresentation::TypeID, const MEDCALC::VectorFieldParameters&); MEDCALC_EXPORT void updateSlices(MEDPresentation::TypeID, const MEDCALC::SlicesParameters&); // MEDCALC_EXPORT void updateDeflectionShape(MEDPresentation::TypeID, const MEDCALC::DeflectionShapeParameters&); -// MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&); + MEDCALC_EXPORT void updatePointSprite(MEDPresentation::TypeID, const MEDCALC::PointSpriteParameters&); MEDCALC_EXPORT CORBA::Boolean removePresentation(MEDPresentation::TypeID); MEDCALC_EXPORT CORBA::Boolean activateView(MEDPresentation::TypeID); diff --git a/src/MEDCalc/cmp/MEDPresentationMeshView.cxx b/src/MEDCalc/cmp/MEDPresentationMeshView.cxx index 83678f19b..60ce767e6 100644 --- a/src/MEDCalc/cmp/MEDPresentationMeshView.cxx +++ b/src/MEDCalc/cmp/MEDPresentationMeshView.cxx @@ -38,8 +38,8 @@ MEDPresentationMeshView::MEDPresentationMeshView(const MEDCALC::MeshViewParamete setIntProperty(MEDPresentationMeshView::PROP_MESH_MODE, params.mode); } -std::string -MEDPresentationMeshView::getMeshViewCommand() const +void +MEDPresentationMeshView::representationType() { std::ostringstream oss1; @@ -59,8 +59,7 @@ MEDPresentationMeshView::getMeshViewCommand() const STDLOG(mes); throw KERNEL::createSalomeException(mes); } - - return oss1.str(); + pushAndExecPyLine(oss1.str()); } void @@ -70,19 +69,16 @@ MEDPresentationMeshView::internalGeneratePipeline() MEDPyLockWrapper lock; - std::ostringstream oss; - std::string view(getRenderViewVar()); + createSource(); + setOrCreateRenderView(); - oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');"; - pushAndExecPyLine(oss.str()); oss.str(""); - pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX + std::ostringstream oss; oss << _objVar << " = " << _srcObjVar << ";"; pushAndExecPyLine(oss.str()); oss.str(""); - oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");"; - pushAndExecPyLine(oss.str()); oss.str(""); - pushAndExecPyLine(getMeshViewCommand()); - pushAndExecPyLine(getResetCameraCommand()); - pushAndExecPyLine("pvs.Render();"); + + showObject(); + representationType(); + resetCameraAndRender(); } void @@ -106,8 +102,7 @@ MEDPresentationMeshView::updateMeshMode(const MEDCALC::MeshModeType mode) // Update the pipeline: { MEDPyLockWrapper lock; - std::string cmd = getMeshViewCommand(); - pushAndExecPyLine(cmd); + representationType(); pushAndExecPyLine("pvs.Render();"); } } diff --git a/src/MEDCalc/cmp/MEDPresentationMeshView.hxx b/src/MEDCalc/cmp/MEDPresentationMeshView.hxx index 30c6d8bca..9eb9ecede 100644 --- a/src/MEDCalc/cmp/MEDPresentationMeshView.hxx +++ b/src/MEDCalc/cmp/MEDPresentationMeshView.hxx @@ -41,7 +41,7 @@ protected: void updateMeshMode(const MEDCALC::MeshModeType mode); virtual void internalGeneratePipeline(); - std::string getMeshViewCommand() const; + void representationType(); private: MEDCALC::MeshViewParameters _params; diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx index 18fdff4d3..9dbc17ff8 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx @@ -17,39 +17,90 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#include "MEDPyLockWrapper.hxx" + #include "MEDPresentationPointSprite.hxx" +#include "MEDPresentationException.hxx" + +#include +#undef LOG // should be fixed in KERNEL - double definition +#include + +#include + +const std::string MEDPresentationPointSprite::TYPE_NAME = "MEDPresentationPointSprite"; + +MEDPresentationPointSprite::MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params, + const MEDCALC::ViewModeType viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params) +{ +} void MEDPresentationPointSprite::internalGeneratePipeline() { -// PyGILState_STATE _gil_state = PyGILState_Ensure(); -// -// std::string cmd = std::string("import pvsimple as pvs;"); -// cmd += getRenderViewCommand(_params.viewMode); // define __view1 -// -// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');"); -// cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);"); -// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));"); -// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);"); -// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();"); -// cmd += std::string("__disp1.SetRepresentationType('Point Sprite');"); -// cmd += std::string("pvs.Render();"); -// -// cmd += getResetCameraCommand(); -// -// //std::cerr << "Python command:" << std::endl; -// //std::cerr << cmd << std::endl; -// PyRun_SimpleString(cmd.c_str()); -// // Retrieve Python object for internal storage: -// PyObject* obj = getPythonObjectFromMain("__obj1"); -// PyObject* disp = getPythonObjectFromMain("__disp1"); -// pushInternal(obj, disp); -// -// PyGILState_Release(_gil_state); + MEDPresentation::internalGeneratePipeline(); + + MEDPyLockWrapper lock; + + setOrCreateRenderView(); // instanciate __viewXXX + createSource(); + + // Populate internal array of available components: + fillAvailableFieldComponents(); + int nbCompo = getIntProperty(MEDPresentation::PROP_NB_COMPONENTS); + + // Point sprite needs point data: + applyCellToPointIfNeeded(); + + pushAndExecPyLine(_objVar + " = " + _srcObjVar); + + showObject(); // needs to be done before cell size computation to be sure ParaView has computed bounds, etc ... + + // Compute cell average size in the mesh to have a nice scaling ratio: + std::ostringstream oss; + oss << "import medcalc; __avgSize=medcalc.ComputeCellAverageSize(" << _srcObjVar << ");"; + pushAndExecPyLine(oss.str()); oss.str(""); + + colorBy("POINTS"); // like in Contour + + // Set point sprite: + oss << _dispVar << ".SetRepresentationType('Point Sprite');"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".PointSpriteDefaultsInitialized = 1;"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".RadiusArray = ['POINTS', '" << _fieldName << "'];"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".RadiusMode = 'Scalar';"; + pushAndExecPyLine(oss.str()); oss.str(""); + + oss << _dispVar << ".RadiusVectorComponent = " << _selectedComponentIndex << ";"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".RadiusIsProportional = 0 ;"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".RadiusTransferFunctionEnabled = 1 ;"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".MaxPixelSize = 30 ;"; // Avoid too big balls + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _dispVar << ".RadiusRange = [0.0, __avgSize];"; + pushAndExecPyLine(oss.str()); oss.str(""); + + showScalarBar(); + rescaleTransferFunction(); + selectColorMap(); + resetCameraAndRender(); } void MEDPresentationPointSprite::updatePipeline(const MEDCALC::PointSpriteParameters& params) { - // :TODO: + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (std::string(params.displayedComponent) != std::string(_params.displayedComponent)) + updateComponent(std::string(params.displayedComponent)); + if (params.scalarBarRange != _params.scalarBarRange) + updateScalarBarRange(params.scalarBarRange); + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); } diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx index 56d83e27b..e38b9ea1f 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.hxx @@ -26,13 +26,15 @@ class MEDCALC_EXPORT MEDPresentationPointSprite : public MEDPresentation { public: - MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params) : - MEDPresentation(params.fieldHandlerId, "MEDPresentationPointSprite"), _params(params) - {} + static const std::string TYPE_NAME; + + MEDPresentationPointSprite(const MEDCALC::PointSpriteParameters& params, const MEDCALC::ViewModeType viewMode); virtual ~MEDPresentationPointSprite() {} void updatePipeline(const MEDCALC::PointSpriteParameters& params); - MEDCALC::ViewModeType getViewMode() { return _params.viewMode; } + + void getParameters(MEDCALC::PointSpriteParameters & params) const { params = _params; } ; + void setParameters(const MEDCALC::PointSpriteParameters & params) { _params = params; } ; protected: virtual void internalGeneratePipeline(); diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 79af31efd..7c0c21a84 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -43,34 +43,21 @@ MEDPresentationScalarMap::internalGeneratePipeline() MEDPyLockWrapper lock; - std::ostringstream oss; - std::string view(getRenderViewVar()); - - pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX - - oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');"; - pushAndExecPyLine(oss.str()); oss.str(""); + setOrCreateRenderView(); // instanciate __viewXXX + createSource(); // Populate internal array of available components: fillAvailableFieldComponents(); -// dumpIntProperties(); -// dumpStringProperties(); + // Nothing to do in a scalar map, obj = source: pushAndExecPyLine(_objVar + " = " + _srcObjVar); - oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << getRescaleCommand(); - pushAndExecPyLine(oss.str()); oss.str(""); - oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; - pushAndExecPyLine(oss.str()); oss.str(""); - pushAndExecPyLine(getColorMapCommand()); oss.str(""); - pushAndExecPyLine(getResetCameraCommand()); - pushAndExecPyLine("pvs.Render();"); + showObject(); + colorBy(_fieldType); + showScalarBar(); + rescaleTransferFunction(); + selectColorMap(); + resetCameraAndRender(); // Retrieve Python object for internal storage: // PyObject* p_obj = getPythonObjectFromMain(obj.c_str()); diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.cxx b/src/MEDCalc/cmp/MEDPresentationSlices.cxx index 3e51ee28f..16dbf4fad 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.cxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.cxx @@ -38,17 +38,16 @@ MEDPresentationSlices::MEDPresentationSlices(const MEDCALC::SlicesParameters& pa setIntProperty(MEDPresentationSlices::PROP_SLICE_ORIENTATION, params.orientation); } -std::string -MEDPresentationSlices::getNbSlicesCommand() const +void +MEDPresentationSlices::setNumberOfSlices() { std::ostringstream oss1; // TODO // oss1 << _objVar << ".SliceType.Normal = " << norm << ";"; - return oss1.str(); } -std::string -MEDPresentationSlices::getOrientationCommand() const +void +MEDPresentationSlices::selectSliceOrientation() { std::ostringstream oss1; std::string norm; @@ -83,7 +82,7 @@ MEDPresentationSlices::getOrientationCommand() const } oss1 << _objVar << ".SliceType.Normal = " << norm << ";"; - return oss1.str(); + pushAndExecPyLine(oss1.str()); oss1.str(""); } @@ -95,35 +94,28 @@ MEDPresentationSlices::internalGeneratePipeline() MEDPyLockWrapper lock; std::ostringstream oss_o, oss; - std::string view(getRenderViewVar()); - oss << _srcObjVar << " = pvs.MEDReader(FileName='" << _fileName << "');"; - pushAndExecPyLine(oss.str()); oss.str(""); + createSource(); // Populate internal array of available components: fillAvailableFieldComponents(); - pushAndExecPyLine( getRenderViewCommand() ); // instanciate __viewXXX + setOrCreateRenderView(); // instanciate __viewXXX + oss << _objVar << " = pvs.Slice(Input=" << _srcObjVar << ");"; pushAndExecPyLine(oss.str()); oss.str(""); + + showObject(); + oss << _objVar << ".SliceType = 'Plane';"; pushAndExecPyLine(oss.str()); oss.str(""); // Set slice orientation - pushAndExecPyLine(getOrientationCommand()); - - oss << _dispVar << " = pvs.Show(" << _objVar << ", " << view << ");"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << "pvs.ColorBy(" << _dispVar << ", ('" << _fieldType << "', '" << _fieldName << "'));"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << _dispVar << ".SetScalarBarVisibility(" << view << ", True);"; - pushAndExecPyLine(oss.str()); oss.str(""); - oss << getRescaleCommand(); - pushAndExecPyLine(oss.str()); oss.str(""); - oss << _lutVar << " = pvs.GetColorTransferFunction('" << _fieldName << "');"; - pushAndExecPyLine(oss.str()); oss.str(""); - pushAndExecPyLine(getColorMapCommand()); oss.str(""); - pushAndExecPyLine(getResetCameraCommand()); - pushAndExecPyLine("pvs.Render();"); + selectSliceOrientation(); + colorBy(_fieldType); + showScalarBar(); + rescaleTransferFunction(); + selectColorMap(); + resetCameraAndRender(); } void @@ -156,8 +148,7 @@ MEDPresentationSlices::updateNbSlices(const int nbSlices) // Update the pipeline: { MEDPyLockWrapper lock; - std::string cmd = getNbSlicesCommand(); - pushAndExecPyLine(cmd); + setNumberOfSlices(); pushAndExecPyLine("pvs.Render();"); } } @@ -173,8 +164,7 @@ MEDPresentationSlices::updateOrientation(const MEDCALC::SliceOrientationType ori // Update the pipeline: { MEDPyLockWrapper lock; - std::string cmd = getOrientationCommand(); - pushAndExecPyLine(cmd); + selectSliceOrientation(); pushAndExecPyLine("pvs.Render();"); } } diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.hxx b/src/MEDCalc/cmp/MEDPresentationSlices.hxx index 923747534..81d5ae7e8 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.hxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.hxx @@ -43,8 +43,8 @@ protected: void updateOrientation(const MEDCALC::SliceOrientationType orientation); virtual void internalGeneratePipeline(); - std::string getNbSlicesCommand() const; - std::string getOrientationCommand() const; + void setNumberOfSlices(); + void selectSliceOrientation(); private: MEDCALC::SlicesParameters _params; diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx index 979f8ed8c..f922e29df 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx @@ -17,39 +17,83 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#include "MEDPyLockWrapper.hxx" + #include "MEDPresentationVectorField.hxx" +#include "MEDPresentationException.hxx" + +#include +#undef LOG // should be fixed in KERNEL - double definition +#include + +#include + +const std::string MEDPresentationVectorField::TYPE_NAME = "MEDPresentationVectorField"; + +MEDPresentationVectorField::MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params, + const MEDCALC::ViewModeType viewMode) : + MEDPresentation(params.fieldHandlerId, TYPE_NAME, viewMode, params.colorMap, params.scalarBarRange), _params(params) +{ +} void MEDPresentationVectorField::internalGeneratePipeline() { -// PyGILState_STATE _gil_state = PyGILState_Ensure(); -// -// std::string cmd = std::string("import pvsimple as pvs;"); -// cmd += getRenderViewCommand(_params.viewMode); // define __view1 -// -// cmd += std::string("__obj1 = pvs.MEDReader(FileName='") + _fileName + std::string("');"); -// cmd += std::string("__disp1 = pvs.Show(__obj1, __view1);"); -// cmd += std::string("pvs.ColorBy(__disp1, ('") + _fieldType + std::string("', '") + _fieldName + std::string("'));"); -// cmd += std::string("__disp1.SetScalarBarVisibility(__view1, True);"); -// cmd += std::string("__disp1.RescaleTransferFunctionToDataRangeOverTime();"); -// cmd += std::string("__disp1.SetRepresentationType('3D Glyphs');"); -// cmd += std::string("pvs.Render();"); -// -// cmd += getResetCameraCommand(); -// -// //std::cerr << "Python command:" << std::endl; -// //std::cerr << cmd << std::endl; -// PyRun_SimpleString(cmd.c_str()); -// // Retrieve Python object for internal storage: -// PyObject* obj = getPythonObjectFromMain("__obj1"); -// PyObject* disp = getPythonObjectFromMain("__disp1"); -// pushInternal(obj, disp); -// -// PyGILState_Release(_gil_state); + MEDPresentation::internalGeneratePipeline(); + + MEDPyLockWrapper lock; + + setOrCreateRenderView(); + createSource(); + + // Populate internal array of available components: + fillAvailableFieldComponents(); + if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) <= 1) + { + const char * msg = "Vector field presentation does not work for scalar field!"; // this message will appear in GUI too + STDLOG(msg); + throw KERNEL::createSalomeException(msg); + } + + std::ostringstream oss; + oss << _objVar << " = pvs.Glyph(Input=" << _srcObjVar << ", GlyphType='Arrow');"; + pushAndExecPyLine(oss.str()); oss.str(""); + + showObject(); // to be done first so that the scale factor computation properly works + + oss << _objVar << ".Scalars = ['"<< _fieldType << "', 'None'];"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".Vectors = ['"<< _fieldType << "', '" << _fieldName << "'];"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".ScaleMode = 'vector';"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".GlyphMode = 'All Points';"; + pushAndExecPyLine(oss.str()); oss.str(""); +// oss << _objVar << "GlyphTransform = 'Transform2';"; // not sure this is really needed? +// pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".ScaleFactor = 0.1;"; + pushAndExecPyLine(oss.str()); oss.str(""); + // Auto-tuning of the scale factor: +// oss << "import medcalc; medcalc.SetDefaultScaleFactor(active=" << _objVar << ");"; +// pushAndExecPyLine(oss.str()); oss.str(""); + + colorBy("POINTS"); + showScalarBar(); + rescaleTransferFunction(); + selectColorMap(); + resetCameraAndRender(); } void MEDPresentationVectorField::updatePipeline(const MEDCALC::VectorFieldParameters& params) { - // :TODO: + if (params.fieldHandlerId != _params.fieldHandlerId) + throw KERNEL::createSalomeException("Unexpected updatePipeline error! Mismatching fieldHandlerId!"); + + if (std::string(params.displayedComponent) != std::string(_params.displayedComponent)) + updateComponent(std::string(params.displayedComponent)); + if (params.scalarBarRange != _params.scalarBarRange) + updateScalarBarRange(params.scalarBarRange); + if (params.colorMap != _params.colorMap) + updateColorMap(params.colorMap); } diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx index 758cb152e..3c37fba53 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx @@ -26,19 +26,22 @@ class MEDCALC_EXPORT MEDPresentationVectorField : public MEDPresentation { public: - MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params) : - MEDPresentation(params.fieldHandlerId, "MEDPresentationVectorField"), _params(params) - {} + static const std::string TYPE_NAME; + + MEDPresentationVectorField(const MEDCALC::VectorFieldParameters& params, const MEDCALC::ViewModeType viewMode); virtual ~MEDPresentationVectorField() {} void updatePipeline(const MEDCALC::VectorFieldParameters& params); - MEDCALC::ViewModeType getViewMode() { return _params.viewMode; } + + void getParameters(MEDCALC::VectorFieldParameters & params) const { params = _params; } ; + void setParameters(const MEDCALC::VectorFieldParameters & params) { _params = params; } ; protected: virtual void internalGeneratePipeline(); private: MEDCALC::VectorFieldParameters _params; + }; #endif diff --git a/src/MEDCalc/gui/CMakeLists.txt b/src/MEDCalc/gui/CMakeLists.txt index 0ff4b8f45..f968a8381 100644 --- a/src/MEDCalc/gui/CMakeLists.txt +++ b/src/MEDCalc/gui/CMakeLists.txt @@ -39,7 +39,7 @@ SET(MEDCALCGUI_SOURCES XmedDataModel.cxx MEDWidgetHelper.cxx MEDWidgetHelperMeshView.cxx - MEDWidgetHelperScalarMap.cxx + MEDWidgetHelperComponent.cxx MEDWidgetHelperContour.cxx MEDWidgetHelperSlices.cxx ) @@ -57,9 +57,12 @@ SET(MEDCALCGUI_HEADERS ProcessingController.hxx MEDWidgetHelper.hxx MEDWidgetHelperMeshView.hxx + MEDWidgetHelperComponent.hxx MEDWidgetHelperScalarMap.hxx MEDWidgetHelperContour.hxx MEDWidgetHelperSlices.hxx + MEDWidgetHelperPointSprite.hxx + MEDWidgetHelperVectorField.hxx ) IF(SALOME_MED_WITH_QTTESTING) diff --git a/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx b/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx new file mode 100644 index 000000000..947fc3434 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx @@ -0,0 +1,50 @@ +// Copyright (C) 2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "MEDWidgetHelperComponent.hxx" +#include "PresentationController.hxx" + +MEDWidgetHelperComponent::MEDWidgetHelperComponent(const PresentationController * presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId, + const std::string & presName, WidgetPresentationParameters * paramW): + MEDWidgetHelper(presController, presManager, presId, presName, paramW) +{} + +MEDWidgetHelperComponent::~MEDWidgetHelperComponent() +{} + +void MEDWidgetHelperComponent::udpateWidget() +{ + MEDWidgetHelper::udpateWidget(); + + _paramWidget->setComponents(_allCompos, _selectedCompo); + + // Connect combo box changes + QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), + _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); + QObject::connect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) ); +} + +void MEDWidgetHelperComponent::releaseWidget() +{ + MEDWidgetHelper::releaseWidget(); + + QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), + _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); + QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) ); +} diff --git a/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx b/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx new file mode 100644 index 000000000..58c774f15 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperComponent.hxx @@ -0,0 +1,46 @@ +// Copyright (C) 2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERCOMPONENT_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERCOMPONENT_HXX_ + +#include "MEDWidgetHelper.hxx" + +class PresentationController; + +/** + * Abstract class to manage all presentations having only the component name to change. + */ +class MEDWidgetHelperComponent: public MEDWidgetHelper +{ + Q_OBJECT + +public: + MEDWidgetHelperComponent(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW); + virtual ~MEDWidgetHelperComponent(); + + virtual void udpateWidget(); + virtual void releaseWidget(); + + virtual std::string getPythonTag() const = 0; +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERCOMPONENT_HXX_ */ diff --git a/src/MEDCalc/gui/MEDWidgetHelperPointSprite.hxx b/src/MEDCalc/gui/MEDWidgetHelperPointSprite.hxx new file mode 100644 index 000000000..0ad72e410 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperPointSprite.hxx @@ -0,0 +1,43 @@ +// Copyright (C) 2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERPOINTSPRITE_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERPOINTSPRITE_HXX_ + +#include "MEDWidgetHelperComponent.hxx" + +class PresentationController; + +class MEDWidgetHelperPointSprite: public MEDWidgetHelperComponent +{ + Q_OBJECT + +public: + MEDWidgetHelperPointSprite(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW): + MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW) + {} + + virtual ~MEDWidgetHelperPointSprite() {} + + virtual std::string getPythonTag() const { return "PointSprite"; } +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERPOINTSPRITE_HXX_ */ diff --git a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx deleted file mode 100644 index 755bf80fa..000000000 --- a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.cxx +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2016 CEA/DEN, EDF R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// - -#include "MEDWidgetHelperScalarMap.hxx" -#include "MEDPresentationScalarMap.hxx" // from component side. -#include "PresentationController.hxx" - -#include - -MEDWidgetHelperScalarMap::MEDWidgetHelperScalarMap(const PresentationController * presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId, - const std::string & presName, WidgetPresentationParameters * paramW): - MEDWidgetHelper(presController, presManager, presId, presName, paramW) -{ -} - -MEDWidgetHelperScalarMap::~MEDWidgetHelperScalarMap() -{} - -void MEDWidgetHelperScalarMap::udpateWidget() -{ - MEDWidgetHelper::udpateWidget(); - - // Scalar map presentation needs the component name, that's all. - _paramWidget->setComponents(_allCompos, _selectedCompo); - - // Connect combo box changes - QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), - _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); - QObject::connect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) ); -} - -void MEDWidgetHelperScalarMap::releaseWidget() -{ - MEDWidgetHelper::releaseWidget(); - - QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), - _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); - QObject::disconnect( _paramWidget, SIGNAL(comboCompoIndexChanged(int)), this, SLOT(onComponentChanged(int)) ); -} diff --git a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx index ee17a5307..d3ba5c056 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperScalarMap.hxx @@ -20,22 +20,22 @@ #ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ #define SRC_MEDCALC_GUI_MEDWIDGETHELPERSCALARMAP_HXX_ -#include "MEDWidgetHelper.hxx" +#include "MEDWidgetHelperComponent.hxx" class PresentationController; -class MEDWidgetHelperScalarMap: public MEDWidgetHelper +class MEDWidgetHelperScalarMap: public MEDWidgetHelperComponent { Q_OBJECT public: MEDWidgetHelperScalarMap(const PresentationController* presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, - WidgetPresentationParameters * paramW); - virtual ~MEDWidgetHelperScalarMap(); + WidgetPresentationParameters * paramW): + MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW) + {} - virtual void udpateWidget(); - virtual void releaseWidget(); + virtual ~MEDWidgetHelperScalarMap() {} virtual std::string getPythonTag() const { return "ScalarMap"; } }; diff --git a/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx b/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx new file mode 100644 index 000000000..daca5dfb9 --- /dev/null +++ b/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx @@ -0,0 +1,43 @@ +// Copyright (C) 2016 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_ +#define SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_ + +#include "MEDWidgetHelperComponent.hxx" + +class PresentationController; + +class MEDWidgetHelperVectorField: public MEDWidgetHelperComponent +{ + Q_OBJECT + +public: + MEDWidgetHelperVectorField(const PresentationController* presController, + MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, + WidgetPresentationParameters * paramW): + MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW) + {} + + virtual ~MEDWidgetHelperVectorField() {} + + virtual std::string getPythonTag() const { return "VectorField"; } +}; + +#endif /* SRC_MEDCALC_GUI_MEDWIDGETHELPERVECTORFIELD_HXX_ */ diff --git a/src/MEDCalc/gui/PresentationController.cxx b/src/MEDCalc/gui/PresentationController.cxx index ffd9bab25..359ed79ce 100644 --- a/src/MEDCalc/gui/PresentationController.cxx +++ b/src/MEDCalc/gui/PresentationController.cxx @@ -31,11 +31,17 @@ #include "MEDPresentationScalarMap.hxx" #include "MEDPresentationContour.hxx" #include "MEDPresentationSlices.hxx" +#include "MEDPresentationPointSprite.hxx" +#include "MEDPresentationVectorField.hxx" +//#include "MEDPresentationDeflectionShape.hxx" #include "MEDWidgetHelperMeshView.hxx" #include "MEDWidgetHelperScalarMap.hxx" #include "MEDWidgetHelperContour.hxx" #include "MEDWidgetHelperSlices.hxx" +#include "MEDWidgetHelperPointSprite.hxx" +#include "MEDWidgetHelperVectorField.hxx" +//#include "MEDWidgetHelperDeflectionShape.hxx" #include #include @@ -489,26 +495,28 @@ PresentationController::processPresentationEvent(const PresentationEvent* event) } else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_CONTOUR ) { commands += QString("presentation_id = medcalc.MakeContour(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") - .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); commands += QString("presentation_id"); } - // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) { - // commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - // commands += QString("presentation_id"); - // } - else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) { + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_SLICES ) { commands += QString("presentation_id = medcalc.MakeSlices(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") - .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); commands += QString("presentation_id"); - } + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_VECTOR_FIELD ) { + commands += QString("presentation_id = medcalc.MakeVectorField(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { + commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), viewMode=%2, scalarBarRange=%3, colorMap=%4)") + .arg(fieldHandler->id).arg(viewMode).arg(scalarBarRange).arg(colorMap); + commands += QString("presentation_id"); + } + // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_DEFLECTION_SHAPE ) { // commands += QString("presentation_id = medcalc.MakeDeflectionShape(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); // commands += QString("presentation_id"); - // } - // else if ( event->eventtype == PresentationEvent::EVENT_VIEW_OBJECT_POINT_SPRITE ) { - // commands += QString("presentation_id = medcalc.MakePointSprite(accessField(%1), %2)").arg(fieldHandler->id).arg(viewMode); - // commands += QString("presentation_id"); - // } // [ABN] using event mechanism for this is awkward? TODO: direct implementation in each // dedicated widget helper class? @@ -571,7 +579,7 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager std::map::const_iterator it =_presHelperMap.find(presId); if (it != _presHelperMap.end()) return (*it).second; - MEDWidgetHelper * wh; + MEDWidgetHelper * wh = 0; if (type == MEDPresentationMeshView::TYPE_NAME) wh = new MEDWidgetHelperMeshView(this, _presManager, presId, name, _widgetPresentationParameters); else if (type == MEDPresentationScalarMap::TYPE_NAME) @@ -579,10 +587,15 @@ PresentationController::findOrCreateWidgetHelper(MEDCALC::MEDPresentationManager else if (type == MEDPresentationContour::TYPE_NAME) wh = new MEDWidgetHelperContour(this, _presManager, presId, name, _widgetPresentationParameters); else if (type == MEDPresentationSlices::TYPE_NAME) - wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters); + wh = new MEDWidgetHelperSlices(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationVectorField::TYPE_NAME) + wh = new MEDWidgetHelperVectorField(this, _presManager, presId, name, _widgetPresentationParameters); + else if (type == MEDPresentationPointSprite::TYPE_NAME) + wh = new MEDWidgetHelperPointSprite(this, _presManager, presId, name, _widgetPresentationParameters); else { - STDLOG("findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!"); + const char * msg ="findOrCreateWidgetHelper(): NOT IMPLEMENTED !!!"; + STDLOG(msg); } _presHelperMap[presId] = wh; return wh; diff --git a/src/MEDCalc/gui/PresentationEvent.hxx b/src/MEDCalc/gui/PresentationEvent.hxx index 648ebf102..92b8dc4f9 100644 --- a/src/MEDCalc/gui/PresentationEvent.hxx +++ b/src/MEDCalc/gui/PresentationEvent.hxx @@ -12,6 +12,7 @@ typedef struct { EVENT_VIEW_OBJECT_SCALAR_MAP, EVENT_VIEW_OBJECT_SLICES, EVENT_VIEW_OBJECT_VECTOR_FIELD, + EVENT_DELETE_PRESENTATION, EVENT_CHANGE_COMPONENT, @@ -19,7 +20,9 @@ typedef struct { EVENT_CHANGE_TIME_RANGE, EVENT_CHANGE_MESH_MODE, + EVENT_CHANGE_NB_CONTOUR, + EVENT_CHANGE_SLICE_ORIENTATION, EVENT_CHANGE_NB_SLICES }; diff --git a/src/MEDCalc/test/tui/point_sprite.py b/src/MEDCalc/test/tui/point_sprite.py new file mode 100644 index 000000000..5a86b51c4 --- /dev/null +++ b/src/MEDCalc/test/tui/point_sprite.py @@ -0,0 +1,40 @@ +# Copyright (C) 2016 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import os +from time import sleep + +import medcalc +medcalc.medconsole.setConsoleGlobals(globals()) +import MEDCALC +from medcalc.medconsole import accessField + +from medcalc_testutils import GetMEDFileDirTUI + +if 1: + datafile = os.path.join(GetMEDFileDirTUI(), "smooth_surface_and_field.med") + source_id = medcalc.LoadDataSource(datafile) + presentation_id = medcalc.MakePointSprite(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) +else: + datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med") + source_id = medcalc.LoadDataSource(datafile) + presentation_id = medcalc.MakePointSprite(accessField(55), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) + +sleep(1) +medcalc.RemovePresentation(presentation_id) diff --git a/src/MEDCalc/test/tui/slices.py b/src/MEDCalc/test/tui/slices.py index 413a3d118..e3edd10ba 100644 --- a/src/MEDCalc/test/tui/slices.py +++ b/src/MEDCalc/test/tui/slices.py @@ -30,7 +30,9 @@ from medcalc_testutils import GetMEDFileDirTUI datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med") source_id = medcalc.LoadDataSource(datafile) -presentation_id = medcalc.MakeSlices(accessField(0), MEDCALC.VIEW_MODE_REPLACE, colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW) +presentation_id = medcalc.MakeSlices(accessField(0), MEDCALC.VIEW_MODE_REPLACE, + colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW, + sliceOrientation=MEDCALC.SLICE_NORMAL_TO_Z) # normal to Z to see something! sleep(1) medcalc.RemovePresentation(presentation_id) sleep(1) diff --git a/src/MEDCalc/test/tui/tests.set b/src/MEDCalc/test/tui/tests.set index e2cad1b1e..06c61c4d6 100644 --- a/src/MEDCalc/test/tui/tests.set +++ b/src/MEDCalc/test/tui/tests.set @@ -25,4 +25,7 @@ SET(TEST_NAMES # contour # slices # mesh_view +# point_sprite +# vector_field +# deflection_shape ) diff --git a/src/MEDCalc/test/tui/vector_field.py b/src/MEDCalc/test/tui/vector_field.py new file mode 100644 index 000000000..de17aa5df --- /dev/null +++ b/src/MEDCalc/test/tui/vector_field.py @@ -0,0 +1,40 @@ +# Copyright (C) 2016 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import os +from time import sleep + +import medcalc +medcalc.medconsole.setConsoleGlobals(globals()) +import MEDCALC +from medcalc.medconsole import accessField + +from medcalc_testutils import GetMEDFileDirTUI + +datafile = os.path.join(GetMEDFileDirTUI(), "agitateur.med") +source_id = medcalc.LoadDataSource(datafile) + +# Field 55 = VITESSE_ELEM_DOM (ON_CELLS) +presentation_id = medcalc.MakeVectorField(accessField(57), viewMode=MEDCALC.VIEW_MODE_REPLACE, + colorMap=MEDCALC.COLOR_MAP_BLUE_TO_RED_RAINBOW, + scalarBarRange=MEDCALC.SCALAR_BAR_CURRENT_TIMESTEP + ) +sleep(1) +medcalc.RemovePresentation(presentation_id) +sleep(1) diff --git a/src/MEDCalc/tui/__init__.py b/src/MEDCalc/tui/__init__.py index a409f477b..ee461af8a 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -42,21 +42,29 @@ from medio import LoadImageAsDataSource from medpresentation import MakeMeshView from medpresentation import MakeScalarMap from medpresentation import MakeContour -#from medpresentation import MakeVectorField +from medpresentation import MakeVectorField from medpresentation import MakeSlices -#from medpresentation import MakeDeflectionShape -#from medpresentation import MakePointSprite +from medpresentation import MakePointSprite from medpresentation import RemovePresentation +#from medpresentation import MakeDeflectionShape from medpresentation import GetMeshViewParameters from medpresentation import GetScalarMapParameters from medpresentation import GetContourParameters from medpresentation import GetSlicesParameters +from medpresentation import GetPointSpriteParameters +from medpresentation import GetVectorFieldParameters +#from medpresentation import GetDeflectionShapeParameters from medpresentation import UpdateMeshView from medpresentation import UpdateScalarMap from medpresentation import UpdateContour from medpresentation import UpdateSlices +from medpresentation import UpdateVectorField +from medpresentation import UpdatePointSprite +#from medpresentation import UpdateDeflectionShape + +from medpresentation import SetDefaultScaleFactor, ComputeCellAverageSize, GetDomainCenter # Console commands import medconsole diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index c1da528a4..40cad1ece 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -70,17 +70,25 @@ def MakeContour(proxy, notifyGui_error("An error occured while creating the contour:\n" + e.details.text) raise Exception(e.details.text) -## -# -#def MakeVectorField(proxy, -# viewMode=MEDCALC.VIEW_MODE_DEFAULT -# ): -# params = MEDCALC.VectorFieldParameters(proxy.id, viewMode) -# presentation_id = __manager.makeVectorField(params) -# notifyGui_addPresentation(proxy.id, presentation_id) -# return presentation_id -## # + +def MakeVectorField(proxy, + viewMode=MEDCALC.VIEW_MODE_DEFAULT, + displayedComponent=MEDCALC.DISPLAY_DEFAULT, + scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, + colorMap=MEDCALC.COLOR_MAP_DEFAULT + ): + # Create the presentation instance in CORBA engine + # The engine in turn creates the ParaView pipeline elements + params = MEDCALC.VectorFieldParameters(proxy.id, displayedComponent, scalarBarRange, colorMap) + try: + presentation_id = __manager.makeVectorField(params, viewMode) + notifyGui_addPresentation(proxy.id, presentation_id) + return presentation_id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occured while creating the vector field:\n" + e.details.text) + raise Exception(e.details.text) + def MakeSlices(proxy, viewMode=MEDCALC.VIEW_MODE_DEFAULT, displayedComponent=MEDCALC.DISPLAY_DEFAULT, @@ -110,17 +118,22 @@ def MakeSlices(proxy, # return presentation_id ## # -#def MakePointSprite(proxy, -# viewMode=MEDCALC.VIEW_MODE_DEFAULT, -# displayedComponent=MEDCALC.DISPLAY_DEFAULT, -# scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, -# colorMap=MEDCALC.COLOR_MAP_DEFAULT, -# ): -# params = MEDCALC.PointSpriteParameters(proxy.id, viewMode, displayedComponent, scalarBarRange, colorMap) -# presentation_id = __manager.makePointSprite(params) -# notifyGui_addPresentation(proxy.id, presentation_id) -# return presentation_id -# +def MakePointSprite(proxy, + viewMode=MEDCALC.VIEW_MODE_DEFAULT, + displayedComponent=MEDCALC.DISPLAY_DEFAULT, + scalarBarRange=MEDCALC.SCALAR_BAR_RANGE_DEFAULT, + colorMap=MEDCALC.COLOR_MAP_DEFAULT + ): + # Create the presentation instance in CORBA engine + # The engine in turn creates the ParaView pipeline elements + params = MEDCALC.PointSpriteParameters(proxy.id, displayedComponent, scalarBarRange, colorMap) + try: + presentation_id = __manager.makePointSprite(params, viewMode) + notifyGui_addPresentation(proxy.id, presentation_id) + return presentation_id + except SALOME.SALOME_Exception as e: + notifyGui_error("An error occured while creating the point sprite:\n" + e.details.text) + raise Exception(e.details.text) def RemovePresentation(presentation_id): ok = __manager.removePresentation(presentation_id) @@ -128,20 +141,131 @@ def RemovePresentation(presentation_id): notifyGui_removePresentation(presentation_id) # -def GetGENERICParameters(tag, presentation_id): +def __GetGENERICParameters(tag, presentation_id): exec "params = __manager.get%sParameters(presentation_id)" % tag return params -GetMeshViewParameters = lambda pres_id: GetGENERICParameters("MeshView", pres_id) -GetScalarMapParameters = lambda pres_id: GetGENERICParameters("ScalarMap", pres_id) -GetContourParameters = lambda pres_id: GetGENERICParameters("Contour", pres_id) -GetSlicesParameters = lambda pres_id: GetGENERICParameters("Slices", pres_id) +GetMeshViewParameters = lambda pres_id: __GetGENERICParameters("MeshView", pres_id) +GetScalarMapParameters = lambda pres_id: __GetGENERICParameters("ScalarMap", pres_id) +GetContourParameters = lambda pres_id: __GetGENERICParameters("Contour", pres_id) +GetSlicesParameters = lambda pres_id: __GetGENERICParameters("Slices", pres_id) +GetPointSpriteParameters = lambda pres_id: __GetGENERICParameters("PointSprite", pres_id) +GetVectorFieldParameters = lambda pres_id: __GetGENERICParameters("VectorField", pres_id) +#GetDeflectionShapeParameters = lambda pres_id: __GetGENERICParameters("DeflectionShape", pres_id) -def UpdateGENERIC(tag, presentation_id, params): +def __UpdateGENERIC(tag, presentation_id, params): exec "__manager.update%s(presentation_id, params)" % tag -UpdateMeshView = lambda pres_id, params: UpdateGENERIC("MeshView", pres_id, params) -UpdateScalarMap = lambda pres_id, params: UpdateGENERIC("ScalarMap", pres_id, params) -UpdateContour = lambda pres_id, params: UpdateGENERIC("Contour", pres_id, params) -UpdateSlices = lambda pres_id, params: UpdateGENERIC("Slices", pres_id, params) +UpdateMeshView = lambda pres_id, params: __UpdateGENERIC("MeshView", pres_id, params) +UpdateScalarMap = lambda pres_id, params: __UpdateGENERIC("ScalarMap", pres_id, params) +UpdateContour = lambda pres_id, params: __UpdateGENERIC("Contour", pres_id, params) +UpdateSlices = lambda pres_id, params: __UpdateGENERIC("Slices", pres_id, params) +UpdateVectorField = lambda pres_id, params: __UpdateGENERIC("VectorField", pres_id, params) +UpdatePointSprite = lambda pres_id, params: __UpdateGENERIC("PointSprite", pres_id, params) +#UpdateDeflectionShape = lambda pres_id, params: __UpdateGENERIC("DeflectionShape", pres_id, params) + +def ComputeCellAverageSize(obj): + """ + @return the average cell size + """ + bb, nCells = obj.GetDataInformation().GetBounds(), obj.GetDataInformation().GetNumberOfCells() + bb = zip(bb[::2], bb[1::2]) + deltas = [x[1]-x[0] for x in bb] + vol = reduce(lambda x,y:x*y, deltas, 1.0) + cellSize = (vol/nCells)**(1.0/3.0) # necessarily 3D in ParaView + return cellSize + +def GetDomainCenter(obj): + """ + @return the center of the domain as the central point of the bounding box + """ + bb = obj.GetDataInformation().GetBounds() + bb = zip(bb[::2], bb[1::2]) + mids = [x[0] + 0.5*(x[1]-x[0]) for x in bb] + return mids + +# Taken from paraview.simple from CEA ParaView's version: +def SetDefaultScaleFactor(active=None): + """Provides a good display to the bounding box of the mesh and min / max of the field. + This method available for filters: Warp By Vector, Glyph and Tensor Glyph""" + if not active: + active = GetActiveSource() + if not active: + return + name = active.__class__.__name__ + if (name == 'WarpByVector' or name == 'TensorGlyph') and hasattr(active, 'ScaleFactor'): + import math + datainfo = active.GetProperty("Input").SMProperty.GetProxy(0).GetDataInformation() + if not datainfo: + active.ScaleFactor = 1.0 + return + nbcells = datainfo.GetNumberOfCells() + nbpoints = datainfo.GetNumberOfPoints() + nbelem = nbcells + if nbelem == 0: + nbelem = nbpoints + abounds = datainfo.GetBounds() + volume = 1 + vol = 0 + idim = 0 + i = 0 + eps = 1.0e-38 + while i < 6 : + vol = math.fabs( abounds[i+1] - abounds[i] ) + if vol > 0: + idim += 1 + volume *= vol + i += 2 + if nbelem == 0 or math.fabs(idim) < eps: + active.ScaleFactor = 0.0 + return + volume /= nbelem + scalefactor = pow( volume, 1.0 / idim ) + maximum = 1.0 + property = active.GetProperty('ScaleFactor') + domain = None + if property.GetDomain('vector_range').__class__.__name__ == 'vtkSMArrayRangeDomain': + domain = property.GetDomain('vector_range') + if property.GetDomain('tensor_range').__class__.__name__ == 'vtkSMArrayRangeDomain': + domain = property.GetDomain('tensor_range') + if not domain is None: + if domain.GetMaximumExists(3): + maximum = domain.GetMaximum(3) + if math.fabs(maximum) > eps: + scalefactor /= maximum + active.ScaleFactor = scalefactor + return + if name == 'Glyph' and hasattr(active, 'ScaleFactor') and hasattr(active, 'UseCellsCenter') and hasattr(active, 'ScaleMode'): + import math + scaledextent = 1.0 + property = active.GetProperty('ScaleFactor') + bounds_domain = property.GetDomain('bounds') + if bounds_domain.__class__.__name__ == 'vtkSMBoundsDomain': + if bounds_domain.GetMaximumExists(0): + scaledextent = bounds_domain.GetMaximum(0) + usecellscenter = active.GetProperty('UseCellsCenter').GetData() + sdomain = "cells_" + if usecellscenter == 0: + sdomain = "points_" + divisor = 1.0 + scalemode_domain = active.GetProperty('ScaleMode') + scalemode = scalemode_domain.ConvertValue(scalemode_domain.GetData()) + if scalemode == 0: + sdomain += "scalar_range" + domain = property.GetDomain(sdomain) + if domain.__class__.__name__ == 'vtkSMArrayRangeDomain': + if domain.GetMaximumExists(0): + divisor = domain.GetMaximum(0) + if scalemode == 1 or scalemode == 2: + sdomain += "vector_range" + domain = property.GetDomain(sdomain) + if domain.__class__.__name__ == 'vtkSMArrayRangeDomain': + if domain.GetMaximumExists(3): + divisor = domain.GetMaximum(3) + divisor = math.fabs(divisor) + if divisor < 0.000000001: + divisor = 1 + scalefactor = scaledextent / divisor + active.ScaleFactor = scalefactor + return