From 738aa8277ff77d8cb1e98d7844ee2197affd1e4e Mon Sep 17 00:00:00 2001 From: abn Date: Thu, 4 Aug 2016 16:31:56 +0200 Subject: [PATCH] [MEDCalc] Proper autoscale for vector field. + various bug fixes: component should not be available in VectorField but should be in Slices + scalar bar was wrongly keeping memory of compo selected in previous presentation --- idl/MEDPresentationManager.idl | 1 - src/MEDCalc/cmp/MEDPresentation.cxx | 25 +++++- src/MEDCalc/cmp/MEDPresentation.hxx | 4 +- src/MEDCalc/cmp/MEDPresentation.txx | 1 - src/MEDCalc/cmp/MEDPresentationContour.cxx | 3 +- src/MEDCalc/cmp/MEDPresentationManager_i.cxx | 9 +- src/MEDCalc/cmp/MEDPresentationManager_i.hxx | 2 +- .../cmp/MEDPresentationPointSprite.cxx | 2 +- src/MEDCalc/cmp/MEDPresentationScalarMap.cxx | 2 +- src/MEDCalc/cmp/MEDPresentationSlices.cxx | 2 +- .../cmp/MEDPresentationVectorField.cxx | 33 ++++--- .../cmp/MEDPresentationVectorField.hxx | 1 + src/MEDCalc/gui/MEDWidgetHelper.cxx | 4 + src/MEDCalc/gui/MEDWidgetHelperComponent.cxx | 4 - src/MEDCalc/gui/MEDWidgetHelperSlices.cxx | 9 +- src/MEDCalc/gui/MEDWidgetHelperSlices.hxx | 4 +- .../gui/MEDWidgetHelperVectorField.hxx | 6 +- src/MEDCalc/tui/__init__.py | 2 +- src/MEDCalc/tui/medpresentation.py | 88 +------------------ 19 files changed, 72 insertions(+), 130 deletions(-) diff --git a/idl/MEDPresentationManager.idl b/idl/MEDPresentationManager.idl index c045eec36..2d9e06634 100644 --- a/idl/MEDPresentationManager.idl +++ b/idl/MEDPresentationManager.idl @@ -113,7 +113,6 @@ module MEDCALC struct VectorFieldParameters { long fieldHandlerId; - string displayedComponent; // DISPLAY_EUCLIDEAN_NORM or any component name - only used to color the glyphs ScalarBarRangeType scalarBarRange; ColorMapType colorMap; }; diff --git a/src/MEDCalc/cmp/MEDPresentation.cxx b/src/MEDCalc/cmp/MEDPresentation.cxx index 1060819d1..43ce20db5 100644 --- a/src/MEDCalc/cmp/MEDPresentation.cxx +++ b/src/MEDCalc/cmp/MEDPresentation.cxx @@ -76,15 +76,17 @@ MEDPresentation::MEDPresentation(MEDPresentation::TypeID fieldHandlerId, const s // Python variables: int id = GeneratePythonId(); - std::ostringstream oss_o, oss_d, oss_l, oss_s; + std::ostringstream oss_o, oss_d, oss_l, oss_s, oss_r; oss_o << "__obj" << id; oss_s << "__srcObj" << id; oss_d << "__disp" << id; oss_l << "__lut" << id; + oss_r << "__range" << id; _objVar = oss_o.str(); _srcObjVar = oss_s.str(); _dispVar = oss_d.str(); _lutVar = oss_l.str(); + _rangeVar = oss_r.str(); } MEDPresentation::~MEDPresentation() @@ -321,16 +323,23 @@ MEDPresentation::selectFieldComponent() * Needs the LUT, so to be called after selectColorMap for the first time. */ void -MEDPresentation::fixScalarBarTitle() +MEDPresentation::scalarBarTitle() { // get selected component name: - std::string compoName("Magnitude"); + std::string compoName; if (_selectedComponentIndex != -1) { std::ostringstream oss1; oss1 << MEDPresentation::PROP_COMPONENT << _selectedComponentIndex; compoName = getStringProperty(oss1.str()); } + else + { + if (getIntProperty(MEDPresentation::PROP_NB_COMPONENTS) == 1) + compoName = ""; + else + compoName = "Magnitude"; + } std::ostringstream oss; oss << "pvs.GetScalarBar(" << _lutVar << ").ComponentTitle = '" << compoName << "';"; pushAndExecPyLine(oss.str()); oss.str(""); @@ -356,6 +365,8 @@ MEDPresentation::selectColorMap() throw KERNEL::createSalomeException("MEDPresentation::getColorMapCommand(): invalid colormap!"); } pushAndExecPyLine(oss.str()); + + selectFieldComponent(); // somehow PV keeps the LUT parameters of the previous presentation, so better reset this. } void @@ -399,8 +410,16 @@ MEDPresentation::rescaleTransferFunction() throw KERNEL::createSalomeException("MEDPresentation::getRescaleCommand(): invalid range!"); } pushAndExecPyLine(oss.str()); oss.str(""); + // Get min-max + oss << _rangeVar << " = [" << _dispVar << ".LookupTable.RGBPoints[0], " << _dispVar << ".LookupTable.RGBPoints[-4]];"; + pushAndExecPyLine(oss.str()); + + // Adapt scalar bar title + scalarBarTitle(); } + + int MEDPresentation::GeneratePythonId() { diff --git a/src/MEDCalc/cmp/MEDPresentation.hxx b/src/MEDCalc/cmp/MEDPresentation.hxx index dc2e7aeed..b60bb47b9 100644 --- a/src/MEDCalc/cmp/MEDPresentation.hxx +++ b/src/MEDCalc/cmp/MEDPresentation.hxx @@ -84,7 +84,7 @@ protected: void showScalarBar(); void rescaleTransferFunction(); void selectColorMap(); - void fixScalarBarTitle(); + void scalarBarTitle(); void resetCameraAndRender(); virtual void internalGeneratePipeline(); @@ -150,6 +150,8 @@ protected: std::string _dispVar; ///! ParaView LUT variable in the Python scripting commands std::string _lutVar; + ///! ParaView variable in Python holding the data range + std::string _rangeVar; private: ///! Pipeline elements diff --git a/src/MEDCalc/cmp/MEDPresentation.txx b/src/MEDCalc/cmp/MEDPresentation.txx index bb3410b5c..84b4137c4 100644 --- a/src/MEDCalc/cmp/MEDPresentation.txx +++ b/src/MEDCalc/cmp/MEDPresentation.txx @@ -92,7 +92,6 @@ MEDPresentation::updateComponent(const std::string& newCompo) selectFieldComponent(); // The component has changed, we need to rescale the scalar bar to adapt: rescaleTransferFunction(); - fixScalarBarTitle(); // should be fixed in PV one day! pushAndExecPyLine("pvs.Render();"); } } diff --git a/src/MEDCalc/cmp/MEDPresentationContour.cxx b/src/MEDCalc/cmp/MEDPresentationContour.cxx index f08493b30..e32b5ff2c 100644 --- a/src/MEDCalc/cmp/MEDPresentationContour.cxx +++ b/src/MEDCalc/cmp/MEDPresentationContour.cxx @@ -84,9 +84,10 @@ MEDPresentationContour::internalGeneratePipeline() // Set number of contours setNumberContours(); colorBy("POINTS"); // necessarily POINTS because of the conversion above + showScalarBar(); - rescaleTransferFunction(); selectColorMap(); + rescaleTransferFunction(); resetCameraAndRender(); } diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx index 876b3ec1c..c787a16e9 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.cxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.cxx @@ -200,13 +200,12 @@ MEDPresentationManager_i::getSlicesParameters(MEDPresentation::TypeID presentati return tmp._retn(); } -MEDCALC::VectorFieldParameters* +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::VectorFieldParameters p; + _getParameters(presentationID, p); + return p; } MEDCALC::PointSpriteParameters* diff --git a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx index 9f89afcc1..95fd9edf3 100644 --- a/src/MEDCalc/cmp/MEDPresentationManager_i.hxx +++ b/src/MEDCalc/cmp/MEDPresentationManager_i.hxx @@ -57,7 +57,7 @@ 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::VectorFieldParameters getVectorFieldParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT MEDCALC::PointSpriteParameters* getPointSpriteParameters(MEDPresentation::TypeID presentationID); MEDCALC_EXPORT void updateMeshView(MEDPresentation::TypeID, const MEDCALC::MeshViewParameters&); diff --git a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx index 9dbc17ff8..dfa7ddd17 100644 --- a/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx +++ b/src/MEDCalc/cmp/MEDPresentationPointSprite.cxx @@ -86,8 +86,8 @@ MEDPresentationPointSprite::internalGeneratePipeline() pushAndExecPyLine(oss.str()); oss.str(""); showScalarBar(); - rescaleTransferFunction(); selectColorMap(); + rescaleTransferFunction(); resetCameraAndRender(); } diff --git a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx index 7c0c21a84..78c228b50 100644 --- a/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx +++ b/src/MEDCalc/cmp/MEDPresentationScalarMap.cxx @@ -55,8 +55,8 @@ MEDPresentationScalarMap::internalGeneratePipeline() showObject(); colorBy(_fieldType); showScalarBar(); - rescaleTransferFunction(); selectColorMap(); + rescaleTransferFunction(); resetCameraAndRender(); // Retrieve Python object for internal storage: diff --git a/src/MEDCalc/cmp/MEDPresentationSlices.cxx b/src/MEDCalc/cmp/MEDPresentationSlices.cxx index 83945b32d..09447d8ad 100644 --- a/src/MEDCalc/cmp/MEDPresentationSlices.cxx +++ b/src/MEDCalc/cmp/MEDPresentationSlices.cxx @@ -68,8 +68,8 @@ MEDPresentationSlices::generateAndDisplay() colorBy(_fieldType); showScalarBar(); - rescaleTransferFunction(); selectColorMap(); + rescaleTransferFunction(); resetCameraAndRender(); } diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx index f922e29df..e17510815 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.cxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.cxx @@ -36,6 +36,17 @@ MEDPresentationVectorField::MEDPresentationVectorField(const MEDCALC::VectorFiel { } +void +MEDPresentationVectorField::autoScale() +{ + std::ostringstream oss; + oss << "import medcalc;"; + pushAndExecPyLine(oss.str()); oss.str(""); + oss << _objVar << ".ScaleFactor = 2.0*medcalc.ComputeCellAverageSize(__srcObj0)/(" << _rangeVar + << "[1]-" << _rangeVar << "[0]);"; + pushAndExecPyLine(oss.str()); oss.str(""); +} + void MEDPresentationVectorField::internalGeneratePipeline() { @@ -50,7 +61,7 @@ MEDPresentationVectorField::internalGeneratePipeline() 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 + 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); } @@ -69,18 +80,18 @@ MEDPresentationVectorField::internalGeneratePipeline() 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 << "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(); + rescaleTransferFunction(); + + autoScale(); // to be called after transfer function so we have the range + resetCameraAndRender(); } @@ -90,10 +101,12 @@ MEDPresentationVectorField::updatePipeline(const MEDCALC::VectorFieldParameters& 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); + { + updateScalarBarRange(params.scalarBarRange); + autoScale(); + pushAndExecPyLine("pvs.Render();"); + } if (params.colorMap != _params.colorMap) updateColorMap(params.colorMap); } diff --git a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx index 3c37fba53..339bf02a0 100644 --- a/src/MEDCalc/cmp/MEDPresentationVectorField.hxx +++ b/src/MEDCalc/cmp/MEDPresentationVectorField.hxx @@ -38,6 +38,7 @@ public: protected: virtual void internalGeneratePipeline(); + void autoScale(); private: MEDCALC::VectorFieldParameters _params; diff --git a/src/MEDCalc/gui/MEDWidgetHelper.cxx b/src/MEDCalc/gui/MEDWidgetHelper.cxx index 8869c847b..8935a3ade 100644 --- a/src/MEDCalc/gui/MEDWidgetHelper.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelper.cxx @@ -69,6 +69,8 @@ void MEDWidgetHelper::updateWidget(bool connect) if (connect) { + QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), + _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); QObject::connect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) ); QObject::connect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) ); } @@ -76,6 +78,8 @@ void MEDWidgetHelper::updateWidget(bool connect) void MEDWidgetHelper::releaseWidget() { + QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), + _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); QObject::disconnect( _paramWidget, SIGNAL(comboScalarBarRangeIndexChanged(int)), this, SLOT(onScalarBarRangeChanged(int)) ); QObject::disconnect( _paramWidget, SIGNAL(comboColorMapIndexChanged(int)), this, SLOT(onColorMapChanged(int)) ); diff --git a/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx b/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx index 01a29e9ed..34136e965 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelperComponent.cxx @@ -37,8 +37,6 @@ void MEDWidgetHelperComponent::updateWidget(bool connect) if (connect) { // 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)) ); } } @@ -47,7 +45,5 @@ 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/MEDWidgetHelperSlices.cxx b/src/MEDCalc/gui/MEDWidgetHelperSlices.cxx index eb99e8775..f0827b507 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperSlices.cxx +++ b/src/MEDCalc/gui/MEDWidgetHelperSlices.cxx @@ -28,7 +28,7 @@ MEDWidgetHelperSlices::MEDWidgetHelperSlices(const PresentationController * presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, WidgetPresentationParameters * paramW): - MEDWidgetHelper(presController, presManager, presId, presName, paramW), + MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW), _nbSlices(-1), _sliceOrientation(MEDCALC::SLICE_ORIENTATION_DEFAULT) {} @@ -46,8 +46,7 @@ void MEDWidgetHelperSlices::loadParametersFromEngine() void MEDWidgetHelperSlices::updateWidget(bool connect) { - MEDWidgetHelper::updateWidget(connect); - STDLOG("MEDWidgetHelperSlices::udpateWidget() nbSlices is " << _nbSlices); + MEDWidgetHelperComponent::updateWidget(connect); _paramWidget->setNbSlices(_nbSlices); _paramWidget->setSliceOrientation(_sliceOrientation); @@ -55,8 +54,6 @@ void MEDWidgetHelperSlices::updateWidget(bool connect) // Connect combo box changes if (connect) { - QObject::connect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), - _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); QObject::connect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) ); QObject::connect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) ); } @@ -66,8 +63,6 @@ void MEDWidgetHelperSlices::releaseWidget() { MEDWidgetHelper::releaseWidget(); - QObject::disconnect( this, SIGNAL(presentationUpdateSignal(const PresentationEvent *)), - _presController, SIGNAL(presentationSignal(const PresentationEvent *)) ); QObject::disconnect( _paramWidget, SIGNAL(spinBoxValueChanged(int)), this, SLOT(onNbSlicesChanged(int)) ); QObject::disconnect( _paramWidget, SIGNAL(comboOrientIndexChanged(int)), this, SLOT(onSliceOrientationChanged(int)) ); } diff --git a/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx b/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx index bce48ef03..c814e9a73 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperSlices.hxx @@ -20,11 +20,11 @@ #ifndef SRC_MEDCALC_GUI_MEDWIDGETHELPERSLICES_HXX_ #define SRC_MEDCALC_GUI_MEDWIDGETHELPERSLICES_HXX_ -#include "MEDWidgetHelper.hxx" +#include "MEDWidgetHelperComponent.hxx" class PresentationController; -class MEDWidgetHelperSlices: public MEDWidgetHelper +class MEDWidgetHelperSlices: public MEDWidgetHelperComponent { Q_OBJECT diff --git a/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx b/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx index daca5dfb9..6ee04de46 100644 --- a/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx +++ b/src/MEDCalc/gui/MEDWidgetHelperVectorField.hxx @@ -24,7 +24,7 @@ class PresentationController; -class MEDWidgetHelperVectorField: public MEDWidgetHelperComponent +class MEDWidgetHelperVectorField: public MEDWidgetHelper { Q_OBJECT @@ -32,12 +32,12 @@ public: MEDWidgetHelperVectorField(const PresentationController* presController, MEDCALC::MEDPresentationManager_ptr presManager, int presId, const std::string & presName, WidgetPresentationParameters * paramW): - MEDWidgetHelperComponent(presController, presManager, presId, presName, paramW) + MEDWidgetHelper(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/tui/__init__.py b/src/MEDCalc/tui/__init__.py index 1f1f0fd9d..949fadd91 100644 --- a/src/MEDCalc/tui/__init__.py +++ b/src/MEDCalc/tui/__init__.py @@ -64,7 +64,7 @@ from medpresentation import UpdateVectorField from medpresentation import UpdatePointSprite #from medpresentation import UpdateDeflectionShape -from medpresentation import SetDefaultScaleFactor, ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins +from medpresentation import ComputeCellAverageSize, GetDomainCenter, GetSliceOrigins # Console commands import medconsole diff --git a/src/MEDCalc/tui/medpresentation.py b/src/MEDCalc/tui/medpresentation.py index 6b23e20bd..01defc0da 100644 --- a/src/MEDCalc/tui/medpresentation.py +++ b/src/MEDCalc/tui/medpresentation.py @@ -74,13 +74,12 @@ def MakeContour(proxy, 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) + params = MEDCALC.VectorFieldParameters(proxy.id, scalarBarRange, colorMap) try: presentation_id = __manager.makeVectorField(params, viewMode) notifyGui_addPresentation(proxy.id, presentation_id) @@ -186,91 +185,6 @@ def GetDomainCenter(obj): 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 - def GetSliceOrigins(obj, nbSlices, normal): """ Compute all origin points for the position of the slices. -- 2.39.2